diff options
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; } |