From c8bf38e5fb717d40635a2a89b22ed71b0de4266b Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 1 Dec 2020 13:33:34 +0100 Subject: Squashed 'dependencies/uthash/' content from commit 8e67ced git-subtree-dir: dependencies/uthash git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90 --- tests/test79.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test79.c (limited to 'tests/test79.c') diff --git a/tests/test79.c b/tests/test79.c new file mode 100644 index 000000000..4abbe94b1 --- /dev/null +++ b/tests/test79.c @@ -0,0 +1,71 @@ +#include +#include +#include "uthash.h" + +typedef struct hs_t { + int id; + int tag; + UT_hash_handle hh; +} hs_t; + + +static void pr(hs_t **hdpp) +{ + hs_t *el, *tmp, *hdp = *hdpp; + HASH_ITER(hh, hdp, el, tmp) { + printf("id %d, tag %d\n",el->id,el->tag); + } +} + +int main() +{ + + hs_t *hs_head=NULL, *tmp, *replaced=NULL; + + tmp = (hs_t*)malloc(sizeof(hs_t)); + if (tmp == NULL) { + exit(-1); + } + tmp->id = 10; + tmp->tag = 100; + HASH_REPLACE_INT(hs_head,id,tmp,replaced); + if(replaced == NULL) { + printf("added %d %d\n",tmp->id,tmp->tag); + } else { + printf("ERROR, ended up replacing a value, replaced: %p\n",(void*)replaced); + } + + pr(&hs_head); + + tmp = (hs_t*)malloc(sizeof(hs_t)); + if (tmp == NULL) { + exit(-1); + } + tmp->id=11; + tmp->tag = 101; + HASH_REPLACE_INT(hs_head,id,tmp,replaced); + if(replaced == NULL) { + printf("added %d %d\n",tmp->id,tmp->tag); + } else { + printf("ERROR, ended up replacing a value, replaced: %p\n",(void*)replaced); + } + + pr(&hs_head); + + tmp = (hs_t*)malloc(sizeof(hs_t)); + if (tmp == NULL) { + exit(-1); + } + tmp->id=11; + tmp->tag = 102; + HASH_REPLACE_INT(hs_head,id,tmp,replaced); + if(replaced == NULL) { + printf("ERROR, exected to replace a value with key: %d\n",tmp->id); + } else { + printf("replaced %d that had tag %d with tag %d\n",tmp->id,replaced->tag,tmp->tag); + } + + pr(&hs_head); + + return 0; +} -- cgit v1.2.3