[tracker/wip/carlosg/deserializer-cursors: 15/15] tests: Assert that cursors have the right connection assigned




commit 31f489b4b53be04bd0e95767763a86ee73c53158
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 1 18:46:04 2022 +0200

    tests: Assert that cursors have the right connection assigned
    
    Test for tracker_sparql_cursor_get_connection() returning the right
    thing on cursor and statement tests.

 tests/libtracker-sparql/tracker-cursor-test.c    | 18 ++++++++++--------
 tests/libtracker-sparql/tracker-statement-test.c |  6 +++++-
 2 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/tests/libtracker-sparql/tracker-cursor-test.c b/tests/libtracker-sparql/tracker-cursor-test.c
index 38fa701e6..a3dabf1c4 100644
--- a/tests/libtracker-sparql/tracker-cursor-test.c
+++ b/tests/libtracker-sparql/tracker-cursor-test.c
@@ -141,12 +141,12 @@ query_and_compare_results (TrackerSparqlConnection *conn,
        GError *error = NULL;
 
        cursor_check = tracker_sparql_connection_query (direct, query, NULL, &error);
-
        g_assert_no_error (error);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor_check) == direct);
 
        cursor = tracker_sparql_connection_query (conn, query, NULL, &error);
-
        g_assert_no_error (error);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        compare_cursors (cursor_check, cursor);
 
@@ -183,9 +183,8 @@ test_tracker_sparql_query_iterate_error (gpointer      fixture,
        const gchar *query = "bork bork bork";
 
        cursor = tracker_sparql_connection_query (conn, query, NULL, &error);
-
        /* tracker_sparql_query_iterate should return null on error */
-       g_assert_true (!cursor);
+       g_assert_null (cursor);
 
        /* error should be set, along with its message, note: we don't
         * use g_assert_error() because the code does not match the
@@ -209,9 +208,9 @@ test_tracker_sparql_query_iterate_empty (gpointer      fixture,
        const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier 
\"thisannotationdoesnotexist\"}";
 
        cursor = tracker_sparql_connection_query (conn, query, NULL, &error);
-
        g_assert_true (cursor);
        g_assert_no_error (error);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        g_assert_false (tracker_sparql_cursor_next (cursor, NULL, NULL));
        g_assert_true (tracker_sparql_cursor_get_n_columns (cursor) == 1);
@@ -232,9 +231,9 @@ test_tracker_sparql_query_iterate_close_early (gpointer      fixture,
        const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject}";
 
        cursor = tracker_sparql_connection_query (conn, query, NULL, &error);
-
        g_assert_true (cursor);
        g_assert_no_error (error);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        g_assert_true (tracker_sparql_cursor_next (cursor, NULL, NULL));
 
@@ -254,14 +253,14 @@ async_query_cb (GObject      *source_object,
        g_main_loop_quit (data->main_loop);
 
        cursor = tracker_sparql_connection_query_finish (conn, result, &error);
-
        g_assert_no_error (error);
        g_assert_true (cursor != NULL);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        cursor_check = tracker_sparql_connection_query (direct, data->query, NULL, &error);
-
        g_assert_no_error (error);
        g_assert_true (cursor_check != NULL);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor_check) == direct);
 
        compare_cursors (cursor_check, cursor);
 
@@ -501,6 +500,7 @@ test_tracker_sparql_cursor_next_async_query (TrackerSparqlConnection *conn,
                                                  &error);
        g_assert_no_error (error);
        g_assert_true (cursor != NULL);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        tracker_sparql_cursor_next_async (cursor,
                                          cancellable,
@@ -543,6 +543,7 @@ test_tracker_sparql_cursor_get_variable_name (gpointer      fixture,
                                                  NULL, &error);
        g_assert_no_error (error);
        g_assert_true (cursor != NULL);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        tracker_sparql_cursor_next (cursor, NULL, &error);
        g_assert_no_error (error);
@@ -581,6 +582,7 @@ test_tracker_sparql_cursor_get_value_type (gpointer      fixture,
                                                  NULL, &error);
        g_assert_no_error (error);
        g_assert_true (cursor != NULL);
+       g_assert_true (tracker_sparql_cursor_get_connection (cursor) == conn);
 
        tracker_sparql_cursor_next (cursor, NULL, &error);
        g_assert_no_error (error);
diff --git a/tests/libtracker-sparql/tracker-statement-test.c 
b/tests/libtracker-sparql/tracker-statement-test.c
index 09cee6781..95f62cf69 100644
--- a/tests/libtracker-sparql/tracker-statement-test.c
+++ b/tests/libtracker-sparql/tracker-statement-test.c
@@ -212,6 +212,7 @@ query_statement (TestFixture   *test_fixture,
                stmt = tracker_sparql_connection_query_statement (test_fixture->conn, query,
                                                                  NULL, &error);
                g_free (query);
+               g_assert_true (tracker_sparql_statement_get_connection (stmt) == test_fixture->conn);
        }
 
        g_assert_no_error (error);
@@ -227,10 +228,11 @@ query_statement (TestFixture   *test_fixture,
        }
 
        cursor = tracker_sparql_statement_execute (stmt, NULL, &error);
-       g_object_unref (stmt);
 
        if (test_info->output_file) {
                g_assert_no_error (error);
+               g_assert_true (tracker_sparql_cursor_get_connection (cursor) ==
+                              tracker_sparql_statement_get_connection (stmt));
 
                path = g_build_filename (TOP_SRCDIR, "tests", "libtracker-sparql",
                                         test_info->output_file, NULL);
@@ -240,6 +242,8 @@ query_statement (TestFixture   *test_fixture,
        } else {
                g_assert_nonnull (error);
        }
+
+       g_object_unref (stmt);
 }
 
 TrackerSparqlConnection *


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