blob: a0895243c5da393da63d1bd93dc2f6839638a1cf (
plain)
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
|
#include <boost/test/unit_test.hpp>
#include "mempool.h"
#include "leafdata.h"
using namespace ::boost::unit_test;
namespace mempool_test {
const char* fname = "mempool-test-delete-me";
void cleanup() {
::unlink( fname );
}
void deallocate() {
cleanup();
mempool<leaf_data_pool_traits> pool( std::auto_ptr<memory_manager>( new mmap_manager( fname ) ) );
std::vector<leafdataptr> pointers;
for ( int i = 0; i != 32; ++i ) {
pointers.push_back( pool.allocate( 16 ) );
leafdata::init( pointers.back() );
}
const unsigned size = pool.size();
for ( int i = 0; i != pointers.size(); ++i ) {
pool.deallocate(pointers.at(i));
}
for ( int i = 0; i != 32; ++i ) {
pointers.push_back( pool.allocate( 16 ) );
leafdata::init( pointers.back() );
}
BOOST_CHECK_EQUAL( size, pool.size() );
}
void large() {
cleanup();
mempool<leaf_data_pool_traits> pool( std::auto_ptr<memory_manager>( new mmap_manager( fname ) ) );
pool.allocate( 4095 );
pool.allocate( 4097 );
pool.allocate( 4096*2 );
pool.allocate( 4096*4 );
pool.allocate( 4096*8 );
}
test_suite* get_suite() {
test_suite* test = BOOST_TEST_SUITE( "Mempool Tests" );
test->add( BOOST_TEST_CASE( &deallocate ) );
test->add( BOOST_TEST_CASE( &large ) );
return test;
}
} // namespace
|