diff -r c7af4ec56e19 -r 9c219a62070d test/mpool_tests.c --- a/test/mpool_tests.c Thu May 31 09:18:26 2012 +0200 +++ b/test/mpool_tests.c Thu May 31 12:51:22 2012 +0200 @@ -6,22 +6,20 @@ #include "mpool_tests.h" -UCX_TEST_BEGIN(test_ucx_mempool_new) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_new) { UcxMempool *pool = ucx_mempool_new(16); - + UCX_TEST_BEGIN UCX_TEST_ASSERT(pool->size == 16, "wrong size") UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter") UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed") - + UCX_TEST_END ucx_mempool_free(pool); - - UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_mempool_malloc) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) { UcxMempool *pool = ucx_mempool_new(1); - + UCX_TEST_BEGIN intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented") @@ -33,15 +31,14 @@ UCX_TEST_ASSERT(*test == 5, "wrong pointer") + UCX_TEST_END ucx_mempool_free(pool); - - UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_mempool_malloc_with_chcap) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) { UcxMempool *pool = ucx_mempool_new(1); - + UCX_TEST_BEGIN ucx_mempool_malloc(pool, sizeof(int)); intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); @@ -54,23 +51,22 @@ UCX_TEST_ASSERT(*test == 5, "wrong pointer") + UCX_TEST_END ucx_mempool_free(pool); - - UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_mempool_calloc) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) { UcxMempool *pool = ucx_mempool_new(1); + UCX_TEST_BEGIN intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); UCX_TEST_ASSERT(test != NULL, "no memory for test data") UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed") + UCX_TEST_END ucx_mempool_free(pool); - - UCX_TEST_END } void test_setdestr(void* elem) { @@ -78,14 +74,15 @@ *cb = 42; } -UCX_TEST_BEGIN(test_ucx_mempool_set_destr) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_set_destr) { + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); + UCX_TEST_BEGIN UcxMempool *pool = ucx_mempool_new(2); ucx_mempool_malloc(pool, sizeof(intptr_t)); intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") test[0] = 5; test[1] = (intptr_t) cb; @@ -100,20 +97,19 @@ ucx_mempool_free(pool); UCX_TEST_ASSERT(*cb == 42, "destructor not called") - - free(cb); UCX_TEST_END + if (cb != NULL) free(cb); } -UCX_TEST_BEGIN(test_ucx_mempool_reg_destr) { +UCX_TEST_IMPLEMENT(test_ucx_mempool_reg_destr) { + intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); + UCX_TEST_BEGIN UcxMempool *pool = ucx_mempool_new(1); - intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); - - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") test[0] = 5; test[1] = (intptr_t) cb; @@ -127,23 +123,22 @@ UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed") ucx_mempool_free(pool); - free(test); - UCX_TEST_ASSERT(*cb == 42, "destructor not called") + UCX_TEST_END - free(cb); - - UCX_TEST_END + if (test != NULL) free(test); + if (cb != NULL) free(cb); } -UCX_TEST_BEGIN(test_ucx_mempool_realloc) { - +UCX_TEST_IMPLEMENT(test_ucx_mempool_realloc) { + + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); + UCX_TEST_BEGIN UcxMempool *pool = ucx_mempool_new(2); ucx_mempool_malloc(pool, sizeof(intptr_t)); intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); - - intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); + UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") test[0] = 5; test[1] = (intptr_t) cb; @@ -167,8 +162,7 @@ ucx_mempool_free(pool); UCX_TEST_ASSERT(*cb == 42, "destructor not called") - - free(cb); UCX_TEST_END + if (cb != NULL) free(cb); }