summaryrefslogtreecommitdiffstats
path: root/indexlib/tests/leafdatavector-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/leafdatavector-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/leafdatavector-test.cpp')
-rw-r--r--indexlib/tests/leafdatavector-test.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/indexlib/tests/leafdatavector-test.cpp b/indexlib/tests/leafdatavector-test.cpp
new file mode 100644
index 000000000..8763327e6
--- /dev/null
+++ b/indexlib/tests/leafdatavector-test.cpp
@@ -0,0 +1,129 @@
+#include <boost/test/unit_test.hpp>
+#include <map>
+#include "leafdatavector.h"
+
+using namespace ::boost::unit_test;
+namespace leafdatavector_test {
+
+const char* fname = "leafdatavector-test-delete-me";
+void cleanup() {
+ leafdatavector::remove( fname );
+}
+
+void simple() {
+ cleanup();
+ leafdatavector f( fname );
+ f.add( 0, 1 );
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 1u );
+ BOOST_CHECK_EQUAL( f.get( 0 )[ 0 ], 1u );
+ f.add( 0, 2 );
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 2u );
+}
+
+void persistent() {
+ cleanup();
+ {
+ leafdatavector f( fname );
+ f.add( 0, 1 );
+ }
+ {
+ leafdatavector f( fname );
+ BOOST_CHECK_EQUAL( f.get( 0 )[ 0 ], 1u );
+ }
+}
+
+void complicated() {
+ cleanup();
+ leafdatavector f( fname );
+
+ f.add( 0, 1 );
+ f.add( 0, 3 );
+ f.add( 1, 3 );
+ f.add( 0, 2 );
+ f.add( 0, 4 );
+ f.add( 1, 8 );
+ f.add( 2, 4 );
+ f.add( 1, 5 );
+ f.add( 2, 5 );
+ f.add( 0, 5 );
+ f.add( 0, 9 );
+
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 6u );
+ BOOST_CHECK_EQUAL( f.get( 1 ).size(), 3u );
+ BOOST_CHECK_EQUAL( f.get( 2 ).size(), 2u );
+ std::vector<unsigned> one = f.get( 1 );
+ std::sort( one.begin(), one.end() );
+ BOOST_CHECK_EQUAL( one.size(), 3u );
+ BOOST_CHECK_EQUAL( one[ 0 ], 3u );
+ BOOST_CHECK_EQUAL( one[ 1 ], 5u );
+ BOOST_CHECK_EQUAL( one[ 2 ], 8u );
+}
+
+void unique() {
+ cleanup();
+ leafdatavector f( fname );
+
+ f.add( 0, 1 );
+ f.add( 0, 1 );
+ f.add( 0, 1 );
+
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 1u );
+
+ f.add( 0, 4 );
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 2u );
+
+ f.add( 0, 1 );
+ f.add( 0, 4 );
+
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 2u );
+
+}
+
+void large() {
+ cleanup();
+ leafdatavector f( fname );
+ std::map<uint, uint> counts;
+
+ for ( uint i = 0; i != 32; ++i ) {
+ for ( uint j = 0; j != 256 + 3; ++j ) {
+ uint ref = i * ( j + 51 ) / 13 + i % 75 + j + 3;
+ f.add( j, ref );
+ ++counts[ j ];
+ }
+ }
+ for ( std::map<uint,uint>::const_iterator first = counts.begin(), past = counts.end();
+ first != past; ++first ) {
+ BOOST_CHECK_EQUAL( first->second, f.get( first->first ).size() );
+ }
+
+}
+
+void one_zero() {
+ cleanup();
+ leafdatavector f( fname );
+
+ f.add( 0, 0 );
+ f.add( 0, 1 );
+ f.add( 0, 3 );
+
+ BOOST_CHECK_EQUAL( f.get( 0 ).size(), 3u );
+ BOOST_CHECK_EQUAL( f.get( 0 )[ 0 ], 0u );
+ BOOST_CHECK_EQUAL( f.get( 0 )[ 1 ], 1u );
+ BOOST_CHECK_EQUAL( f.get( 0 )[ 2 ], 3u );
+
+}
+
+
+test_suite* get_suite() {
+ test_suite* test = BOOST_TEST_SUITE( "leafdatavector tests" );
+ test->add( BOOST_TEST_CASE( &simple ) );
+ test->add( BOOST_TEST_CASE( &persistent ) );
+ test->add( BOOST_TEST_CASE( &complicated ) );
+ test->add( BOOST_TEST_CASE( &unique ) );
+ test->add( BOOST_TEST_CASE( &large ) );
+ test->add( BOOST_TEST_CASE( &one_zero ) );
+ return test;
+}
+
+} // namespace
+