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/test46.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test46.c')
-rw-r--r-- | tests/test46.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/test46.c b/tests/test46.c new file mode 100644 index 000000000..b3ac63762 --- /dev/null +++ b/tests/test46.c @@ -0,0 +1,84 @@ +#include <stdio.h> +#include "utarray.h" + +static int strsort(const void *_a, const void *_b) +{ + const char *a = *(const char* const *)_a; + const char *b = *(const char* const *)_b; + return strcmp(a,b); +} + +static int revsort(const void *_a, const void *_b) +{ + const char *a = *(const char* const *)_a; + const char *b = *(const char* const *)_b; + return strcmp(b,a); +} + +int main() +{ + UT_array *strs,*strs2; + char *s, **p=NULL; + utarray_new(strs, &ut_str_icd); + s=(char*)"hello"; + utarray_push_back(strs, &s); + s=(char*)"world"; + utarray_push_back(strs, &s); + while ( (p=(char**)utarray_next(strs,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + s=(char*)"begin"; + utarray_insert(strs,&s,0); + while ( (p=(char**)utarray_next(strs,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_new(strs2, &ut_str_icd); + s=(char*)"alt"; + utarray_push_back(strs2, &s); + s=(char*)"oth"; + utarray_push_back(strs2, &s); + utarray_inserta(strs2, strs, 1); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_erase(strs2,0,2); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_pop_back(strs2); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_concat(strs2, strs); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_clear(strs2); + utarray_concat(strs2, strs); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + printf("sorting strs2\n"); + utarray_sort(strs2,strsort); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + printf("reverse sorting strs2\n"); + utarray_sort(strs2,revsort); + while ( (p=(char**)utarray_next(strs2,p)) != NULL ) { + printf("%s ",*p); + } + printf("\n"); + utarray_clear(strs2); + utarray_free(strs2); + utarray_free(strs); + return 0; +} |