olaf@9: /* olaf@9: * tests of list implementation olaf@9: */ olaf@9: olaf@9: #include olaf@9: #include olaf@9: olaf@9: #include "ucx/list.h" olaf@9: #include "ucx/dlist.h" olaf@9: olaf@9: struct test1_data { olaf@9: int values[3]; olaf@9: int i; olaf@9: }; olaf@9: olaf@9: int list_tests_foreach1(void *v, void *custom) { olaf@9: UcxDlist *dl = (UcxDlist*)v; olaf@9: struct test1_data *tdata = (struct test1_data*)custom; olaf@9: olaf@9: tdata->values[tdata->i] = *(int*)dl->data; olaf@9: tdata->i++; olaf@9: } olaf@9: olaf@9: int list_tests() { olaf@9: int r = 0; olaf@9: int v[8]; olaf@9: UcxDlist *dl = NULL; olaf@9: // build list 0,1,2,3,4,5,6,7 olaf@9: for(int i=0;i<8;i++) { olaf@9: v[i] = i; olaf@9: dl = ucx_dlist_append(dl, &v[i]); olaf@9: } olaf@9: olaf@9: for(int i=0;i<8;i++) { olaf@9: UcxDlist *elm = ucx_dlist_get(dl, i); olaf@9: if(elm == NULL) { olaf@9: fprintf(stderr, "ucx_dlist_get failed: element is NULL\n"); olaf@9: } olaf@9: if(elm->data == NULL) { olaf@9: fprintf(stderr, "ucx_dlist_get failed: data is NULL\n"); olaf@9: } olaf@9: int *data = (int*)elm->data; olaf@9: if(*data != i) { olaf@9: fprintf(stderr, "ucx_dlist_get failed with index %d\n", i); olaf@9: } olaf@9: } olaf@9: olaf@9: //TODO: ucx_dlist_free test olaf@9: olaf@9: dl = NULL; olaf@9: // build list 4,0,4 olaf@9: dl = ucx_dlist_prepend(dl, &v[0]); olaf@9: dl = ucx_dlist_prepend(dl, &v[5]); olaf@9: dl = ucx_dlist_append(dl, &v[5]); olaf@9: olaf@9: struct test1_data tdata; olaf@9: tdata.i = 0; olaf@9: ucx_dlist_foreach(dl, list_tests_foreach1, &tdata); olaf@9: olaf@9: if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { olaf@9: fprintf(stderr, "prepend/append test failed\n"); olaf@9: } olaf@9: olaf@9: return r; olaf@9: }