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 | |
| 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
| -rw-r--r-- | NEWS | 43 | ||||
| -rw-r--r-- | libzeitgeist/API_CHANGES | 39 | ||||
| -rw-r--r-- | libzeitgeist/Makefile.am | 2 | ||||
| -rw-r--r-- | libzeitgeist/TODO | 12 | ||||
| -rw-r--r-- | libzeitgeist/datamodel.vala | 62 | ||||
| -rw-r--r-- | libzeitgeist/ontology.vala.in | 2 | ||||
| -rw-r--r-- | src/db-reader.vala | 4 | ||||
| -rw-r--r-- | src/engine.vala | 61 | ||||
| -rw-r--r-- | src/table-lookup.vala | 2 | ||||
| -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 | ||||
| -rwxr-xr-x | tools/ontology_graph.py | 93 |
28 files changed, 511 insertions, 241 deletions
@@ -1,8 +1,45 @@ -2012-XX-XX: Zeitgeist 0.9.X "..." ---------------------------------------- +2012-XX-XX: Zeitgeist 1.0 Beta 1 +-------------------------------- + +This version introduces libzeitgeist2, a Vala port of the previously +independent libzeitgeist library. Now everything you need to work with +Zeitgeist, be it with C, Vala or Python, is included in this tarball. + +Please note that starting from this release Vala 0.18 is required to +build Zeitgeist. Engine: - - Fixed database migration of WebDataObject, blah blah + - Fixed insertion of large event sets. + - Fixed database migration to WebDataObject (from some RemoteDataObjects). + - Events missing required meta-data are now rejected. + +FTS: + - Fixed to respect ZEITGEIST_DATA_PATH. + +Python API: + - RelevantResultType is now included in "from datamodel import *". + +If you were using the external libzeitgeist, you need to be aware that +libzeitgeist2 has some API differences: + - For Vala developers: getters/setters replaced with properties, etc. + - For C developers: the use of floating references has been removed. + - Redesigned ResultSet (removed peek() and seek(); introduced reset(); + renamed next() to next_value()). + - Changed the return type of zeitgeist_log_get_events to GPtrArray; + now it works correctly when requesting non-existant events. + - Added an actor parameter to the event_new_full constructor. + - Added a current_uri parameter to the subject_new_full constructor. + - Added a GError parameter to several functions involving variants. + - Renamed timestamp_for_now to timestamp_now. + - Renamed data_source_is_enabled to data_source_get_enabled. + - Renamed the "connected" property to "is-connected". + - Introduced the missing ZeitgeistRelevantResultType enum. + - Introduced get_data_source_from_id. + - Introduced zeitgeist_{event,subject}_matches_template. + - Introduced zeitgeist_event_take_subject. + - Introduced zeitgeist_time_range_intersect. + - Removed event_new_full_valist and events_from_valist. + - Removed time_range_get_{start,end}_iso8601. 2012-08-26: Zeitgeist 0.9.5 "Sun Devil" --------------------------------------- diff --git a/libzeitgeist/API_CHANGES b/libzeitgeist/API_CHANGES deleted file mode 100644 index a039151b..00000000 --- a/libzeitgeist/API_CHANGES +++ /dev/null @@ -1,39 +0,0 @@ -API CHANGES FROM LIBZEITGEIST1: - - - removed reference stealing - - "connected" property renamed to "is-connected" - - DataSource.is_enabled renamed to get_enabled (?) - - introduced ZeitgeistRelevantResultType - - event_new_full now has an actor parameter - - subject_new_full now has a current_uri parameter - - introduced result_type_is_sort_order_asc (or hide it?) - - removed event_new_full_valist and events_from_valist - - introduced get_data_source_from_id - - introduced zeitgeist_{event,subject}_matches_template - - some functions involving variants now have a GError parameter - - introduced zeitgeist_event_take_subject - - introduced zeitgeist_time_range_intersect - - removed time_range_get_{start,end}_iso8601 - - changed timestamp_for_now to be timestamp_now - - zeitgeist_log_get_events now returns GPtrArray (and works - with NULL-events) - - ResultSet: removed peek() and seek(); introduced reset(); - next() renamed to next_value() - - added current_origin to subjects - -Vala: - - stuff is more valaish (eg. properties vs set/get) - - -------------------------------------------------- - -LIBZEITGEIST2 TODO: - - gtkdoc: document enum values - - gtkdoc: make index.html nice - - gtkdoc: add object hierarchy page - - gtkdoc: split stuff (eg. datamodel.html) into 1 page for class - - gtkdoc: fix api index so that eveyrthing isn't under Z - - gtkdoc: show properties & signals!! - - lots of documentation missing - - make zeitgeist_events_to_variant_with_limit internal? - - make utils.* internal? diff --git a/libzeitgeist/Makefile.am b/libzeitgeist/Makefile.am index ab5894a4..0a4d034f 100644 --- a/libzeitgeist/Makefile.am +++ b/libzeitgeist/Makefile.am @@ -1,4 +1,4 @@ -NULL = +NULL = lib_LTLIBRARIES = libzeitgeist-2.0.la diff --git a/libzeitgeist/TODO b/libzeitgeist/TODO new file mode 100644 index 00000000..6ffd5efc --- /dev/null +++ b/libzeitgeist/TODO @@ -0,0 +1,12 @@ +LIBZEITGEIST2 TODO: + - Review examples: make sure they don't leak! + - gtkdoc: document enum values + - gtkdoc: make index.html nice + - gtkdoc: add object hierarchy page + - gtkdoc: split stuff (eg. datamodel.html) into 1 page for class + - gtkdoc: fix api index so that eveyrthing isn't under Z + - gtkdoc: show properties & signals!! + - lots of documentation missing + - make zeitgeist_events_to_variant_with_limit internal? + - make utils.* internal? + - "introduced result_type_is_sort_order_asc" - add to NEWS or hide it diff --git a/libzeitgeist/datamodel.vala b/libzeitgeist/datamodel.vala index be2153cf..f7956ed0 100644 --- a/libzeitgeist/datamodel.vala +++ b/libzeitgeist/datamodel.vala @@ -40,6 +40,14 @@ namespace Zeitgeist throw new DataModelError.INVALID_SIGNATURE (error_message); } + private string? next_string_or_null (VariantIter iter) + { + string text = iter.next_value ().get_string (); + if (text != "") + return text; + return null; + } + [CCode (type_signature = "(xx)")] public class TimeRange: Object { @@ -462,22 +470,12 @@ namespace Zeitgeist timestamp = Timestamp.from_now (); else timestamp = int64.parse (str_timestamp); - interpretation = event_array.next_value ().get_string (); - if (interpretation == "") - interpretation = null; - manifestation = event_array.next_value ().get_string (); - if (manifestation == "") - manifestation = null; - actor = event_array.next_value ().get_string (); - if (actor == "") - actor = null; + interpretation = next_string_or_null (event_array); + manifestation = next_string_or_null (event_array); + actor = next_string_or_null (event_array); // let's keep this compatible with older clients if (event_props >= 6) - { - origin = event_array.next_value ().get_string (); - if (origin == "") - origin = null; - } + origin = next_string_or_null (event_array); for (int i = 0; i < subjects_array.n_children (); ++i) { Variant subject_variant = subjects_array.next_value (); @@ -727,8 +725,8 @@ namespace Zeitgeist public string? origin { get; set; } public string? text { get; set; } public string? storage { get; set; } - // FIXME: current_{uri,origin} is often the same as uri, we don't - // need to waste memory for it + // FIXME: current_{uri,origin} are often the same as uri, we don't + // need to waste memory for them public string? current_uri { get; set; } public string? current_origin { get; set; } @@ -781,32 +779,18 @@ namespace Zeitgeist var subject_props = iter.n_children (); assert_sig (subject_props >= 7, "Missing subject information"); - uri = iter.next_value().get_string (); - if (uri == "") - uri = null; - interpretation = iter.next_value().get_string (); - if (interpretation == "") - interpretation = null; - manifestation = iter.next_value().get_string (); - if (manifestation == "") - manifestation = null; - origin = iter.next_value().get_string (); - if (origin == "") - origin = null; - mimetype = iter.next_value().get_string (); - if (mimetype == "") - mimetype = null; - text = iter.next_value().get_string (); - if (text == "") - text = null; - storage = iter.next_value().get_string (); - if (storage == "") - storage = null; + uri = next_string_or_null (iter); + interpretation = next_string_or_null (iter); + manifestation = next_string_or_null (iter); + origin = next_string_or_null (iter); + mimetype = next_string_or_null (iter); + text = next_string_or_null (iter); + storage = next_string_or_null (iter); // let's keep this compatible with older clients if (subject_props >= 8) - current_uri = iter.next_value().get_string (); + current_uri = next_string_or_null (iter); if (subject_props >= 9) - current_origin = iter.next_value().get_string (); + current_origin = next_string_or_null (iter); } public Variant to_variant () diff --git a/libzeitgeist/ontology.vala.in b/libzeitgeist/ontology.vala.in index cf5392e9..7f5cbedf 100644 --- a/libzeitgeist/ontology.vala.in +++ b/libzeitgeist/ontology.vala.in @@ -38,7 +38,7 @@ namespace Zeitgeist return symbol.display_name; } - public static unowned string get_description(string symbol_uri) + public static unowned string get_description (string symbol_uri) { initialize_symbols (); diff --git a/src/db-reader.vala b/src/db-reader.vala index ee560cf9..e99fea24 100644 --- a/src/db-reader.vala +++ b/src/db-reader.vala @@ -835,10 +835,10 @@ public class DbReader : Object /** * If the value ends with the wildcard character, throw an error. */ - protected void assert_no_wildcard (string field, string? val) + protected void assert_no_wildcard (string field, string val) throws EngineError { - if (val == null || !val.has_suffix ("*")) + if (!val.has_suffix ("*")) return; string error_message = "Field '%s' doesn't support prefix search".printf (field); diff --git a/src/engine.vala b/src/engine.vala index 8b6cf8f8..38a83eb2 100644 --- a/src/engine.vala +++ b/src/engine.vala @@ -97,12 +97,27 @@ public class Engine : DbReader private void preprocess_event (Event event) throws EngineError { + if (is_empty_string (event.interpretation) + || is_empty_string (event.manifestation) + || is_empty_string (event.actor)) + { + throw new EngineError.INVALID_ARGUMENT ( + "Incomplete event: interpretation, manifestation and actor " + + "are required"); + } + // Iterate through subjects and check for validity - for (int i = 0; i < event.num_subjects(); ++i) + for (int i = 0; i < event.num_subjects (); ++i) { unowned Subject subject = event.subjects[i]; - // If current_{uri,origin} is unset, give it the same value as URI + if (is_empty_string (subject.uri)) + { + throw new EngineError.INVALID_ARGUMENT ( + "Incomplete event: subject without URI"); + } + + // If current_{uri,origin} are unset, set them to the same as URI if (is_empty_string (subject.current_uri)) subject.current_uri = subject.uri; if (is_empty_string (subject.current_origin)) @@ -234,6 +249,15 @@ public class Engine : DbReader storages.flush (); } + private void bind_cached_reference (Sqlite.Statement stmt, + int position, TableLookup table, string? value_) + { + if (value_ != null) + stmt.bind_int64 (position, table.id_for_string (value_)); + else + stmt.bind_null (position); + } + private uint32 insert_event (Event event) throws EngineError requires (event.id == 0) requires (event.num_subjects () > 0) @@ -254,11 +278,11 @@ public class Engine : DbReader insert_stmt.bind_int64 (1, event.id); insert_stmt.bind_int64 (2, event.timestamp); - insert_stmt.bind_int64 (3, - interpretations_table.id_for_string (event.interpretation)); - insert_stmt.bind_int64 (4, - manifestations_table.id_for_string (event.manifestation)); - insert_stmt.bind_int64 (5, actors_table.id_for_string (event.actor)); + bind_cached_reference (insert_stmt, 3, interpretations_table, + event.interpretation); + bind_cached_reference (insert_stmt, 4, manifestations_table, + event.manifestation); + bind_cached_reference (insert_stmt, 5, actors_table, event.actor); insert_stmt.bind_text (6, event.origin); insert_stmt.bind_int64 (7, payload_id); @@ -270,14 +294,14 @@ public class Engine : DbReader insert_stmt.bind_text (8, subject.uri); insert_stmt.bind_text (9, subject.current_uri); - insert_stmt.bind_int64 (10, - interpretations_table.id_for_string (subject.interpretation)); - insert_stmt.bind_int64 (11, - manifestations_table.id_for_string (subject.manifestation)); + bind_cached_reference (insert_stmt, 10, interpretations_table, + subject.interpretation); + bind_cached_reference (insert_stmt, 11, manifestations_table, + subject.manifestation); insert_stmt.bind_text (12, subject.origin); insert_stmt.bind_text (13, subject.current_origin); - insert_stmt.bind_int64 (14, - mimetypes_table.id_for_string (subject.mimetype)); + bind_cached_reference (insert_stmt, 14, mimetypes_table, + subject.mimetype); insert_stmt.bind_text (15, subject.text); // FIXME: Consider a storages_table table. Too dangerous? insert_stmt.bind_text (16, subject.storage); @@ -299,11 +323,12 @@ public class Engine : DbReader retrieval_stmt.reset (); retrieval_stmt.bind_int64 (1, event.timestamp); - retrieval_stmt.bind_int64 (2, - interpretations_table.id_for_string (event.interpretation)); - retrieval_stmt.bind_int64 (3, - manifestations_table.id_for_string (event.manifestation)); - retrieval_stmt.bind_int64 (4, actors_table.id_for_string (event.actor)); + bind_cached_reference (retrieval_stmt, 2, + interpretations_table, event.interpretation); + bind_cached_reference (retrieval_stmt, 3, + manifestations_table, event.manifestation); + bind_cached_reference (retrieval_stmt, 4, + actors_table, event.actor); if ((rc = retrieval_stmt.step ()) != Sqlite.ROW) { database.assert_not_corrupt (rc); diff --git a/src/table-lookup.vala b/src/table-lookup.vala index dfdcbbe4..e56012a0 100644 --- a/src/table-lookup.vala +++ b/src/table-lookup.vala @@ -85,7 +85,7 @@ namespace Zeitgeist.SQLite * @see id_try_string * */ - public int id_for_string (string? name) throws EngineError + public int id_for_string (string name) throws EngineError { int id = value_to_id.lookup (name); if (id == 0) 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++; diff --git a/tools/ontology_graph.py b/tools/ontology_graph.py new file mode 100755 index 00000000..76524ee3 --- /dev/null +++ b/tools/ontology_graph.py @@ -0,0 +1,93 @@ +#! /usr/bin/env python +# -.- coding: utf-8 -.- + +# Zeitgeist - Ontology viewer +# +# Copyright © 2012 Collabora Ltd. +# By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import sys +import pydot + +from zeitgeist import datamodel + +graphs = { + 'event_interpretation': datamodel.Interpretation.EVENT_INTERPRETATION, + 'event_manifestation': datamodel.Manifestation.EVENT_MANIFESTATION, + 'subject_interpretation': datamodel._SYMBOLS_BY_URI['Interpretation'], + # ie. nie.InformationElement, + 'subject_manifestation': datamodel._SYMBOLS_BY_URI['Manifestation'] + # ie. nie.DataObject, +} + +USAGE = 'Usage: %s [type] [output]\n\n\tAvailable types: ' % sys.argv[0] +USAGE += ', '.join(graphs.iterkeys()) + +def introspect(graph, symbol, parent=None, exclude_set=()): + """ + Adds the given symbol to the graph and recursively does the same + for its childs. + """ + + if symbol in exclude_set: + return + + node = pydot.Node(symbol.display_name) + graph.add_node(node) + + if parent: + edge = pydot.Edge(parent, node) + graph.add_edge(edge) + + for subsymbol in symbol.get_children(): + introspect(graph, subsymbol, node, exclude_set) + +def generate_graph(symbol, exclude_set): + """ + Generates a graph starting with the given root symbol. + """ + + print 'Introspecting ontology and generating graph...' + graph = pydot.Dot(graph_type='graph') + introspect(graph, symbol, None, exclude_set) + return graph + +def main(): + if len(sys.argv) != 3 or sys.argv[1] not in graphs: + raise SystemExit, USAGE + + graph_type = sys.argv[1] + exclude = [] + if graph_type.startswith('subject_'): + exclude.append(datamodel.Interpretation.EVENT_INTERPRETATION) + exclude.append(datamodel.Manifestation.EVENT_MANIFESTATION) + graph = generate_graph(graphs[graph_type], exclude) + + filename = sys.argv[2] + ext = (filename.rsplit('.', 1) + [None])[1] + if ext is None: + filename += '.png' + ext = 'png' + + if not hasattr(graph, 'write_'+ext): + raise SystemExit, 'Invalid file extension: %s' % ext + getattr(graph, 'write_'+ext)(filename) + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + pass |
