test/list_tests.c

changeset 19
cdd7a3173249
parent 18
69636f81db31
child 22
76cdd8209f1f
     1.1 --- a/test/list_tests.c	Wed Jan 04 14:51:54 2012 +0100
     1.2 +++ b/test/list_tests.c	Wed Jan 11 12:19:48 2012 +0100
     1.3 @@ -31,16 +31,6 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -int list_tests_foreach(void *v, void *custom) {
     1.8 -    UcxList *dl = (UcxList*)v;
     1.9 -    struct test1_data *tdata = (struct test1_data*)custom;
    1.10 -
    1.11 -    tdata->values[tdata->i] = *(int*)dl->data;
    1.12 -    tdata->i++;
    1.13 -    
    1.14 -    return 0;
    1.15 -}
    1.16 -
    1.17  int dlist_tests() {
    1.18      int r = 0;
    1.19      int v[8];
    1.20 @@ -101,17 +91,21 @@
    1.21      dl2 = ucx_dlist_append(dl2, &v[4]);
    1.22      if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) {
    1.23          fprintf(stderr, "ucx_dlist_equals failed (false negative)\n");
    1.24 +        r--;
    1.25      }
    1.26      dl2->next->data = NULL;
    1.27      if (ucx_dlist_equals(dl, dl2, NULL, NULL)) {
    1.28          fprintf(stderr, "ucx_dlist_equals failed (false positive)\n");
    1.29 +        r--;
    1.30      }
    1.31      dl2->next->data = &(tdata.values[1]);
    1.32      if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) {
    1.33          fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n");
    1.34 +        r--;
    1.35      }
    1.36      if (ucx_dlist_equals(dl, dl2, NULL, NULL)) {
    1.37          fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n");
    1.38 +        r--;
    1.39      }
    1.40      ucx_dlist_free(dl2);
    1.41      
    1.42 @@ -119,6 +113,7 @@
    1.43      dl2 = ucx_dlist_clone(dl, NULL, NULL);
    1.44      if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) {
    1.45          fprintf(stderr, "ucx_dlist_clone (without copy) failed\n");
    1.46 +        r--;
    1.47      }
    1.48      ucx_dlist_free(dl2);
    1.49      
    1.50 @@ -127,88 +122,3 @@
    1.51      return r;
    1.52  }
    1.53  
    1.54 -int list_tests() {
    1.55 -    int r = 0;
    1.56 -    int v[8];
    1.57 -    UcxList *dl = NULL;
    1.58 -    // build list 0,1,2,3,4,5,6,7
    1.59 -    printf("   Test ucx_list_append\n");
    1.60 -    fflush(stdout);
    1.61 -    for(int i=0;i<8;i++) {
    1.62 -        v[i] = i;
    1.63 -        dl = ucx_list_append(dl, &v[i]);
    1.64 -    }
    1.65 -
    1.66 -    printf("   Test ucx_list_get\n");
    1.67 -    fflush(stdout);
    1.68 -    for(int i=0;i<8;i++) {
    1.69 -        UcxList *elm = ucx_list_get(dl, i);
    1.70 -        if(elm == NULL) {
    1.71 -            fprintf(stderr, "ucx_list_get failed: element is NULL\n");
    1.72 -            r--;
    1.73 -        }
    1.74 -        if(elm->data == NULL) {
    1.75 -            fprintf(stderr, "ucx_list_get failed: data is NULL\n");
    1.76 -            r--;
    1.77 -        }
    1.78 -        int *data = (int*)elm->data;
    1.79 -        if(*data != i) {
    1.80 -            fprintf(stderr, "ucx_list_get failed with index %d\n", i);
    1.81 -            r--;
    1.82 -        }
    1.83 -    }
    1.84 -
    1.85 -    printf("   Test ucx_list_free\n");
    1.86 -    fflush(stdout);
    1.87 -    ucx_list_free(dl);
    1.88 -
    1.89 -    dl = NULL;
    1.90 -    // build list 4,0,4
    1.91 -    printf("   Test ucx_list_prepend\n");
    1.92 -    dl = ucx_list_prepend(dl, &v[0]);
    1.93 -    dl = ucx_list_prepend(dl, &v[4]);
    1.94 -    dl = ucx_list_append(dl, &v[4]);
    1.95 -
    1.96 -    struct test1_data tdata;
    1.97 -    tdata.i = 0;
    1.98 -    ucx_list_foreach(dl, list_tests_foreach, &tdata);
    1.99 -
   1.100 -    if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) {
   1.101 -        fprintf(stderr, "prepend/append test failed\n");
   1.102 -        fprintf(stderr, "content: [%d, %d, %d]\n",
   1.103 -                tdata.values[0], tdata.values[1], tdata.values[2]);
   1.104 -        r--;
   1.105 -    }
   1.106 -    
   1.107 -    printf("   Test ucx_list_equals\n");
   1.108 -    UcxList *dl2 = NULL;
   1.109 -    dl2 = ucx_list_append(dl2, &v[4]);
   1.110 -    dl2 = ucx_list_append(dl2, &v[0]);
   1.111 -    dl2 = ucx_list_append(dl2, &v[4]);
   1.112 -    if (!ucx_list_equals(dl, dl2, NULL, NULL)) {
   1.113 -        fprintf(stderr, "ucx_list_equals failed (false negative)\n");
   1.114 -    }
   1.115 -    dl2->next->data = NULL;
   1.116 -    if (ucx_list_equals(dl, dl2, NULL, NULL)) {
   1.117 -        fprintf(stderr, "ucx_list_equals failed (false positive)\n");
   1.118 -    }
   1.119 -    dl2->next->data = &(tdata.values[1]);
   1.120 -    if (!ucx_list_equals(dl, dl2, int_cmp, NULL)) {
   1.121 -        fprintf(stderr, "ucx_list_equals failed (cmp_func false negative)\n");
   1.122 -    }
   1.123 -    if (ucx_list_equals(dl, dl2, NULL, NULL)) {
   1.124 -        fprintf(stderr, "ucx_list_equals failed (cmp_func false positive)\n");
   1.125 -    }
   1.126 -    ucx_list_free(dl2);
   1.127 -    
   1.128 -    printf("   Test ucx_list_clone\n");
   1.129 -    dl2 = ucx_list_clone(dl, NULL, NULL);
   1.130 -    if (!ucx_list_equals(dl, dl2, NULL, NULL)) {
   1.131 -        fprintf(stderr, "ucx_list_clone (without copy) failed\n");
   1.132 -    }
   1.133 -    ucx_list_free(dl2);
   1.134 -    
   1.135 -    printf("   TODO: test clone with copy\n");
   1.136 -
   1.137 -    return r;
   1.138 -}

mercurial