[tracker/wip/carlosg/local-connection-mapping: 8/8] tests: Test locally mapped connections in the services tests




commit a25219fc2e58ec4447b9d12a41d4469eafbf1950
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Apr 4 12:52:23 2021 +0200

    tests: Test locally mapped connections in the services tests
    
    Also relate the 2 connections via tracker_sparql_connection_map_connection
    so we can test the "private:xyz" special URIs.

 tests/libtracker-data/tracker-service-test.c | 36 ++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/tests/libtracker-data/tracker-service-test.c b/tests/libtracker-data/tracker-service-test.c
index d6caed5b3..ba4d60150 100644
--- a/tests/libtracker-data/tracker-service-test.c
+++ b/tests/libtracker-data/tracker-service-test.c
@@ -32,6 +32,7 @@ typedef struct _TestInfo TestInfo;
 struct _TestInfo {
        const gchar *test_name;
        gboolean expect_query_error;
+       gboolean local_connection;
 };
 
 const TestInfo tests[] = {
@@ -205,6 +206,10 @@ test_sparql_query (TestInfo      *test_info,
                g_usleep (100);
        }
 
+       tracker_sparql_connection_map_connection (local,
+                                                 "other-connection",
+                                                 remote);
+
        query_filename = g_strconcat (test_prefix, ".rq", NULL);
        g_file_get_contents (query_filename, &query, NULL, &error);
        g_assert_no_error (error);
@@ -213,8 +218,12 @@ test_sparql_query (TestInfo      *test_info,
        results_filename = g_strconcat (test_prefix, ".out", NULL);
        g_free (test_prefix);
 
-       uri = g_strdup_printf ("dbus:%s",
-                              g_dbus_connection_get_unique_name (dbus_conn));
+       if (test_info->local_connection) {
+               uri = g_strdup_printf ("private:other-connection");
+       } else {
+               uri = g_strdup_printf ("dbus:%s",
+                                      g_dbus_connection_get_unique_name (dbus_conn));
+       }
 
        /* perform actual query */
        service_query = g_strdup_printf (query, uri);
@@ -247,6 +256,16 @@ setup (TestInfo      *info,
        *info = *test;
 }
 
+static void
+setup_local (TestInfo      *info,
+             gconstpointer  context)
+{
+       const TestInfo *test = context;
+
+       *info = *test;
+       info->local_connection = TRUE;
+}
+
 static void
 teardown (TestInfo      *info,
           gconstpointer  context)
@@ -267,15 +286,24 @@ main (int argc, char **argv)
        dbus_conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
        g_assert_no_error (error);
 
-       /* add test cases */
+       /* add DBus test cases */
        for (i = 0; i < G_N_ELEMENTS (tests); i++) {
                gchar *testpath;
 
-               testpath = g_strconcat ("/libtracker-data/", tests[i].test_name, NULL);
+               testpath = g_strconcat ("/libtracker-data/dbus/", tests[i].test_name, NULL);
                g_test_add (testpath, TestInfo, &tests[i], setup, test_sparql_query, teardown);
                g_free (testpath);
        }
 
+       /* add local test cases */
+       for (i = 0; i < G_N_ELEMENTS (tests); i++) {
+               gchar *testpath;
+
+               testpath = g_strconcat ("/libtracker-data/local/", tests[i].test_name, NULL);
+               g_test_add (testpath, TestInfo, &tests[i], setup_local, test_sparql_query, teardown);
+               g_free (testpath);
+       }
+
        /* run tests */
        result = g_test_run ();
 


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