summaryrefslogtreecommitdiffstats
path: root/indexlib/tests/mempool-test.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /indexlib/tests/mempool-test.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
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
Diffstat (limited to 'indexlib/tests/mempool-test.cpp')
-rw-r--r--indexlib/tests/mempool-test.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/indexlib/tests/mempool-test.cpp b/indexlib/tests/mempool-test.cpp
new file mode 100644
index 000000000..a0895243c
--- /dev/null
+++ b/indexlib/tests/mempool-test.cpp
@@ -0,0 +1,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
+