summaryrefslogtreecommitdiffstats
path: root/indexlib/tests/match-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/match-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/match-test.cpp')
-rw-r--r--indexlib/tests/match-test.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/indexlib/tests/match-test.cpp b/indexlib/tests/match-test.cpp
new file mode 100644
index 000000000..16b8a8e95
--- /dev/null
+++ b/indexlib/tests/match-test.cpp
@@ -0,0 +1,99 @@
+#include <boost/test/unit_test.hpp>
+#include "match.h"
+
+using namespace ::boost::unit_test;
+namespace match_test {
+using indexlib::Match;
+
+void cleanup() {
+}
+
+void simple() {
+ cleanup();
+ Match m( "pat" );
+ BOOST_CHECK_EQUAL( m.process( "not here" ), false );
+ BOOST_CHECK_EQUAL( m.process( "p a t" ), false );
+ BOOST_CHECK_EQUAL( m.process( "pa t" ), false );
+
+
+ BOOST_CHECK_EQUAL( m.process( "pat" ), true );
+ BOOST_CHECK_EQUAL( m.process( "pattern" ), true );
+ BOOST_CHECK_EQUAL( m.process( " pat " ), true );
+ BOOST_CHECK_EQUAL( m.process( "zpat patx ipato " ), true );
+}
+
+void empty() {
+ cleanup();
+ {
+ Match m( "pat" );
+ BOOST_CHECK( !m.process( "" ) );
+ }
+ {
+ Match m( "" );
+ BOOST_CHECK( m.process( "" ) );
+ BOOST_CHECK( m.process( "string" ) );
+ }
+}
+
+
+void string() {
+ cleanup();
+ Match m( std::string( "pat" ) );
+
+ BOOST_CHECK_EQUAL( m.process( std::string( "not here" ) ), false );
+ BOOST_CHECK_EQUAL( m.process( std::string( "here pattern" ) ), true );
+}
+
+void casesensitive() {
+ cleanup();
+ Match m( std::string( "pat" ), ~Match::caseinsensitive );
+
+ BOOST_CHECK_EQUAL( m.process( std::string( "PAT" ) ), false );
+ BOOST_CHECK_EQUAL( m.process( std::string( "aPATa" ) ), false );
+ BOOST_CHECK_EQUAL( m.process( std::string( "pAt" ) ), false );
+ BOOST_CHECK_EQUAL( m.process( std::string( "pattern" ) ), true );
+}
+
+void caseinsensitive() {
+ cleanup();
+ Match m( std::string( "pat" ), Match::caseinsensitive );
+
+ BOOST_CHECK_EQUAL( m.process( std::string( "PAT" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "aPATa" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "pAt" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "pattern" ) ), true );
+}
+
+
+void verylarge() {
+ cleanup();
+ Match m( std::string( "pat0123456789012345678901234567890" ) );
+
+ BOOST_CHECK_EQUAL( m.process( std::string( "pat0123456789012345678901234567890" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat0123456789012345678901234567890" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat0123456789012345678901234567890xxxxxxxx" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat01234x6789012345678901234567890xxxxxxxx" ) ), false );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat01234x678901234567890123456789xxxxxxxxx" ) ), false );
+
+ m = Match( std::string( "12345678901234567890123456789012" ) );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat012345678901234567890123456789012xxxxxxxxx" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat012345678901234567890123456789012" ) ), true );
+ BOOST_CHECK_EQUAL( m.process( std::string( "xxxxxxpat01234x678901234567890123456789xxxxxxxxx" ) ), false );
+}
+
+
+
+
+test_suite* get_suite() {
+ test_suite* test = BOOST_TEST_SUITE( "Match tests" );
+ test->add( BOOST_TEST_CASE( &simple ) );
+ test->add( BOOST_TEST_CASE( &empty ) );
+ test->add( BOOST_TEST_CASE( &string ) );
+ test->add( BOOST_TEST_CASE( &casesensitive ) );
+ test->add( BOOST_TEST_CASE( &caseinsensitive ) );
+ test->add( BOOST_TEST_CASE( &verylarge ) );
+ return test;
+}
+
+} // namespace
+