[gnome-photos/sam/tracker3: 19/27] tests: Add photos-test-tracker-queries




commit 84a237b657abe723431e5a6186f065948f02461c
Author: Sam Thursfield <sam afuera me uk>
Date:   Wed May 27 20:39:56 2020 +0200

    tests: Add photos-test-tracker-queries
    
    This test aims to build and run every Tracker query. We don't check the
    results yet as we run the query against an empty data, but we do at
    least check that it's valid SPARQL and that nothing crashed.

 tests/unit/meson.build                   |   1 +
 tests/unit/photos-test-tracker-queries.c | 117 +++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+)
---
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index 3e4e0d62..59c6ea88 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -14,6 +14,7 @@ test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
 tests = {
   'photos-test-gegl': {},
   'photos-test-pipeline': {},
+  'photos-test-tracker-queries': {}
 }
 
 test_data = [
diff --git a/tests/unit/photos-test-tracker-queries.c b/tests/unit/photos-test-tracker-queries.c
new file mode 100644
index 00000000..70aff286
--- /dev/null
+++ b/tests/unit/photos-test-tracker-queries.c
@@ -0,0 +1,117 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2020 Sam Thursfield
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <locale.h>
+
+#include <glib.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+#include "photos-application.h"
+#include "photos-debug.h"
+#include "photos-query.h"
+#include "photos-query-builder.h"
+#include "photos-search-context.h"
+#include "photos-search-provider.h"
+
+
+typedef struct
+{
+  TrackerSparqlConnection *connection;
+} PhotosTestTrackerQueriesFixture;
+
+
+static void
+photos_test_tracker_queries_setup (PhotosTestTrackerQueriesFixture *fixture, gconstpointer user_data)
+{
+  g_autoptr (GError) error = NULL;
+
+  fixture->connection = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE,
+                                                       NULL,
+                                                       tracker_sparql_get_ontology_nepomuk (),
+                                                       NULL,
+                                                       &error);
+  g_assert_no_error (error);
+}
+
+static void
+photos_test_tracker_queries_teardown (PhotosTestTrackerQueriesFixture *fixture, gconstpointer user_data)
+{
+  g_object_unref (fixture->connection);
+}
+
+
+static void
+test_count_query (TrackerSparqlConnection *connection, PhotosSearchContextState *state, PhotosQueryFlags 
flags)
+{
+  g_autoptr (PhotosQuery) query;
+  g_autoptr (GError) error = NULL;
+
+  query = photos_query_builder_count_query (state, flags);
+
+  g_debug ("Testing query: %s", photos_query_get_sparql (query));
+  tracker_sparql_connection_query (connection,
+                                   photos_query_get_sparql (query),
+                                   NULL,
+                                   &error);
+
+  g_assert_no_error (error);
+}
+
+static void
+photos_test_tracker_count_queries (PhotosTestTrackerQueriesFixture *fixture, gconstpointer user_data)
+{
+  g_autoptr (GApplication) app;
+  g_autoptr (PhotosSearchProvider) search_provider;
+  PhotosSearchContextState *state;
+
+  app = photos_application_new ();
+  search_provider = photos_search_provider_new ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (search_provider));
+
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_UNFILTERED);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_COLLECTIONS);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_FAVORITES);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_IMPORT);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_LOCAL);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_OVERVIEW);
+  test_count_query (fixture->connection, state, PHOTOS_QUERY_FLAGS_SEARCH);
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+  gint exit_status;
+
+  setlocale (LC_ALL, "");
+  g_test_init (&argc, &argv, NULL);
+  photos_debug_init ();
+
+  g_test_add ("/tracker/queries/count",
+              PhotosTestTrackerQueriesFixture,
+              NULL,
+              photos_test_tracker_queries_setup,
+              photos_test_tracker_count_queries,
+              photos_test_tracker_queries_teardown);
+
+  exit_status = g_test_run ();
+
+  return exit_status;
+}


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