test/mpool_tests.c

Sun, 04 Nov 2012 20:50:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 04 Nov 2012 20:50:12 +0100
changeset 75
990734f548ef
parent 69
fb59270b1de3
child 103
08018864fb91
permissions
-rw-r--r--

fixed some compiler warnings

13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 *
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 */
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
5 #include <stdint.h>
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
6
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 #include "mpool_tests.h"
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
9 UCX_TEST_IMPLEMENT(test_ucx_mempool_new) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
10 UcxMempool *pool = ucx_mempool_new(16);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
11 UCX_TEST_BEGIN
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
12 UCX_TEST_ASSERT(pool->size == 16, "wrong size");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
13 UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
14 UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
15 UCX_TEST_END
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
16 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
17 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
19 UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
20
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
21 UcxMempool *pool = ucx_mempool_new(1);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
22 UCX_TEST_BEGIN
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
23 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
24
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
25 UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
26 UCX_TEST_ASSERT(pool->size == 1, "chcap called");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
27
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
28 intptr_t *pooladdr =
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
29 (intptr_t*)((char*)pool->data[0] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
30 *pooladdr = 5;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
31
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
32 UCX_TEST_ASSERT(*test == 5, "wrong pointer");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
33
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
34 UCX_TEST_END
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
35 ucx_mempool_free(pool);
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 }
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
38 UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
39
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
40 UcxMempool *pool = ucx_mempool_new(1);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
41 UCX_TEST_BEGIN
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
42 ucx_mempool_malloc(pool, sizeof(int));
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
43 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
44
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
45 UCX_TEST_ASSERT(pool->ndata == 2, "counter not incremented");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
46 UCX_TEST_ASSERT(pool->size == 17, "chcap not called");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
47
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
48 intptr_t *pooladdr =
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
49 (intptr_t*)((char*)pool->data[1] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
50 *pooladdr = 5;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
51
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
52 UCX_TEST_ASSERT(*test == 5, "wrong pointer");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
53
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
54 UCX_TEST_END
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
55 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
56 }
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
57
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
58 UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
59
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
60 UcxMempool *pool = ucx_mempool_new(1);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
61 UCX_TEST_BEGIN
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
62
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
63 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
64
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
65 UCX_TEST_ASSERT(test != NULL, "no memory for test data");
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
66 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
67
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
68 UCX_TEST_END
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
69 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
70 }
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
71
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
72 void test_setdestr(void* elem) {
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
73 intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1];
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
74 *cb = 42;
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 }
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
77 UCX_TEST_IMPLEMENT(test_ucx_mempool_set_destr) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
78
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
79 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
80 UCX_TEST_BEGIN
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
81 UcxMempool *pool = ucx_mempool_new(2);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
82
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
83 ucx_mempool_malloc(pool, sizeof(intptr_t));
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
84 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
85
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
86 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
87
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
88 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
89 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
90
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
91 ucx_mempool_set_destr(test, test_setdestr);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
92 UCX_TEST_ASSERT(
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
93 *(ucx_destructor*)(pool->data[1]) == test_setdestr, "failed")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
94 UCX_TEST_ASSERT(
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
95 test[0] == 5 && test[1] == (intptr_t) cb, "setdestr destroyed data")
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
96
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
97 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
98
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
99 UCX_TEST_ASSERT(*cb == 42, "destructor not called");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
100
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
101 UCX_TEST_END
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
102 if (cb != NULL) free(cb);
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
103 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
106 UCX_TEST_IMPLEMENT(test_ucx_mempool_reg_destr) {
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
107
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
108 intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t));
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
109 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
110 UCX_TEST_BEGIN
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
111 UcxMempool *pool = ucx_mempool_new(1);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
112
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
113 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
114
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
115 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
116 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
117
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
118 ucx_mempool_reg_destr(pool, test, test_setdestr);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
119
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
120 ucx_destructor *pooladdr = (ucx_destructor*)
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
121 ((char*)pool->data[0] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
122
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
123 UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
124
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
125 ucx_mempool_free(pool);
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
126 UCX_TEST_ASSERT(*cb == 42, "destructor not called");
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
127 UCX_TEST_END
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
128
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
129 if (test != NULL) free(test);
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
130 if (cb != NULL) free(cb);
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
131 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
133 UCX_TEST_IMPLEMENT(test_ucx_mempool_realloc) {
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
134
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
135 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
136 UCX_TEST_BEGIN
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
137 UcxMempool *pool = ucx_mempool_new(2);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
138
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
139 ucx_mempool_malloc(pool, sizeof(intptr_t));
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
140 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
141
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
142 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data");
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
143
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
144 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
145 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
146
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
147 ucx_mempool_set_destr(test, test_setdestr);
14
b78e174b6814 Fixed realloc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
148
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
149 intptr_t *rtest, n = 2;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
150 do {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
151 n *= 2;
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
152 UCX_TEST_ASSERT(n < 65536, "test corrupt - no movement for realloc");
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 40
diff changeset
153 rtest = (intptr_t*) ucx_mempool_realloc(pool, test, n*sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
154 } while (rtest == test);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
155 test = rtest;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
156
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
157 UCX_TEST_ASSERT(*(ucx_destructor*)(pool->data[1]) == test_setdestr,
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
158 "realloc killed destructor")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
159 UCX_TEST_ASSERT(
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
160 test[0] == 5 && test[1] == (intptr_t) cb, "realloc destroyed data")
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
161
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
162 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
163
40
583718dd4cf3 added semicolons to assert makros
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
164 UCX_TEST_ASSERT(*cb == 42, "destructor not called");
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
166 UCX_TEST_END
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
167 if (cb != NULL) free(cb);
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }

mercurial