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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (C) 2013 Codership Oy <info@codership.com>
// $Id: gu_mem_pool_test.cpp 3446 2014-01-13 01:33:30Z teemu $
#define TEST_SIZE 1024
#include "gu_mem_pool.hpp"
#include "gu_mem_pool_test.hpp"
START_TEST (unsafe)
{
gu::MemPoolUnsafe mp(10, 1, "unsafe");
void* const buf0(mp.acquire());
fail_if(NULL == buf0);
void* const buf1(mp.acquire());
fail_if(NULL == buf1);
fail_if(buf0 == buf1);
mp.recycle(buf0);
void* const buf2(mp.acquire());
fail_if(NULL == buf2);
fail_if(buf0 != buf2);
log_info << mp;
mp.recycle(buf1);
mp.recycle(buf2);
}
END_TEST
START_TEST (safe)
{
gu::MemPoolSafe mp(10, 1, "safe");
void* const buf0(mp.acquire());
fail_if(NULL == buf0);
void* const buf1(mp.acquire());
fail_if(NULL == buf1);
fail_if(buf0 == buf1);
mp.recycle(buf0);
void* const buf2(mp.acquire());
fail_if(NULL == buf2);
fail_if(buf0 != buf2);
log_info << mp;
mp.recycle(buf1);
mp.recycle(buf2);
}
END_TEST
Suite *gu_mem_pool_suite(void)
{
Suite *s = suite_create("gu::MemPool");
TCase *tc_mem = tcase_create("gu_mem_pool");
suite_add_tcase (s, tc_mem);
tcase_add_test(tc_mem, unsafe);
tcase_add_test(tc_mem, safe);
return s;
}
|