diff options
author | Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> | 2012-05-03 16:48:56 +0200 |
---|---|---|
committer | Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> | 2012-05-03 16:48:56 +0200 |
commit | 6fbb4c2b9648a75ff95439e3fa4193558762563f (patch) | |
tree | 8c6cc793bd2ecb628bd9897a45262411a49c0c30 /extensions | |
parent | 6657fe221da26b1cfd37a5bc1bc4cc80ebeb52cf (diff) | |
parent | 1897c150b841c249100fcfd225a3626b742565f8 (diff) | |
download | zeitgeist-6fbb4c2b9648a75ff95439e3fa4193558762563f.tar.gz |
Merge branch 'master' into libzeitgeist2
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/fts++/indexer.cpp | 5 | ||||
-rw-r--r-- | extensions/fts++/test/test-indexer.cpp | 41 | ||||
-rw-r--r-- | extensions/fts++/zeitgeist-fts.vala | 10 |
3 files changed, 51 insertions, 5 deletions
diff --git a/extensions/fts++/indexer.cpp b/extensions/fts++/indexer.cpp index af96eac7..483caf7f 100644 --- a/extensions/fts++/indexer.cpp +++ b/extensions/fts++/indexer.cpp @@ -561,12 +561,13 @@ bool Indexer::IndexUri (std::string const& uri, std::string const& origin) size_t question_mark = uri.find ('?'); if (question_mark != std::string::npos) { - std::string stripped (uri, 0, question_mark - 1); + std::string stripped (uri, 0, question_mark); basename = g_path_get_basename (stripped.c_str ()); } else { - basename = g_file_get_basename (f); + // g_file_get_basename would unescape the uri, we don't want that here + basename = g_path_get_basename (uri.c_str ()); } // step 2) unescape and check that it's valid utf8 diff --git a/extensions/fts++/test/test-indexer.cpp b/extensions/fts++/test/test-indexer.cpp index 62ca4118..8330a5ea 100644 --- a/extensions/fts++/test/test-indexer.cpp +++ b/extensions/fts++/test/test-indexer.cpp @@ -88,6 +88,21 @@ assert_nth_result_has_text (GPtrArray* results, int n, const char *text) g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, text); } +// This function only supports events with a single subject, +// since that's enough for the tests in this file. +static void +assert_nth_result_has_uri (GPtrArray* results, int n, const char *text) +{ + g_assert_cmpuint (n, <, results->len); + ZeitgeistEvent *event = (ZeitgeistEvent*) results->pdata[n]; + g_assert (event); + g_assert_cmpint (zeitgeist_event_num_subjects (event), ==, 1); + ZeitgeistSubject *subject = (ZeitgeistSubject*) + g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); + g_assert (subject); + g_assert_cmpstr (zeitgeist_subject_get_uri (subject), ==, text); +} + static ZeitgeistEvent* create_test_event1 (void) { ZeitgeistEvent *event = zeitgeist_event_new (); @@ -609,6 +624,30 @@ test_simple_underscores (Fixture *fix, gconstpointer data) } static void +test_simple_escaped_string (Fixture *fix, gconstpointer data) // (LP: #594171) +{ + guint matches; + guint event_id; + ZeitgeistEvent* event; + GPtrArray* results; + + // add test events to DBs + const char uri[] = "http://encodings.com/percentage-%25-is-fun"; + const char text[] = "%25 is the encoding for a percentage"; + event_id = index_event (fix, create_test_event_simple (uri, text)); + + // Search for MostPopularSubjects + results = search_simple (fix, "percentage", NULL, + ZEITGEIST_RESULT_TYPE_MOST_POPULAR_SUBJECTS, &matches); + + g_assert_cmpuint (matches, >, 0); + g_assert_cmpuint (results->len, ==, 1); + assert_nth_result_has_id (results, 0, event_id); + assert_nth_result_has_uri (results, 0, uri); + assert_nth_result_has_text (results, 0, text); +} + +static void test_simple_camelcase (Fixture *fix, gconstpointer data) { guint matches; @@ -1147,6 +1186,8 @@ void test_indexer_create_suite (void) setup, test_simple_noexpand_valid, teardown); g_test_add ("/Zeitgeist/FTS/Indexer/Simple/Underscores", Fixture, 0, setup, test_simple_underscores, teardown); + g_test_add ("/Zeitgeist/FTS/Indexer/Simple/EscapedString", Fixture, 0, + setup, test_simple_escaped_string, teardown); g_test_add ("/Zeitgeist/FTS/Indexer/Simple/Camelcase", Fixture, 0, setup, test_simple_camelcase, teardown); g_test_add ("/Zeitgeist/FTS/Indexer/Simple/PrefixWithDashes", Fixture, 0, diff --git a/extensions/fts++/zeitgeist-fts.vala b/extensions/fts++/zeitgeist-fts.vala index 7800a828..29ea1f4d 100644 --- a/extensions/fts++/zeitgeist-fts.vala +++ b/extensions/fts++/zeitgeist-fts.vala @@ -69,10 +69,10 @@ namespace Zeitgeist indexer = new Indexer (engine); } - private void do_quit () + private void close () { engine.close (); - mainloop.quit (); + indexer = null; // close the index } public void register_dbus_object (DBusConnection conn) throws IOError @@ -231,6 +231,10 @@ namespace Zeitgeist if (instance != null) { + // Close any database connections + instance.close (); + + // Release the bus name Bus.unown_name (owner_id); instance.unregister_dbus_object (); instance = null; @@ -249,7 +253,7 @@ namespace Zeitgeist static void safe_exit () { - instance.do_quit (); + mainloop.quit (); } static int main (string[] args) |