test/test_allocator.c

changeset 414
81a4c3a63e65
parent 410
76b76f0f046b
child 419
b5d6cb88d05d
--- a/test/test_allocator.c	Sun Feb 14 15:37:12 2021 +0100
+++ b/test/test_allocator.c	Mon Mar 01 22:19:06 2021 +0100
@@ -49,6 +49,21 @@
     free(test);
 }
 
+void test_default_reallocate(void) {
+    void *test = calloc(8, 1);
+    memcpy(test, "Test", 4);
+    int rval = cxReallocate(cxDefaultAllocator, &test, 16);
+    CU_ASSERT_EQUAL(rval, 0);
+    CU_ASSERT_PTR_NOT_NULL(test)
+    CU_ASSERT_STRING_EQUAL("Test", test)
+    free(test);
+}
+
+void test_reallocate_null(void) {
+    int rval = cxReallocate(cxDefaultAllocator, NULL, 16);
+    CU_ASSERT_EQUAL(rval, EINVAL);
+}
+
 void test_default_calloc(void) {
     void *test = cxCalloc(cxDefaultAllocator, 8, 2);
     CU_ASSERT_PTR_NOT_NULL(test)
@@ -78,7 +93,9 @@
             !CU_add_test(suite, "default allocator available", test_default_allocator_available) ||
             !CU_add_test(suite, "test of malloc()", test_default_malloc)||
             !CU_add_test(suite, "test of realloc()", test_default_realloc) ||
-            !CU_add_test(suite, "test of realloc()", test_default_calloc) ||
+            !CU_add_test(suite, "test of realloc() via cxReallocate", test_default_reallocate) ||
+            !CU_add_test(suite, "test of cxReallocate with NULL", test_default_reallocate) ||
+            !CU_add_test(suite, "test of calloc()", test_default_calloc) ||
             !CU_add_test(suite, "test of free()", test_default_free)
             ) {
         CU_cleanup_registry();

mercurial