[tracker/wip/carlosg/tracker-3.0-api-breaks: 40/63] tests: Move functional test into libtracker-data



commit e77c3a35cd74459f424f8d8df86f892a6ad831aa
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 30 13:26:04 2019 +0100

    tests: Move functional test into libtracker-data
    
    The insert-or-replace functional IPC test wasn't actually doing
    any specific functional testing, rather testing the INSERT OR REPLACE
    special syntax.
    
    It makes more sense to test for this specifically in libtracker-data
    tests. Also spares us a tracker_sparql_connection_get() call, which
    we are aiming to remove.

 tests/functional-tests/ipc/meson.build             |   8 -
 .../ipc/test-insert-or-replace.vala                | 156 -----------------
 tests/libtracker-data/meson.build                  |   9 +-
 .../tracker-insert-or-replace-test.c               | 186 +++++++++++++++++++++
 4 files changed, 193 insertions(+), 166 deletions(-)
---
diff --git a/tests/functional-tests/ipc/meson.build b/tests/functional-tests/ipc/meson.build
index 4bcfb0540..839fcefdc 100644
--- a/tests/functional-tests/ipc/meson.build
+++ b/tests/functional-tests/ipc/meson.build
@@ -14,14 +14,6 @@ test_env.set('TRACKER_DB_ONTOLOGIES_DIR', tracker_uninstalled_nepomuk_ontologies
 test_env.set('TRACKER_LANGUAGE_STOP_WORDS_DIR', tracker_uninstalled_stop_words_dir)
 test_env.set('TRACKER_TEST_DOMAIN_ONTOLOGY_RULE', tracker_uninstalled_domain_rule)
 
-insert_or_replace_test = executable('test-insert-or-replace',
-  'test-insert-or-replace.vala', tracker_sparql_vapi,
-  dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('insert-or-replace', python,
-  args: sandbox_args + [insert_or_replace_test],
-  env: test_env,
-  suite: ['functional', 'ipc'])
-
 bus_query_cancellation_test = executable('test-bus-query-cancellation',
   'test-bus-query-cancellation.c',
   c_args: functional_ipc_test_c_args,
diff --git a/tests/libtracker-data/meson.build b/tests/libtracker-data/meson.build
index 54ffc560c..e531c1f73 100644
--- a/tests/libtracker-data/meson.build
+++ b/tests/libtracker-data/meson.build
@@ -1,7 +1,12 @@
+data_test_c_args = test_c_args + [
+  '-DTEST_ONTOLOGIES_DIR="@0@"'.format(tracker_uninstalled_nepomuk_ontologies_dir),
+]
+
 libtracker_data_tests = [
     'crc32',
     'ontology-change',
     'sparql-blank',
+    'insert-or-replace',
 ]
 
 libtracker_data_slow_tests = [
@@ -17,7 +22,7 @@ foreach base_name: libtracker_data_tests
 
     binary = executable(binary_name, source,
       dependencies: libtracker_data_test_deps,
-      c_args: test_c_args)
+      c_args: data_test_c_args)
 
     tests += {
       'name': base_name,
@@ -33,7 +38,7 @@ foreach base_name: libtracker_data_slow_tests
 
     binary = executable(binary_name, source,
       dependencies: libtracker_data_test_deps,
-      c_args: test_c_args)
+      c_args: data_test_c_args)
 
       tests += {
         'name': base_name,
diff --git a/tests/libtracker-data/tracker-insert-or-replace-test.c 
b/tests/libtracker-data/tracker-insert-or-replace-test.c
new file mode 100644
index 000000000..d815deaac
--- /dev/null
+++ b/tests/libtracker-data/tracker-insert-or-replace-test.c
@@ -0,0 +1,186 @@
+#include "config.h"
+
+#include <string.h>
+#include <locale.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib/gstdio.h>
+
+#include <libtracker-data/tracker-data.h>
+
+static gchar *insert_query_replace = "\
+DELETE { ?r nao:hasTag ?tag . }\
+WHERE {\
+       ?r a nco:PhoneNumber;\
+          nco:phoneNumber \"02141730585%d\";\
+          nao:hasTag ?tag .\
+}\
+\
+DELETE {\
+       ?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,\
+            nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNumber,\
+            nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .\
+} WHERE {\
+       ?r a nco:PhoneNumber;\
+          nco:phoneNumber \"02141730585%d\" .\
+}\
+\
+INSERT {\
+       _:tel a nco:PhoneNumber ;\
+             nco:phoneNumber \"02141730585%d\" .\
+} WHERE {\
+       OPTIONAL {\
+               ?r a nco:PhoneNumber;\
+                  nco:phoneNumber \"02141730585%d\" .\
+       }\
+       FILTER(!bound(?r)) .\
+}\
+\
+INSERT OR REPLACE { <mailto:rhome0 example com%d> a nco:EmailAddress ;\
+               nco:emailAddress \"rhome0 example com%d\" . }\
+\
+DELETE { <contact:r:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }\
+WHERE { <contact:r:%d> a nco:PersonContact ; nco:hasAffiliation ?e }\
+\
+INSERT OR REPLACE {\
+       _:af1 a nco:Affiliation ;\
+             rdfs:label \"Work\" ;\
+             nco:hasEmailAddress <mailto:rhome0 example com%d> .\
+\
+       _:af2 a nco:Affiliation ;\
+             rdfs:label \"Other\" ;\
+             nco:hasPhoneNumber ?tel .\
+\
+       <contact:r:%d> a nco:PersonContact ;\
+                      nco:nameGiven \"First %d\" ;\
+                      nco:nameFamily \"Last %d\" ;\
+                      nco:hasAffiliation _:af1 ;\
+                      nco:hasAffiliation _:af2 ;\
+                      nie:contentCreated \"2011-03-14T13:47:25\" ;\
+                      nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\" .\
+} WHERE {\
+       ?tel nco:phoneNumber \"02141730585%d\"\
+}";
+
+static gchar *insert_query_original = "\
+DELETE { ?r nao:tag ?tag . }\
+WHERE {\
+       ?r a nco:PhoneNumber; nco:phoneNumber \"2141730585%d\";\
+          nao:hasTag ?tag .\
+}\
+\
+DELETE {\
+       ?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,\
+            nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNumber,\
+            nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .\
+} WHERE {\
+       ?r a nco:PhoneNumber;\
+          nco:phoneNumber \"2141730585%d\" .\
+}\
+\
+INSERT {\
+       _:tel a nco:PhoneNumber ;\
+             nco:phoneNumber \"2141730585%d\" .\
+} WHERE {\
+       OPTIONAL {\
+               ?r a nco:PhoneNumber;\
+                  nco:phoneNumber \"2141730585%d\" .\
+       }\
+       FILTER(!bound(?r)) .\
+}\
+\
+INSERT { <mailto:home0 example com%d> a nco:EmailAddress ;\
+                       nco:emailAddress \"home0 example com%d\" . }\
+\
+DELETE { <contact:o:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }\
+WHERE { <contact:o:%d> a nco:PersonContact ; nco:hasAffiliation ?e }\
+\
+DELETE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\
+    <contact:o:%d> ?predicate ?object .\
+} } WHERE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\
+    <contact:o:%d> ?predicate ?object .\
+    FILTER(?predicate NOT IN (nco:contactLocalUID,nco:contactUID,rdf:type)) .\
+} }\
+\
+INSERT { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\
+       _:af1 a nco:Affiliation ;\
+             rdfs:label \"Work\" ;\
+             nco:hasEmailAddress <mailto:home0 example com%d> .\
+\
+       _:af2 a nco:Affiliation ;\
+             rdfs:label \"Other\" ;\
+             nco:hasPhoneNumber ?tel .\
+\
+       <contact:o:%d> a nco:PersonContact ;\
+                      nco:nameGiven \"First %d\" ;\
+                      nco:nameFamily \"Last %d\" ;\
+                      nco:hasAffiliation _:af1 ;\
+                      nco:hasAffiliation _:af2 ;\
+                      nie:contentCreated \"2011-03-14T13:47:25\" ;\
+                      nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\" .\
+} } WHERE {\
+       ?tel nco:phoneNumber \"2141730585%d\"\
+}";
+
+#define N_QUERIES 100
+
+int
+main (int argc, char *argv[])
+{
+       TrackerDataManager *manager;
+       GError *error = NULL;
+       GFile *cache, *ontology;
+       gchar *test_data_dir;
+       gchar *query;
+       gint i;
+       GTimer *timer;
+
+       test_data_dir = g_build_filename (g_get_tmp_dir (),
+                                         "insert-or-replace-test-data-XXXXXX",
+                                         NULL);
+       g_mkdtemp (test_data_dir);
+
+       cache = g_file_new_for_path (test_data_dir);
+       ontology = g_file_new_for_path (TEST_ONTOLOGIES_DIR);
+
+       manager = tracker_data_manager_new (0, cache, ontology,
+                                           FALSE, 100, 100);
+       g_initable_init (G_INITABLE (manager), NULL, &error);
+       g_assert_no_error (error);
+
+       timer = g_timer_new ();
+
+       for (i = 0; i < N_QUERIES; i++) {
+               query = g_strdup_printf (insert_query_replace,
+                                        i, i, i, i, i, i, i, i, i , i, i, i, i);
+               tracker_data_update_sparql (tracker_data_manager_get_data (manager),
+                                           query, &error);
+               g_assert_no_error (error);
+               g_free (query);
+       }
+
+       g_print ("REPLACE  : %u contacts: %f\n",
+                N_QUERIES, g_timer_elapsed (timer, NULL));
+       g_timer_destroy (timer);
+       timer = g_timer_new ();
+
+       for (i = 0; i < N_QUERIES; i++) {
+               query = g_strdup_printf (insert_query_original,
+                                        i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
+               tracker_data_update_sparql (tracker_data_manager_get_data (manager),
+                                           query, &error);
+               g_assert_no_error (error);
+               g_free (query);
+       }
+
+       g_print ("ORIGINAL : %u contacts: %f\n", N_QUERIES,
+                g_timer_elapsed (timer, NULL));
+       g_timer_destroy (timer);
+
+       g_object_unref (manager);
+       g_object_unref (cache);
+       g_object_unref (ontology);
+
+       return 0;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]