[tracker/wip/carlosg/statement-fixes: 3/7] tests: Really test TrackerSparqlStatement on all connections




commit 78da61bdf3fe4c7efcdcd81be3f0724578233b39
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Nov 10 23:12:43 2021 +0200

    tests: Really test TrackerSparqlStatement on all connections
    
    Since we were using the static TestInfo structs to hold the connection,
    we were simply overwriting it in a loop when adding the tests. This made
    just the last TrackerSparqlConnection (dbus) to be tested.
    
    Separate this bit, and pass new memory to each individual test, so they
    are ensured to use the intended connection. This makes the direct
    TrackerSparqlStatement explicitly tested as well.

 tests/libtracker-sparql/tracker-statement-test.c | 26 ++++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/tests/libtracker-sparql/tracker-statement-test.c 
b/tests/libtracker-sparql/tracker-statement-test.c
index 0fe55065b..77b54c431 100644
--- a/tests/libtracker-sparql/tracker-statement-test.c
+++ b/tests/libtracker-sparql/tracker-statement-test.c
@@ -33,7 +33,6 @@ typedef struct {
        const gchar *arg2;
        const gchar *arg3;
        gboolean service;
-       TrackerSparqlConnection *conn;
 } TestInfo;
 
 TestInfo tests[] = {
@@ -66,6 +65,11 @@ TestInfo tests[] = {
        { "cast-2", "/test/sparql/statement/cast.rq", "statement/cast.out", "2021-02-24T22:01:02Z" },
 };
 
+typedef struct {
+       TestInfo *test;
+       TrackerSparqlConnection *conn;
+} TestFixture;
+
 typedef struct {
        TrackerSparqlConnection *direct;
        GDBusConnection *dbus_conn;
@@ -166,16 +170,16 @@ check_result (TrackerSparqlCursor *cursor,
 }
 
 static void
-setup (TestInfo      *test_info,
+setup (TestFixture   *fixture,
        gconstpointer  context)
 {
-       const TestInfo *test = context;
+       const TestFixture *test = context;
 
-       *test_info = *test;
+       *fixture = *test;
 }
 
 static void
-query_statement (TestInfo      *test_info,
+query_statement (TestFixture   *test_fixture,
                  gconstpointer  context)
 {
        TrackerSparqlStatement *stmt;
@@ -183,10 +187,11 @@ query_statement (TestInfo      *test_info,
        GError *error = NULL;
        gchar *path, *query;
        GDateTime *date_time;
+       TestInfo *test_info = test_fixture->test;
 
        if (test_info->query_file[0] == '/') {
                /* Absolute paths refer to GResource paths here */
-               stmt = tracker_sparql_connection_load_statement_from_gresource (test_info->conn,
+               stmt = tracker_sparql_connection_load_statement_from_gresource (test_fixture->conn,
                                                                                test_info->query_file,
                                                                                NULL, &error);
        } else {
@@ -204,7 +209,7 @@ query_statement (TestInfo      *test_info,
                        query = service_query;
                }
 
-               stmt = tracker_sparql_connection_query_statement (test_info->conn, query,
+               stmt = tracker_sparql_connection_query_statement (test_fixture->conn, query,
                                                                  NULL, &error);
                g_free (query);
        }
@@ -309,14 +314,17 @@ add_tests (TrackerSparqlConnection *conn,
        guint i;
 
        for (i = 0; i < G_N_ELEMENTS (tests); i++) {
+               TestFixture *fixture;
                gchar *testpath;
 
                if (tests[i].service && !run_service_tests)
                        continue;
 
-               tests[i].conn = conn;
+               fixture = g_new0 (TestFixture, 1);
+               fixture->conn = conn;
+               fixture->test = &tests[i];
                testpath = g_strconcat ("/libtracker-sparql/statement/", name, "/", tests[i].test_name, NULL);
-               g_test_add (testpath, TestInfo, &tests[i], setup, query_statement, NULL);
+               g_test_add (testpath, TestFixture, fixture, setup, query_statement, NULL);
                g_free (testpath);
        }
 }


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