[tracker/ontology-cope] tests/libtracker-data: Added unit tests
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/ontology-cope] tests/libtracker-data: Added unit tests
- Date: Wed, 24 Mar 2010 10:19:27 +0000 (UTC)
commit e67d37b092c2c84b7d436a686308a6468a314889
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Mar 24 11:17:17 2010 +0100
tests/libtracker-data: Added unit tests
For coping with ontology changes and journal replaying (and both combined)
tests/libtracker-data/backup/backup.ontology | 4 ++-
.../change/ontologies/99-example.ontology | 37 ++++++++++++++++++++
.../change/source/99-example.ontology.v1 | 12 ++++++
.../change/source/99-example.ontology.v2 | 21 +++++++++++
.../change/source/99-example.ontology.v3 | 29 +++++++++++++++
.../change/source/99-example.ontology.v4 | 37 ++++++++++++++++++++
tests/libtracker-data/change/test-1.out | 1 +
tests/libtracker-data/change/test-1.rq | 1 +
tests/libtracker-data/change/test-2.out | 1 +
tests/libtracker-data/change/test-2.rq | 1 +
tests/libtracker-data/change/test-3.out | 1 +
tests/libtracker-data/change/test-3.rq | 1 +
.../change/updates/99-example.queries.v2 | 3 ++
.../change/updates/99-example.queries.v3 | 6 +++
.../change/updates/99-example.queries.v4 | 6 +++
tests/libtracker-data/ontologies/20-dc.ontology | 19 ++++++++++
tests/libtracker-data/ontologies/31-nao.ontology | 23 ++++++++++++
tests/libtracker-data/tracker-backup-test.c | 16 +++++---
tests/libtracker-data/tracker-ontology-test.c | 15 ++++----
19 files changed, 220 insertions(+), 14 deletions(-)
---
diff --git a/tests/libtracker-data/backup/backup.ontology b/tests/libtracker-data/backup/backup.ontology
index f870982..4fb3f9c 100644
--- a/tests/libtracker-data/backup/backup.ontology
+++ b/tests/libtracker-data/backup/backup.ontology
@@ -3,8 +3,10 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
@prefix foo: <http://example.org/ns#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
-foo: a tracker:Namespace ;
+foo: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:04Z" ;
tracker:prefix "foo" .
foo:class1 a rdfs:Class .
diff --git a/tests/libtracker-data/change/ontologies/99-example.ontology b/tests/libtracker-data/change/ontologies/99-example.ontology
new file mode 100644
index 0000000..706d77c
--- /dev/null
+++ b/tests/libtracker-data/change/ontologies/99-example.ontology
@@ -0,0 +1,37 @@
+ prefix example: <http://example/> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+example: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:04Z" ;
+ tracker:prefix "example" .
+
+example:A a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:B a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:b a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range example:B .
+
+example:i1 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
+example:i2 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
+example:ib a rdf:Property ;
+ rdfs:domain example:B ;
+ rdfs:range xsd:integer .
+
+example:sb a rdf:Property ;
+ rdfs:domain example:B ;
+ rdfs:range xsd:string .
+
diff --git a/tests/libtracker-data/change/source/99-example.ontology.v1 b/tests/libtracker-data/change/source/99-example.ontology.v1
new file mode 100644
index 0000000..6822e77
--- /dev/null
+++ b/tests/libtracker-data/change/source/99-example.ontology.v1
@@ -0,0 +1,12 @@
+ prefix example: <http://example/> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+example: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:01Z" ;
+ tracker:prefix "example" .
+
+
diff --git a/tests/libtracker-data/change/source/99-example.ontology.v2 b/tests/libtracker-data/change/source/99-example.ontology.v2
new file mode 100644
index 0000000..fefb68f
--- /dev/null
+++ b/tests/libtracker-data/change/source/99-example.ontology.v2
@@ -0,0 +1,21 @@
+ prefix example: <http://example/> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+example: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:02Z" ;
+ tracker:prefix "example" .
+
+example:A a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:B a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:b a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range example:B .
+
diff --git a/tests/libtracker-data/change/source/99-example.ontology.v3 b/tests/libtracker-data/change/source/99-example.ontology.v3
new file mode 100644
index 0000000..a3abb92
--- /dev/null
+++ b/tests/libtracker-data/change/source/99-example.ontology.v3
@@ -0,0 +1,29 @@
+ prefix example: <http://example/> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+example: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:03Z" ;
+ tracker:prefix "example" .
+
+example:A a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:B a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:b a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range example:B .
+
+example:i1 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
+example:i2 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
diff --git a/tests/libtracker-data/change/source/99-example.ontology.v4 b/tests/libtracker-data/change/source/99-example.ontology.v4
new file mode 100644
index 0000000..706d77c
--- /dev/null
+++ b/tests/libtracker-data/change/source/99-example.ontology.v4
@@ -0,0 +1,37 @@
+ prefix example: <http://example/> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+example: a tracker:Namespace, tracker:Ontology ;
+ nao:lastModified "2010-03-23T11:00:04Z" ;
+ tracker:prefix "example" .
+
+example:A a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:B a rdfs:Class ;
+ rdfs:subClassOf rdfs:Resource .
+
+example:b a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range example:B .
+
+example:i1 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
+example:i2 a rdf:Property ;
+ rdfs:domain example:A ;
+ rdfs:range xsd:integer .
+
+example:ib a rdf:Property ;
+ rdfs:domain example:B ;
+ rdfs:range xsd:integer .
+
+example:sb a rdf:Property ;
+ rdfs:domain example:B ;
+ rdfs:range xsd:string .
+
diff --git a/tests/libtracker-data/change/test-1.out b/tests/libtracker-data/change/test-1.out
new file mode 100644
index 0000000..eb2d304
--- /dev/null
+++ b/tests/libtracker-data/change/test-1.out
@@ -0,0 +1 @@
+"b02"
diff --git a/tests/libtracker-data/change/test-1.rq b/tests/libtracker-data/change/test-1.rq
new file mode 100644
index 0000000..2c33817
--- /dev/null
+++ b/tests/libtracker-data/change/test-1.rq
@@ -0,0 +1 @@
+select ?b02 { <a01> example:b ?b02 }
diff --git a/tests/libtracker-data/change/test-2.out b/tests/libtracker-data/change/test-2.out
new file mode 100644
index 0000000..a6550ef
--- /dev/null
+++ b/tests/libtracker-data/change/test-2.out
@@ -0,0 +1 @@
+"2" "2"
diff --git a/tests/libtracker-data/change/test-2.rq b/tests/libtracker-data/change/test-2.rq
new file mode 100644
index 0000000..552f800
--- /dev/null
+++ b/tests/libtracker-data/change/test-2.rq
@@ -0,0 +1 @@
+select ?a ?b { <a01> example:i2 ?a ; example:i1 ?b }
diff --git a/tests/libtracker-data/change/test-3.out b/tests/libtracker-data/change/test-3.out
new file mode 100644
index 0000000..dc3682e
--- /dev/null
+++ b/tests/libtracker-data/change/test-3.out
@@ -0,0 +1 @@
+"2" "s2"
diff --git a/tests/libtracker-data/change/test-3.rq b/tests/libtracker-data/change/test-3.rq
new file mode 100644
index 0000000..25d5f3c
--- /dev/null
+++ b/tests/libtracker-data/change/test-3.rq
@@ -0,0 +1 @@
+select ?ib ?sb { <b02> example:ib ?ib; example:sb ?sb }
diff --git a/tests/libtracker-data/change/updates/99-example.queries.v2 b/tests/libtracker-data/change/updates/99-example.queries.v2
new file mode 100644
index 0000000..eca5c37
--- /dev/null
+++ b/tests/libtracker-data/change/updates/99-example.queries.v2
@@ -0,0 +1,3 @@
+insert { <b01> a example:B . <a01> a example:A ; example:b <b01> }
+delete { <a01> example:b <b01> }
+insert { <b02> a example:B . <a01> example:b <b02> }
diff --git a/tests/libtracker-data/change/updates/99-example.queries.v3 b/tests/libtracker-data/change/updates/99-example.queries.v3
new file mode 100644
index 0000000..de01e37
--- /dev/null
+++ b/tests/libtracker-data/change/updates/99-example.queries.v3
@@ -0,0 +1,6 @@
+insert { <a01> example:i1 1 }
+delete { <a01> example:i1 1 }
+insert { <a01> example:i1 2 }
+insert { <a01> example:i2 1 }
+delete { <a01> example:i2 1 }
+insert { <a01> example:i2 2 }
diff --git a/tests/libtracker-data/change/updates/99-example.queries.v4 b/tests/libtracker-data/change/updates/99-example.queries.v4
new file mode 100644
index 0000000..6f37824
--- /dev/null
+++ b/tests/libtracker-data/change/updates/99-example.queries.v4
@@ -0,0 +1,6 @@
+insert { <b02> example:ib 1 }
+delete { <b02> example:ib 1 }
+insert { <b02> example:ib 2 }
+insert { <b02> example:sb "s1" }
+delete { <b02> example:sb "s1" }
+insert { <b02> example:sb "s2" }
diff --git a/tests/libtracker-data/ontologies/20-dc.ontology b/tests/libtracker-data/ontologies/20-dc.ontology
new file mode 100644
index 0000000..3567110
--- /dev/null
+++ b/tests/libtracker-data/ontologies/20-dc.ontology
@@ -0,0 +1,19 @@
+ prefix dc: <http://purl.org/dc/elements/1.1/> .
+ prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+dc: a tracker:Namespace, tracker:Ontology ;
+ tracker:prefix "dc" ;
+ nao:lastModified "2010-03-23T16:00:00Z" .
+
+dc:date a rdf:Property ;
+ rdfs:label "Date" ;
+ rdfs:comment "A point or period of time associated with an event in the lifecycle of the resource." ;
+ rdfs:domain rdfs:Resource ;
+ rdfs:range xsd:dateTime .
+
+
diff --git a/tests/libtracker-data/ontologies/31-nao.ontology b/tests/libtracker-data/ontologies/31-nao.ontology
new file mode 100644
index 0000000..8303bc1
--- /dev/null
+++ b/tests/libtracker-data/ontologies/31-nao.ontology
@@ -0,0 +1,23 @@
+ prefix dc: <http://purl.org/dc/elements/1.1/> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+ prefix nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#> .
+ prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+
+nao: a tracker:Namespace, tracker:Ontology ;
+ tracker:prefix "nao" ;
+ nao:lastModified "2010-03-23T16:00:00Z" .
+
+nao:lastModified a rdf:Property ;
+ rdfs:label "lastModified" ;
+ rdfs:comment "last modification date" ;
+ rdfs:subPropertyOf dc:date ;
+ nrl:maxCardinality 1 ;
+ rdfs:domain rdfs:Resource ;
+ rdfs:range xsd:dateTime .
+
+
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index bf539c3..1e0abd4 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -90,7 +90,7 @@ test_backup_and_restore (void)
gchar *data_prefix, *data_filename, *backup_filename, *db_location, *meta_db;
GError *error = NULL;
GFile *backup_file;
- const gchar *test_schemas[2] = { NULL, NULL };
+ gchar *test_schemas[4] = { NULL, NULL, NULL, NULL };
db_location = g_build_path (G_DIR_SEPARATOR_S, g_get_current_dir (), "tracker", NULL);
data_prefix = g_build_path (G_DIR_SEPARATOR_S,
@@ -100,10 +100,12 @@ test_backup_and_restore (void)
/*
* This function uses $(data_prefix).ontology
*/
- test_schemas[0] = data_prefix;
+ test_schemas[0] = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", "ontologies", "20-dc", NULL);
+ test_schemas[1] = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", "ontologies", "31-nao", NULL);
+ test_schemas[2] = data_prefix;
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- test_schemas,
+ (const gchar **) test_schemas,
NULL, FALSE);
/* load data set */
@@ -152,16 +154,18 @@ test_backup_and_restore (void)
g_unlink (meta_db);
g_free (meta_db);
- test_schemas[0] = data_prefix;
tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- test_schemas,
+ (const gchar **) test_schemas,
NULL, FALSE);
check_content_in_db (0, 0);
test_schemas[0] = data_prefix;
- tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL, test_schemas);
+ tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL, (const gchar **) test_schemas);
check_content_in_db (3, 1);
+ g_free (test_schemas[0]);
+ g_free (test_schemas[1]);
+
g_assert_cmpint (backup_calls, ==, 2);
}
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 2bc52c5..a289a67 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -23,6 +23,7 @@
#include <glib.h>
#include <gio/gio.h>
+#include <glib/gstdio.h>
#include <libtracker-db/tracker-db.h>
@@ -82,6 +83,8 @@ const TestInfo nmo_tests[] = {
const TestInfo change_tests[] = {
{ "change/test-1", "change/data-1" },
+ { "change/test-2", "change/data-2" },
+ { "change/test-3", "change/data-3" },
{ NULL }
};
@@ -121,8 +124,8 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
{
TrackerDBResultSet *result_set;
GError *error = NULL;
- gchar *query;
- gchar *results;
+ gchar *query = NULL;
+ gchar *results = NULL;
GString *test_results;
g_file_get_contents (query_filename, &query, NULL, &error);
@@ -224,8 +227,8 @@ test_ontology_change (void)
prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL);
- test_schemas[0] = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "ontologies", "20-dc", NULL);
- test_schemas[1] = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "ontologies", "31-nao", NULL);
+ test_schemas[0] = g_build_path (G_DIR_SEPARATOR_S, prefix, "ontologies", "20-dc", NULL);
+ test_schemas[1] = g_build_path (G_DIR_SEPARATOR_S, prefix, "ontologies", "31-nao", NULL);
test_schemas[2] = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "ontologies", "99-example", NULL);
ontology_file = g_build_path (G_DIR_SEPARATOR_S, prefix, "change", "ontologies", "99-example.ontology", NULL);
@@ -283,18 +286,16 @@ test_ontology_change (void)
for (i = 0; change_tests[i].test_name != NULL; i++) {
gchar *query_filename;
gchar *results_filename;
- gchar *query;
gchar *test_prefix;
test_prefix = g_build_filename (prefix, change_tests[i].test_name, NULL);
query_filename = g_strconcat (test_prefix, ".rq", NULL);
results_filename = g_strconcat (test_prefix, ".out", NULL);
- query_helper (query, results_filename);
+ query_helper (query_filename, results_filename);
g_free (test_prefix);
g_free (query_filename);
- g_free (query);
g_free (results_filename);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]