[tracker/parser] Added unit-test for Turtle parser



commit aa82b2ec2a99df24e5073be0b731d51d04a91454
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Aug 19 14:12:21 2009 +0200

    Added unit-test for Turtle parser

 configure.ac                                       |    1 +
 src/libtracker-data/tracker-data-manager.c         |   28 ++++++++++----------
 tests/libtracker-data/tracker-sparql-test.c        |    6 ++--
 tests/libtracker-data/turtle/Makefile.am           |    7 +++++
 .../turtle/turtle-data-001.ontology                |   20 ++++++++++++++
 tests/libtracker-data/turtle/turtle-data-001.ttl   |    5 +++
 tests/libtracker-data/turtle/turtle-query-001.out  |    1 +
 tests/libtracker-data/turtle/turtle-query-001.rq   |    7 +++++
 8 files changed, 58 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3700c01..9c9ec33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1431,6 +1431,7 @@ AC_CONFIG_FILES([
 	tests/libtracker-data/regex/Makefile
 	tests/libtracker-data/sort/Makefile
 	tests/libtracker-data/error/Makefile
+	tests/libtracker-data/turtle/Makefile
 	tests/libtracker-db/Makefile
 	tests/Makefile
 	tests/tracker-miner-fs/Makefile
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 3cb483e..bb3b91c 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -79,8 +79,8 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 		predicate = tracker_turtle_reader_get_predicate (reader);
 		object = tracker_turtle_reader_get_object (reader);
 
-		if (strcmp (predicate, RDF_TYPE) == 0) {
-			if (strcmp (object, RDFS_CLASS) == 0) {
+		if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
+			if (g_strcmp0 (object, RDFS_CLASS) == 0) {
 				TrackerClass *class;
 
 				if (tracker_ontology_get_class_by_uri (subject) != NULL) {
@@ -92,7 +92,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 				tracker_class_set_uri (class, subject);
 				tracker_ontology_add_class (class);
 				g_object_unref (class);
-			} else if (strcmp (object, RDF_PROPERTY) == 0) {
+			} else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
 				TrackerProperty *property;
 
 				if (tracker_ontology_get_property_by_uri (subject) != NULL) {
@@ -104,7 +104,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 				tracker_property_set_uri (property, subject);
 				tracker_ontology_add_property (property);
 				g_object_unref (property);
-			} else if (strcmp (object, TRACKER_PREFIX "Namespace") == 0) {
+			} else if (g_strcmp0 (object, TRACKER_PREFIX "Namespace") == 0) {
 				TrackerNamespace *namespace;
 
 				if (tracker_ontology_get_namespace_by_uri (subject) != NULL) {
@@ -117,7 +117,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 				tracker_ontology_add_namespace (namespace);
 				g_object_unref (namespace);
 			}
-		} else if (strcmp (predicate, RDFS_SUB_CLASS_OF) == 0) {
+		} else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
 			TrackerClass *class, *super_class;
 
 			class = tracker_ontology_get_class_by_uri (subject);
@@ -133,7 +133,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			}
 
 			tracker_class_add_super_class (class, super_class);
-		} else if (strcmp (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
+		} else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
 			TrackerProperty *property, *super_property;
 
 			property = tracker_ontology_get_property_by_uri (subject);
@@ -149,7 +149,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			}
 
 			tracker_property_add_super_property (property, super_property);
-		} else if (strcmp (predicate, RDFS_DOMAIN) == 0) {
+		} else if (g_strcmp0 (predicate, RDFS_DOMAIN) == 0) {
 			TrackerProperty *property;
 			TrackerClass *domain;
 
@@ -166,7 +166,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			}
 
 			tracker_property_set_domain (property, domain);
-		} else if (strcmp (predicate, RDFS_RANGE) == 0) {
+		} else if (g_strcmp0 (predicate, RDFS_RANGE) == 0) {
 			TrackerProperty *property;
 			TrackerClass *range;
 
@@ -183,7 +183,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			}
 
 			tracker_property_set_range (property, range);
-		} else if (strcmp (predicate, NRL_MAX_CARDINALITY) == 0) {
+		} else if (g_strcmp0 (predicate, NRL_MAX_CARDINALITY) == 0) {
 			TrackerProperty *property;
 
 			property = tracker_ontology_get_property_by_uri (subject);
@@ -195,7 +195,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			if (atoi (object) == 1) {
 				tracker_property_set_multiple_values (property, FALSE);
 			}
-		} else if (strcmp (predicate, TRACKER_PREFIX "indexed") == 0) {
+		} else if (g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0) {
 			TrackerProperty *property;
 
 			property = tracker_ontology_get_property_by_uri (subject);
@@ -207,7 +207,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			if (strcmp (object, "true") == 0) {
 				tracker_property_set_indexed (property, TRUE);
 			}
-		} else if (strcmp (predicate, TRACKER_PREFIX "transient") == 0) {
+		} else if (g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0) {
 			TrackerProperty *property;
 
 			property = tracker_ontology_get_property_by_uri (subject);
@@ -216,10 +216,10 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 				continue;
 			}
 
-			if (strcmp (object, "true") == 0) {
+			if (g_strcmp0 (object, "true") == 0) {
 				tracker_property_set_transient (property, TRUE);
 			}
-		} else if (strcmp (predicate, TRACKER_PREFIX "fulltextIndexed") == 0) {
+		} else if (g_strcmp0 (predicate, TRACKER_PREFIX "fulltextIndexed") == 0) {
 			TrackerProperty *property;
 
 			property = tracker_ontology_get_property_by_uri (subject);
@@ -231,7 +231,7 @@ load_ontology_file_from_path (const gchar	 *ontology_file)
 			if (strcmp (object, "true") == 0) {
 				tracker_property_set_fulltext_indexed (property, TRUE);
 			}
-		} else if (strcmp (predicate, TRACKER_PREFIX "prefix") == 0) {
+		} else if (g_strcmp0 (predicate, TRACKER_PREFIX "prefix") == 0) {
 			TrackerNamespace *namespace;
 
 			namespace = tracker_ontology_get_namespace_by_uri (subject);
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index e389670..c719074 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -68,13 +68,13 @@ const TestInfo tests[] = {
 	{ "sort/query-sort-2", "sort/data-sort-1", FALSE },
 	{ "sort/query-sort-3", "sort/data-sort-3", FALSE },
 	{ "sort/query-sort-4", "sort/data-sort-4", FALSE },
-	{ "sort/query-sort-5", "sort/data-sort-4", FALSE },
-
+	{ "sort/query-sort-5", "sort/data-sort-4", FALSE }, 
 	/* Bracket error after WHERE */
 	{ "error/query-error-1", "error/query-error-1", TRUE }, 
-
 	/* Unknown property */
 	{ "error/query-error-2", "error/query-error-2", TRUE },
+
+	{ "turtle/turtle-query-001", "turtle/turtle-data-001", FALSE },
 	{ NULL }
 };
 
diff --git a/tests/libtracker-data/turtle/Makefile.am b/tests/libtracker-data/turtle/Makefile.am
new file mode 100644
index 0000000..3927a2a
--- /dev/null
+++ b/tests/libtracker-data/turtle/Makefile.am
@@ -0,0 +1,7 @@
+include $(top_srcdir)/Makefile.decl
+
+EXTRA_DIST = 			 \
+	turtle-data-001.ontology \
+	turtle-data-001.ttl	 \
+	turtle-query-001.out	 \
+	turtle-query-001.rq
diff --git a/tests/libtracker-data/turtle/turtle-data-001.ontology b/tests/libtracker-data/turtle/turtle-data-001.ontology
new file mode 100644
index 0000000..4fcb8bc
--- /dev/null
+++ b/tests/libtracker-data/turtle/turtle-data-001.ontology
@@ -0,0 +1,20 @@
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix foo: <http://example.org/ns#> .
+ prefix : <http://other.example.org/ns#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+
+foo: a tracker:Namespace ;
+	tracker:prefix "foo" .
+
+: a tracker:Namespace ;
+	tracker:prefix "" .
+
+: a rdf:Property ;
+	rdfs:domain rdfs:Resource ;
+	rdfs:range rdfs:Resource .
+
+foo: a rdf:Property ;
+	rdfs:domain rdfs:Resource ;
+	rdfs:range rdfs:Resource .
diff --git a/tests/libtracker-data/turtle/turtle-data-001.ttl b/tests/libtracker-data/turtle/turtle-data-001.ttl
new file mode 100755
index 0000000..f35829d
--- /dev/null
+++ b/tests/libtracker-data/turtle/turtle-data-001.ttl
@@ -0,0 +1,5 @@
+# this is a complete turtle document
+ prefix foo: <http://example.org/ns#> .
+ prefix : <http://other.example.org/ns#> .
+foo:bar foo: : .
+:bar : foo:bar .
diff --git a/tests/libtracker-data/turtle/turtle-query-001.out b/tests/libtracker-data/turtle/turtle-query-001.out
new file mode 100755
index 0000000..17a15e2
--- /dev/null
+++ b/tests/libtracker-data/turtle/turtle-query-001.out
@@ -0,0 +1 @@
+"http://other.example.org/ns#";	"http://example.org/ns#bar";
diff --git a/tests/libtracker-data/turtle/turtle-query-001.rq b/tests/libtracker-data/turtle/turtle-query-001.rq
new file mode 100755
index 0000000..e42b4ce
--- /dev/null
+++ b/tests/libtracker-data/turtle/turtle-query-001.rq
@@ -0,0 +1,7 @@
+PREFIX foo: <http://example.org/ns#> 
+PREFIX : <http://other.example.org/ns#> 
+
+SELECT ?foo ?bar WHERE {
+  foo:bar foo: ?foo .
+  :bar : ?bar .
+}



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