diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2024-10-17 12:16:20 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2024-10-17 12:16:20 +0200 |
commit | 9a14454d3c5589373253571cee7428c593adefd9 (patch) | |
tree | 2ebd3c81ca4594ed2c9b1267a7af31d8cd1646e9 /tests/test57.c | |
parent | 1fa53c5bf8d0717f784c79abaa5111f88ab00221 (diff) |
Squashed 'dependencies/uthash/' changes from bf152630..f69112c0
f69112c0 utarray: Fix typo in docs
619fe95c Fix MSVC warning C4127 in HASH_BLOOM_TEST (#261)
eeba1961 uthash: Improve the docs for HASH_ADD_INORDER
ca98384c HASH_DEL should be able to delete a const-qualified node
095425f7 utlist: Add one more assertion in DL_DELETE2
399bf74b utarray: Stop making `oom` a synonym for `utarray_oom`
85bf75ab utarray_str_cpy: Remove strdup; utarray_oom() if strdup fails.
1a53f304 GitHub CI: Also test building the docs (#248)
4d01591e The MCST Elbrus C Compiler supports __typeof. (#247)
1e0baf06 CI: Add GitHub Actions CI
8844b529 Update test57.c per a suggestion by @mark-summerfield
44a66fe8 Update http:// URLs to https://, and copyright dates to 2022. NFC.
git-subtree-dir: dependencies/uthash
git-subtree-split: f69112c04f1b6e059b8071cb391a1fcc83791a00
Diffstat (limited to 'tests/test57.c')
-rw-r--r-- | tests/test57.c | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/tests/test57.c b/tests/test57.c index 3b89fb52d..7ba3b81ae 100644 --- a/tests/test57.c +++ b/tests/test57.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdlib.h> +#include <assert.h> +#include <stddef.h> #include "uthash.h" typedef struct { @@ -8,25 +8,46 @@ typedef struct { UT_hash_handle hh; } el_t; +el_t *findit(el_t *hash, void *keytofind) +{ + el_t *found; + HASH_FIND_PTR(hash, &keytofind, found); + return found; +} + int main() { - el_t *d; el_t *hash = NULL; - char *someaddr = NULL; - el_t *e = (el_t*)malloc(sizeof(el_t)); - if (!e) { - return -1; - } - e->key = (void*)someaddr; - e->i = 1; - HASH_ADD_PTR(hash,key,e); - HASH_FIND_PTR(hash, &someaddr, d); - if (d != NULL) { - printf("found\n"); - } - - /* release memory */ - HASH_DEL(hash,e); - free(e); + el_t e1; + el_t e2; + + e1.key = NULL; + e1.i = 1; + + e2.key = &e2; + e2.i = 2; + + assert(findit(hash, NULL) == NULL); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == NULL); + + HASH_ADD_PTR(hash, key, &e1); + assert(findit(hash, NULL) == &e1); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == NULL); + + HASH_ADD_PTR(hash, key, &e2); + assert(findit(hash, NULL) == &e1); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == &e2); + + HASH_DEL(hash, &e1); + assert(findit(hash, NULL) == NULL); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == &e2); + + HASH_CLEAR(hh, hash); + assert(hash == NULL); + return 0; } |