summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2022-05-01 11:11:03 +0200
committerCarlos Garnacho <carlosg@gnome.org>2022-05-01 19:44:47 +0200
commit5e49addc89c8d6eb19291baea874482d89643b78 (patch)
treeb20f698e564ab1a2c40ec73e64f9413634ed8583 /tests
parent1398c33e183f92bef3cad7532cc31b095c55bdb8 (diff)
downloadtracker-5e49addc89c8d6eb19291baea874482d89643b78.tar.gz
tests: Merge cursor tests into their own executable
At tests/libtracker-sparql there is a few scattered tests that check for high-level cursor behavior. We'll want to run those for all connection types, and cursor formats. So far separate them all to a distinct test executable so they can be refactored together.
Diffstat (limited to 'tests')
-rw-r--r--tests/libtracker-sparql/meson.build11
-rw-r--r--tests/libtracker-sparql/tracker-cursor-test.c637
-rw-r--r--tests/libtracker-sparql/tracker-fd-test.c325
-rw-r--r--tests/libtracker-sparql/tracker-sparql-test.c216
4 files changed, 648 insertions, 541 deletions
diff --git a/tests/libtracker-sparql/meson.build b/tests/libtracker-sparql/meson.build
index 9f6733f9e..c3e1e097c 100644
--- a/tests/libtracker-sparql/meson.build
+++ b/tests/libtracker-sparql/meson.build
@@ -41,6 +41,17 @@ tests += {
'suite': ['sparql'],
}
+tracker_cursor_test = executable('tracker-cursor-test',
+ 'tracker-cursor-test.c',
+ dependencies: [tracker_common_dep, tracker_sparql_dep],
+ c_args: libtracker_sparql_test_c_args)
+
+tests += {
+ 'name': 'cursor',
+ 'exe': tracker_cursor_test,
+ 'suite': ['sparql'],
+}
+
test_gresources = gnome.compile_resources('test_gresources', 'statement-queries.gresource.xml')
tracker_statement_test = executable('tracker-statement-test',
diff --git a/tests/libtracker-sparql/tracker-cursor-test.c b/tests/libtracker-sparql/tracker-cursor-test.c
new file mode 100644
index 000000000..7bdd2882f
--- /dev/null
+++ b/tests/libtracker-sparql/tracker-cursor-test.c
@@ -0,0 +1,637 @@
+/*
+ * Copyright (C) 2010, Codeminded BVBA <abustany@gnome.org>
+ * Copyright (C) 2022, Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libtracker-sparql/tracker-sparql.h>
+
+/* This MUST be larger than TRACKER_STEROIDS_BUFFER_SIZE */
+#define LONG_NAME_SIZE 128 * 1024 * sizeof(char)
+
+typedef struct {
+ GMainLoop *main_loop;
+ const gchar *query;
+} AsyncData;
+
+static TrackerSparqlConnection *connection;
+gboolean started = FALSE;
+
+static GMainLoop *main_loop;
+
+#define N_QUERIES 3
+
+static GCancellable *cancellables[N_QUERIES] = { NULL, };
+
+static const gchar *queries[N_QUERIES] = {
+ /* #1 */
+ "SELECT ?p WHERE { ?p nrl:indexed true }",
+ /* #2 */
+ "SELECT ?prefix ?ns WHERE { ?ns a nrl:Namespace ; nrl:prefix ?prefix }",
+ /* #3 */
+ "SELECT ?p WHERE { ?p nrl:fulltextIndexed true }",
+};
+
+static void
+delete_test_data (gpointer *fixture,
+ gconstpointer user_data)
+{
+ GError *error = NULL;
+ const char *delete_query = "DELETE { "
+ "<urn:testdata1> a rdfs:Resource ."
+ "<urn:testdata2> a rdfs:Resource ."
+ "<urn:testdata3> a rdfs:Resource ."
+ "<urn:testdata4> a rdfs:Resource ."
+ "}";
+
+ tracker_sparql_connection_update (connection, delete_query, NULL, &error);
+ g_assert_no_error (error);
+}
+
+static void
+insert_test_data (gpointer *fixture,
+ gconstpointer user_data)
+{
+ GError *error = NULL;
+ char *longName = g_malloc (LONG_NAME_SIZE);
+ char *filled_query;
+
+ /* Ensure data is deleted */
+ delete_test_data (fixture, user_data);
+
+ memset (longName, 'a', LONG_NAME_SIZE);
+
+ longName[LONG_NAME_SIZE - 1] = '\0';
+
+ filled_query = g_strdup_printf ("INSERT {"
+ " <urn:testdata1> a nfo:FileDataObject ; nie:url \"/foo/bar\" ."
+ " <urn:testdata2> a nfo:FileDataObject ; nie:url \"/plop/coin\" ."
+ " <urn:testdata3> a nmm:Artist ; nmm:artistName \"testArtist\" ."
+ " <urn:testdata4> a nmm:Photo ; nao:identifier \"%s\" ."
+ "}", longName);
+
+ tracker_sparql_connection_update (connection, filled_query, NULL, &error);
+ g_assert_no_error (error);
+
+ g_free (filled_query);
+ g_free (longName);
+}
+
+static void
+compare_cursors (TrackerSparqlCursor *cursor_a,
+ TrackerSparqlCursor *cursor_b)
+{
+ while (tracker_sparql_cursor_next (cursor_a, NULL, NULL) && tracker_sparql_cursor_next (cursor_b, NULL, NULL)) {
+ g_assert_cmpstr (tracker_sparql_cursor_get_string (cursor_a, 0, NULL),
+ ==,
+ tracker_sparql_cursor_get_string (cursor_b, 0, NULL));
+ }
+
+ /* Check that both cursors are at the end (same number of rows) */
+ g_assert_true (!tracker_sparql_cursor_next (cursor_a, NULL, NULL));
+ g_assert_true (!tracker_sparql_cursor_next (cursor_b, NULL, NULL));
+}
+
+static void
+query_and_compare_results (const char *query)
+{
+ TrackerSparqlCursor *cursor_glib;
+ TrackerSparqlCursor *cursor_fd;
+ GError *error = NULL;
+
+ cursor_glib = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ g_assert_no_error (error);
+
+ cursor_fd = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ g_assert_no_error (error);
+
+ compare_cursors (cursor_glib, cursor_fd);
+
+ g_object_unref (cursor_glib);
+ g_object_unref (cursor_fd);
+}
+
+static void
+test_tracker_sparql_query_iterate (gpointer *fixture,
+ gconstpointer user_data)
+{
+ query_and_compare_results ("SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}");
+}
+
+static void
+test_tracker_sparql_query_iterate_largerow (gpointer *fixture,
+ gconstpointer user_data)
+{
+ query_and_compare_results ("SELECT nao:identifier(?r) WHERE {?r a nmm:Photo}");
+}
+
+/* Runs an invalid query */
+static void
+test_tracker_sparql_query_iterate_error (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ const gchar *query = "bork bork bork";
+
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ /* tracker_sparql_query_iterate should return null on error */
+ g_assert_true (!cursor);
+
+ /* error should be set, along with its message, note: we don't
+ * use g_assert_error() because the code does not match the
+ * enum values for TRACKER_SPARQL_ERROR_*, this is due to
+ * dbus/error matching between client/server. This should be
+ * fixed in gdbus.
+ */
+ g_assert_true (error != NULL && error->domain == TRACKER_SPARQL_ERROR);
+
+ g_error_free (error);
+}
+
+/* Runs a query returning an empty set */
+static void
+test_tracker_sparql_query_iterate_empty_subprocess (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier \"thisannotationdoesnotexist\"}";
+
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ g_assert_true (tracker_sparql_cursor_next (cursor, NULL, NULL));
+
+ /* Testing we fail with this error:
+ *
+ * Tracker-CRITICAL **:
+ * tracker_bus_fd_cursor_real_get_string: assertion '(_tmp0_
+ * < _tmp2_) && (_tmp3_ != NULL)' failed
+ */
+ tracker_sparql_cursor_get_string (cursor, 0, NULL);
+}
+
+static void
+test_tracker_sparql_query_iterate_empty (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier \"thisannotationdoesnotexist\"}";
+
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ g_assert_true (cursor);
+ g_assert_no_error (error);
+
+ g_assert_true (!tracker_sparql_cursor_next (cursor, NULL, NULL));
+ /* This should be 1, the original test had it wrong: there's one column,
+ * no matter if there are no results*/
+ g_assert_true (tracker_sparql_cursor_get_n_columns (cursor) == 1);
+
+ g_test_trap_subprocess ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_empty/subprocess", 0, 0);
+ g_test_trap_assert_failed ();
+
+ g_object_unref (cursor);
+}
+
+/* Closes the cursor before all results are read */
+static void
+test_tracker_sparql_query_iterate_sigpipe (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject}";
+
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+ g_assert_true (cursor);
+ g_assert_no_error (error);
+
+ g_assert_true (tracker_sparql_cursor_next (cursor, NULL, NULL));
+
+ g_object_unref (cursor);
+}
+
+static void
+async_query_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TrackerSparqlCursor *cursor_fd;
+ TrackerSparqlCursor *cursor_glib;
+ AsyncData *data = user_data;
+ GError *error = NULL;
+
+ g_main_loop_quit (data->main_loop);
+
+ cursor_fd = tracker_sparql_connection_query_finish (connection, result, &error);
+
+ g_assert_no_error (error);
+ g_assert_true (cursor_fd != NULL);
+
+ cursor_glib = tracker_sparql_connection_query (connection, data->query, NULL, &error);
+
+ g_assert_no_error (error);
+ g_assert_true (cursor_glib != NULL);
+
+ compare_cursors (cursor_glib, cursor_fd);
+
+ g_object_unref (cursor_fd);
+ g_object_unref (cursor_glib);
+}
+
+static void
+test_tracker_sparql_query_iterate_async (gpointer *fixture,
+ gconstpointer user_data)
+{
+ const gchar *query = "SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}";
+ GMainLoop *main_loop;
+ AsyncData *data;
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ data = g_slice_new (AsyncData);
+ data->main_loop = main_loop;
+ data->query = query;
+
+ tracker_sparql_connection_query_async (connection,
+ query,
+ NULL,
+ async_query_cb,
+ data);
+
+ g_main_loop_run (main_loop);
+
+ g_slice_free (AsyncData, data);
+ g_main_loop_unref (main_loop);
+}
+
+static void
+cancel_query_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GMainLoop *main_loop = user_data;
+ GError *error = NULL;
+
+ g_main_loop_quit (main_loop);
+
+ tracker_sparql_connection_query_finish (connection, result, &error);
+
+ /* An error should be returned (cancelled!) */
+ g_assert_true (error);
+}
+
+static void
+test_tracker_sparql_query_iterate_async_cancel (gpointer *fixture,
+ gconstpointer user_data)
+{
+ const gchar *query = "SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}";
+ GMainLoop *main_loop;
+ GCancellable *cancellable = g_cancellable_new ();
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ tracker_sparql_connection_query_async (connection,
+ query,
+ cancellable,
+ cancel_query_cb,
+ main_loop);
+
+ g_cancellable_cancel (cancellable);
+
+ g_main_loop_run (main_loop);
+
+ g_main_loop_unref (main_loop);
+}
+
+TrackerSparqlConnection *
+create_local_connection (GError **error)
+{
+ TrackerSparqlConnection *conn;
+ GFile *store, *ontology;
+ gchar *path;
+
+ path = g_build_filename (g_get_tmp_dir (), "libtracker-sparql-test-XXXXXX", NULL);
+ g_mkdtemp_full (path, 0700);
+ store = g_file_new_for_path (path);
+ g_free (path);
+
+ ontology = g_file_new_for_path (TEST_ONTOLOGIES_DIR);
+
+ conn = tracker_sparql_connection_new (0, store, ontology, NULL, error);
+ g_object_unref (store);
+ g_object_unref (ontology);
+
+ return conn;
+}
+
+static gpointer
+thread_func (gpointer user_data)
+{
+ GDBusConnection *dbus_conn = user_data;
+ TrackerSparqlConnection *direct;
+ TrackerEndpointDBus *endpoint;
+ GMainContext *context;
+ GMainLoop *main_loop;
+
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+
+ main_loop = g_main_loop_new (context, FALSE);
+
+ direct = create_local_connection (NULL);
+ if (!direct)
+ return NULL;
+
+ endpoint = tracker_endpoint_dbus_new (direct, dbus_conn, NULL, NULL, NULL);
+ if (!endpoint)
+ return NULL;
+
+ started = TRUE;
+ g_main_loop_run (main_loop);
+
+ return NULL;
+}
+
+static TrackerSparqlConnection *
+create_dbus_connection (GError **error)
+{
+ TrackerSparqlConnection *dbus;
+ GDBusConnection *dbus_conn;
+ GThread *thread;
+
+ dbus_conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (!dbus_conn)
+ return NULL;
+
+ thread = g_thread_new (NULL, thread_func, dbus_conn);
+
+ while (!started)
+ g_usleep (100);
+
+ dbus = tracker_sparql_connection_bus_new (g_dbus_connection_get_unique_name (dbus_conn),
+ NULL, dbus_conn, error);
+ g_thread_unref (thread);
+
+ return dbus;
+}
+
+static void test_tracker_sparql_cursor_next_async_query (TrackerSparqlConnection *connection,
+ guint query);
+
+static void
+test_tracker_sparql_cursor_next_async_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ gboolean success;
+ static guint finished = 0;
+ static gint next = 0;
+ gint next_to_cancel = 1;
+ gint query;
+
+ query = GPOINTER_TO_INT(user_data);
+
+ g_assert_true (result != NULL);
+ success = tracker_sparql_cursor_next_finish (TRACKER_SPARQL_CURSOR (source),
+ result,
+ &error);
+
+ if (finished == 1 && next == next_to_cancel) {
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ g_print ("# Got Cancellation GError\n");
+ } else {
+ g_assert_no_error (error);
+ }
+
+ cursor = TRACKER_SPARQL_CURSOR (source);
+ g_assert_true (cursor != NULL);
+ connection = tracker_sparql_cursor_get_connection (cursor);
+
+ if (!success) {
+ finished++;
+ next = 0;
+
+ if (finished == 1 || finished == 2) {
+ test_tracker_sparql_cursor_next_async_query (connection,
+ finished);
+ } else if (finished == 3) {
+ g_main_loop_quit (main_loop);
+ }
+ } else {
+ next++;
+
+ /* Random number here for next_count_to_cancel is "2",
+ * just want to do this mid-cursor iteration
+ */
+ if (next == next_to_cancel && finished == 1) {
+ /* Cancel */
+ g_print ("# Cancelling cancellable: at count:%d\n", next);
+ g_cancellable_cancel (cancellables[query]);
+ }
+
+ tracker_sparql_cursor_next_async (cursor,
+ cancellables[query],
+ test_tracker_sparql_cursor_next_async_cb,
+ user_data);
+ }
+}
+
+static void
+test_tracker_sparql_cursor_next_async_query (TrackerSparqlConnection *connection,
+ guint query)
+{
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+
+ g_assert_true (query < G_N_ELEMENTS (queries));
+ g_print ("# ASYNC query %d starting:\n", query);
+
+ cancellables[query] = g_cancellable_new ();
+ g_assert_true (cancellables[query] != NULL);
+
+ cursor = tracker_sparql_connection_query (connection,
+ queries[query],
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert_true (cursor != NULL);
+
+ tracker_sparql_cursor_next_async (cursor,
+ cancellables[query],
+ test_tracker_sparql_cursor_next_async_cb,
+ GINT_TO_POINTER(query));
+}
+
+static void
+test_tracker_sparql_cursor_next_async (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlConnection *connection;
+ GError *error = NULL;
+
+ main_loop = g_main_loop_new (NULL, TRUE);
+
+ /* So, the idea here:
+ * 1. Test async cursor_next() call.
+ * 2. Make sure we can cancel a cursor_next() call and start a new query (was failing)
+ * 3. Handle multiple async queries + async cursor_next() calls.
+ */
+
+ connection = create_local_connection (&error);
+ g_assert_no_error (error);
+ g_assert_true (connection != NULL);
+
+ test_tracker_sparql_cursor_next_async_query (connection, 0);
+ g_main_loop_run (main_loop);
+}
+
+static void
+test_tracker_sparql_cursor_get_variable_name (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+
+ connection = create_local_connection (&error);
+ g_assert_no_error (error);
+ g_assert_true (connection != NULL);
+
+ cursor = tracker_sparql_connection_query (connection,
+ "SELECT ?urn ?added ?label ?unbound { "
+ " ?urn nrl:added ?added ; "
+ " rdfs:label ?label . "
+ "} LIMIT 1",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_true (cursor != NULL);
+
+ tracker_sparql_cursor_next (cursor, NULL, &error);
+ g_assert_no_error (error);
+
+ g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 0),
+ ==,
+ "urn");
+ g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 1),
+ ==,
+ "added");
+ g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 2),
+ ==,
+ "label");
+ g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 3),
+ ==,
+ "unbound");
+
+ tracker_sparql_cursor_close (cursor);
+ tracker_sparql_connection_close (connection);
+}
+
+static void
+test_tracker_sparql_cursor_get_value_type (gpointer *fixture,
+ gconstpointer user_data)
+{
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+
+ connection = create_local_connection (&error);
+ g_assert_no_error (error);
+ g_assert_true (connection != NULL);
+
+ cursor = tracker_sparql_connection_query (connection,
+ "SELECT ?urn ?added ?label ?unbound { "
+ " ?urn nrl:added ?added ; "
+ " rdfs:label ?label . "
+ "} LIMIT 1",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_true (cursor != NULL);
+
+ tracker_sparql_cursor_next (cursor, NULL, &error);
+ g_assert_no_error (error);
+
+ g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 0),
+ ==,
+ TRACKER_SPARQL_VALUE_TYPE_URI);
+ g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 1),
+ ==,
+ TRACKER_SPARQL_VALUE_TYPE_DATETIME);
+ g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 2),
+ ==,
+ TRACKER_SPARQL_VALUE_TYPE_STRING);
+ g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 3),
+ ==,
+ TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+
+ tracker_sparql_cursor_close (cursor);
+ tracker_sparql_connection_close (connection);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ connection = create_dbus_connection (NULL);
+
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_largerow", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_largerow, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_error", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_error, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_empty", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_empty, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_empty/subprocess", gpointer, NULL,
+ insert_test_data, test_tracker_sparql_query_iterate_empty_subprocess, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_sigpipe", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_sigpipe, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_async", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_async, delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_query_iterate_async_cancel", gpointer, NULL, insert_test_data,
+ test_tracker_sparql_query_iterate_async_cancel, delete_test_data);
+
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_cursor_next_async",
+ gpointer, NULL, insert_test_data,
+ test_tracker_sparql_cursor_next_async,
+ delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_cursor_get_variable_name",
+ gpointer, NULL, insert_test_data,
+ test_tracker_sparql_cursor_get_variable_name,
+ delete_test_data);
+ g_test_add ("/libtracker-sparql/cursor/tracker_sparql_cursor_get_value_type",
+ gpointer, NULL, insert_test_data,
+ test_tracker_sparql_cursor_get_value_type,
+ delete_test_data);
+
+ return g_test_run ();
+}
diff --git a/tests/libtracker-sparql/tracker-fd-test.c b/tests/libtracker-sparql/tracker-fd-test.c
index a896903d5..84400e779 100644
--- a/tests/libtracker-sparql/tracker-fd-test.c
+++ b/tests/libtracker-sparql/tracker-fd-test.c
@@ -80,214 +80,6 @@ insert_test_data (gpointer *fixture,
g_free (longName);
}
-/*
- * I comment that part out because I don't know how anonymous node hashing
- * works, but if we know two SparqlUpdate calls are going to return the same
- * urns we could use those functions to compare the results between the normal
- * and fast method. I wrote them before realizing I wouldn't know how to use
- * them.
- */
-/*
-static gboolean
-compare_hash_tables (GHashTable *h1, GHashTable *h2)
-{
- GHashTableIter i1, i2;
- gpointer k1, v1, k2, v2;
-
- if (g_hash_table_size (h1) != g_hash_table_size (h2)) {
- return FALSE;
- }
-
- g_hash_table_iter_init (&i1, h1);
- g_hash_table_iter_init (&i2, h2);
-
- while (g_hash_table_iter_next (&i1, &k1, &v1)) {
- g_hash_table_iter_next (&i2, &k2, &v2);
-
- if (g_strcmp0 (k1, k2)) {
- return FALSE;
- }
-
- if (g_strcmp0 (v1, v2)) {
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-compare_results (GPtrArray *r1, GPtrArray *r2)
-{
- int i, j;
-
- if (!r1 || !r2) {
- return FALSE;
- }
-
- if (r1->len != r2->len) {
- return FALSE;
- }
-
- for (i = 0; i < r1->len; i++) {
- GPtrArray *inner1, *inner2;
-
- inner1 = g_ptr_array_index (r1, i);
- inner2 = g_ptr_array_index (r2, i);
-
- if (inner1->len != inner2->len) {
- return FALSE;
- }
-
- for (j = 0; j < inner1->len; j++) {
- GHashTable *h1, *h2;
-
- h1 = g_ptr_array_index (inner1, j);
- h2 = g_ptr_array_index (inner2, j);
-
- if (!compare_hash_tables (h1, h2)) {
- return FALSE;
- }
- }
- }
-
- return TRUE;
-}
-*/
-
-static void
-query_and_compare_results (const char *query)
-{
- TrackerSparqlCursor *cursor_glib;
- TrackerSparqlCursor *cursor_fd;
- GError *error = NULL;
-
- cursor_glib = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- g_assert_no_error (error);
-
- cursor_fd = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- g_assert_no_error (error);
-
- while (tracker_sparql_cursor_next (cursor_glib, NULL, NULL) && tracker_sparql_cursor_next (cursor_fd, NULL, NULL)) {
- g_assert_cmpstr (tracker_sparql_cursor_get_string (cursor_glib, 0, NULL),
- ==,
- tracker_sparql_cursor_get_string (cursor_fd, 0, NULL));
- }
-
- /* Check that both cursors are at the end (same number of rows) */
- g_assert_true (!tracker_sparql_cursor_next (cursor_glib, NULL, NULL));
- g_assert_true (!tracker_sparql_cursor_next (cursor_fd, NULL, NULL));
-
- g_object_unref (cursor_glib);
- g_object_unref (cursor_fd);
-}
-
-static void
-test_tracker_sparql_query_iterate (gpointer *fixture,
- gconstpointer user_data)
-{
- query_and_compare_results ("SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}");
-}
-
-static void
-test_tracker_sparql_query_iterate_largerow (gpointer *fixture,
- gconstpointer user_data)
-{
- query_and_compare_results ("SELECT nao:identifier(?r) WHERE {?r a nmm:Photo}");
-}
-
-/* Runs an invalid query */
-static void
-test_tracker_sparql_query_iterate_error (gpointer *fixture,
- gconstpointer user_data)
-{
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- const gchar *query = "bork bork bork";
-
- cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- /* tracker_sparql_query_iterate should return null on error */
- g_assert_true (!cursor);
-
- /* error should be set, along with its message, note: we don't
- * use g_assert_error() because the code does not match the
- * enum values for TRACKER_SPARQL_ERROR_*, this is due to
- * dbus/error matching between client/server. This should be
- * fixed in gdbus.
- */
- g_assert_true (error != NULL && error->domain == TRACKER_SPARQL_ERROR);
-
- g_error_free (error);
-}
-
-/* Runs a query returning an empty set */
-static void
-test_tracker_sparql_query_iterate_empty_subprocess (gpointer *fixture,
- gconstpointer user_data)
-{
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier \"thisannotationdoesnotexist\"}";
-
- cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- g_assert_true (tracker_sparql_cursor_next (cursor, NULL, NULL));
-
- /* Testing we fail with this error:
- *
- * Tracker-CRITICAL **:
- * tracker_bus_fd_cursor_real_get_string: assertion '(_tmp0_
- * < _tmp2_) && (_tmp3_ != NULL)' failed
- */
- tracker_sparql_cursor_get_string (cursor, 0, NULL);
-}
-
-static void
-test_tracker_sparql_query_iterate_empty (gpointer *fixture,
- gconstpointer user_data)
-{
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier \"thisannotationdoesnotexist\"}";
-
- cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- g_assert_true (cursor);
- g_assert_no_error (error);
-
- g_assert_true (!tracker_sparql_cursor_next (cursor, NULL, NULL));
- /* This should be 1, the original test had it wrong: there's one column,
- * no matter if there are no results*/
- g_assert_true (tracker_sparql_cursor_get_n_columns (cursor) == 1);
-
- g_test_trap_subprocess ("/steroids/tracker/tracker_sparql_query_iterate_empty/subprocess", 0, 0);
- g_test_trap_assert_failed ();
-
- g_object_unref (cursor);
-}
-
-/* Closes the cursor before all results are read */
-static void
-test_tracker_sparql_query_iterate_sigpipe (gpointer *fixture,
- gconstpointer user_data)
-{
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject}";
-
- cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
-
- g_assert_true (cursor);
- g_assert_no_error (error);
-
- g_assert_true (tracker_sparql_cursor_next (cursor, NULL, NULL));
-
- g_object_unref (cursor);
-}
-
static void
test_tracker_sparql_update_fast_small (gpointer *fixture,
gconstpointer user_data)
@@ -518,107 +310,6 @@ test_tracker_batch_sparql_update_fast (gpointer *fixture,
}
static void
-async_query_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- TrackerSparqlCursor *cursor_fd;
- TrackerSparqlCursor *cursor_glib;
- AsyncData *data = user_data;
- GError *error = NULL;
-
- g_main_loop_quit (data->main_loop);
-
- cursor_fd = tracker_sparql_connection_query_finish (connection, result, &error);
-
- g_assert_no_error (error);
- g_assert_true (cursor_fd != NULL);
-
- cursor_glib = tracker_sparql_connection_query (connection, data->query, NULL, &error);
-
- g_assert_no_error (error);
- g_assert_true (cursor_glib != NULL);
-
- while (tracker_sparql_cursor_next (cursor_fd, NULL, NULL) &&
- tracker_sparql_cursor_next (cursor_glib, NULL, NULL)) {
- g_assert_cmpstr (tracker_sparql_cursor_get_string (cursor_fd, 0, NULL),
- ==,
- tracker_sparql_cursor_get_string (cursor_glib, 0, NULL));
- }
-
- g_assert_true (!tracker_sparql_cursor_next (cursor_fd, NULL, NULL));
- g_assert_true (!tracker_sparql_cursor_next (cursor_glib, NULL, NULL));
-
- g_object_unref (cursor_fd);
- g_object_unref (cursor_glib);
-}
-
-static void
-test_tracker_sparql_query_iterate_async (gpointer *fixture,
- gconstpointer user_data)
-{
- const gchar *query = "SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}";
- GMainLoop *main_loop;
- AsyncData *data;
-
- main_loop = g_main_loop_new (NULL, FALSE);
-
- data = g_slice_new (AsyncData);
- data->main_loop = main_loop;
- data->query = query;
-
- tracker_sparql_connection_query_async (connection,
- query,
- NULL,
- async_query_cb,
- data);
-
- g_main_loop_run (main_loop);
-
- g_slice_free (AsyncData, data);
- g_main_loop_unref (main_loop);
-}
-
-static void
-cancel_query_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- GMainLoop *main_loop = user_data;
- GError *error = NULL;
-
- g_main_loop_quit (main_loop);
-
- tracker_sparql_connection_query_finish (connection, result, &error);
-
- /* An error should be returned (cancelled!) */
- g_assert_true (error);
-}
-
-static void
-test_tracker_sparql_query_iterate_async_cancel (gpointer *fixture,
- gconstpointer user_data)
-{
- const gchar *query = "SELECT ?r nie:url(?r) WHERE {?r a nfo:FileDataObject}";
- GMainLoop *main_loop;
- GCancellable *cancellable = g_cancellable_new ();
-
- main_loop = g_main_loop_new (NULL, FALSE);
-
- tracker_sparql_connection_query_async (connection,
- query,
- cancellable,
- cancel_query_cb,
- main_loop);
-
- g_cancellable_cancel (cancellable);
-
- g_main_loop_run (main_loop);
-
- g_main_loop_unref (main_loop);
-}
-
-static void
async_update_callback (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
@@ -817,18 +508,6 @@ main (gint argc, gchar **argv)
connection = create_dbus_connection (NULL);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_largerow", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_largerow, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_error", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_error, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_empty", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_empty, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_empty/subprocess", gpointer, NULL,
- insert_test_data, test_tracker_sparql_query_iterate_empty_subprocess, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_sigpipe", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_sigpipe, delete_test_data);
g_test_add ("/steroids/tracker/tracker_sparql_update_fast_small", gpointer, NULL, insert_test_data,
test_tracker_sparql_update_fast_small, delete_test_data);
g_test_add ("/steroids/tracker/tracker_sparql_update_fast_large", gpointer, NULL, insert_test_data,
@@ -845,10 +524,6 @@ main (gint argc, gchar **argv)
test_tracker_sparql_update_blank_fast_no_blanks, delete_test_data);
g_test_add ("/steroids/tracker/tracker_batch_sparql_update_fast", gpointer, NULL, insert_test_data,
test_tracker_batch_sparql_update_fast, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_async", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_async, delete_test_data);
- g_test_add ("/steroids/tracker/tracker_sparql_query_iterate_async_cancel", gpointer, NULL, insert_test_data,
- test_tracker_sparql_query_iterate_async_cancel, delete_test_data);
g_test_add ("/steroids/tracker/tracker_sparql_update_async", gpointer, NULL, insert_test_data,
test_tracker_sparql_update_async, delete_test_data);
g_test_add ("/steroids/tracker/tracker_sparql_update_async_cancel", gpointer, NULL, insert_test_data,
diff --git a/tests/libtracker-sparql/tracker-sparql-test.c b/tests/libtracker-sparql/tracker-sparql-test.c
index 66a74e1a1..d8ad04d3c 100644
--- a/tests/libtracker-sparql/tracker-sparql-test.c
+++ b/tests/libtracker-sparql/tracker-sparql-test.c
@@ -38,24 +38,6 @@ ESCAPE_TEST_DATA test_data [] = {
{ NULL, NULL }
};
-static GMainLoop *main_loop;
-
-#define N_QUERIES 3
-
-static GCancellable *cancellables[N_QUERIES] = { NULL, };
-
-/* OK: query 0 with either query 4 or 5.
- * FAIL: query 4 and 5 together (requires data to exist)
- */
-static const gchar *queries[N_QUERIES] = {
- /* #1 */
- "SELECT ?p WHERE { ?p nrl:indexed true }",
- /* #2 */
- "SELECT ?prefix ?ns WHERE { ?ns a nrl:Namespace ; nrl:prefix ?prefix }",
- /* #3 */
- "SELECT ?p WHERE { ?p nrl:fulltextIndexed true }",
-};
-
TrackerSparqlConnection *
create_local_connection (GError **error)
{
@@ -100,198 +82,6 @@ test_tracker_sparql_escape_uri_vprintf (void)
g_free (result);
}
-static void test_tracker_sparql_cursor_next_async_query (TrackerSparqlConnection *connection,
- guint query);
-
-static void
-test_tracker_sparql_cursor_next_async_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- TrackerSparqlConnection *connection;
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- gboolean success;
- static guint finished = 0;
- static gint next = 0;
- gint next_to_cancel = 1;
- gint query;
-
- query = GPOINTER_TO_INT(user_data);
-
- g_assert_true (result != NULL);
- success = tracker_sparql_cursor_next_finish (TRACKER_SPARQL_CURSOR (source),
- result,
- &error);
-
- if (finished == 1 && next == next_to_cancel) {
- g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
- g_print ("# Got Cancellation GError\n");
- } else {
- g_assert_no_error (error);
- }
-
- cursor = TRACKER_SPARQL_CURSOR (source);
- g_assert_true (cursor != NULL);
- connection = tracker_sparql_cursor_get_connection (cursor);
-
- if (!success) {
- finished++;
- next = 0;
-
- if (finished == 1 || finished == 2) {
- test_tracker_sparql_cursor_next_async_query (connection,
- finished);
- } else if (finished == 3) {
- g_main_loop_quit (main_loop);
- }
- } else {
- next++;
-
- /* Random number here for next_count_to_cancel is "2",
- * just want to do this mid-cursor iteration
- */
- if (next == next_to_cancel && finished == 1) {
- /* Cancel */
- g_print ("# Cancelling cancellable: at count:%d\n", next);
- g_cancellable_cancel (cancellables[query]);
- }
-
- tracker_sparql_cursor_next_async (cursor,
- cancellables[query],
- test_tracker_sparql_cursor_next_async_cb,
- user_data);
- }
-}
-
-static void
-test_tracker_sparql_cursor_next_async_query (TrackerSparqlConnection *connection,
- guint query)
-{
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
-
- g_assert_true (query < G_N_ELEMENTS (queries));
- g_print ("# ASYNC query %d starting:\n", query);
-
- cancellables[query] = g_cancellable_new ();
- g_assert_true (cancellables[query] != NULL);
-
- cursor = tracker_sparql_connection_query (connection,
- queries[query],
- NULL,
- &error);
- g_assert_no_error (error);
- g_assert_true (cursor != NULL);
-
- tracker_sparql_cursor_next_async (cursor,
- cancellables[query],
- test_tracker_sparql_cursor_next_async_cb,
- GINT_TO_POINTER(query));
-}
-
-static void
-test_tracker_sparql_cursor_next_async (void)
-{
- TrackerSparqlConnection *connection;
- GError *error = NULL;
-
- main_loop = g_main_loop_new (NULL, TRUE);
-
- /* So, the idea here:
- * 1. Test async cursor_next() call.
- * 2. Make sure we can cancel a cursor_next() call and start a new query (was failing)
- * 3. Handle multiple async queries + async cursor_next() calls.
- */
-
- connection = create_local_connection (&error);
- g_assert_no_error (error);
- g_assert_true (connection != NULL);
-
- test_tracker_sparql_cursor_next_async_query (connection, 0);
- g_main_loop_run (main_loop);
-}
-
-static void
-test_tracker_sparql_cursor_get_variable_name (void)
-{
- TrackerSparqlConnection *connection;
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
-
- connection = create_local_connection (&error);
- g_assert_no_error (error);
- g_assert_true (connection != NULL);
-
- cursor = tracker_sparql_connection_query (connection,
- "SELECT ?urn ?added ?label ?unbound { "
- " ?urn nrl:added ?added ; "
- " rdfs:label ?label . "
- "} LIMIT 1",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_true (cursor != NULL);
-
- tracker_sparql_cursor_next (cursor, NULL, &error);
- g_assert_no_error (error);
-
- g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 0),
- ==,
- "urn");
- g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 1),
- ==,
- "added");
- g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 2),
- ==,
- "label");
- g_assert_cmpstr (tracker_sparql_cursor_get_variable_name (cursor, 3),
- ==,
- "unbound");
-
- tracker_sparql_cursor_close (cursor);
- tracker_sparql_connection_close (connection);
-}
-
-static void
-test_tracker_sparql_cursor_get_value_type (void)
-{
- TrackerSparqlConnection *connection;
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
-
- connection = create_local_connection (&error);
- g_assert_no_error (error);
- g_assert_true (connection != NULL);
-
- cursor = tracker_sparql_connection_query (connection,
- "SELECT ?urn ?added ?label ?unbound { "
- " ?urn nrl:added ?added ; "
- " rdfs:label ?label . "
- "} LIMIT 1",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_true (cursor != NULL);
-
- tracker_sparql_cursor_next (cursor, NULL, &error);
- g_assert_no_error (error);
-
- g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 0),
- ==,
- TRACKER_SPARQL_VALUE_TYPE_URI);
- g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 1),
- ==,
- TRACKER_SPARQL_VALUE_TYPE_DATETIME);
- g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 2),
- ==,
- TRACKER_SPARQL_VALUE_TYPE_STRING);
- g_assert_cmpint (tracker_sparql_cursor_get_value_type (cursor, 3),
- ==,
- TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
-
- tracker_sparql_cursor_close (cursor);
- tracker_sparql_connection_close (connection);
-}
-
/* Test that we return an error if no ontology is passed. */
static void
test_tracker_sparql_connection_no_ontology (void)
@@ -369,12 +159,6 @@ main (gint argc, gchar **argv)
test_tracker_sparql_connection_no_ontology);
g_test_add_func ("/libtracker-sparql/tracker-sparql/tracker_sparql_connection_interleaved",
test_tracker_sparql_connection_interleaved);
- g_test_add_func ("/libtracker-sparql/tracker-sparql/tracker_sparql_cursor_next_async",
- test_tracker_sparql_cursor_next_async);
- g_test_add_func ("/libtracker-sparql/tracker-sparql/tracker_sparql_cursor_get_variable_name",
- test_tracker_sparql_cursor_get_variable_name);
- g_test_add_func ("/libtracker-sparql/tracker-sparql/tracker_sparql_cursor_get_value_type",
- test_tracker_sparql_cursor_get_value_type);
g_test_add_func ("/libtracker-sparql/tracker-sparql/tracker_check_version",
test_tracker_check_version);