test/list_tests.c

Thu, 09 Feb 2012 10:40:19 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 09 Feb 2012 10:40:19 +0100
changeset 25
3192553c0df1
parent 24
e04822101291
child 27
22644e2572bc
permissions
-rw-r--r--

changed hgignore filter

9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * tests of list implementation
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 */
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 #include <stdio.h>
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 #include <stdlib.h>
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 #include "ucx/list.h"
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 #include "ucx/dlist.h"
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
11 struct foreach_testdata {
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 int values[3];
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 int i;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 };
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
16 void* int_cpy(void* source, void* data) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
17 void *dest = malloc(sizeof(int));
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
18 if (dest != NULL) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
19 *((int*)dest) = *((int*)source);
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
20 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
21 return dest;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
22 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
23
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
24 int int_cmp(void* e1, void *e2, void *data) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
25 if (e1 == NULL || e2 == NULL) return (e1 == e2) ? 0 : -1;
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
26
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
27 int *i1 = (int*)e1, *i2 = (int*)e2;
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
28 int r = (*i1) - (*i2);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
29 return (r < 0) ? -1 : (r == 0 ? 0 : 1);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
30 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
31
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
32 int dlist_tests_foreach(void *v, void *custom) {
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 UcxDlist *dl = (UcxDlist*)v;
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
34 struct foreach_testdata *tdata = (struct foreach_testdata*)custom;
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 tdata->values[tdata->i] = *(int*)dl->data;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 tdata->i++;
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
38
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
39 return 0;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
40 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
41
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
42 int dlist_free_content(void *v, void *custom) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
43 UcxDlist *dl = (UcxDlist*)v;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
44 free(dl->data);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
45 return 0;
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
48 int dlist_tests() {
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 int r = 0;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 int v[8];
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 UcxDlist *dl = NULL;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 // build list 0,1,2,3,4,5,6,7
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
53 printf(" Test ucx_dlist_append\n");
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
54 fflush(stdout);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 for(int i=0;i<8;i++) {
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 v[i] = i;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 dl = ucx_dlist_append(dl, &v[i]);
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
60 printf(" Test ucx_dlist_get\n");
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
61 fflush(stdout);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 for(int i=0;i<8;i++) {
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 UcxDlist *elm = ucx_dlist_get(dl, i);
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 if(elm == NULL) {
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 fprintf(stderr, "ucx_dlist_get failed: element is NULL\n");
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
66 r--;
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
67 } else if(elm->data == NULL) {
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 fprintf(stderr, "ucx_dlist_get failed: data is NULL\n");
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
69 r--;
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
70 } else {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
71 int *data = (int*)elm->data;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
72 if(*data != i) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
73 fprintf(stderr, "ucx_dlist_get failed with index %d\n", i);
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
74 r--;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
75 }
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
79 printf(" Test ucx_dlist_free\n");
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
80 fflush(stdout);
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
81 ucx_dlist_free(dl);
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
82
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 dl = NULL;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 // build list 4,0,4
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
85 printf(" Test ucx_dlist_prepend\n");
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 dl = ucx_dlist_prepend(dl, &v[0]);
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
87 dl = ucx_dlist_prepend(dl, &v[4]);
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
88 dl = ucx_dlist_append(dl, &v[4]);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
90 struct foreach_testdata tdata;
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 tdata.i = 0;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
92 ucx_dlist_foreach(dl, dlist_tests_foreach, &tdata);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) {
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 fprintf(stderr, "prepend/append test failed\n");
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
96 fprintf(stderr, "content: [%d, %d, %d]\n",
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
97 tdata.values[0], tdata.values[1], tdata.values[2]);
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
98 r--;
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
101 printf(" Test ucx_dlist_equals\n");
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
102 UcxDlist *dl2 = NULL;
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
103 dl2 = ucx_dlist_append(dl2, &v[4]);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
104 dl2 = ucx_dlist_append(dl2, &v[0]);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
105 dl2 = ucx_dlist_append(dl2, &v[4]);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
106 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
107 fprintf(stderr, "ucx_dlist_equals failed (false negative)\n");
19
cdd7a3173249 Removed linked list from tests (assume that they are correct if the dlist tests are correct)
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
108 r--;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
109 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
110 dl2->next->data = NULL;
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
111 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
112 fprintf(stderr, "ucx_dlist_equals failed (false positive)\n");
19
cdd7a3173249 Removed linked list from tests (assume that they are correct if the dlist tests are correct)
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
113 r--;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
114 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
115 dl2->next->data = &(tdata.values[1]);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
116 if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
117 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n");
19
cdd7a3173249 Removed linked list from tests (assume that they are correct if the dlist tests are correct)
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
118 r--;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
119 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
120 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
121 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n");
19
cdd7a3173249 Removed linked list from tests (assume that they are correct if the dlist tests are correct)
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
122 r--;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
123 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
124 ucx_dlist_free(dl2);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
125
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
126 printf(" Test ucx_dlist_clone\n");
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
127 dl2 = ucx_dlist_clone(dl, NULL, NULL);
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
128 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) {
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
129 fprintf(stderr, "ucx_dlist_clone (without copy) failed\n");
19
cdd7a3173249 Removed linked list from tests (assume that they are correct if the dlist tests are correct)
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
130 r--;
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
131 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
132 ucx_dlist_free(dl2);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
133
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
134 printf(" Test ucx_dlist_clone with copy\n");
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
135 dl2 = ucx_dlist_clone(dl, int_cpy, NULL);
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
136 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
137 if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
138 fprintf(stderr, "ucx_dlist_clone (with copy) failed (compare)\n");
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
139 r--;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
140 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
141 } else {
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
142 fprintf(stderr, "ucx_dlist_clone (with copy) failed (identity)\n");
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
143 r--;
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
144 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
145 ucx_dlist_foreach(dl, dlist_free_content, NULL);
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
146 ucx_dlist_free(dl2);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
147
22
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
148 ucx_dlist_free(dl);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
149
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
150 dl = NULL;
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
151 printf(" Test ucx_dlist_remove\n");
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
152 dl = ucx_dlist_append(dl, &v[4]);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
153 dl = ucx_dlist_append(dl, &v[0]);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
154 dl = ucx_dlist_append(dl, &v[3]);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
155 dl = ucx_dlist_remove(dl, dl->next);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
156 if (ucx_dlist_size(dl) == 2) {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
157 if ((*((int*)(dl->data)) != 4) || (*((int*)(dl->next->data)) != 3)) {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
158 fprintf(stderr, "ucx_dlist_remove failed (wrong data)\n");
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
159 r--;
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
160 }
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
161 } else {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
162 fprintf(stderr, "ucx_dlist_remove failed (wrong size)\n");
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
163 r--;
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
164 }
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
165 dl = ucx_dlist_remove(dl, dl);
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
166 if (ucx_dlist_size(dl) == 1) {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
167 if ((*((int*)(dl->data)) != 3)) {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
168 fprintf(stderr, "ucx_dlist_remove first failed (wrong data)\n");
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
169 r--;
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
170 }
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
171 } else {
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
172 fprintf(stderr, "ucx_dlist_remove first failed (wrong size)\n");
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
173 r--;
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
174 }
76cdd8209f1f added ucx_dlist_remove and tests + fixed makefile error
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
175
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 return r;
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 }
11
4f6082f99bd7 Added list tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
178

mercurial