[tracker] Unit test for backup/restore (fails)
- From: Ivan Frade <ifrade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] Unit test for backup/restore (fails)
- Date: Mon, 15 Mar 2010 15:54:02 +0000 (UTC)
commit 9e153aeea128ed03b6050827cf10c58e7aa65505
Author: Ivan Frade <ivan frade nokia com>
Date: Mon Mar 15 17:05:29 2010 +0200
Unit test for backup/restore (fails)
configure.ac | 1 +
tests/libtracker-data/Makefile.am | 9 ++-
tests/libtracker-data/backup/Makefile.am | 6 +
tests/libtracker-data/backup/backup.data | 11 ++
tests/libtracker-data/backup/backup.ontology | 16 +++
tests/libtracker-data/tracker-backup-test.c | 174 ++++++++++++++++++++++++++
6 files changed, 216 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f1278f6..dd8e544 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1680,6 +1680,7 @@ AC_CONFIG_FILES([
tests/libtracker-data/sort/Makefile
tests/libtracker-data/subqueries/Makefile
tests/libtracker-data/error/Makefile
+ tests/libtracker-data/backup/Makefile
tests/libtracker-data/turtle/Makefile
tests/libtracker-miner/Makefile
tests/libtracker-db/Makefile
diff --git a/tests/libtracker-data/Makefile.am b/tests/libtracker-data/Makefile.am
index ccd6da2..275b943 100644
--- a/tests/libtracker-data/Makefile.am
+++ b/tests/libtracker-data/Makefile.am
@@ -16,6 +16,7 @@ SUBDIRS = \
sort \
subqueries \
error \
+ backup \
turtle
noinst_PROGRAMS = $(TEST_PROGS)
@@ -23,7 +24,8 @@ noinst_PROGRAMS = $(TEST_PROGS)
TEST_PROGS += \
tracker-sparql \
tracker-sparql-blank \
- tracker-ontology
+ tracker-ontology \
+ tracker-backup
INCLUDES = \
-DTRACKER_COMPILATION \
@@ -65,4 +67,9 @@ tracker_ontology_SOURCES = \
tracker_ontology_LDADD = $(common_ldadd)
+tracker_backup_SOURCES = \
+ tracker-backup-test.c
+
+tracker_backup_LDADD = $(common_ldadd)
+
EXTRA_DIST = dawg-testcases
diff --git a/tests/libtracker-data/backup/Makefile.am b/tests/libtracker-data/backup/Makefile.am
new file mode 100644
index 0000000..51b6de8
--- /dev/null
+++ b/tests/libtracker-data/backup/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/Makefile.decl
+
+EXTRA_DIST = \
+ backup.ontology \
+ backup.data
+
diff --git a/tests/libtracker-data/backup/backup.data b/tests/libtracker-data/backup/backup.data
new file mode 100644
index 0000000..cbc3f78
--- /dev/null
+++ b/tests/libtracker-data/backup/backup.data
@@ -0,0 +1,11 @@
+ prefix foo: <http://example.org/ns#> .
+
+foo:instance11 a foo:class1 .
+foo:instance12 a foo:class1 .
+foo:instance13 a foo:class1 .
+
+foo:instance21 a foo:class2 .
+foo:instance22 a foo:class2 .
+foo:instance23 a foo:class2 .
+
+foo:instance11 foo:propertyX foo:instance21 .
diff --git a/tests/libtracker-data/backup/backup.ontology b/tests/libtracker-data/backup/backup.ontology
new file mode 100644
index 0000000..f870982
--- /dev/null
+++ b/tests/libtracker-data/backup/backup.ontology
@@ -0,0 +1,16 @@
+# this is a complete turtle document
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ 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#> .
+
+foo: a tracker:Namespace ;
+ tracker:prefix "foo" .
+
+foo:class1 a rdfs:Class .
+foo:class2 a rdfs:Class .
+
+foo:propertyX a rdf:Property ;
+ rdfs:domain foo:class1 ;
+ rdfs:range foo:class2 .
+
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
new file mode 100644
index 0000000..57db6f0
--- /dev/null
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2009, Nokia (urho konttori nokia com)
+ *
+ * This library 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 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libtracker-common/tracker-common.h>
+#include <libtracker-db/tracker-db.h>
+
+#include <libtracker-data/tracker-data-manager.h>
+#include <libtracker-data/tracker-data-query.h>
+#include <libtracker-data/tracker-data-update.h>
+#include <libtracker-data/tracker-sparql-query.h>
+#include <libtracker-data/tracker-data-backup.h>
+
+static gint backup_calls = 0;
+
+static void
+backup_finished_cb (GError *error, gpointer user_data)
+{
+ g_assert (TRUE);
+ backup_calls += 1;
+}
+
+static gboolean
+check_content_in_db (gint expected_instances, gint expected_relations)
+{
+ GError *error = NULL;
+ gchar *query_instances_1 = "SELECT ?u WHERE { ?u a foo:class1. }";
+ gchar *query_relation = "SELECT ?a ?b WHERE { ?a foo:propertyX ?b }";
+ TrackerDBResultSet *result_set;
+
+ result_set = tracker_data_query_sparql (query_instances_1, &error);
+ g_assert_no_error (error);
+ if (expected_instances == 0) {
+ g_assert (result_set == NULL);
+ } else {
+ g_assert_cmpint (tracker_db_result_set_get_n_rows (result_set), ==, expected_instances);
+ g_object_unref (result_set);
+ }
+
+ result_set = tracker_data_query_sparql (query_relation, &error);
+ g_assert_no_error (error);
+ if (expected_relations == 0) {
+ g_assert (result_set == NULL);
+ } else {
+ g_assert_cmpint (tracker_db_result_set_get_n_rows (result_set), ==, expected_relations);
+ g_object_unref (result_set);
+ }
+
+ return TRUE;
+}
+/*
+ * Load ontology a few instances
+ * Run a couple of queries to check it is ok
+ * Back-up.
+ * Nuke the DB.
+ * Restore
+ * Run again the queries
+ */
+static void
+test_backup_and_restore (void)
+{
+ gchar *data_prefix, *data_filename, *backup_filename, *db_location, *meta_db;
+ GError *error = NULL;
+ GFile *backup_file;
+
+ db_location = g_build_path (G_DIR_SEPARATOR_S, g_get_current_dir (), "tracker", NULL);
+ data_prefix = g_build_path (G_DIR_SEPARATOR_S,
+ TOP_SRCDIR, "tests", "libtracker-data", "backup", "backup",
+ NULL);
+
+ /*
+ * This function uses $(data_prefix).ontology
+ */
+ tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_prefix,
+ NULL);
+
+ /* load data set */
+ data_filename = g_strconcat (data_prefix, ".data", NULL);
+ if (g_file_test (data_filename, G_FILE_TEST_IS_REGULAR)) {
+ tracker_data_begin_transaction ();
+ tracker_turtle_reader_load (data_filename, &error);
+ tracker_data_commit_transaction ();
+ g_assert_no_error (error);
+ } else {
+ g_assert_not_reached ();
+ }
+ g_free (data_filename);
+
+ /* Check everything is correct */
+ check_content_in_db (3, 1);
+
+ backup_filename = g_build_path (G_DIR_SEPARATOR_S,
+ db_location, "tracker.dump",
+ NULL);
+ backup_file = g_file_new_for_path (backup_filename);
+ g_free (backup_filename);
+ tracker_data_backup_save (backup_file,
+ backup_finished_cb,
+ NULL,
+ NULL);
+ tracker_data_manager_shutdown ();
+
+ meta_db = g_build_path (G_DIR_SEPARATOR_S, db_location, "meta.db", NULL);
+ g_unlink (meta_db);
+ g_free (meta_db);
+
+ tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_prefix,
+ NULL);
+ check_content_in_db (0, 0);
+
+ tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL);
+ check_content_in_db (3, 1);
+
+ g_assert_cmpint (backup_calls, ==, 2);
+}
+
+int
+main (int argc, char **argv)
+{
+ gint result;
+ gchar *current_dir;
+
+ g_type_init ();
+
+ if (!g_thread_supported ()) {
+ g_thread_init (NULL);
+ }
+
+ g_test_init (&argc, &argv, NULL);
+
+ current_dir = g_get_current_dir ();
+
+ g_setenv ("XDG_DATA_HOME", current_dir, TRUE);
+ g_setenv ("XDG_CACHE_HOME", current_dir, TRUE);
+ g_setenv ("TRACKER_DB_SQL_DIR", TOP_SRCDIR "/data/db/", TRUE);
+ g_setenv ("TRACKER_DB_ONTOLOGIES_DIR", TOP_SRCDIR "/data/ontologies/", TRUE);
+
+ g_free (current_dir);
+
+ g_test_add_func ("/tracker/libtracker-data/backup/save_and_restore",
+ test_backup_and_restore);
+ /* run tests */
+ result = g_test_run ();
+
+ /* clean up */
+ g_print ("Removing temporary data\n");
+ g_spawn_command_line_async ("rm -R tracker/", NULL);
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]