From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- indexlib/tests/mempool-test.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 indexlib/tests/mempool-test.cpp (limited to 'indexlib/tests/mempool-test.cpp') diff --git a/indexlib/tests/mempool-test.cpp b/indexlib/tests/mempool-test.cpp new file mode 100644 index 00000000..a0895243 --- /dev/null +++ b/indexlib/tests/mempool-test.cpp @@ -0,0 +1,53 @@ +#include +#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 pool( std::auto_ptr( new mmap_manager( fname ) ) ); + + std::vector 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 pool( std::auto_ptr( 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 + -- cgit v1.2.3