diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
commit | c8bf38e5fb717d40635a2a89b22ed71b0de4266b (patch) | |
tree | 63751b2f5497c6f99e1c6a78f23a8e6e5c49833f /tests/test42.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test42.c')
-rw-r--r-- | tests/test42.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test42.c b/tests/test42.c new file mode 100644 index 000000000..4da8f03dd --- /dev/null +++ b/tests/test42.c @@ -0,0 +1,90 @@ +#include <stdio.h> +#include "utlist.h" + +typedef struct el { + int id; + struct el *next, *prev; +} el; + +static int eltcmp(el *a, el *b) +{ + return a->id - b->id; +} + +int main() +{ + int i; + el *head = NULL; + el els[10], *e, *tmp, *tmp2; + for(i=0; i<10; i++) { + els[i].id=(int)'a'+i; + } + + /* test LL macros */ + printf("LL macros\n"); + LL_APPEND(head,&els[0]); + LL_APPEND(head,&els[1]); + LL_APPEND(head,&els[2]); + LL_FOREACH(head,e) { + printf("%c ", e->id); + } + printf("\n"); + LL_SEARCH_SCALAR(head, e, id, 'b'); + if (e != NULL) { + printf("search scalar found b\n"); + } + LL_SEARCH(head, e, &els[0], eltcmp); + if (e != NULL) { + printf("search found %c\n",e->id); + } + LL_FOREACH_SAFE(head,e,tmp) { + LL_DELETE(head,e); + } + + printf("\n"); + + /* test DL macros */ + printf("DL macros\n"); + DL_APPEND(head,&els[0]); + DL_APPEND(head,&els[1]); + DL_APPEND(head,&els[2]); + DL_FOREACH(head,e) { + printf("%c ", e->id); + } + printf("\n"); + DL_SEARCH_SCALAR(head, e, id, 'b'); + if (e != NULL) { + printf("search scalar found b\n"); + } + DL_SEARCH(head, e, &els[0], eltcmp); + if (e != NULL) { + printf("search found %c\n",e->id); + } + DL_FOREACH_SAFE(head,e,tmp) { + DL_DELETE(head,e); + } + printf("\n"); + + /* test CDL macros */ + printf("CDL macros\n"); + CDL_PREPEND(head,&els[0]); + CDL_PREPEND(head,&els[1]); + CDL_PREPEND(head,&els[2]); + CDL_FOREACH(head,e) { + printf("%c ", e->id); + } + printf("\n"); + CDL_SEARCH_SCALAR(head, e, id, 'b'); + if (e != NULL) { + printf("search scalar found b\n"); + } + CDL_SEARCH(head, e, &els[0], eltcmp); + if (e != NULL) { + printf("search found %c\n",e->id); + } + CDL_FOREACH_SAFE(head,e,tmp,tmp2) { + CDL_DELETE(head,e); + } + + return 0; +} |