Sat, 31 Dec 2011 18:57:30 +0100
Added dlist tests
test/Makefile | file | annotate | diff | comparison | revisions | |
test/list_tests.c | file | annotate | diff | comparison | revisions | |
test/list_tests.h | file | annotate | diff | comparison | revisions | |
test/main.c | file | annotate | diff | comparison | revisions | |
ucx/list.h | file | annotate | diff | comparison | revisions |
1.1 --- a/test/Makefile Sat Dec 31 18:46:48 2011 +0100 1.2 +++ b/test/Makefile Sat Dec 31 18:57:30 2011 +0100 1.3 @@ -28,7 +28,7 @@ 1.4 1.5 include ../$(CONF).mk 1.6 1.7 -SRC = main.c 1.8 +SRC = main.c list_tests.c 1.9 1.10 OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT)) 1.11
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/list_tests.c Sat Dec 31 18:57:30 2011 +0100 2.3 @@ -0,0 +1,65 @@ 2.4 +/* 2.5 + * tests of list implementation 2.6 + */ 2.7 + 2.8 +#include <stdio.h> 2.9 +#include <stdlib.h> 2.10 + 2.11 +#include "ucx/list.h" 2.12 +#include "ucx/dlist.h" 2.13 + 2.14 +struct test1_data { 2.15 + int values[3]; 2.16 + int i; 2.17 +}; 2.18 + 2.19 +int list_tests_foreach1(void *v, void *custom) { 2.20 + UcxDlist *dl = (UcxDlist*)v; 2.21 + struct test1_data *tdata = (struct test1_data*)custom; 2.22 + 2.23 + tdata->values[tdata->i] = *(int*)dl->data; 2.24 + tdata->i++; 2.25 +} 2.26 + 2.27 +int list_tests() { 2.28 + int r = 0; 2.29 + int v[8]; 2.30 + UcxDlist *dl = NULL; 2.31 + // build list 0,1,2,3,4,5,6,7 2.32 + for(int i=0;i<8;i++) { 2.33 + v[i] = i; 2.34 + dl = ucx_dlist_append(dl, &v[i]); 2.35 + } 2.36 + 2.37 + for(int i=0;i<8;i++) { 2.38 + UcxDlist *elm = ucx_dlist_get(dl, i); 2.39 + if(elm == NULL) { 2.40 + fprintf(stderr, "ucx_dlist_get failed: element is NULL\n"); 2.41 + } 2.42 + if(elm->data == NULL) { 2.43 + fprintf(stderr, "ucx_dlist_get failed: data is NULL\n"); 2.44 + } 2.45 + int *data = (int*)elm->data; 2.46 + if(*data != i) { 2.47 + fprintf(stderr, "ucx_dlist_get failed with index %d\n", i); 2.48 + } 2.49 + } 2.50 + 2.51 + //TODO: ucx_dlist_free test 2.52 + 2.53 + dl = NULL; 2.54 + // build list 4,0,4 2.55 + dl = ucx_dlist_prepend(dl, &v[0]); 2.56 + dl = ucx_dlist_prepend(dl, &v[5]); 2.57 + dl = ucx_dlist_append(dl, &v[5]); 2.58 + 2.59 + struct test1_data tdata; 2.60 + tdata.i = 0; 2.61 + ucx_dlist_foreach(dl, list_tests_foreach1, &tdata); 2.62 + 2.63 + if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { 2.64 + fprintf(stderr, "prepend/append test failed\n"); 2.65 + } 2.66 + 2.67 + return r; 2.68 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/list_tests.h Sat Dec 31 18:57:30 2011 +0100 3.3 @@ -0,0 +1,23 @@ 3.4 +/* 3.5 + * File: list_tests.h 3.6 + * Author: olaf 3.7 + * 3.8 + * Created on 31. Dezember 2011, 18:07 3.9 + */ 3.10 + 3.11 +#ifndef LIST_TESTS_H 3.12 +#define LIST_TESTS_H 3.13 + 3.14 +#ifdef __cplusplus 3.15 +extern "C" { 3.16 +#endif 3.17 + 3.18 +int list_tests(); 3.19 + 3.20 + 3.21 +#ifdef __cplusplus 3.22 +} 3.23 +#endif 3.24 + 3.25 +#endif /* LIST_TESTS_H */ 3.26 +
4.1 --- a/test/main.c Sat Dec 31 18:46:48 2011 +0100 4.2 +++ b/test/main.c Sat Dec 31 18:57:30 2011 +0100 4.3 @@ -29,8 +29,14 @@ 4.4 #include <stdio.h> 4.5 #include <stdlib.h> 4.6 4.7 +#include "list_tests.h" 4.8 + 4.9 int main(int argc, char **argv) { 4.10 - printf("Hello World!\n"); 4.11 + printf("UCX Tests\n---------\n\n"); 4.12 + 4.13 + if(list_tests()) { 4.14 + fprintf(stderr, "list_tests failed\n"); 4.15 + } 4.16 4.17 return EXIT_SUCCESS; 4.18 }
5.1 --- a/ucx/list.h Sat Dec 31 18:46:48 2011 +0100 5.2 +++ b/ucx/list.h Sat Dec 31 18:57:30 2011 +0100 5.3 @@ -20,7 +20,7 @@ 5.4 5.5 UcxList *ucx_list_append(UcxList *l, void *data); 5.6 UcxList *ucx_list_prepend(UcxList *l, void *data); 5.7 -UcxList *ucx_list_concat(UcxList *l1, UcxDlist *l2); 5.8 +UcxList *ucx_list_concat(UcxList *l1, UcxList *l2); 5.9 UcxList *ucx_list_last(UcxList *l); 5.10 UcxList *ucx_list_get(UcxList *l, int index); 5.11 size_t ucx_list_size(UcxList *l);