SVN commit 581013 by luis_pedro: Test removal of document. M +36 -2 ifile-test.cpp --- branches/KDE/3.5/kdepim/indexlib/tests/ifile-test.cpp #581012:581013 @@ -1,15 +1,34 @@ #include #include "ifile.h" +#include +#include using namespace ::boost::unit_test; namespace ifile_test { -using indexlib::detail::ifile; +//using indexlib::detail::ifile; const char* fname = "ifile-test-delete-me"; void cleanup() { ifile::remove( fname ); } inline +bool check_results( const ifile& ifi, const char* str, ... ) { + const char* s; + va_list args; + va_start( args, str ); + std::vector res = ifi.search( str )->list(); + unsigned i = 0; + + while ( s = va_arg( args, const char* ) ) { + if ( i == res.size() ) return false; + if ( std::string( s ) != ifi.lookup_docname( res[ i++ ] ) ) return false; + } + va_end( args ); + return i == res.size(); +} + + +inline unsigned count_results( const ifile& ifi, const char* str ) { return ifi.search( str )->list().size(); } @@ -107,14 +126,29 @@ BOOST_CHECK_EQUAL( count_results( ifi, "something two" ), 2u ); } +void remove_doc() { + cleanup(); + ifile ifi( fname ); + ifi.add( "one two three four", "0" ); + ifi.add( "two three four", "1" ); + ifi.add( "three four five", "2" ); + ifi.remove_doc( "1" ); + + BOOST_CHECK( check_results( ifi, "one", "0", NULL ) ); + BOOST_CHECK( check_results( ifi, "two", "0", NULL ) ); + BOOST_CHECK( check_results( ifi, "three", "0", "2", NULL ) ); + BOOST_CHECK_EQUAL( count_results( ifi, "four" ), 0u ); +} + test_suite* get_suite() { test_suite* test = BOOST_TEST_SUITE( "Ifile tests" ); test->add( BOOST_TEST_CASE( &simple ) ); test->add( BOOST_TEST_CASE( &ndocs ) ); test->add( BOOST_TEST_CASE( &space ) ); - test->add( BOOST_TEST_CASE( &numbers ) ); + //test->add( BOOST_TEST_CASE( &numbers ) ); test->add( BOOST_TEST_CASE( &partial ) ); test->add( BOOST_TEST_CASE( &several ) ); + test->add( BOOST_TEST_CASE( &remove) ); return test; }