Wed, 27 Feb 2013 11:48:29 +0100
renamed comparator to utils module and added copy functions
9 | 1 | /* |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
2 | * tests of dlist implementation |
9 | 3 | */ |
4 | ||
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
5 | #include "dlist_tests.h" |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
90
diff
changeset
|
6 | #include "ucx/utils.h" |
9 | 7 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
8 | UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
9 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
10 | UCX_TEST_BEGIN |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
11 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
12 | UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
13 | "failed"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
14 | |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
15 | list = ucx_dlist_append(list, (void*)" World!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
16 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
17 | UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
18 | "failed"); |
40
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
19 | UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
20 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
21 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
22 | ucx_dlist_free(list); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
23 | } |
9 | 24 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
25 | UCX_TEST_IMPLEMENT(test_ucx_dlist_prepend) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
26 | UcxDlist *list = ucx_dlist_prepend(NULL, (void*)" World!"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
27 | UCX_TEST_BEGIN |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
28 | |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
29 | list = ucx_dlist_prepend(list, (void*)"Hello"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
30 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
31 | UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
32 | "failed"); |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
33 | UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
34 | "failed"); |
40
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
35 | UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
36 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
37 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
38 | ucx_dlist_free(list); |
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
|
39 | } |
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 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
41 | UCX_TEST_IMPLEMENT(test_ucx_dlist_equals) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
42 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
43 | list = ucx_dlist_append(list, (void*)" World!"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
44 | UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
45 | list2 = ucx_dlist_prepend(list2, (void*)"Hello"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
46 | UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
47 | list3 = ucx_dlist_prepend(list3, (void*)"Hallo"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
48 | UCX_TEST_BEGIN |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
49 | |
89 | 50 | UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, ucx_strcmp, NULL), "failed"); |
51 | UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, ucx_strcmp, NULL), "failed"); | |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
52 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
53 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
54 | ucx_dlist_free(list3); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
55 | ucx_dlist_free(list2); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
56 | ucx_dlist_free(list); |
18
69636f81db31
added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
57 | } |
69636f81db31
added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
58 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
59 | UCX_TEST_IMPLEMENT(test_ucx_dlist_concat) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
60 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
61 | UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
62 | UCX_TEST_BEGIN |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
63 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
64 | list = ucx_dlist_concat(list, list2); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
65 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
66 | UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
67 | "failed"); |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
68 | UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
69 | "failed"); |
40
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
70 | UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
71 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
72 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
73 | ucx_dlist_free(list); |
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
|
74 | } |
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 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
76 | UCX_TEST_IMPLEMENT(test_ucx_dlist_size) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
77 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"This "); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
78 | UCX_TEST_BEGIN |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
79 | list = ucx_dlist_append(list, (void*)"list "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
80 | list = ucx_dlist_append(list, (void*)"has "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
81 | list = ucx_dlist_append(list, (void*)"size "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
82 | list = ucx_dlist_append(list, (void*)"5!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
83 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
84 | UCX_TEST_ASSERT(ucx_dlist_size(list) == 5, "failed"); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
85 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
86 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
87 | ucx_dlist_free(list); |
9 | 88 | } |
89 | ||
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
90 | UCX_TEST_IMPLEMENT(test_ucx_dlist_first) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
91 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
92 | UCX_TEST_BEGIN |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
93 | list = ucx_dlist_append(list, (void*)"the "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
94 | list = ucx_dlist_append(list, (void*)"first!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
95 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
96 | const char* first = (const char*) (ucx_dlist_first(list)->data); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
97 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
98 | UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
99 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
100 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
101 | ucx_dlist_free(list); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
102 | } |
9 | 103 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
104 | UCX_TEST_IMPLEMENT(test_ucx_dlist_last) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
105 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
106 | UCX_TEST_BEGIN |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
107 | list = ucx_dlist_append(list, (void*)"the "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
108 | list = ucx_dlist_append(list, (void*)"last!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
109 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
110 | const char* last = (const char*) (ucx_dlist_last(list)->data); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
111 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
112 | UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
113 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
114 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
115 | ucx_dlist_free(list); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
116 | } |
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
|
117 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
118 | UCX_TEST_IMPLEMENT(test_ucx_dlist_get) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
119 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
120 | UCX_TEST_BEGIN |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
121 | list = ucx_dlist_append(list, (void*)"the "); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
122 | list = ucx_dlist_append(list, (void*)"mid!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
123 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
124 | const char* mid = (const char*) (ucx_dlist_get(list, 1)->data); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
125 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
126 | UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
127 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
128 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
129 | ucx_dlist_free(list); |
9 | 130 | } |
11 | 131 | |
90
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
132 | UCX_TEST_IMPLEMENT(test_ucx_dlist_contains) { |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
133 | UcxDlist *l = ucx_dlist_append(NULL, (void*)"Contains "); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
134 | UCX_TEST_BEGIN |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
135 | l = ucx_dlist_append(l, (void*)"a "); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
136 | l = ucx_dlist_append(l, (void*)"string!"); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
137 | |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
138 | UCX_TEST_ASSERT(ucx_dlist_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed"); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
139 | UCX_TEST_ASSERT(!ucx_dlist_contains(l,(void*)"a",ucx_strcmp,NULL),"failed"); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
140 | |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
141 | UCX_TEST_END |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
142 | ucx_dlist_free(l); |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
143 | } |
ef3163857e88
added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
144 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
145 | UCX_TEST_IMPLEMENT(test_ucx_dlist_remove) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
146 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
147 | UCX_TEST_BEGIN |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
148 | list = ucx_dlist_append(list, (void*)" fucking"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
149 | list = ucx_dlist_append(list, (void*)" World!"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
150 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
151 | list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
152 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
153 | UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
154 | "failed"); |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
155 | UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
156 | "failed"); |
40
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
157 | UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
158 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
159 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
160 | ucx_dlist_free(list); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
161 | } |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
162 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
163 | UCX_TEST_IMPLEMENT(test_ucx_dlist_clone) { |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
164 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
165 | char *hello = (char*)malloc(6); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
166 | char *world = (char*)malloc(8); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
167 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
168 | memcpy(hello, "Hello", 6); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
169 | memcpy(world, " World!", 8); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
170 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
171 | UcxDlist *list = ucx_dlist_append(NULL, hello); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
172 | list = ucx_dlist_append(list, world); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
173 | |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
90
diff
changeset
|
174 | UcxDlist *copy = ucx_dlist_clone(list, ucx_strcpy, NULL); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
175 | UCX_TEST_BEGIN |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
176 | |
89 | 177 | UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, ucx_strcmp, NULL), "failed"); |
40
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
178 | UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); |
583718dd4cf3
added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
179 | UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
180 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
181 | UCX_TEST_END |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
182 | free(copy->next->data); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
183 | free(copy->data); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
184 | |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
185 | free(world); |
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
186 | free(hello); |
30 | 187 | ucx_dlist_free(list); |
188 | ucx_dlist_free(copy); | |
27
22644e2572bc
removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
189 | } |
35
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
190 | |
36
a9d656e4f7ce
changed API of sort algorithms (no further hint for the algorithms used in preparation for the upcomming change from qsort to natural merge sort)
Mike Becker <universe@uap-core.de>
parents:
35
diff
changeset
|
191 | UCX_TEST_IMPLEMENT(test_ucx_dlist_sort) { |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
192 | UcxDlist *list = ucx_dlist_append(NULL, (void*)"this"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
193 | list = ucx_dlist_append(list, (void*)"is"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
194 | list = ucx_dlist_append(list, (void*)"a"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
195 | list = ucx_dlist_append(list, (void*)"test"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
196 | list = ucx_dlist_append(list, (void*)"for"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
197 | list = ucx_dlist_append(list, (void*)"partial"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
198 | list = ucx_dlist_append(list, (void*)"correctness"); |
35
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
199 | |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
200 | UcxDlist *expected = ucx_dlist_append(NULL, (void*)"a"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
201 | expected = ucx_dlist_append(expected, (void*)"correctness"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
202 | expected = ucx_dlist_append(expected, (void*)"for"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
203 | expected = ucx_dlist_append(expected, (void*)"is"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
204 | expected = ucx_dlist_append(expected, (void*)"partial"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
205 | expected = ucx_dlist_append(expected, (void*)"test"); |
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
206 | expected = ucx_dlist_append(expected, (void*)"this"); |
35
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
207 | |
89 | 208 | list = ucx_dlist_sort(list, ucx_strcmp, NULL); |
35
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
209 | |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
210 | UCX_TEST_BEGIN |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
211 | UCX_TEST_ASSERT( |
89 | 212 | ucx_dlist_equals(list, expected, ucx_strcmp, NULL), "failed"); |
35
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
213 | UcxDlist *l = list; |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
214 | UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null"); |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
215 | while (l->next != NULL) { |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
216 | UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted"); |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
217 | l = l->next; |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
218 | } |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
219 | UCX_TEST_END |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
220 | |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
221 | ucx_dlist_free(expected); |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
222 | ucx_dlist_free(list); |
fdabd1240b69
added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
223 | } |