From 2f1a2fa9c7828cf836377f168ce4199a43df2c56 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Sun, 20 Jun 2010 20:58:32 +0000 Subject: [PATCH] More FTS tests. --- src/core/database.h | 1 + tests/database_test.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/core/database.h b/src/core/database.h index a5d884adf..f89278eec 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -77,6 +77,7 @@ class Database : public QObject { FRIEND_TEST(DatabaseTest, FTSOpenParsesSimpleInput); FRIEND_TEST(DatabaseTest, FTSOpenParsesUTF8Input); FRIEND_TEST(DatabaseTest, FTSOpenParsesMultipleTokens); + FRIEND_TEST(DatabaseTest, FTSCursorWorks); // Do static initialisation like loading sqlite functions. static void StaticInit(); diff --git a/tests/database_test.cpp b/tests/database_test.cpp index de508a495..87f9e7c8c 100644 --- a/tests/database_test.cpp +++ b/tests/database_test.cpp @@ -180,3 +180,34 @@ TEST_F(DatabaseTest, FTSOpenParsesMultipleTokens) { EXPECT_EQ(10, tokens[1].start_offset); EXPECT_EQ(13, tokens[1].end_offset); } + +TEST_F(DatabaseTest, FTSCursorWorks) { + sqlite3_tokenizer_cursor* cursor = NULL; + Database::FTSOpen(NULL, "Röyksopp foo", 13, &cursor); + ASSERT_TRUE(cursor); + Database::UnicodeTokenizerCursor* real_cursor = reinterpret_cast(cursor); + + const char* token; + int bytes = 0; + int start_offset = 42; + int end_offset = 0; + int position = 42; + int rc = Database::FTSNext(cursor, &token, &bytes, &start_offset, &end_offset, &position); + EXPECT_EQ(SQLITE_OK, rc); + EXPECT_STREQ("royksopp", token); + EXPECT_EQ(8, bytes); + EXPECT_EQ(0, start_offset); + EXPECT_EQ(9, end_offset); + EXPECT_EQ(0, position); + + rc = Database::FTSNext(cursor, &token, &bytes, &start_offset, &end_offset, &position); + EXPECT_EQ(rc, SQLITE_OK); + EXPECT_STREQ("foo", token); + EXPECT_EQ(3, bytes); + EXPECT_EQ(10, start_offset); + EXPECT_EQ(13, end_offset); + EXPECT_EQ(1, position); + + rc = Database::FTSNext(cursor, &token, &bytes, &start_offset, &end_offset, &position); + EXPECT_EQ(SQLITE_DONE, rc); +}