[tracker/wip/carlosg/serialize-api: 51/53] tests: Add serialize tests
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/serialize-api: 51/53] tests: Add serialize tests
- Date: Mon, 13 Dec 2021 01:10:26 +0000 (UTC)
commit 14cdd6010b772a47df70398b00e4c2a4716f1099
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Nov 27 15:13:34 2021 +0100
tests: Add serialize tests
Test both connection and statement serialization API
tests/libtracker-sparql/meson.build | 11 +
.../libtracker-sparql/serialize/construct-trig.out | 21 ++
.../libtracker-sparql/serialize/construct-trig.rq | 5 +
.../libtracker-sparql/serialize/construct-ttl.out | 19 ++
tests/libtracker-sparql/serialize/construct-ttl.rq | 5 +
.../serialize/describe-graph-trig.out | 47 +++
.../serialize/describe-graph-trig.rq | 5 +
.../serialize/describe-graph-ttl.out | 29 ++
.../serialize/describe-graph-ttl.rq | 5 +
.../serialize/describe-single-trig.out | 22 ++
.../serialize/describe-single-trig.rq | 1 +
.../serialize/describe-single-ttl.out | 20 ++
.../serialize/describe-single-ttl.rq | 1 +
.../serialize/describe-var-trig.out | 23 ++
.../serialize/describe-var-trig.rq | 3 +
.../serialize/describe-var-ttl.out | 21 ++
.../serialize/describe-var-ttl.rq | 3 +
tests/libtracker-sparql/tracker-serialize-test.c | 338 +++++++++++++++++++++
18 files changed, 579 insertions(+)
---
diff --git a/tests/libtracker-sparql/meson.build b/tests/libtracker-sparql/meson.build
index 17badcab9..9f6733f9e 100644
--- a/tests/libtracker-sparql/meson.build
+++ b/tests/libtracker-sparql/meson.build
@@ -54,3 +54,14 @@ tests += {
'exe': tracker_statement_test,
'suite': ['sparql'],
}
+
+tracker_serialize_test = executable('tracker-serialize-test',
+ 'tracker-serialize-test.c',
+ dependencies: [tracker_common_dep, tracker_sparql_dep],
+ c_args: libtracker_sparql_test_c_args + test_c_args)
+
+tests += {
+ 'name': 'serialize',
+ 'exe': tracker_serialize_test,
+ 'suite': ['sparql'],
+}
diff --git a/tests/libtracker-sparql/serialize/construct-trig.out
b/tests/libtracker-sparql/serialize/construct-trig.out
new file mode 100644
index 000000000..65d6809e3
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/construct-trig.out
@@ -0,0 +1,21 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+{
+ <a> <http://example.com/#prop> "Foo" .
+
+ <b> <http://example.com/#prop> "Foo" .
+}
diff --git a/tests/libtracker-sparql/serialize/construct-trig.rq
b/tests/libtracker-sparql/serialize/construct-trig.rq
new file mode 100644
index 000000000..6f9753b34
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/construct-trig.rq
@@ -0,0 +1,5 @@
+CONSTRUCT {
+ ?u <http://example.com/#prop> "Foo"
+} WHERE {
+ ?u a nmm:MusicPiece
+}
diff --git a/tests/libtracker-sparql/serialize/construct-ttl.out
b/tests/libtracker-sparql/serialize/construct-ttl.out
new file mode 100644
index 000000000..432f87a3c
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/construct-ttl.out
@@ -0,0 +1,19 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+<a> <http://example.com/#prop> "Foo" .
+
+<b> <http://example.com/#prop> "Foo" .
diff --git a/tests/libtracker-sparql/serialize/construct-ttl.rq
b/tests/libtracker-sparql/serialize/construct-ttl.rq
new file mode 100644
index 000000000..6f9753b34
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/construct-ttl.rq
@@ -0,0 +1,5 @@
+CONSTRUCT {
+ ?u <http://example.com/#prop> "Foo"
+} WHERE {
+ ?u a nmm:MusicPiece
+}
diff --git a/tests/libtracker-sparql/serialize/describe-graph-trig.out
b/tests/libtracker-sparql/serialize/describe-graph-trig.out
new file mode 100644
index 000000000..ac95a7f36
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-graph-trig.out
@@ -0,0 +1,47 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+GRAPH <B> {
+ <a> nmm:trackNumber 1 .
+
+ <b> nmm:beatsPerMinute 120 .
+}
+
+GRAPH <A> {
+ <a> nie:title "Aaa" ;
+ dc:title "Aaa" ;
+}
+
+GRAPH <B> {
+
+}
+
+GRAPH <A> {
+}
+
+GRAPH <B> {
+
+}
+
+GRAPH <A> {
+ <a> rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece" .
+}
+
+GRAPH <B> {
+ <a> rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece" .
+
+ <b> rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece" .
+}
diff --git a/tests/libtracker-sparql/serialize/describe-graph-trig.rq
b/tests/libtracker-sparql/serialize/describe-graph-trig.rq
new file mode 100644
index 000000000..fc6ad9904
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-graph-trig.rq
@@ -0,0 +1,5 @@
+DESCRIBE ?u {
+ GRAPH ?g {
+ ?u a nmm:MusicPiece .
+ }
+}
diff --git a/tests/libtracker-sparql/serialize/describe-graph-ttl.out
b/tests/libtracker-sparql/serialize/describe-graph-ttl.out
new file mode 100644
index 000000000..5d52de100
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-graph-ttl.out
@@ -0,0 +1,29 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+<a> nmm:trackNumber 1 .
+
+<b> nmm:beatsPerMinute 120 .
+
+<a> nie:title "Aaa" ;
+ dc:title "Aaa" ;
+
+
+
+
+<a> rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece", "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece" .
+
+<b> rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource",
"http://tracker.api.gnome.org/ontology/v3/nie#InformationElement",
"http://tracker.api.gnome.org/ontology/v3/nfo#Media",
"http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece" .
diff --git a/tests/libtracker-sparql/serialize/describe-graph-ttl.rq
b/tests/libtracker-sparql/serialize/describe-graph-ttl.rq
new file mode 100644
index 000000000..b08eb84a1
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-graph-ttl.rq
@@ -0,0 +1,5 @@
+DESCRIBE ?u {
+ GRAPH ?g {
+ ?u a rdfs:Resource .
+ }
+}
diff --git a/tests/libtracker-sparql/serialize/describe-single-trig.out
b/tests/libtracker-sparql/serialize/describe-single-trig.out
new file mode 100644
index 000000000..6e485625d
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-single-trig.out
@@ -0,0 +1,22 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+{
+ rdfs:Resource nrl:classSpecification "https://www.w3.org/TR/rdf-schema/#ch_resource" ;
+ rdfs:label "All Resources" ;
+ rdfs:comment "All resources" ;
+ rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource", "http://www.w3.org/2000/01/rdf-schema#Class" .
+}
diff --git a/tests/libtracker-sparql/serialize/describe-single-trig.rq
b/tests/libtracker-sparql/serialize/describe-single-trig.rq
new file mode 100644
index 000000000..2584aa749
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-single-trig.rq
@@ -0,0 +1 @@
+DESCRIBE rdfs:Resource
diff --git a/tests/libtracker-sparql/serialize/describe-single-ttl.out
b/tests/libtracker-sparql/serialize/describe-single-ttl.out
new file mode 100644
index 000000000..fed9b04df
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-single-ttl.out
@@ -0,0 +1,20 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+rdfs:Resource nrl:classSpecification "https://www.w3.org/TR/rdf-schema/#ch_resource" ;
+ rdfs:label "All Resources" ;
+ rdfs:comment "All resources" ;
+ rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource", "http://www.w3.org/2000/01/rdf-schema#Class" .
diff --git a/tests/libtracker-sparql/serialize/describe-single-ttl.rq
b/tests/libtracker-sparql/serialize/describe-single-ttl.rq
new file mode 100644
index 000000000..2584aa749
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-single-ttl.rq
@@ -0,0 +1 @@
+DESCRIBE rdfs:Resource
diff --git a/tests/libtracker-sparql/serialize/describe-var-trig.out
b/tests/libtracker-sparql/serialize/describe-var-trig.out
new file mode 100644
index 000000000..f4a3af0e5
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-var-trig.out
@@ -0,0 +1,23 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+{
+ rdfs:Class nrl:classSpecification "https://www.w3.org/TR/rdf-schema/#ch_class" ;
+ rdfs:label "Class" ;
+ rdfs:comment "The class of classes" ;
+ rdfs:subClassOf "http://www.w3.org/2000/01/rdf-schema#Resource" ;
+ rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource", "http://www.w3.org/2000/01/rdf-schema#Class" .
+}
diff --git a/tests/libtracker-sparql/serialize/describe-var-trig.rq
b/tests/libtracker-sparql/serialize/describe-var-trig.rq
new file mode 100644
index 000000000..20463c01d
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-var-trig.rq
@@ -0,0 +1,3 @@
+DESCRIBE ?u {
+ ?u rdfs:label ~arg1
+}
diff --git a/tests/libtracker-sparql/serialize/describe-var-ttl.out
b/tests/libtracker-sparql/serialize/describe-var-ttl.out
new file mode 100644
index 000000000..6718f7bed
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-var-ttl.out
@@ -0,0 +1,21 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix nao: <http://tracker.api.gnome.org/ontology/v3/nao#> .
+@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix fts: <http://tracker.api.gnome.org/ontology/v3/fts#> .
+@prefix nmm: <http://tracker.api.gnome.org/ontology/v3/nmm#> .
+@prefix slo: <http://tracker.api.gnome.org/ontology/v3/slo#> .
+@prefix tracker: <http://tracker.api.gnome.org/ontology/v3/tracker#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix nfo: <http://tracker.api.gnome.org/ontology/v3/nfo#> .
+@prefix osinfo: <http://tracker.api.gnome.org/ontology/v3/osinfo#> .
+@prefix nco: <http://tracker.api.gnome.org/ontology/v3/nco#> .
+@prefix nie: <http://tracker.api.gnome.org/ontology/v3/nie#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix mfo: <http://tracker.api.gnome.org/ontology/v3/mfo#> .
+
+rdfs:Class nrl:classSpecification "https://www.w3.org/TR/rdf-schema/#ch_class" ;
+ rdfs:label "Class" ;
+ rdfs:comment "The class of classes" ;
+ rdfs:subClassOf "http://www.w3.org/2000/01/rdf-schema#Resource" ;
+ rdf:type "http://www.w3.org/2000/01/rdf-schema#Resource", "http://www.w3.org/2000/01/rdf-schema#Class" .
diff --git a/tests/libtracker-sparql/serialize/describe-var-ttl.rq
b/tests/libtracker-sparql/serialize/describe-var-ttl.rq
new file mode 100644
index 000000000..20463c01d
--- /dev/null
+++ b/tests/libtracker-sparql/serialize/describe-var-ttl.rq
@@ -0,0 +1,3 @@
+DESCRIBE ?u {
+ ?u rdfs:label ~arg1
+}
diff --git a/tests/libtracker-sparql/tracker-serialize-test.c
b/tests/libtracker-sparql/tracker-serialize-test.c
new file mode 100644
index 000000000..26cef2023
--- /dev/null
+++ b/tests/libtracker-sparql/tracker-serialize-test.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright (C) 2020, Red Hat Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+typedef struct {
+ const gchar *test_name;
+ const gchar *query_file;
+ const gchar *output_file;
+ TrackerRdfFormat format;
+ const gchar *arg1;
+} TestInfo;
+
+TestInfo tests[] = {
+ { "ttl/var", "serialize/describe-var-ttl.rq", "serialize/describe-var-ttl.out",
TRACKER_RDF_FORMAT_TURTLE, "Class" },
+ { "ttl/single", "serialize/describe-single-ttl.rq", "serialize/describe-single-ttl.out",
TRACKER_RDF_FORMAT_TURTLE, NULL },
+ { "ttl/graph", "serialize/describe-graph-ttl.rq", "serialize/describe-graph-ttl.out",
TRACKER_RDF_FORMAT_TURTLE, NULL },
+ { "ttl/construct", "serialize/construct-ttl.rq", "serialize/construct-ttl.out",
TRACKER_RDF_FORMAT_TURTLE, NULL },
+ { "trig/var", "serialize/describe-var-trig.rq", "serialize/describe-var-trig.out",
TRACKER_RDF_FORMAT_TRIG, "Class" },
+ { "trig/single", "serialize/describe-single-trig.rq", "serialize/describe-single-trig.out",
TRACKER_RDF_FORMAT_TRIG, NULL },
+ { "trig/graph", "serialize/describe-graph-trig.rq", "serialize/describe-graph-trig.out",
TRACKER_RDF_FORMAT_TRIG, NULL },
+ { "trig/construct", "serialize/construct-trig.rq", "serialize/construct-trig.out",
TRACKER_RDF_FORMAT_TRIG, NULL },
+};
+
+typedef struct {
+ TestInfo *test;
+ TrackerSparqlConnection *conn;
+ GMainLoop *loop;
+ GInputStream *istream;
+} TestFixture;
+
+typedef struct {
+ TrackerSparqlConnection *direct;
+ GDBusConnection *dbus_conn;
+} StartupData;
+
+static gboolean started = FALSE;
+static const gchar *bus_name = NULL;
+
+static void
+check_result (GInputStream *istream,
+ const gchar *results_filename)
+{
+ gchar *results;
+ GError *nerror = NULL;
+ GError *error = NULL;
+ gchar *quoted_results;
+ gchar *command_line;
+ gchar *quoted_command_line;
+ gchar *shell;
+ gchar *diff;
+ gchar output[8096] = { 0 };
+
+ g_input_stream_read_all (istream,
+ output, sizeof (output),
+ NULL, NULL, &error);
+ g_assert_no_error (error);
+
+ g_file_get_contents (results_filename, &results, NULL, &nerror);
+ g_assert_no_error (nerror);
+ g_clear_error (&nerror);
+
+ /* compare results with reference output */
+ quoted_results = g_shell_quote (output);
+ command_line = g_strdup_printf ("echo -n %s | grep -v -e nrl:modified -e nrl:added | diff -u %s -",
quoted_results, results_filename);
+ quoted_command_line = g_shell_quote (command_line);
+ shell = g_strdup_printf ("sh -c %s", quoted_command_line);
+ g_spawn_command_line_sync (shell, &diff, NULL, NULL, &error);
+ g_assert_no_error (error);
+
+ if (diff && *diff)
+ g_error ("%s", diff);
+
+ g_free (quoted_results);
+ g_free (command_line);
+ g_free (quoted_command_line);
+ g_free (shell);
+ g_free (diff);
+
+ g_free (results);
+}
+
+static void
+setup (TestFixture *fixture,
+ gconstpointer context)
+{
+ const TestFixture *test = context;
+
+ *fixture = *test;
+}
+
+static void
+serialize_stmt_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFixture *fixture = user_data;
+ GError *error = NULL;
+
+ fixture->istream =
+ tracker_sparql_statement_serialize_finish (TRACKER_SPARQL_STATEMENT (source),
+ res, &error);
+ g_assert_no_error (error);
+ g_main_loop_quit (fixture->loop);
+}
+
+
+static void
+serialize_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TestFixture *fixture = user_data;
+ GError *error = NULL;
+
+ fixture->istream =
+ tracker_sparql_connection_serialize_finish (TRACKER_SPARQL_CONNECTION (source),
+ res, &error);
+ g_assert_no_error (error);
+ g_main_loop_quit (fixture->loop);
+}
+
+static void
+serialize (TestFixture *test_fixture,
+ gconstpointer context)
+{
+ TrackerSparqlStatement *stmt;
+ GError *error = NULL;
+ gchar *path, *query;
+ TestInfo *test_info = test_fixture->test;
+
+ test_fixture->loop = g_main_loop_new (NULL, FALSE);
+
+ 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->arg1) {
+ stmt = tracker_sparql_connection_query_statement (test_fixture->conn,
+ query,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+
+ tracker_sparql_statement_bind_string (stmt, "arg1", test_info->arg1);
+
+ tracker_sparql_statement_serialize_async (stmt,
+ test_info->format,
+ NULL,
+ serialize_stmt_cb,
+ test_fixture);
+ g_object_unref (stmt);
+ } else {
+ tracker_sparql_connection_serialize_async (test_fixture->conn,
+ test_info->format,
+ query,
+ NULL,
+ serialize_cb,
+ test_fixture);
+ }
+
+ g_main_loop_run (test_fixture->loop);
+
+ g_assert_nonnull (test_fixture->istream);
+
+ path = g_build_filename (TOP_SRCDIR, "tests", "libtracker-sparql",
+ test_info->output_file, NULL);
+ check_result (test_fixture->istream, path);
+ g_input_stream_close (test_fixture->istream, NULL, NULL);
+ g_object_unref (test_fixture->istream);
+ g_free (path);
+}
+
+static void
+populate_data (TrackerSparqlConnection *conn)
+{
+ TrackerResource *res;
+ GError *error = NULL;
+
+ /* Add some test data in different graphs */
+ res = tracker_resource_new ("a");
+ tracker_resource_set_uri (res, "rdf:type", "nmm:MusicPiece");
+ tracker_resource_set_uri (res, "nie:title", "Aaa");
+ tracker_sparql_connection_update_resource (conn, "A", res, NULL, &error);
+ g_assert_no_error (error);
+ g_object_unref (res);
+
+ res = tracker_resource_new ("a");
+ tracker_resource_set_uri (res, "rdf:type", "nmm:MusicPiece");
+ tracker_resource_set_int (res, "nmm:trackNumber", 1);
+ tracker_sparql_connection_update_resource (conn, "B", res, NULL, &error);
+ g_assert_no_error (error);
+ g_object_unref (res);
+
+ res = tracker_resource_new ("b");
+ tracker_resource_set_uri (res, "rdf:type", "nmm:MusicPiece");
+ tracker_resource_set_int (res, "nmm:beatsPerMinute", 120);
+ tracker_sparql_connection_update_resource (conn, "B", res, NULL, &error);
+ g_assert_no_error (error);
+ g_object_unref (res);
+}
+
+TrackerSparqlConnection *
+create_local_connection (GError **error)
+{
+ TrackerSparqlConnection *conn;
+ GFile *ontology;
+
+ ontology = g_file_new_for_path (TEST_ONTOLOGIES_DIR);
+
+ conn = tracker_sparql_connection_new (0, NULL, ontology, NULL, error);
+ g_object_unref (ontology);
+
+ populate_data (conn);
+
+ return conn;
+}
+
+static gpointer
+thread_func (gpointer user_data)
+{
+ StartupData *data = user_data;
+ TrackerEndpointDBus *endpoint;
+ TrackerEndpointHttp *endpoint_http;
+ 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);
+
+ endpoint = tracker_endpoint_dbus_new (data->direct, data->dbus_conn, NULL, NULL, NULL);
+ if (!endpoint)
+ return NULL;
+
+ endpoint_http = tracker_endpoint_http_new (data->direct, 54322, NULL, NULL, NULL);
+ if (!endpoint_http)
+ return NULL;
+
+ started = TRUE;
+ g_main_loop_run (main_loop);
+
+ return NULL;
+}
+
+static gboolean
+create_connections (TrackerSparqlConnection **dbus,
+ TrackerSparqlConnection **direct,
+ TrackerSparqlConnection **remote,
+ GError **error)
+{
+ StartupData data;
+ GThread *thread;
+
+ data.direct = create_local_connection (NULL);
+ if (!data.direct)
+ return FALSE;
+ data.dbus_conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (!data.dbus_conn)
+ return FALSE;
+
+ thread = g_thread_new (NULL, thread_func, &data);
+
+ while (!started)
+ g_usleep (100);
+
+ bus_name = g_dbus_connection_get_unique_name (data.dbus_conn);
+ *dbus = tracker_sparql_connection_bus_new (bus_name,
+ NULL, data.dbus_conn, error);
+ *direct = create_local_connection (error);
+ *remote = tracker_sparql_connection_remote_new ("http://127.0.0.1:54322/sparql");
+ g_thread_unref (thread);
+
+ return TRUE;
+}
+
+static void
+add_tests (TrackerSparqlConnection *conn,
+ const gchar *name,
+ gboolean run_service_tests)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (tests); i++) {
+ TestFixture *fixture;
+ gchar *testpath;
+
+ fixture = g_new0 (TestFixture, 1);
+ fixture->conn = conn;
+ fixture->test = &tests[i];
+ testpath = g_strconcat ("/libtracker-sparql/serialize/", name, "/", tests[i].test_name, NULL);
+ g_test_add (testpath, TestFixture, fixture, setup, serialize, NULL);
+ g_free (testpath);
+ }
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ TrackerSparqlConnection *dbus = NULL, *direct = NULL, *remote = NULL;
+ GError *error = NULL;
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_assert_true (create_connections (&dbus, &direct, &remote, &error));
+ g_assert_no_error (error);
+
+ add_tests (direct, "direct", TRUE);
+ add_tests (dbus, "dbus", FALSE);
+ add_tests (remote, "http", FALSE);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]