← Back to team overview

zeitgeist team mailing list archive

[Branch ~zeitgeist/zeitgeist/bluebird] Rev 429: FTS++: Change to current_uri in some more places. Add random test cases.

 

------------------------------------------------------------
revno: 429
committer: Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
branch nick: bluebird
timestamp: Fri 2012-03-16 18:08:43 +0100
message:
  FTS++: Change to current_uri in some more places. Add random test cases.
modified:
  extensions/fts++/indexer.cpp
  extensions/fts++/test/test-indexer.cpp
  test/dbus/engine-test.py


--
lp:zeitgeist
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'extensions/fts++/indexer.cpp'
--- extensions/fts++/indexer.cpp	2012-03-15 13:39:43 +0000
+++ extensions/fts++/indexer.cpp	2012-03-16 17:08:43 +0000
@@ -262,7 +262,10 @@
     for (unsigned j = 0; j < subjects->len; j++)
     {
       ZeitgeistSubject *subject = (ZeitgeistSubject*) g_ptr_array_index (subjects, j);
+      // For backwards compatibility, we still check URI
       val = zeitgeist_subject_get_uri (subject);
+      if (!val || val[0] == '\0')
+          val = zeitgeist_subject_get_current_uri (subject);
       if (val && val[0] != '\0')
         tmpl.push_back ("zgsu:" + StringUtils::MangleUri (val));
 
@@ -344,7 +347,7 @@
   for (unsigned j = 0; j < subjects->len; j++)
   {
     ZeitgeistSubject *subject = (ZeitgeistSubject*) g_ptr_array_index (subjects, j);
-    val = zeitgeist_subject_get_uri (subject);
+    val = zeitgeist_subject_get_current_uri (subject);
     if (val && val[0] != '\0')
       doc.add_boolean_term (StringUtils::Truncate (FILTER_PREFIX_SUBJECT_URI + StringUtils::MangleUri (val)));
 
@@ -928,12 +931,13 @@
       if (subjects == NULL) continue;
       for (unsigned j = 0; j < subjects->len; j++)
       {
-        const gchar *subj_uri = zeitgeist_subject_get_uri ((ZeitgeistSubject*) subjects->pdata[j]);
+        const gchar *subj_uri = zeitgeist_subject_get_current_uri (
+                (ZeitgeistSubject*) subjects->pdata[j]);
         if (subj_uri == NULL) continue;
         remapper[subj_uri] = event_id;
         ZeitgeistEvent *event = zeitgeist_event_new ();
         ZeitgeistSubject *subject = zeitgeist_subject_new ();
-        zeitgeist_subject_set_uri (subject, subj_uri);
+        zeitgeist_subject_set_current_uri (subject, subj_uri);
         zeitgeist_event_add_subject (event, subject); // FIXME: leaks?
         g_ptr_array_add (event_templates, event);
       }
@@ -976,7 +980,8 @@
       if (subjects == NULL) continue;
       for (unsigned j = 0; j < subjects->len; j++)
       {
-        const gchar *subj_uri = zeitgeist_subject_get_uri ((ZeitgeistSubject*) subjects->pdata[j]);
+        const gchar *subj_uri = zeitgeist_subject_get_current_uri (
+                (ZeitgeistSubject*) subjects->pdata[j]);
         if (subj_uri == NULL) continue;
         relevancy_map[event_id] = relevancy_map[remapper[subj_uri]];
       }

=== modified file 'extensions/fts++/test/test-indexer.cpp'
--- extensions/fts++/test/test-indexer.cpp	2012-03-15 13:39:43 +0000
+++ extensions/fts++/test/test-indexer.cpp	2012-03-16 17:08:43 +0000
@@ -293,6 +293,38 @@
 }
 
 static void
+test_simple_query_empty_database (Fixture *fix, gconstpointer data)
+{
+  guint matches;
+
+  GPtrArray *results =
+    zeitgeist_indexer_search (fix->indexer,
+                              "NothingWillEverMatchThisMwhahahaha",
+                              zeitgeist_time_range_new_anytime (),
+                              g_ptr_array_new (),
+                              0,
+                              10,
+                              ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS,
+                              &matches,
+                              NULL);
+
+  g_assert_cmpuint (matches, ==, 0);
+  g_assert_cmpuint (results->len, ==, 0);
+}
+
+static void
+test_simple_query_no_results (Fixture *fix, gconstpointer data)
+{
+  // add test events to DBs
+  index_event (fix, create_test_event1 ());
+  index_event (fix, create_test_event2 ());
+  index_event (fix, create_test_event3 ());
+  index_event (fix, create_test_event4 ());
+
+  test_simple_query_empty_database (fix, data);
+}
+
+static void
 test_simple_with_filter (Fixture *fix, gconstpointer data)
 {
   guint matches;
@@ -889,6 +921,37 @@
   g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id);
 }
 
+static void
+test_simple_least_recent (Fixture *fix, gconstpointer data)
+{
+  guint matches;
+  guint event_id1, event_id2, event_id3, event_id4;
+  ZeitgeistEvent* event;
+ 
+  // add test events to DBs
+  event_id1 = index_event (fix, create_test_event1 ());
+  event_id2 = index_event (fix, create_test_event2 ());
+  event_id3 = index_event (fix, create_test_event3 ());
+  event_id4 = index_event (fix, create_test_event4 ());
+
+  GPtrArray *results =
+    zeitgeist_indexer_search (fix->indexer,
+                              "",
+                              zeitgeist_time_range_new_anytime (),
+                              g_ptr_array_new (),
+                              0,
+                              10,
+                              ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS,
+                              &matches,
+                              NULL);
+
+  g_assert_cmpuint (matches, >, 0);
+  g_assert_cmpuint (results->len, ==, 4);
+
+  //event = (ZeitgeistEvent*) results->pdata[0];
+  //g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id);
+}
+
 G_BEGIN_DECLS
 
 static void discard_message (const gchar *domain,
@@ -902,6 +965,10 @@
 {
   g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQuery", Fixture, 0,
               setup, test_simple_query, teardown);
+  g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQueryEmptyDatabase", Fixture, 0,
+              setup, test_simple_query_empty_database, teardown);
+  g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQueryNoResults", Fixture, 0,
+              setup, test_simple_query_no_results, teardown);
   g_test_add ("/Zeitgeist/FTS/Indexer/SimpleWithFilter", Fixture, 0,
               setup, test_simple_with_filter, teardown);
   g_test_add ("/Zeitgeist/FTS/Indexer/SimpleWithValidFilter", Fixture, 0,

=== modified file 'test/dbus/engine-test.py'
--- test/dbus/engine-test.py	2012-01-02 07:42:53 +0000
+++ test/dbus/engine-test.py	2012-03-16 17:08:43 +0000
@@ -134,7 +134,7 @@
 
 	def testIllegalPredefinedEventId(self):
 		event = Event()
-		event[0][0] = str(23) # This is illegal, we assert the erro later
+		event[0][0] = str(23) # This is illegal, we assert the error later
 		event.timestamp = 0
 		event.interpretation = Manifestation.USER_ACTIVITY
 		event.manifestation = Interpretation.CREATE_EVENT