[gnome-photos/sam/tracker3: 5/6] tests: Add photos-test-tracker-queries



commit 115ac5200a28660b78d5c7d167e730f3d013879a
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                   |   5 +-
 tests/unit/photos-test-tracker-queries.c | 117 +++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 1 deletion(-)
---
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index 6acbf22b..131b87f3 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -18,6 +18,9 @@ tests = {
   'photos-test-pipeline': {
     'dependencies': [gdk_pixbuf_dep, gegl_dep, gio_dep, gio_unix_dep, glib_dep, libgnome_photos_dep]
   },
+  'photos-test-tracker-queries': {
+    'dependencies': [libgnome_photos_app_dep]
+  }
 }
 
 test_data = [
@@ -72,4 +75,4 @@ endforeach
 
 if photos_installed_tests_enabled
   install_data(test_data, install_dir: photos_installed_test_execdir)
-endif
\ No newline at end of file
+endif
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]