test/test_allocator.c

changeset 397
cfc1193b1e65
parent 396
3539dd99ab92
child 410
76b76f0f046b
equal deleted inserted replaced
396:3539dd99ab92 397:cfc1193b1e65
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <CUnit/Basic.h> 31 #include <CUnit/Basic.h>
32 32
33 void test_default_allocator_available(void) { 33 void test_default_allocator_available(void) {
34 cx_allocator_class* clazz = cxDefaultAllocator->cl; 34 cx_allocator_class *clazz = cxDefaultAllocator->cl;
35 CU_ASSERT_PTR_EQUAL(clazz->malloc, cx_malloc_stdlib) 35 CU_ASSERT_PTR_EQUAL(clazz, &cx_default_allocator_class)
36 CU_ASSERT_PTR_EQUAL(clazz->realloc, cx_realloc_stdlib)
37 CU_ASSERT_PTR_EQUAL(clazz->calloc, cx_calloc_stdlib)
38 CU_ASSERT_PTR_EQUAL(clazz->free, cx_free_stdlib)
39 } 36 }
40 37
41 void test_default_malloc(void) { 38 void test_default_malloc(void) {
42 void* test = cxMalloc(cxDefaultAllocator, 16); 39 void *test = cxMalloc(cxDefaultAllocator, 16);
43 CU_ASSERT_PTR_NOT_NULL(test); 40 CU_ASSERT_PTR_NOT_NULL(test);
44 free(test); 41 free(test);
45 } 42 }
46 43
47 void test_default_realloc(void) { 44 void test_default_realloc(void) {
48 void* test = calloc(8, 1); 45 void *test = calloc(8, 1);
49 memcpy(test, "Test", 4); 46 memcpy(test, "Test", 4);
50 test = cxRealloc(cxDefaultAllocator, test, 16); 47 test = cxRealloc(cxDefaultAllocator, test, 16);
51 CU_ASSERT_PTR_NOT_NULL(test); 48 CU_ASSERT_PTR_NOT_NULL(test)
52 CU_ASSERT_STRING_EQUAL("Test", test) 49 CU_ASSERT_STRING_EQUAL("Test", test)
53 free(test); 50 free(test);
54 } 51 }
55 52
56 void test_default_calloc(void) { 53 void test_default_calloc(void) {
57 void* test = cxCalloc(cxDefaultAllocator, 8, 2); 54 void *test = cxCalloc(cxDefaultAllocator, 8, 2);
58 CU_ASSERT_PTR_NOT_NULL(test); 55 CU_ASSERT_PTR_NOT_NULL(test)
59 free(test); 56 free(test);
60 } 57 }
61 58
62 void test_default_free(void) { 59 void test_default_free(void) {
63 void* test = malloc(16); 60 void *test = malloc(16);
64 cxFree(cxDefaultAllocator, test); 61 cxFree(cxDefaultAllocator, test);
65 CU_PASS("Testing standard free is not possible.") 62 CU_PASS("Testing standard free is not possible.")
66 } 63 }
67 64
68 int main() { 65 int main() {
82 (NULL == CU_add_test(suite, "default allocator available", test_default_allocator_available)) || 79 (NULL == CU_add_test(suite, "default allocator available", test_default_allocator_available)) ||
83 (NULL == CU_add_test(suite, "test of malloc()", test_default_malloc)) || 80 (NULL == CU_add_test(suite, "test of malloc()", test_default_malloc)) ||
84 (NULL == CU_add_test(suite, "test of realloc()", test_default_realloc)) || 81 (NULL == CU_add_test(suite, "test of realloc()", test_default_realloc)) ||
85 (NULL == CU_add_test(suite, "test of realloc()", test_default_calloc)) || 82 (NULL == CU_add_test(suite, "test of realloc()", test_default_calloc)) ||
86 (NULL == CU_add_test(suite, "test of free()", test_default_free)) 83 (NULL == CU_add_test(suite, "test of free()", test_default_free))
87 ) { 84 ) {
88 CU_cleanup_registry(); 85 CU_cleanup_registry();
89 return CU_get_error(); 86 return CU_get_error();
90 } 87 }
91 88
92 CU_basic_set_mode(CU_BRM_NORMAL); 89 CU_basic_set_mode(CU_BRM_NORMAL);

mercurial