38 CX_TEST_ASSERT(map != NULL); |
38 CX_TEST_ASSERT(map != NULL); |
39 CxList *list_from_map = cxKvListAsList(map); |
39 CxList *list_from_map = cxKvListAsList(map); |
40 CX_TEST_ASSERT(list_from_map == list); |
40 CX_TEST_ASSERT(list_from_map == list); |
41 } |
41 } |
42 cxListFree(list); |
42 cxListFree(list); |
|
43 } |
|
44 |
|
45 CX_TEST(test_kv_list_free_as_map) { |
|
46 CxTestingAllocator talloc; |
|
47 cx_testing_allocator_init(&talloc); |
|
48 CX_TEST_DO { |
|
49 CxList *list = cxKvListCreate(&talloc.base, NULL, 1); |
|
50 cxListAddArray(list, "test", 4); |
|
51 CxMap *map = cxKvListAsMap(list); |
|
52 cxMapFree(map); |
|
53 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
|
54 } |
|
55 cx_testing_allocator_destroy(&talloc); |
|
56 } |
|
57 |
|
58 CX_TEST(test_kv_list_free_as_list) { |
|
59 CxTestingAllocator talloc; |
|
60 cx_testing_allocator_init(&talloc); |
|
61 CX_TEST_DO { |
|
62 CxMap *map = cxKvListCreateAsMap(&talloc.base, NULL, sizeof(int)); |
|
63 int x = 5; |
|
64 cxMapPut(map, "test", &x); |
|
65 CxList *list = cxKvListAsList(map); |
|
66 cxListFree(list); |
|
67 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
|
68 } |
|
69 cx_testing_allocator_destroy(&talloc); |
43 } |
70 } |
44 |
71 |
45 CX_TEST(test_kv_list_map_put) { |
72 CX_TEST(test_kv_list_map_put) { |
46 CxList *list = cxKvListCreateSimple(sizeof(int)); |
73 CxList *list = cxKvListCreateSimple(sizeof(int)); |
47 int x; |
74 int x; |
90 CX_TEST_ASSERT(0 != cxMapRemove(map, "xyz")); |
117 CX_TEST_ASSERT(0 != cxMapRemove(map, "xyz")); |
91 } |
118 } |
92 cxListFree(list); |
119 cxListFree(list); |
93 } |
120 } |
94 |
121 |
|
122 static int kv_list_test_destr_val; |
|
123 static void kv_list_test_destr(void *data) { |
|
124 kv_list_test_destr_val = *(int*)data; |
|
125 } |
|
126 |
|
127 CX_TEST(test_kv_list_map_remove_destr_in_list) { |
|
128 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
129 int x; |
|
130 CX_TEST_DO { |
|
131 x = 0xabcd; |
|
132 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
|
133 cxKvListSetKey(list, 0, "xyz"); |
|
134 |
|
135 cxDefineDestructor(list, kv_list_test_destr); |
|
136 kv_list_test_destr_val = 0; |
|
137 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); |
|
138 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
139 } |
|
140 cxListFree(list); |
|
141 } |
|
142 |
|
143 CX_TEST(test_kv_list_map_remove_destr_in_map) { |
|
144 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
|
145 int x; |
|
146 CX_TEST_DO { |
|
147 x = 0xabcd; |
|
148 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
149 |
|
150 cxDefineDestructor(map, kv_list_test_destr); |
|
151 kv_list_test_destr_val = 0; |
|
152 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
|
153 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
154 } |
|
155 cxMapFree(map); |
|
156 } |
|
157 |
95 CxTestSuite *cx_test_suite_kv_list_specifics(void) { |
158 CxTestSuite *cx_test_suite_kv_list_specifics(void) { |
96 CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); |
159 CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); |
97 |
160 |
98 cx_test_register(suite, test_kv_list_map_as_list); |
161 cx_test_register(suite, test_kv_list_map_as_list); |
|
162 cx_test_register(suite, test_kv_list_free_as_map); |
|
163 cx_test_register(suite, test_kv_list_free_as_list); |
99 cx_test_register(suite, test_kv_list_map_put); |
164 cx_test_register(suite, test_kv_list_map_put); |
100 cx_test_register(suite, test_kv_list_map_remove); |
165 cx_test_register(suite, test_kv_list_map_remove); |
|
166 cx_test_register(suite, test_kv_list_map_remove_destr_in_list); |
|
167 cx_test_register(suite, test_kv_list_map_remove_destr_in_map); |
101 |
168 |
102 return suite; |
169 return suite; |
103 } |
170 } |