1.1 --- a/test/mpool_tests.c Thu May 31 09:18:26 2012 +0200 1.2 +++ b/test/mpool_tests.c Thu May 31 12:51:22 2012 +0200 1.3 @@ -6,22 +6,20 @@ 1.4 1.5 #include "mpool_tests.h" 1.6 1.7 -UCX_TEST_BEGIN(test_ucx_mempool_new) { 1.8 +UCX_TEST_IMPLEMENT(test_ucx_mempool_new) { 1.9 UcxMempool *pool = ucx_mempool_new(16); 1.10 - 1.11 + UCX_TEST_BEGIN 1.12 UCX_TEST_ASSERT(pool->size == 16, "wrong size") 1.13 UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter") 1.14 UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed") 1.15 - 1.16 + UCX_TEST_END 1.17 ucx_mempool_free(pool); 1.18 - 1.19 - UCX_TEST_END 1.20 } 1.21 1.22 -UCX_TEST_BEGIN(test_ucx_mempool_malloc) { 1.23 +UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) { 1.24 1.25 UcxMempool *pool = ucx_mempool_new(1); 1.26 - 1.27 + UCX_TEST_BEGIN 1.28 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); 1.29 1.30 UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented") 1.31 @@ -33,15 +31,14 @@ 1.32 1.33 UCX_TEST_ASSERT(*test == 5, "wrong pointer") 1.34 1.35 + UCX_TEST_END 1.36 ucx_mempool_free(pool); 1.37 - 1.38 - UCX_TEST_END 1.39 } 1.40 1.41 -UCX_TEST_BEGIN(test_ucx_mempool_malloc_with_chcap) { 1.42 +UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) { 1.43 1.44 UcxMempool *pool = ucx_mempool_new(1); 1.45 - 1.46 + UCX_TEST_BEGIN 1.47 ucx_mempool_malloc(pool, sizeof(int)); 1.48 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); 1.49 1.50 @@ -54,23 +51,22 @@ 1.51 1.52 UCX_TEST_ASSERT(*test == 5, "wrong pointer") 1.53 1.54 + UCX_TEST_END 1.55 ucx_mempool_free(pool); 1.56 - 1.57 - UCX_TEST_END 1.58 } 1.59 1.60 -UCX_TEST_BEGIN(test_ucx_mempool_calloc) { 1.61 +UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) { 1.62 1.63 UcxMempool *pool = ucx_mempool_new(1); 1.64 + UCX_TEST_BEGIN 1.65 1.66 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); 1.67 1.68 UCX_TEST_ASSERT(test != NULL, "no memory for test data") 1.69 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed") 1.70 1.71 + UCX_TEST_END 1.72 ucx_mempool_free(pool); 1.73 - 1.74 - UCX_TEST_END 1.75 } 1.76 1.77 void test_setdestr(void* elem) { 1.78 @@ -78,14 +74,15 @@ 1.79 *cb = 42; 1.80 } 1.81 1.82 -UCX_TEST_BEGIN(test_ucx_mempool_set_destr) { 1.83 +UCX_TEST_IMPLEMENT(test_ucx_mempool_set_destr) { 1.84 1.85 + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.86 + UCX_TEST_BEGIN 1.87 UcxMempool *pool = ucx_mempool_new(2); 1.88 1.89 ucx_mempool_malloc(pool, sizeof(intptr_t)); 1.90 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); 1.91 1.92 - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.93 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") 1.94 1.95 test[0] = 5; test[1] = (intptr_t) cb; 1.96 @@ -100,20 +97,19 @@ 1.97 ucx_mempool_free(pool); 1.98 1.99 UCX_TEST_ASSERT(*cb == 42, "destructor not called") 1.100 - 1.101 - free(cb); 1.102 1.103 UCX_TEST_END 1.104 + if (cb != NULL) free(cb); 1.105 } 1.106 1.107 1.108 -UCX_TEST_BEGIN(test_ucx_mempool_reg_destr) { 1.109 +UCX_TEST_IMPLEMENT(test_ucx_mempool_reg_destr) { 1.110 1.111 + intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); 1.112 + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.113 + UCX_TEST_BEGIN 1.114 UcxMempool *pool = ucx_mempool_new(1); 1.115 1.116 - intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); 1.117 - 1.118 - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.119 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") 1.120 1.121 test[0] = 5; test[1] = (intptr_t) cb; 1.122 @@ -127,23 +123,22 @@ 1.123 UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed") 1.124 1.125 ucx_mempool_free(pool); 1.126 - free(test); 1.127 - 1.128 UCX_TEST_ASSERT(*cb == 42, "destructor not called") 1.129 + UCX_TEST_END 1.130 1.131 - free(cb); 1.132 - 1.133 - UCX_TEST_END 1.134 + if (test != NULL) free(test); 1.135 + if (cb != NULL) free(cb); 1.136 } 1.137 1.138 -UCX_TEST_BEGIN(test_ucx_mempool_realloc) { 1.139 - 1.140 +UCX_TEST_IMPLEMENT(test_ucx_mempool_realloc) { 1.141 + 1.142 + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.143 + UCX_TEST_BEGIN 1.144 UcxMempool *pool = ucx_mempool_new(2); 1.145 1.146 ucx_mempool_malloc(pool, sizeof(intptr_t)); 1.147 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); 1.148 - 1.149 - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); 1.150 + 1.151 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") 1.152 1.153 test[0] = 5; test[1] = (intptr_t) cb; 1.154 @@ -167,8 +162,7 @@ 1.155 ucx_mempool_free(pool); 1.156 1.157 UCX_TEST_ASSERT(*cb == 42, "destructor not called") 1.158 - 1.159 - free(cb); 1.160 1.161 UCX_TEST_END 1.162 + if (cb != NULL) free(cb); 1.163 }