| 117 CX_TEST_ASSERT(arr_capacity < 128); |
117 CX_TEST_ASSERT(arr_capacity < 128); |
| 118 } |
118 } |
| 119 cxFreeDefault(arr); |
119 cxFreeDefault(arr); |
| 120 } |
120 } |
| 121 |
121 |
| |
122 CX_TEST(test_array_add16) { |
| |
123 CX_ARRAY_DECLARE_SIZED(char, arr, uint16_t); |
| |
124 cx_array_initialize(arr, 300); |
| |
125 arr_size = 270; |
| |
126 int result; |
| |
127 CX_TEST_DO { |
| |
128 char elem = 'A'; |
| |
129 result = cx_array_simple_add(arr, elem); |
| |
130 CX_TEST_ASSERT(result == 0); |
| |
131 CX_TEST_ASSERT(arr[270] == 'A'); |
| |
132 CX_TEST_ASSERT(arr_size == 271); |
| |
133 CX_TEST_ASSERT(arr_capacity == 300); |
| |
134 |
| |
135 char *hello = "Hello"; |
| |
136 result = cx_array_simple_copy(arr, 9000, hello, 5); |
| |
137 CX_TEST_ASSERT(result == 0); |
| |
138 CX_TEST_ASSERT(arr[9000] == 'H'); |
| |
139 CX_TEST_ASSERT(arr[9001] == 'e'); |
| |
140 CX_TEST_ASSERT(arr[9002] == 'l'); |
| |
141 CX_TEST_ASSERT(arr[9003] == 'l'); |
| |
142 CX_TEST_ASSERT(arr[9004] == 'o'); |
| |
143 CX_TEST_ASSERT(arr_size == 9005); |
| |
144 CX_TEST_ASSERT(arr_capacity == 9*1024); |
| |
145 |
| |
146 // does not fit into 16-bit sized array |
| |
147 result = cx_array_simple_copy(arr, 65532, hello, 5); |
| |
148 CX_TEST_ASSERT(result != 0); |
| |
149 CX_TEST_ASSERT(errno == EOVERFLOW); |
| |
150 CX_TEST_ASSERT(arr_size == 9005); |
| |
151 CX_TEST_ASSERT(arr_capacity == 9*1024); |
| |
152 } |
| |
153 cxFreeDefault(arr); |
| |
154 } |
| |
155 |
| 122 CX_TEST(test_array_copy_unsupported_width) { |
156 CX_TEST(test_array_copy_unsupported_width) { |
| 123 CX_ARRAY_DECLARE_SIZED(int, arr, uint16_t); |
157 CX_ARRAY_DECLARE_SIZED(int, arr, uint16_t); |
| 124 cx_array_initialize(arr, 16); |
158 cx_array_initialize(arr, 16); |
| 125 int result; |
159 int result; |
| 126 CX_TEST_DO { |
160 CX_TEST_DO { |
| 137 ); |
171 ); |
| 138 CX_TEST_ASSERT(result != 0); |
172 CX_TEST_ASSERT(result != 0); |
| 139 CX_TEST_ASSERT(errno == EINVAL); |
173 CX_TEST_ASSERT(errno == EINVAL); |
| 140 CX_TEST_ASSERT(arr_size == 0); |
174 CX_TEST_ASSERT(arr_size == 0); |
| 141 CX_TEST_ASSERT(arr_capacity == 16); |
175 CX_TEST_ASSERT(arr_capacity == 16); |
| |
176 } |
| |
177 cxFreeDefault(arr); |
| |
178 } |
| |
179 |
| |
180 CX_TEST(test_array_copy_overlap) { |
| |
181 CX_ARRAY_DECLARE_SIZED(char, arr, uint8_t); |
| |
182 cx_array_initialize(arr, 16); |
| |
183 strcpy(arr, "Hello, World!"); |
| |
184 CX_TEST_DO { |
| |
185 errno = 0; |
| |
186 int result = cx_array_simple_copy(arr, 7, arr, 14); |
| |
187 CX_TEST_ASSERT(result == 0); |
| |
188 CX_TEST_ASSERT(errno == 0); |
| |
189 CX_TEST_ASSERT(arr_size == 21); |
| |
190 CX_TEST_ASSERT(arr_capacity == 32); |
| |
191 CX_TEST_ASSERT(0 == memcmp(arr, "Hello, Hello, World!\0", 21)); |
| 142 } |
192 } |
| 143 cxFreeDefault(arr); |
193 cxFreeDefault(arr); |
| 144 } |
194 } |
| 145 |
195 |
| 146 CX_TEST(test_array_reserve) { |
196 CX_TEST(test_array_reserve) { |
| 3284 CxTestSuite *cx_test_suite_array_list(void) { |
3334 CxTestSuite *cx_test_suite_array_list(void) { |
| 3285 CxTestSuite *suite = cx_test_suite_new("array_list"); |
3335 CxTestSuite *suite = cx_test_suite_new("array_list"); |
| 3286 |
3336 |
| 3287 cx_test_register(suite, test_array_add); |
3337 cx_test_register(suite, test_array_add); |
| 3288 cx_test_register(suite, test_array_add8); |
3338 cx_test_register(suite, test_array_add8); |
| |
3339 cx_test_register(suite, test_array_add16); |
| 3289 cx_test_register(suite, test_array_copy_unsupported_width); |
3340 cx_test_register(suite, test_array_copy_unsupported_width); |
| |
3341 cx_test_register(suite, test_array_copy_overlap); |
| 3290 cx_test_register(suite, test_array_reserve); |
3342 cx_test_register(suite, test_array_reserve); |
| 3291 cx_test_register(suite, test_array_reserve_unsupported_width); |
3343 cx_test_register(suite, test_array_reserve_unsupported_width); |
| 3292 cx_test_register(suite, test_array_insert_sorted); |
3344 cx_test_register(suite, test_array_insert_sorted); |
| 3293 cx_test_register(suite, test_array_insert_unique); |
3345 cx_test_register(suite, test_array_insert_unique); |
| 3294 cx_test_register(suite, test_array_binary_search); |
3346 cx_test_register(suite, test_array_binary_search); |