diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2021-07-25 14:07:21 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2021-11-06 15:07:13 +0100 |
commit | 074c37c281aad036912e0d3a38be9fb6237d7188 (patch) | |
tree | 3fda0fd4d35611026bc0d56647e5a392559811c9 /tests | |
parent | 3e9e17ad6c2b6a7f3c28276106f23ac6ac27557c (diff) | |
download | tracker-074c37c281aad036912e0d3a38be9fb6237d7188.tar.gz |
tests: Add tests for loading statements from resources
Include most tests in a GResource, and run those from there in addition
to the tracker_sparql_connection_query_statement() API, so we additionally
test loading from resources.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libtracker-sparql/meson.build | 3 | ||||
-rw-r--r-- | tests/libtracker-sparql/statement-queries.gresource.xml | 15 | ||||
-rw-r--r-- | tests/libtracker-sparql/tracker-statement-test.c | 45 |
3 files changed, 51 insertions, 12 deletions
diff --git a/tests/libtracker-sparql/meson.build b/tests/libtracker-sparql/meson.build index d4f5c556d..17badcab9 100644 --- a/tests/libtracker-sparql/meson.build +++ b/tests/libtracker-sparql/meson.build @@ -41,8 +41,11 @@ tests += { 'suite': ['sparql'], } +test_gresources = gnome.compile_resources('test_gresources', 'statement-queries.gresource.xml') + tracker_statement_test = executable('tracker-statement-test', 'tracker-statement-test.c', + test_gresources, dependencies: [tracker_common_dep, tracker_sparql_dep], c_args: libtracker_sparql_test_c_args + test_c_args) diff --git a/tests/libtracker-sparql/statement-queries.gresource.xml b/tests/libtracker-sparql/statement-queries.gresource.xml new file mode 100644 index 000000000..a9fcd4865 --- /dev/null +++ b/tests/libtracker-sparql/statement-queries.gresource.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/test/sparql/"> + <file>statement/cast.rq</file> + <file>statement/datetime.rq</file> + <file>statement/filter.rq</file> + <file>statement/limit.rq</file> + <file>statement/object-iri.rq</file> + <file>statement/object.rq</file> + <file>statement/offset.rq</file> + <file>statement/simple-error.rq</file> + <file>statement/simple.rq</file> + <file>statement/subject.rq</file> + </gresource> +</gresources> diff --git a/tests/libtracker-sparql/tracker-statement-test.c b/tests/libtracker-sparql/tracker-statement-test.c index df9276489..0fe55065b 100644 --- a/tests/libtracker-sparql/tracker-statement-test.c +++ b/tests/libtracker-sparql/tracker-statement-test.c @@ -38,19 +38,32 @@ typedef struct { TestInfo tests[] = { { "simple", "statement/simple.rq", "statement/simple.out", "hello" }, + { "simple-2", "/test/sparql/statement/simple.rq", "statement/simple.out", "hello" }, { "simple-error", "statement/simple-error.rq" }, + { "simple-error-2", "/test/sparql/statement/simple-error.rq" }, { "object", "statement/object.rq", "statement/object.out", "Music album" }, + { "object-2", "/test/sparql/statement/object.rq", "statement/object.out", "Music album" }, { "object-iri", "statement/object-iri.rq", "statement/object-iri.out", "http://tracker.api.gnome.org/ontology/v3/nfo#MediaList" }, + { "object-iri-2", "/test/sparql/statement/object-iri.rq", "statement/object-iri.out", "http://tracker.api.gnome.org/ontology/v3/nfo#MediaList" }, { "subject", "statement/subject.rq", "statement/subject.out", "http://tracker.api.gnome.org/ontology/v3/nmm#MusicAlbum" }, { "subject-2", "statement/subject.rq", "statement/subject-2.out", "urn:nonexistent" }, + { "subject-3", "/test/sparql/statement/subject.rq", "statement/subject.out", "http://tracker.api.gnome.org/ontology/v3/nmm#MusicAlbum" }, + { "subject-4", "/test/sparql/statement/subject.rq", "statement/subject-2.out", "urn:nonexistent" }, { "filter", "statement/filter.rq", "statement/filter.out", "http://tracker.api.gnome.org/ontology/v3/nmm#MusicAlbum", "Music album" }, + { "filter-2", "/test/sparql/statement/filter.rq", "statement/filter.out", "http://tracker.api.gnome.org/ontology/v3/nmm#MusicAlbum", "Music album" }, { "service", "statement/service.rq", "statement/service.out", "Music album", NULL, NULL, TRUE }, { "limit", "statement/limit.rq", "statement/limit.out", "1" }, { "limit-2", "statement/limit.rq", "statement/limit-2.out", "2" }, + { "limit-3", "/test/sparql/statement/limit.rq", "statement/limit.out", "1" }, + { "limit-4", "/test/sparql/statement/limit.rq", "statement/limit-2.out", "2" }, { "offset", "statement/offset.rq", "statement/offset.out", "0" }, { "offset-2", "statement/offset.rq", "statement/offset-2.out", "1" }, + { "offset-3", "/test/sparql/statement/offset.rq", "statement/offset.out", "0" }, + { "offset-4", "/test/sparql/statement/offset.rq", "statement/offset-2.out", "1" }, { "datetime", "statement/datetime.rq", "statement/datetime.out", NULL, NULL, "2020-12-04T04:10:03Z" }, + { "datetime-2", "/test/sparql/statement/datetime.rq", "statement/datetime.out", NULL, NULL, "2020-12-04T04:10:03Z" }, { "cast", "statement/cast.rq", "statement/cast.out", "2021-02-24T22:01:02Z" }, + { "cast-2", "/test/sparql/statement/cast.rq", "statement/cast.out", "2021-02-24T22:01:02Z" }, }; typedef struct { @@ -171,23 +184,31 @@ query_statement (TestInfo *test_info, gchar *path, *query; GDateTime *date_time; - path = g_build_filename (TOP_SRCDIR, "tests", "libtracker-sparql", - test_info->query_file, NULL); - g_file_get_contents (path, &query, NULL, &error); - g_assert_no_error (error); - g_free (path); + if (test_info->query_file[0] == '/') { + /* Absolute paths refer to GResource paths here */ + stmt = tracker_sparql_connection_load_statement_from_gresource (test_info->conn, + test_info->query_file, + NULL, &error); + } else { + path = g_build_filename (TOP_SRCDIR, "tests", "libtracker-sparql", + test_info->query_file, NULL); + g_file_get_contents (path, &query, NULL, &error); + g_assert_no_error (error); + g_free (path); + + if (test_info->service) { + gchar *service_query; - if (test_info->service) { - gchar *service_query; + service_query = g_strdup_printf (query, bus_name); + g_free (query); + query = service_query; + } - service_query = g_strdup_printf (query, bus_name); + stmt = tracker_sparql_connection_query_statement (test_info->conn, query, + NULL, &error); g_free (query); - query = service_query; } - stmt = tracker_sparql_connection_query_statement (test_info->conn, query, - NULL, &error); - g_free (query); g_assert_no_error (error); if (test_info->arg1) |