1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/list_tests.c Sat Dec 31 18:57:30 2011 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* 1.5 + * tests of list implementation 1.6 + */ 1.7 + 1.8 +#include <stdio.h> 1.9 +#include <stdlib.h> 1.10 + 1.11 +#include "ucx/list.h" 1.12 +#include "ucx/dlist.h" 1.13 + 1.14 +struct test1_data { 1.15 + int values[3]; 1.16 + int i; 1.17 +}; 1.18 + 1.19 +int list_tests_foreach1(void *v, void *custom) { 1.20 + UcxDlist *dl = (UcxDlist*)v; 1.21 + struct test1_data *tdata = (struct test1_data*)custom; 1.22 + 1.23 + tdata->values[tdata->i] = *(int*)dl->data; 1.24 + tdata->i++; 1.25 +} 1.26 + 1.27 +int list_tests() { 1.28 + int r = 0; 1.29 + int v[8]; 1.30 + UcxDlist *dl = NULL; 1.31 + // build list 0,1,2,3,4,5,6,7 1.32 + for(int i=0;i<8;i++) { 1.33 + v[i] = i; 1.34 + dl = ucx_dlist_append(dl, &v[i]); 1.35 + } 1.36 + 1.37 + for(int i=0;i<8;i++) { 1.38 + UcxDlist *elm = ucx_dlist_get(dl, i); 1.39 + if(elm == NULL) { 1.40 + fprintf(stderr, "ucx_dlist_get failed: element is NULL\n"); 1.41 + } 1.42 + if(elm->data == NULL) { 1.43 + fprintf(stderr, "ucx_dlist_get failed: data is NULL\n"); 1.44 + } 1.45 + int *data = (int*)elm->data; 1.46 + if(*data != i) { 1.47 + fprintf(stderr, "ucx_dlist_get failed with index %d\n", i); 1.48 + } 1.49 + } 1.50 + 1.51 + //TODO: ucx_dlist_free test 1.52 + 1.53 + dl = NULL; 1.54 + // build list 4,0,4 1.55 + dl = ucx_dlist_prepend(dl, &v[0]); 1.56 + dl = ucx_dlist_prepend(dl, &v[5]); 1.57 + dl = ucx_dlist_append(dl, &v[5]); 1.58 + 1.59 + struct test1_data tdata; 1.60 + tdata.i = 0; 1.61 + ucx_dlist_foreach(dl, list_tests_foreach1, &tdata); 1.62 + 1.63 + if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { 1.64 + fprintf(stderr, "prepend/append test failed\n"); 1.65 + } 1.66 + 1.67 + return r; 1.68 +}