tests/test_allocator.c

changeset 1330
33c95cfc088e
parent 1326
9bf5945d91ab
equal deleted inserted replaced
1329:343eac5ac824 1330:33c95cfc088e
44 memcpy(test, "0123456789ABCDEF", 16); 44 memcpy(test, "0123456789ABCDEF", 16);
45 } 45 }
46 cxFree(cxStdlibAllocator, test); 46 cxFree(cxStdlibAllocator, test);
47 } 47 }
48 48
49 CX_TEST(test_allocator_stdlib_zalloc) {
50 void *test = cxZalloc(cxStdlibAllocator, 16);
51 CX_TEST_DO {
52 CX_TEST_ASSERT(test != NULL);
53 CX_TEST_ASSERT(0 == memcmp(test, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16));
54 }
55 cxFree(cxStdlibAllocator, test);
56 }
57
49 CX_TEST(test_allocator_stdlib_calloc) { 58 CX_TEST(test_allocator_stdlib_calloc) {
50 char *test = cxCalloc(cxStdlibAllocator, 8, 2); 59 char *test = cxCalloc(cxStdlibAllocator, 8, 2);
51 CX_TEST_DO { 60 CX_TEST_DO {
52 CX_TEST_ASSERT(test != NULL); 61 CX_TEST_ASSERT(test != NULL);
53 for (int i = 0; i < 16; i++) { 62 for (int i = 0; i < 16; i++) {
104 void *test = cxMallocDefault(16); 113 void *test = cxMallocDefault(16);
105 CX_TEST_DO { 114 CX_TEST_DO {
106 CX_TEST_ASSERT(test != NULL); 115 CX_TEST_ASSERT(test != NULL);
107 // we cannot assert sth. but valgrind will detect an error 116 // we cannot assert sth. but valgrind will detect an error
108 memcpy(test, "0123456789ABCDEF", 16); 117 memcpy(test, "0123456789ABCDEF", 16);
118 }
119 cxFreeDefault(test);
120 }
121
122 CX_TEST(test_allocator_default_zalloc) {
123 void *test = cxZallocDefault(16);
124 CX_TEST_DO {
125 CX_TEST_ASSERT(test != NULL);
126 CX_TEST_ASSERT(0 == memcmp(test, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16));
109 } 127 }
110 cxFreeDefault(test); 128 cxFreeDefault(test);
111 } 129 }
112 130
113 CX_TEST(test_allocator_default_calloc) { 131 CX_TEST(test_allocator_default_calloc) {
268 286
269 CxTestSuite *cx_test_suite_allocator(void) { 287 CxTestSuite *cx_test_suite_allocator(void) {
270 CxTestSuite *suite = cx_test_suite_new("allocator"); 288 CxTestSuite *suite = cx_test_suite_new("allocator");
271 289
272 cx_test_register(suite, test_allocator_stdlib_malloc); 290 cx_test_register(suite, test_allocator_stdlib_malloc);
291 cx_test_register(suite, test_allocator_stdlib_zalloc);
273 cx_test_register(suite, test_allocator_stdlib_calloc); 292 cx_test_register(suite, test_allocator_stdlib_calloc);
274 cx_test_register(suite, test_allocator_stdlib_realloc); 293 cx_test_register(suite, test_allocator_stdlib_realloc);
275 cx_test_register(suite, test_allocator_stdlib_reallocarray); 294 cx_test_register(suite, test_allocator_stdlib_reallocarray);
276 cx_test_register(suite, test_allocator_stdlib_reallocarray_overflow); 295 cx_test_register(suite, test_allocator_stdlib_reallocarray_overflow);
277 cx_test_register(suite, test_allocator_stdlib_free); 296 cx_test_register(suite, test_allocator_stdlib_free);
278 cx_test_register(suite, test_allocator_default_malloc); 297 cx_test_register(suite, test_allocator_default_malloc);
298 cx_test_register(suite, test_allocator_default_zalloc);
279 cx_test_register(suite, test_allocator_default_calloc); 299 cx_test_register(suite, test_allocator_default_calloc);
280 cx_test_register(suite, test_allocator_default_realloc); 300 cx_test_register(suite, test_allocator_default_realloc);
281 cx_test_register(suite, test_allocator_default_reallocarray); 301 cx_test_register(suite, test_allocator_default_reallocarray);
282 cx_test_register(suite, test_allocator_default_reallocarray_overflow); 302 cx_test_register(suite, test_allocator_default_reallocarray_overflow);
283 cx_test_register(suite, test_allocator_default_free); 303 cx_test_register(suite, test_allocator_default_free);

mercurial