-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmem_pool_test.cc
42 lines (30 loc) · 1.03 KB
/
mem_pool_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Util/mem_pool.h"
#include "Util/assert.h"
#include <memory.h>
#include <iostream>
using namespace std;
namespace cwerg {
void BasicTest() {
MemPool<32> pool;
const uint32_t offset1 = pool.New(4);
ASSERT(offset1 == 1, "");
const uint32_t offset2 = pool.New(4);
ASSERT(offset2 == 5, "");
const uint32_t offset3 = pool.New(4);
ASSERT(offset3 == 9, "");
const uint32_t offset4 = pool.New(4);
ASSERT(offset4 == 13, "");
memset(pool.BackingStorage(offset1), 11, 4 * pool.byte_granularity());
memset(pool.BackingStorage(offset2), 22, 4 * pool.byte_granularity());
memset(pool.BackingStorage(offset3), 33, 4 * pool.byte_granularity());
memset(pool.BackingStorage(offset4), 44, 4 * pool.byte_granularity());
ASSERT(*(char*) pool.BackingStorage(offset1) == 11, "");
ASSERT(*(char*) pool.BackingStorage(offset2) == 22, "");
ASSERT(*(char*) pool.BackingStorage(offset3) == 33, "");
ASSERT(*(char*) pool.BackingStorage(offset4) == 44, "");
}
} // namespace cwerg
int main() {
cwerg::BasicTest();
return 0;
}