| 204 CX_TEST_ASSERT(0 == strcmp(test, "Test")); |
204 CX_TEST_ASSERT(0 == strcmp(test, "Test")); |
| 205 } |
205 } |
| 206 free(test); |
206 free(test); |
| 207 } |
207 } |
| 208 |
208 |
| |
209 CX_TEST(test_allocator_reallocate_frees) { |
| |
210 CX_TEST_DO { |
| |
211 void *test = cxCallocDefault(8, 1); |
| |
212 CX_TEST_ASSERT(test != NULL); |
| |
213 int ret = cxReallocateDefault(&test, 0); |
| |
214 CX_TEST_ASSERT(ret == 0); |
| |
215 CX_TEST_ASSERT(test == NULL); |
| |
216 } |
| |
217 } |
| |
218 |
| |
219 CX_TEST(test_allocator_reallocate_low_level_frees) { |
| |
220 CX_TEST_DO { |
| |
221 void *test = calloc(8, 1); |
| |
222 CX_TEST_ASSERT(test != NULL); |
| |
223 int ret = cx_reallocate(&test, 0); |
| |
224 CX_TEST_ASSERT(ret == 0); |
| |
225 CX_TEST_ASSERT(test == NULL); |
| |
226 } |
| |
227 } |
| |
228 |
| 209 CX_TEST(test_allocator_reallocatearray) { |
229 CX_TEST(test_allocator_reallocatearray) { |
| 210 char *test = cxCallocDefault(8, 1); |
230 char *test = cxCallocDefault(8, 1); |
| 211 memcpy(test, "Test", 5); |
231 memcpy(test, "Test", 5); |
| 212 CX_TEST_DO { |
232 CX_TEST_DO { |
| 213 int ret = cxReallocateArrayDefault(&test, 16, 2); |
233 int ret = cxReallocateArrayDefault(&test, 16, 2); |
| 252 CX_TEST_ASSERT(errno == EOVERFLOW); |
272 CX_TEST_ASSERT(errno == EOVERFLOW); |
| 253 CX_TEST_ASSERT(test != NULL); |
273 CX_TEST_ASSERT(test != NULL); |
| 254 CX_TEST_ASSERT(0 == strcmp(test, "Test")); |
274 CX_TEST_ASSERT(0 == strcmp(test, "Test")); |
| 255 } |
275 } |
| 256 free(test); |
276 free(test); |
| |
277 } |
| |
278 |
| |
279 CX_TEST(test_allocator_reallocatearray_frees) { |
| |
280 CX_TEST_DO { |
| |
281 char *test = cxCallocDefault(8, 1); |
| |
282 CX_TEST_ASSERT(test != NULL); |
| |
283 int ret = cxReallocateArrayDefault(&test, 0, 1); |
| |
284 CX_TEST_ASSERT(ret == 0); |
| |
285 CX_TEST_ASSERT(test == NULL); |
| |
286 } |
| |
287 } |
| |
288 |
| |
289 CX_TEST(test_allocator_reallocatearray_low_level_frees) { |
| |
290 CX_TEST_DO { |
| |
291 char *test = calloc(8, 1); |
| |
292 CX_TEST_ASSERT(test != NULL); |
| |
293 int ret = cx_reallocatearray(&test, 0, 1); |
| |
294 CX_TEST_ASSERT(ret == 0); |
| |
295 CX_TEST_ASSERT(test == NULL); |
| |
296 } |
| 257 } |
297 } |
| 258 |
298 |
| 259 static void *test_allocator_mock_failing_realloc( |
299 static void *test_allocator_mock_failing_realloc( |
| 260 cx_attr_unused void *p, |
300 cx_attr_unused void *p, |
| 261 cx_attr_unused void *d, |
301 cx_attr_unused void *d, |
| 302 cx_test_register(suite, test_allocator_default_reallocarray_overflow); |
342 cx_test_register(suite, test_allocator_default_reallocarray_overflow); |
| 303 cx_test_register(suite, test_allocator_default_free); |
343 cx_test_register(suite, test_allocator_default_free); |
| 304 cx_test_register(suite, test_allocator_reallocate); |
344 cx_test_register(suite, test_allocator_reallocate); |
| 305 cx_test_register(suite, test_allocator_reallocate_fails); |
345 cx_test_register(suite, test_allocator_reallocate_fails); |
| 306 cx_test_register(suite, test_allocator_reallocate_low_level); |
346 cx_test_register(suite, test_allocator_reallocate_low_level); |
| |
347 cx_test_register(suite, test_allocator_reallocate_frees); |
| |
348 cx_test_register(suite, test_allocator_reallocate_low_level_frees); |
| 307 cx_test_register(suite, test_allocator_reallocatearray); |
349 cx_test_register(suite, test_allocator_reallocatearray); |
| 308 cx_test_register(suite, test_allocator_reallocatearray_overflow); |
350 cx_test_register(suite, test_allocator_reallocatearray_overflow); |
| 309 cx_test_register(suite, test_allocator_reallocatearray_low_level); |
351 cx_test_register(suite, test_allocator_reallocatearray_low_level); |
| 310 cx_test_register(suite, test_allocator_reallocatearray_low_level_overflow); |
352 cx_test_register(suite, test_allocator_reallocatearray_low_level_overflow); |
| |
353 cx_test_register(suite, test_allocator_reallocatearray_frees); |
| |
354 cx_test_register(suite, test_allocator_reallocatearray_low_level_frees); |
| 311 |
355 |
| 312 return suite; |
356 return suite; |
| 313 } |
357 } |