[tracker/wip/rishi/tracker_sparql_connection_update_array-test-zero-length] libtracker-sparql, tests: Support empty array updates




commit 2418935dbfd9a5552016a6cc5de3822d5f0e3204
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Apr 2 22:35:31 2021 +0200

    libtracker-sparql, tests: Support empty array updates
    
    This is for the convenience of users of the API where the length of
    the array depends on runtime conditions and it's possible that it will
    sometimes be empty.
    
    The 'bus' and 'direct' implementations of the update_array_async
    virtual method are predicated on the length of the array. Hence, as
    long as an empty array is accompanied by a zero length, it should work
    as a NOP.

 src/libtracker-sparql/tracker-connection.c |  1 -
 tests/libtracker-sparql/tracker-fd-test.c  | 46 ++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index 2cacd7735..1be841b68 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -429,7 +429,6 @@ tracker_sparql_connection_update_array_async (TrackerSparqlConnection  *connecti
                                               gpointer                  user_data)
 {
        g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
-       g_return_if_fail (sparql != NULL);
        g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
        TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_array_async (connection,
diff --git a/tests/libtracker-sparql/tracker-fd-test.c b/tests/libtracker-sparql/tracker-fd-test.c
index 7b49990ea..a1ed9bb76 100644
--- a/tests/libtracker-sparql/tracker-fd-test.c
+++ b/tests/libtracker-sparql/tracker-fd-test.c
@@ -376,6 +376,50 @@ test_tracker_sparql_update_array_async (DataFixture   *fixture,
 
 }
 
+static void
+async_update_array_empty_callback (GObject      *source_object,
+                                   GAsyncResult *result,
+                                   gpointer      user_data)
+{
+       GError *error = NULL;
+       AsyncData *data = user_data;
+
+       tracker_sparql_connection_update_array_finish (connection, result, &error);
+
+       /* main error is only set on fatal (D-Bus) errors that apply to the whole update */
+       g_assert_true (error != NULL);
+
+       g_main_loop_quit (data->main_loop);
+}
+
+static void
+test_tracker_sparql_update_array_async_empty (DataFixture   *fixture,
+                                              gconstpointer  user_data)
+{
+       const gchar **queries = NULL;
+       GMainLoop *main_loop;
+       AsyncData *data;
+
+       main_loop = g_main_loop_new (NULL, FALSE);
+
+       data = g_slice_new (AsyncData);
+       data->main_loop = main_loop;
+
+       /* Cast here is because vala doesn't make const-char-** possible :( */
+       tracker_sparql_connection_update_array_async (connection,
+                                                     (char**) queries,
+                                                     0,
+                                                     NULL,
+                                                     async_update_array_empty_callback,
+                                                     data);
+
+       g_main_loop_run (main_loop);
+
+       g_slice_free (AsyncData, data);
+       g_main_loop_unref (main_loop);
+
+}
+
 static void
 test_tracker_sparql_update_fast_error (DataFixture  *fixture,
                                        gconstpointer user_data)
@@ -816,6 +860,8 @@ main (gint argc, gchar **argv)
                        test_tracker_sparql_update_blank_async, delete_test_data);
        g_test_add ("/steroids/tracker/tracker_sparql_update_array_async", DataFixture, NULL, 
insert_test_data,
                        test_tracker_sparql_update_array_async, delete_test_data);
+       g_test_add ("/steroids/tracker/tracker_sparql_update_array_async_empty", DataFixture, NULL, 
insert_test_data,
+                       test_tracker_sparql_update_array_async_empty, delete_test_data);
 
        return g_test_run ();
 }


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