diff options
author | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-10-07 19:20:27 +0200 |
---|---|---|
committer | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-10-07 19:22:20 +0200 |
commit | eb31d78db0ba5cce186a766e467922a2bab78da2 (patch) | |
tree | 047a7939df0f6facf65172ba95fbbef21122b23b /test | |
parent | aaab839a1edabbbb59338490b6ed627ed3b29a16 (diff) | |
parent | a89a0e80aa9e2634e3ac12451a6ede2a788e93df (diff) | |
download | zeitgeist-eb31d78db0ba5cce186a766e467922a2bab78da2.tar.gz |
Merge branch 'master' into current_origin
Conflicts:
libzeitgeist/API_CHANGES
libzeitgeist/datamodel.vala
src/engine.vala
Diffstat (limited to 'test')
-rw-r--r-- | test/c/test-datasource.c | 7 | ||||
-rw-r--r-- | test/c/test-event.c | 9 | ||||
-rw-r--r-- | test/c/test-log.c | 20 | ||||
-rw-r--r-- | test/c/test-mimetypes.c | 7 | ||||
-rw-r--r-- | test/c/test-monitor.c | 9 | ||||
-rw-r--r-- | test/c/test-symbols.c | 7 | ||||
-rw-r--r-- | test/c/test-timerange.c | 11 | ||||
-rw-r--r-- | test/c/test-timestamp.c | 31 | ||||
-rw-r--r-- | test/data/incomplete_events.js | 82 | ||||
-rw-r--r-- | test/data/one_event.js | 20 | ||||
-rw-r--r-- | test/dbus/blacklist-test.py | 30 | ||||
-rw-r--r-- | test/dbus/dsr-test.py | 29 | ||||
-rw-r--r-- | test/dbus/engine-test.py | 84 | ||||
-rw-r--r-- | test/dbus/histogram-test.py | 7 | ||||
-rw-r--r-- | test/dbus/monitor-test.py | 2 | ||||
-rw-r--r-- | test/dbus/remote-test.py | 46 | ||||
-rw-r--r-- | test/dbus/testutils.py | 29 | ||||
-rw-r--r-- | test/direct/datamodel-test.vala | 2 |
18 files changed, 295 insertions, 137 deletions
diff --git a/test/c/test-datasource.c b/test/c/test-datasource.c index 213b4b24..485c228d 100644 --- a/test/c/test-datasource.c +++ b/test/c/test-datasource.c @@ -25,7 +25,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -44,7 +43,7 @@ setup (Fixture *fix, gconstpointer data) static void teardown (Fixture *fix, gconstpointer data) { - g_setenv ("XDG_DATA_DIRS", old_xdg_data_dirs, TRUE); + g_setenv ("XDG_DATA_DIRS", old_xdg_data_dirs, TRUE); } static void @@ -145,13 +144,13 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/DataSource/CreateEmpty", Fixture, NULL, setup, test_create_empty, teardown); g_test_add ("/Zeitgeist/DataSource/CreateFull", Fixture, NULL, setup, test_create_full, teardown); g_test_add ("/Zeitgeist/DataSource/ToFromVariant", Fixture, NULL, setup, test_to_from_variant, teardown); - + return g_test_run(); } diff --git a/test/c/test-event.c b/test/c/test-event.c index 4f9fe576..74bc1c74 100644 --- a/test/c/test-event.c +++ b/test/c/test-event.c @@ -25,7 +25,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -44,7 +43,7 @@ setup (Fixture *fix, gconstpointer data) static void teardown (Fixture *fix, gconstpointer data) { - g_setenv ("XDG_DATA_DIRS", old_xdg_data_dirs, TRUE); + g_setenv ("XDG_DATA_DIRS", old_xdg_data_dirs, TRUE); } static void @@ -130,7 +129,7 @@ test_actor_from_app_info (Fixture *fix, gconstpointer data) appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (TEST_DIR"/test.desktop")); g_assert (G_IS_APP_INFO (appinfo)); - + ev = zeitgeist_event_new (); zeitgeist_event_set_actor_from_app_info (ev, appinfo); @@ -430,7 +429,7 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Event/CreateEmpty", Fixture, NULL, setup, test_create_empty, teardown); g_test_add ("/Zeitgeist/Event/CreateFull", Fixture, NULL, @@ -451,6 +450,6 @@ main (int argc, setup, test_3_events_to_from_variant, teardown); g_test_add ("/Zeitgeist/Event/0EventsToFromVariant", Fixture, NULL, setup, test_0_events_to_from_variant, teardown); - + return g_test_run(); } diff --git a/test/c/test-log.c b/test/c/test-log.c index 83af732a..34c7d7b7 100644 --- a/test/c/test-log.c +++ b/test/c/test-log.c @@ -74,6 +74,7 @@ _on_events_received (ZeitgeistLog *log, GAsyncResult *res, GPtrArray *expected_events) { + GArray *events_array; ZeitgeistResultSet *events; GArray *event_ids; GError *error; @@ -82,7 +83,8 @@ _on_events_received (ZeitgeistLog *log, guint32 event_id; error = NULL; - events = zeitgeist_log_get_events_finish (log, res, &error); + events_array = zeitgeist_log_get_events_finish (log, res, &error); + events = zeitgeist_simple_result_set_new (events_array); if (error) { g_critical ("Failed to get events: %s", error->message); @@ -99,7 +101,7 @@ _on_events_received (ZeitgeistLog *log, i = 0; while (ev = zeitgeist_result_set_next_value (events)) { - g_assert_cmpint (i, ==, zeitgeist_result_set_tell (events)); + g_assert_cmpint (i+1, ==, zeitgeist_result_set_tell (events)); _ev = ZEITGEIST_EVENT (g_ptr_array_index (expected_events, i)); g_assert_cmpstr (zeitgeist_event_get_interpretation (ev), ==, zeitgeist_event_get_interpretation (_ev)); @@ -115,13 +117,13 @@ _on_events_received (ZeitgeistLog *log, g_array_append_val (event_ids, event_id); i++; } - + /* Assert that the end is still what we expect */ g_assert_cmpint (expected_events->len, ==, zeitgeist_result_set_size (events)); g_assert_cmpint (expected_events->len, ==, zeitgeist_result_set_estimated_matches (events)); g_assert_cmpint (i, ==, zeitgeist_result_set_tell (events)); g_assert_cmpint (i, ==, zeitgeist_result_set_size (events)); - + /* This method call now owns event_ids */ zeitgeist_log_delete_events (log, event_ids, NULL, (GAsyncReadyCallback) _on_events_deleted, @@ -174,7 +176,7 @@ test_insert_get_delete (Fixture *fix, gconstpointer data) zeitgeist_event_set_interpretation (ev, "foo://Interp"); zeitgeist_event_set_manifestation (ev, "foo://Manif"); zeitgeist_event_set_actor (ev, "app://firefox.desktop"); - + zeitgeist_subject_set_uri (su, "file:///tmp/bar.txt"); zeitgeist_subject_set_interpretation (su, "foo://TextDoc"); zeitgeist_subject_set_manifestation (su, "foo://File"); @@ -194,10 +196,10 @@ test_insert_get_delete (Fixture *fix, gconstpointer data) (GAsyncReadyCallback) _on_events_inserted, expected_events); g_assert_cmpint (expected_events->len, ==, 1); - + g_timeout_add_seconds (1, (GSourceFunc) _quit_main_loop, fix->mainloop); g_main_loop_run (fix->mainloop); - + } static void @@ -214,11 +216,11 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Log/InsertGetDelete", Fixture, NULL, setup, test_insert_get_delete, teardown); g_test_add ("/Zeitgeist/Log/GetDefault", Fixture, NULL, NULL, test_get_default, NULL); - + return g_test_run(); } diff --git a/test/c/test-mimetypes.c b/test/c/test-mimetypes.c index 7edbc33b..370c84cd 100644 --- a/test/c/test-mimetypes.c +++ b/test/c/test-mimetypes.c @@ -22,7 +22,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -31,13 +30,11 @@ static void teardown (Fixture *fix, gconstpointer data); static void setup (Fixture *fix, gconstpointer data) { - } static void teardown (Fixture *fix, gconstpointer data) { - } static void @@ -84,7 +81,7 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Mime/TextPlain", Fixture, NULL, setup, test_mime_textplain, teardown); g_test_add ("/Zeitgeist/Mime/None", Fixture, NULL, @@ -95,6 +92,6 @@ main (int argc, setup, test_scheme_file, teardown); g_test_add ("/Zeitgeist/UriScheme/None", Fixture, NULL, setup, test_scheme_none, teardown); - + return g_test_run(); } diff --git a/test/c/test-monitor.c b/test/c/test-monitor.c index 6606c982..6a28fc14 100644 --- a/test/c/test-monitor.c +++ b/test/c/test-monitor.c @@ -22,7 +22,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -31,13 +30,11 @@ static void teardown (Fixture *fix, gconstpointer data); static void setup (Fixture *fix, gconstpointer data) { - } static void teardown (Fixture *fix, gconstpointer data) { - } static void @@ -55,7 +52,7 @@ test_create (Fixture *fix, gconstpointer data) "time-range", &tr, "event-templates", &event_templates_, NULL); - + g_assert_cmpint (27, ==, zeitgeist_time_range_get_start (tr)); g_assert_cmpint (68, ==, zeitgeist_time_range_get_end (tr)); @@ -72,9 +69,9 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Monitor/Create", Fixture, NULL, setup, test_create, teardown); - + return g_test_run(); } diff --git a/test/c/test-symbols.c b/test/c/test-symbols.c index af470229..3a63ebe3 100644 --- a/test/c/test-symbols.c +++ b/test/c/test-symbols.c @@ -23,7 +23,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -32,13 +31,11 @@ static void teardown (Fixture *fix, gconstpointer data); static void setup (Fixture *fix, gconstpointer data) { - } static void teardown (Fixture *fix, gconstpointer data) { - } static void @@ -186,7 +183,7 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Symbols/NullNull", Fixture, NULL, setup, test_null_symbols, teardown); g_test_add ("/Zeitgeist/Symbols/FirstNull", Fixture, NULL, @@ -213,6 +210,6 @@ main (int argc, setup, test_vector_image_parents, teardown); g_test_add ("/Zeitgeist/Symbols/SymbolInfo", Fixture, NULL, setup, test_media_complex, teardown); - + return g_test_run(); } diff --git a/test/c/test-timerange.c b/test/c/test-timerange.c index 8c47e496..4fad4183 100644 --- a/test/c/test-timerange.c +++ b/test/c/test-timerange.c @@ -22,7 +22,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -31,13 +30,11 @@ static void teardown (Fixture *fix, gconstpointer data); static void setup (Fixture *fix, gconstpointer data) { - } static void teardown (Fixture *fix, gconstpointer data) { - } static void @@ -74,7 +71,7 @@ test_to_now (Fixture *fix, gconstpointer data) tr = zeitgeist_time_range_new_to_now (); g_assert (0 == zeitgeist_time_range_get_start (tr)); - + /* Since system time is unreliable we simply assert that the end timestamp * is after 2000. This assueres that we catch any uint/int32 overflow * at least */ @@ -89,7 +86,7 @@ test_from_now (Fixture *fix, gconstpointer data) ZeitgeistTimeRange *tr; tr = zeitgeist_time_range_new_from_now (); - + /* Since system time is unreliable we simply assert that the start timestamp * is after 2000. This assueres that we catch any uint/int32 overflow * at least */ @@ -142,7 +139,7 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/TimeRange/Create", Fixture, NULL, setup, test_create, teardown); g_test_add ("/Zeitgeist/TimeRange/Anytime", Fixture, NULL, @@ -155,6 +152,6 @@ main (int argc, setup, test_from_variant, teardown); g_test_add ("/Zeitgeist/TimeRange/ToVariant", Fixture, NULL, setup, test_to_variant, teardown); - + return g_test_run(); } diff --git a/test/c/test-timestamp.c b/test/c/test-timestamp.c index ee442556..83aaee3e 100644 --- a/test/c/test-timestamp.c +++ b/test/c/test-timestamp.c @@ -22,7 +22,6 @@ typedef struct { - } Fixture; static void setup (Fixture *fix, gconstpointer data); @@ -31,13 +30,11 @@ static void teardown (Fixture *fix, gconstpointer data); static void setup (Fixture *fix, gconstpointer data) { - } static void teardown (Fixture *fix, gconstpointer data) { - } static void @@ -55,7 +52,7 @@ static void test_inc_year (Fixture *fix, gconstpointer data) { gchar *d = zeitgeist_timestamp_to_iso8601 (ZEITGEIST_TIMESTAMP_YEAR); - + // Since ZEITGEIST_TIMESTAMP_YEAR accounts for leap years we wont exactly // match "1971-01-01T00:00:00Z" on the hour g_assert (g_str_has_prefix (d, "1971-01-01T")); @@ -69,9 +66,9 @@ test_from_date (Fixture *fix, gconstpointer data) g_date_set_dmy (&date, 25, G_DATE_JUNE, 2000); gint64 from_date = zeitgeist_timestamp_from_date (&date); - + gchar *d = zeitgeist_timestamp_to_iso8601 (from_date); - + /* API guarantees that the timestamp is rounded to midnight */ g_assert_cmpstr ("2000-06-25T00:00:00Z", ==, d); } @@ -91,25 +88,25 @@ test_timeval_conversion (Fixture *fix, gconstpointer data) { GTimeVal tv = { 0 }; gint64 ts, _ts; - + /* Check 0 */ ts = 0; zeitgeist_timestamp_to_timeval (ts, &tv); _ts = zeitgeist_timestamp_from_timeval (&tv); g_assert (ts == _ts); - + /* Check a low number */ ts = 10000; zeitgeist_timestamp_to_timeval (ts, &tv); _ts = zeitgeist_timestamp_from_timeval (&tv); g_assert (ts == _ts); - + /* Check 2010-06-18 */ ts = G_GINT64_CONSTANT (1276849717119); zeitgeist_timestamp_to_timeval (ts, &tv); _ts = zeitgeist_timestamp_from_timeval (&tv); g_assert (ts == _ts); - + /* Note : G_MAXINT64 wont work because GTimeVal uses glongs internally * to track the numbers */ } @@ -119,16 +116,16 @@ test_prev_midnight (Fixture *fix, gconstpointer data) { gint64 ts, midnight; gchar *iso; - + /* Check 2010-06-23T11:19:07Z */ ts = G_GINT64_CONSTANT (1277284743659); - + /* Now the actual test */ midnight = zeitgeist_timestamp_prev_midnight (ts); iso = zeitgeist_timestamp_to_iso8601(midnight); g_assert(g_str_has_prefix (iso, "2010-06-23T00:00:00")); g_free (iso); - + /* Pre midnight of 'midnight' should go one day back */ midnight = zeitgeist_timestamp_prev_midnight (midnight); iso = zeitgeist_timestamp_to_iso8601(midnight); @@ -141,7 +138,7 @@ test_next_midnight (Fixture *fix, gconstpointer data) { gint64 ts, midnight; gchar *iso; - + /* Check 2010-06-23T11:19:07Z */ ts = G_GINT64_CONSTANT (1277284743659); @@ -150,7 +147,7 @@ test_next_midnight (Fixture *fix, gconstpointer data) iso = zeitgeist_timestamp_to_iso8601(midnight); g_assert(g_str_has_prefix (iso, "2010-06-24T00:00:00")); g_free (iso); - + /* Pre midnight of 'midnight' should go one day back */ midnight = zeitgeist_timestamp_next_midnight (midnight); iso = zeitgeist_timestamp_to_iso8601(midnight); @@ -164,7 +161,7 @@ main (int argc, { g_type_init (); g_test_init (&argc, &argv, NULL); - + g_test_add ("/Zeitgeist/Timestamp/FromISO8601", Fixture, NULL, setup, test_from_iso8601, teardown); g_test_add ("/Zeitgeist/Timestamp/IncrementYear", Fixture, NULL, @@ -179,6 +176,6 @@ main (int argc, setup, test_prev_midnight, teardown); g_test_add ("/Zeitgeist/Timestamp/NextMidnight", Fixture, NULL, setup, test_next_midnight, teardown); - + return g_test_run(); } diff --git a/test/data/incomplete_events.js b/test/data/incomplete_events.js index b25e2f21..a855eef1 100644 --- a/test/data/incomplete_events.js +++ b/test/data/incomplete_events.js @@ -11,7 +11,7 @@ "manifestation" : "Hi" },{ "uri" : "http://meh", - "mimetype" : "bs", + "mimetype" : "bs", "interpretation" : "", "manifestation" : "Something" } @@ -24,17 +24,17 @@ "subjects" : [ { "uri" : "file://baz0", - "mimetype" : "text/x-python", + "mimetype" : "text/x-python", "interpretation" : "", "manifestation" : "" },{ "uri" : "file://baz1", - "mimetype" : "text/x-python", + "mimetype" : "text/x-python", "interpretation" : "a", "manifestation" : "" },{ "uri" : "file://baz2", - "mimetype" : "text/x-python", + "mimetype" : "text/x-python", "interpretation" : "", "manifestation" : "b" } @@ -47,10 +47,82 @@ "subjects" : [ { "uri" : "sftp://quiz", - "mimetype" : "text/x-sql", + "mimetype" : "text/x-sql", "interpretation" : "#Audio", "manifestation" : "something else" } ] + },{ + "timestamp" : 1300, + "interpretation" : "", + "manifestation" : "no interpretation", + "actor" : "actor", + "subjects" : [ + { + "uri" : "foo://bar", + "interpretation" : "sint", + "manifestation" : "sman" + } + ] + },{ + "timestamp" : 1300, + "interpretation" : "no manifestation", + "manifestation" : "", + "actor" : "actor", + "subjects" : [ + { + "uri" : "foo://bar", + "interpretation" : "sint", + "manifestation" : "sman" + } + ] + },{ + "timestamp" : 1400, + "interpretation" : "#AccessEvent", + "manifestation" : "#UserActivity", + "actor" : "", + "subjects" : [ + { + "uri" : "foo://bar", + "interpretation" : "sint", + "manifestation" : "sman" + } + ] + },{ + "timestamp" : 500, + "interpretation" : "#AccessEvent", + "manifestation" : "#UserActivity", + "actor" : "Void", + "subjects" : [ + { + "uri" : "file://baz0", + "mimetype" : "text/x-python", + "interpretation" : "", + "manifestation" : "" + },{ + "uri" : "file://baz1", + "mimetype" : "text/x-python", + "interpretation" : "a", + "manifestation" : "" + },{ + "uri" : "", + "mimetype" : "missing/URI", + "interpretation" : "", + "manifestation" : "b" + } + ] + },{ + "timestamp" : 1799, + "interpretation" : "#AccessEvent", + "manifestation" : "#UserActivity", + "actor" : "application://foo.desktop", + "subjects" : [ + { + "uri" : "file:///unknown-mimetype-file", + "mimetype" : "", + "interpretation" : "", + "manifestation" : "" + } + ] } ] diff --git a/test/data/one_event.js b/test/data/one_event.js new file mode 100644 index 00000000..07584216 --- /dev/null +++ b/test/data/one_event.js @@ -0,0 +1,20 @@ +[ + { + "timestamp" : 1349629206110, + "interpretation" : "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#CreateEvent", + "manifestation" : "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#UserActivity", + "actor" : "application://gnome-about.desktop", + "subjects" : [ + { + "uri" : "test://mytest", + "interpretation" : "subject interpretation", + "manifestation" : "subject manifestation", + "origin" : "test://", + "mimetype" : "mime/type", + "text" : "One Event", + "storage" : "MyStorage", + "current_uri" : "test://mytest" + } + ] + } +] diff --git a/test/dbus/blacklist-test.py b/test/dbus/blacklist-test.py index 6f572f05..4933d285 100644 --- a/test/dbus/blacklist-test.py +++ b/test/dbus/blacklist-test.py @@ -7,7 +7,7 @@ # Copyright © 2010 Markus Korn <thekorn@gmx.de> # Copyright © 2010 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> -# Copyright © 2011 Collabora Ltd. +# Copyright © 2011-2012 Collabora Ltd. # By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # # This program is free software: you can redistribute it and/or modify @@ -110,9 +110,10 @@ class BlacklistTest(RemoteTestCase): def testApplyBlacklistWithTwoTemplates(self): # Setup an event we'll use to test insertions event = Event.new_for_values( - timestamp = 1, + timestamp = 0, interpretation=Interpretation.ACCESS_EVENT, manifestation=Manifestation.SCHEDULED_ACTIVITY, + actor="actor", subject_uri="blarg") # With no blacklisted templates we can insert it without problems @@ -169,13 +170,17 @@ class BlacklistTest(RemoteTestCase): # And check that it works self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri="New York is a city")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri="New York is a city NOT")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri="Do you like cheese?")) self._assert_insert_allowed(Event.new_for_values( interpretation=Interpretation.MOVE_EVENT, + manifestation="b", actor="c", subject_uri="kung fu", subject_current_uri="New York is a city")) @@ -189,12 +194,16 @@ class BlacklistTest(RemoteTestCase): # And check that the blacklisting works self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"çàrßá€")) self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"hello")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"hola")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"çàrßá")) def testApplyBlacklistForEventWithEmptyCurrentURI(self): @@ -205,11 +214,16 @@ class BlacklistTest(RemoteTestCase): # Blocking the current_uri works self._assert_insert_blocked(Event.new_for_values( interpretation=Interpretation.MOVE_EVENT, + manifestation="manifestation", + actor="actor", + subject_uri="unrelated", subject_current_uri="t")) # But if we only set uri (and leave it up to Zeitgeist to set current_uri # to the same value? - self._assert_insert_blocked(Event.new_for_values(subject_uri="t")) + self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", + subject_uri="t")) def testApplyBlacklistWithWildcardInURI(self): # We blacklist some particular URIs @@ -219,16 +233,22 @@ class BlacklistTest(RemoteTestCase): # And check that the blacklisting works self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"block me")) self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"block me*")) self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"block me now")) self._assert_insert_blocked(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"block meß :)")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"block mNOT")) self._assert_insert_allowed(Event.new_for_values( + interpretation="a", manifestation="b", actor="c", subject_uri=u"nblock me")) def _get_blacklist_iface(self): @@ -257,7 +277,7 @@ class BlacklistTest(RemoteTestCase): mainloop = self.create_mainloop() template1 = Event.new_for_values( - timestamp=0, + timestamp=1349453012265, interpretation=Interpretation.ACCESS_EVENT, subject_uri="http://nothingtoseehere.gov") @@ -306,3 +326,5 @@ class BlacklistTest(RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/dsr-test.py b/test/dbus/dsr-test.py index 4031ddca..e7b934de 100644 --- a/test/dbus/dsr-test.py +++ b/test/dbus/dsr-test.py @@ -7,7 +7,7 @@ # Copyright © 2009-2011 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # Copyright © 2009-2011 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> # Copyright © 2009-2011 Markus Korn <thekorn@gmx.de> -# Copyright © 2011 Collabora Ltd. +# Copyright © 2011-2012 Collabora Ltd. # By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # By Seif Lotfy <seif@lotfy.com> # @@ -169,27 +169,30 @@ class ZeitgeistRemoteDataSourceRegistryTest(testutils.RemoteTestCase): self.client._registry.RegisterDataSource(*self._ds1) ds = list(self.client._registry.GetDataSources())[0] self.assertEquals(ds[DataSource.Enabled], True) - + # Now we can choose to disable it... self.client._registry.SetDataSourceEnabled(self._ds1[0], False) ds = list(self.client._registry.GetDataSources())[0] self.assertEquals(ds[DataSource.Enabled], False) - - ids = self.insertEventsAndWait([Event.new_for_values( - subject_manifestation = "!stfu:File")]) - + + event = Event.new_for_values( + interpretation="interpretation", + manifestation="manifestation", + actor="actor", + subject_uri="some uri", + subject_manifestation="!stfu:File") + + # ... which will block its events from being inserted + ids = self.insertEventsAndWait([event]) self.assertEquals(ids[0], 0) - + # And enable it again! self.client._registry.SetDataSourceEnabled(self._ds1[0], True) ds = list(self.client._registry.GetDataSources())[0] self.assertEquals(ds[DataSource.Enabled], True) - - ids = self.insertEventsAndWait([Event.new_for_values( - subject_manifestation = "!stfu:File")]) - - self.assertEquals(ids[0], 1) + ids = self.insertEventsAndWait([event]) + self.assertEquals(ids[0], 1) def testGetDataSourceFromId(self): # Insert a data-source -- and then retrieve it by id @@ -283,3 +286,5 @@ class ZeitgeistRemoteDataSourceRegistryTest(testutils.RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/engine-test.py b/test/dbus/engine-test.py index 7217a9ba..fc469298 100644 --- a/test/dbus/engine-test.py +++ b/test/dbus/engine-test.py @@ -1,13 +1,13 @@ #! /usr/bin/python # -.- coding: utf-8 -.- -# remote-test.py +# engine-test.py # # Copyright © 2009-2011 Seif Lotfy <seif@lotfy.com> # Copyright © 2009-2011 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # Copyright © 2009-2011 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> # Copyright © 2009-2011 Markus Korn <thekorn@gmx.de> -# Copyright © 2011 Collabora Ltd. +# Copyright © 2011-2012 Collabora Ltd. # By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # By Seif Lotfy <seif@lotfy.com> # @@ -45,36 +45,12 @@ from zeitgeist.datamodel import (Event, Subject, Interpretation, Manifestation, TimeRange, StorageState, DataSource, NULL_EVENT, ResultType) import testutils -from testutils import parse_events, import_events - -TEST_ACTOR = "/usr/share/applications/gnome-about.desktop" - -# FIXME: move this to a .js file -test_event_1 = None -def create_test_event_1(): - ev = Event() - ev.timestamp = 0 - ev.interpretation = Manifestation.USER_ACTIVITY - ev.manifestation = Interpretation.CREATE_EVENT - ev.actor = TEST_ACTOR - subj = Subject() - subj.uri = u"test://mytest" - subj.manifestation = "lala" - subj.interpretation = "tinky winky" - subj.origin = "test://" - subj.mimetype = "YOMAMA" - subj.text = "SUCKS" - subj.storage = "MyStorage" - subj.current_uri = u"test://mytest" - - ev.append_subject(subj) - return ev - +from testutils import parse_events, import_events, new_event class ZeitgeistEngineTest(testutils.RemoteTestCase): def testSingleInsertGet(self): - test_event_1 = create_test_event_1() + test_event_1 = parse_events("test/data/one_event.js")[0] # Insert item and event ids = self.insertEventsAndWait([test_event_1]) self.assertEquals(1, len(ids)) @@ -175,7 +151,7 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): self.assertTrue(events[0].id == events[1].id == 1) def testFindEventsId(self): - test_event_1 = create_test_event_1() + test_event_1 = parse_events("test/data/one_event.js")[0] self.testSingleInsertGet() result = self.findEventIdsAndWait([]) self.assertEquals(1, len(result)) @@ -194,7 +170,8 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): # revision rainct@ubuntu.com-20091128164327-j8ez3fsifd1gygkr (1185) # Fix _build_templates so that it works when the Subject is empty. self.testSingleInsertGet() - result = self.findEventIdsAndWait([Event.new_for_values(interpretation=Interpretation.LEAVE_EVENT)]) + result = self.findEventIdsAndWait([Event.new_for_values( + interpretation=Interpretation.LEAVE_EVENT)]) self.assertEquals(0, len(result)) def testFindFive(self): @@ -244,10 +221,12 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): self.assertEquals(True, event1.timestamp > event2.timestamp) def testFindWithActor(self): - test_event_1 = create_test_event_1() + test_event_1 = parse_events("test/data/one_event.js")[0] self.testSingleInsertGet() subj = Subject() - event_template = Event.new_for_values(actor=TEST_ACTOR, subjects=[subj,]) + event_template = Event.new_for_values( + actor="application://gnome-about.desktop", + subjects=[subj,]) result = self.findEventIdsAndWait([event_template], num_events = 0, result_type = 1) self.assertEquals(1, len(result)) test_event_1[0][0] = 1 @@ -332,8 +311,8 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): def testGetWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") - event_template = Event.new_for_values(subjects=[subj1, subj2]) - result = self.insertEventsAndWait([event_template]) + event = new_event(subjects=[subj1, subj2]) + result = self.insertEventsAndWait([event]) events = self.getEventsAndWait(result) self.assertEquals(2, len(events[0].subjects)) self.assertEquals("file:///tmp/foo.txt", events[0].subjects[0].uri) @@ -342,11 +321,12 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): def testFindEventIdsWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") - event = Event.new_for_values(subjects=[subj1, subj2]) + event = new_event(subjects=[subj1, subj2]) orig_ids = self.insertEventsAndWait([event]) - result_ids = self.findEventIdsAndWait([Event()], num_events = 0, result_type = 1) - self.assertEquals(orig_ids, list(result_ids)) #FIXME: We need subjects of the same event to be merged - + result_ids = self.findEventIdsAndWait([Event()], num_events=0, + result_type=ResultType.LeastRecentEvents) + self.assertEquals(orig_ids, list(result_ids)) + def testFindEventsEventTemplate(self): import_events("test/data/five_events.js", self) subj = Subject.new_for_values(interpretation="stfu:Bee") @@ -495,7 +475,7 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): self.assertEquals(ev.payload, _ev.payload) def testQueryByParent (self): - ev = Event.new_for_values(subject_interpretation=Interpretation.AUDIO) + ev = new_event(subject_interpretation=Interpretation.AUDIO) _ids = self.insertEventsAndWait([ev]) tmpl = Event.new_for_values(subject_interpretation=Interpretation.MEDIA) @@ -627,8 +607,8 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): def testFindStorageNotExistant(self): events = [ - Event.new_for_values(timestamp=1000, subject_storage="sometext"), - Event.new_for_values(timestamp=2000, subject_storage="anotherplace") + new_event(timestamp=1000, subject_storage="sometext"), + new_event(timestamp=2000, subject_storage="anotherplace") ] ids_in = self.insertEventsAndWait(events) template = Event.new_for_values(subject_storage="xxx") @@ -640,8 +620,8 @@ class ZeitgeistEngineTest(testutils.RemoteTestCase): def testFindStorage(self): events = [ - Event.new_for_values(timestamp=1000, subject_storage="sometext"), - Event.new_for_values(timestamp=2000, subject_storage="anotherplace") + new_event(timestamp=1000, subject_storage="sometext"), + new_event(timestamp=2000, subject_storage="anotherplace") ] ids_in = self.insertEventsAndWait(events) template = Event.new_for_values(subject_storage="sometext") @@ -900,10 +880,10 @@ class ResultTypeTest(testutils.RemoteTestCase): def testResultTypesOldestActorBug641968(self): events = [ - Event.new_for_values(timestamp=1, actor="boo", subject_uri="tmp/boo"), - Event.new_for_values(timestamp=2, actor="boo", subject_uri="home/boo"), - Event.new_for_values(timestamp=3, actor="bar", subject_uri="tmp/boo"), - Event.new_for_values(timestamp=4, actor="baz", subject_uri="tmp/boo"), + new_event(timestamp=1, actor="boo", subject_uri="tmp/boo"), + new_event(timestamp=2, actor="boo", subject_uri="home/boo"), + new_event(timestamp=3, actor="bar", subject_uri="tmp/boo"), + new_event(timestamp=4, actor="baz", subject_uri="tmp/boo"), ] self.insertEventsAndWait(events) @@ -954,10 +934,10 @@ class ResultTypeTest(testutils.RemoteTestCase): # The same test as before, but this time with fewer events so that # it is actually understandable. events = [ - Event.new_for_values(timestamp=1, actor="gedit", subject_uri="oldFile"), - Event.new_for_values(timestamp=2, actor="banshee", subject_uri="oldMusic"), - Event.new_for_values(timestamp=3, actor="banshee", subject_uri="newMusic"), - Event.new_for_values(timestamp=4, actor="gedit", subject_uri="newFile"), + new_event(timestamp=1, actor="gedit", subject_uri="oldFile"), + new_event(timestamp=2, actor="banshee", subject_uri="oldMusic"), + new_event(timestamp=3, actor="banshee", subject_uri="newMusic"), + new_event(timestamp=4, actor="gedit", subject_uri="newFile"), ] self.insertEventsAndWait(events) @@ -1137,3 +1117,5 @@ class ResultTypeTest(testutils.RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/histogram-test.py b/test/dbus/histogram-test.py index 6d30b3f0..d42960f7 100644 --- a/test/dbus/histogram-test.py +++ b/test/dbus/histogram-test.py @@ -31,7 +31,7 @@ import gobject sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from zeitgeist.client import ZeitgeistDBusInterface from zeitgeist.datamodel import * -from testutils import RemoteTestCase, import_events +from testutils import RemoteTestCase, import_events, new_event # # EXPLANATION OF THE TEST: @@ -69,7 +69,8 @@ class HistogramTest(RemoteTestCase): self.histogram = dbus.Interface(obj, "org.gnome.zeitgeist.Histogram") def _createEventOne(self): - ev = Event.new_for_values(interpretation=Interpretation.ACCESS_EVENT, + ev = new_event( + interpretation=Interpretation.ACCESS_EVENT, subject_uri="file://sisisisisisi") ev.manifestation = Manifestation.USER_ACTIVITY @@ -104,3 +105,5 @@ class HistogramTest(RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/monitor-test.py b/test/dbus/monitor-test.py index d3c212f8..62db8104 100644 --- a/test/dbus/monitor-test.py +++ b/test/dbus/monitor-test.py @@ -317,3 +317,5 @@ class ZeitgeistMonitorTest(testutils.RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/remote-test.py b/test/dbus/remote-test.py index 87c4a64f..6f4ac44b 100644 --- a/test/dbus/remote-test.py +++ b/test/dbus/remote-test.py @@ -7,7 +7,7 @@ # Copyright © 2009-2011 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # Copyright © 2009-2011 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> # Copyright © 2009-2011 Markus Korn <thekorn@gmx.de> -# Copyright © 2011 Collabora Ltd. +# Copyright © 2011-2012 Collabora Ltd. # By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> # By Seif Lotfy <seif@lotfy.com> # @@ -67,7 +67,7 @@ class ZeitgeistRemoteAPITest(testutils.RemoteTestCase): self.assertEquals(len(ids), len(events)) result_events = self.getEventsAndWait(ids) self.assertEquals(len(ids), len(result_events)) - + def testGetEvents(self): events = parse_events("test/data/five_events.js") ids = self.insertEventsAndWait(events) + [1000, 2000] @@ -226,9 +226,9 @@ class ZeitgeistRemoteAPITestAdvanced(testutils.RemoteTestCase): def testInsertWithEmptySubjectInterpretationManifestation(self): events = parse_events("test/data/incomplete_events.js") - ids = self.insertEventsAndWait(events) + ids = self.insertEventsAndWait(events[:3]) self.assertEquals(3, len(ids)) - + event = self.getEventsAndWait([ids[0]])[0] self.assertEquals("Hi", event.subjects[0].manifestation) self.assertEquals("", event.subjects[0].interpretation) @@ -247,6 +247,42 @@ class ZeitgeistRemoteAPITestAdvanced(testutils.RemoteTestCase): self.assertEquals("something else", event.subjects[0].manifestation) self.assertEquals("#Audio", event.subjects[0].interpretation) + def testInsertWithEmptySubjectMimeType(self): + events = parse_events("test/data/incomplete_events.js") + ids = self.insertEventsAndWait([events[7]]) + self.assertEquals(1, len(ids)) + + event = self.getEventsAndWait([ids[0]])[0] + self.assertEquals(1, len(event.subjects)) + + subject = event.subjects[0] + self.assertEquals("file:///unknown-mimetype-file", subject.uri) + self.assertEquals("", subject.mimetype) + self.assertEquals(Manifestation.FILE_DATA_OBJECT, subject.manifestation) # FIXME + self.assertEquals("", subject.interpretation) # FIXME + + def testInsertIncompleteEvent(self): + events = parse_events("test/data/incomplete_events.js") + + # Missing interpretation + ids = self.insertEventsAndWait([events[3]]) + self.assertEquals(0, len(ids)) + + # Missing manifestation + ids = self.insertEventsAndWait([events[4]]) + self.assertEquals(0, len(ids)) + + # Missing actor + ids = self.insertEventsAndWait([events[5]]) + self.assertEquals(0, len(ids)) + + def testInsertIncompleteSubject(self): + events = parse_events("test/data/incomplete_events.js") + + # Missing one subject URI + ids = self.insertEventsAndWait([events[6]]) + self.assertEquals(0, len(ids)) + class ZeitgeistRemoteFindEventIdsTest(testutils.RemoteTestCase): """ Test cases with basic tests for FindEventIds. @@ -487,3 +523,5 @@ class ZeitgeistRemotePropertiesTest(testutils.RemoteTestCase): if __name__ == "__main__": unittest.main() + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/dbus/testutils.py b/test/dbus/testutils.py index e964b574..00cb93dd 100644 --- a/test/dbus/testutils.py +++ b/test/dbus/testutils.py @@ -88,6 +88,33 @@ def import_events(path, engine): events = parse_events(path) return engine.insertEventsAndWait(events) +def complete_event(event): + """ + Completes the given event by filling in any required fields that are missing + with some default value. + """ + if not event.interpretation: + event.interpretation = Interpretation.ACCESS_EVENT + if not event.manifestation: + event.manifestation = Manifestation.USER_ACTIVITY + if not event.actor: + event.actor = "application://zeitgeist-test.desktop" + + for subject in event.subjects: + if not subject.uri: + subject.uri = "file:///tmp/example file" + + return event + +def complete_events(events): + return map(complete_event, events) + +def new_event(*args, **kwargs): + """ + Creates a new event, initializing all required fields with default values. + """ + return complete_event(Event.new_for_values(*args, **kwargs)) + def asyncTestMethod(mainloop): """ Any callbacks happening in a MainLoopWithFailure must use @@ -445,3 +472,5 @@ class DBusPrivateMessageBus(object): if ignore_errors: return e raise + +# vim:noexpandtab:ts=4:sw=4 diff --git a/test/direct/datamodel-test.vala b/test/direct/datamodel-test.vala index becaa89d..8f473e3e 100644 --- a/test/direct/datamodel-test.vala +++ b/test/direct/datamodel-test.vala @@ -111,7 +111,7 @@ void foreach_test () SimpleResultSet result_set = new SimpleResultSet (events); int i = 0; - foreach (Event e in result_set) + foreach (Event e in result_set) { assert_cmpint ((int) e.id, OperatorType.EQUAL, i); i++; |