diff options
Diffstat (limited to 'dependencies/uthash/tests/test57.c')
-rw-r--r-- | dependencies/uthash/tests/test57.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/dependencies/uthash/tests/test57.c b/dependencies/uthash/tests/test57.c new file mode 100644 index 000000000..7ba3b81ae --- /dev/null +++ b/dependencies/uthash/tests/test57.c @@ -0,0 +1,53 @@ +#include <assert.h> +#include <stddef.h> +#include "uthash.h" + +typedef struct { + void *key; + int i; + 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 *hash = NULL; + 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; +} |