test/mpool_tests.c

changeset 30
23bb65cbf7a4
parent 28
1666cbeb1db8
child 32
c7af4ec56e19
     1.1 --- a/test/mpool_tests.c	Tue Feb 21 01:13:17 2012 +0100
     1.2 +++ b/test/mpool_tests.c	Fri Feb 24 15:53:50 2012 +0100
     1.3 @@ -2,6 +2,8 @@
     1.4   *
     1.5   */
     1.6  
     1.7 +#include <inttypes.h>
     1.8 +
     1.9  #include "mpool_tests.h"
    1.10  
    1.11  UCX_TEST_BEGIN(test_ucx_mempool_new) {
    1.12 @@ -70,7 +72,7 @@
    1.13  }
    1.14  
    1.15  void test_setdestr(void* elem) {
    1.16 -    int *cb = (int*) ((int*) elem)[1];
    1.17 +    intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1];
    1.18      *cb = 42;
    1.19  }
    1.20  
    1.21 @@ -79,20 +81,19 @@
    1.22      UcxMempool *pool = ucx_mempool_new(2);
    1.23      
    1.24      ucx_mempool_malloc(pool, sizeof(int));
    1.25 -    int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int));
    1.26 +    intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
    1.27      
    1.28 -    int *cb = (int*) malloc(sizeof(int));
    1.29 +    int *cb = (intptr_t*) malloc(sizeof(intptr_t));
    1.30      UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
    1.31      
    1.32 -    test[0] = 5; test[1] = (int) cb;
    1.33 +    test[0] = 5; test[1] = (intptr_t) cb;
    1.34      *cb = 13;
    1.35      
    1.36      ucx_mempool_set_destr(test, test_setdestr);
    1.37 -    
    1.38      UCX_TEST_ASSERT(
    1.39              *(ucx_destructor*)(pool->data[1]) == test_setdestr, "failed")
    1.40      UCX_TEST_ASSERT(
    1.41 -            test[0] == 5 && test[1] == (int) cb, "setdestr destroyed data")
    1.42 +            test[0] == 5 && test[1] == (intptr_t) cb, "setdestr destroyed data")
    1.43      
    1.44      ucx_mempool_free(pool);
    1.45      
    1.46 @@ -108,22 +109,23 @@
    1.47      
    1.48      UcxMempool *pool = ucx_mempool_new(1);
    1.49      
    1.50 -    int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int));
    1.51 +    intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t));
    1.52      
    1.53 -    int *cb = (int*) malloc(sizeof(int));
    1.54 +    intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
    1.55      UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
    1.56      
    1.57 -    test[0] = 5; test[1] = (int) cb;
    1.58 +    test[0] = 5; test[1] = (intptr_t) cb;
    1.59      *cb = 13;
    1.60      
    1.61      ucx_mempool_reg_destr(pool, test, test_setdestr);
    1.62      
    1.63      ucx_destructor *pooladdr = (ucx_destructor*)
    1.64 -            ((char*)pool->data[1] + sizeof(ucx_destructor));
    1.65 +            ((char*)pool->data[0] + sizeof(ucx_destructor));
    1.66      
    1.67      UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed")
    1.68      
    1.69      ucx_mempool_free(pool);
    1.70 +    free(test);
    1.71      
    1.72      UCX_TEST_ASSERT(*cb == 42, "destructor not called")
    1.73  
    1.74 @@ -137,12 +139,12 @@
    1.75      UcxMempool *pool = ucx_mempool_new(2);
    1.76      
    1.77      ucx_mempool_malloc(pool, sizeof(int));
    1.78 -    int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int));
    1.79 +    intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
    1.80      
    1.81 -    int *cb = (int*) malloc(sizeof(int));
    1.82 +    intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
    1.83      UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
    1.84      
    1.85 -    test[0] = 5; test[1] = (int) cb;
    1.86 +    test[0] = 5; test[1] = (intptr_t) cb;
    1.87      *cb = 13;
    1.88      
    1.89      ucx_mempool_set_destr(test, test_setdestr);
    1.90 @@ -151,14 +153,14 @@
    1.91      do {
    1.92          n *= 2;
    1.93          UCX_TEST_ASSERT(n < 65536, "test corrupt - no movement for realloc")
    1.94 -        rtest = ucx_mempool_realloc(pool, test, n*sizeof(int));
    1.95 +        rtest = ucx_mempool_realloc(pool, test, n*sizeof(intptr_t));
    1.96      } while (rtest == test);
    1.97      test = rtest;
    1.98      
    1.99      UCX_TEST_ASSERT(*(ucx_destructor*)(pool->data[1]) == test_setdestr,
   1.100              "realloc killed destructor")
   1.101      UCX_TEST_ASSERT(
   1.102 -            test[0] == 5 && test[1] == (int) cb, "realloc destroyed data")
   1.103 +            test[0] == 5 && test[1] == (intptr_t) cb, "realloc destroyed data")
   1.104      
   1.105      ucx_mempool_free(pool);
   1.106      

mercurial