test/test_basic_mempool.cpp

Wed, 03 Aug 2022 17:27:55 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 03 Aug 2022 17:27:55 +0200
changeset 571
f83583a0bbac
child 572
f0f99dd06d9f
permissions
-rw-r--r--

#201 - add mempool implementation

571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/basic_mempool.h"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include <gtest/gtest.h>
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 class CxBasicMempool : public ::testing::Test {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 protected:
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 CxTestingAllocator testingAllocator;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 CxMempool *pool = nullptr;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 void TearDown() override {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 if (pool != nullptr) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 cxMempoolDestroy(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 EXPECT_TRUE(testingAllocator.verify());
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 };
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 TEST_F(CxBasicMempool, Create) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 pool = cxBasicMempoolCreateSimple(16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 ASSERT_NE(pool->allocator, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 ASSERT_NE(pool->cl, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 EXPECT_NE(pool->cl->destroy, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 ASSERT_NE(pool->allocator->cl, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 EXPECT_EQ(pool->allocator->data, pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 EXPECT_NE(pool->allocator->cl->malloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 EXPECT_NE(pool->allocator->cl->calloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 EXPECT_NE(pool->allocator->cl->realloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 EXPECT_NE(pool->allocator->cl->free, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 EXPECT_EQ(basic_pool->allocator, cxDefaultAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 EXPECT_EQ(basic_pool->size, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 EXPECT_EQ(basic_pool->ndata, 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 EXPECT_NE(basic_pool->data, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 TEST_F(CxBasicMempool, malloc) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 pool = cxBasicMempoolCreate(4, &testingAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 EXPECT_EQ(testingAllocator.alloc_total, 2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 EXPECT_EQ(basic_pool->ndata, 2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 EXPECT_EQ(basic_pool->size, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 EXPECT_EQ(testingAllocator.alloc_total, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 EXPECT_EQ(basic_pool->ndata, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 EXPECT_EQ(basic_pool->size, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 EXPECT_EQ(testingAllocator.alloc_total, 6);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 EXPECT_EQ(basic_pool->ndata, 6);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 EXPECT_GE(basic_pool->size, 6);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 EXPECT_TRUE(testingAllocator.used());
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 TEST_F(CxBasicMempool, calloc) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 pool = cxBasicMempoolCreate(4, &testingAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 auto test = (int *) cxCalloc(pool->allocator, 2, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 ASSERT_NE(test, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 EXPECT_EQ(test[0], 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 EXPECT_EQ(test[1], 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 EXPECT_TRUE(testingAllocator.used());
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 static unsigned test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 static void test_destructor([[maybe_unused]] void *mem) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 test_destructor_called++;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 TEST_F(CxBasicMempool, destructor) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 pool = cxBasicMempoolCreate(4, &testingAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 auto data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 *((int *) data) = 13;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 EXPECT_EQ(*((int *) data), 13);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 cxFree(pool->allocator, data);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 EXPECT_EQ(test_destructor_called, 1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 cxMempoolDestroy(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 pool = nullptr;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 EXPECT_EQ(test_destructor_called, 2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 TEST_F(CxBasicMempool, realloc) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 pool = cxBasicMempoolCreate(4, &testingAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 auto data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 *((int *) data) = 13;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 void *rdata = data;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 unsigned n = 1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 while (rdata == data) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 n <<= 1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 ASSERT_LT(n, 65536); // eventually the memory should be moved elsewhere
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 rdata = cxRealloc(pool->allocator, data, n * sizeof(intptr_t));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 EXPECT_EQ(*((int *) rdata), 13);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 // test if destructor is still intact
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 cxFree(pool->allocator, rdata);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 EXPECT_EQ(test_destructor_called, 1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 TEST_F(CxBasicMempool, free) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 pool = cxBasicMempoolCreate(4, &testingAllocator);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 void *mem1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 void *mem2;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 mem1 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 cxFree(pool->allocator, mem1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 EXPECT_EQ(basic_pool->ndata, 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 mem1 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 mem2 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 EXPECT_EQ(basic_pool->ndata, 5);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 cxFree(pool->allocator, mem1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 EXPECT_EQ(basic_pool->ndata, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 cxFree(pool->allocator, mem2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 EXPECT_EQ(basic_pool->ndata, 3);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 }

mercurial