[tracker] libtracker-data: Fix tracker-backup unit test failures
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-data: Fix tracker-backup unit test failures
- Date: Tue, 19 Aug 2014 20:04:25 +0000 (UTC)
commit 1319d9968c2310cbfac350f99637b691d9feca68
Author: Martyn Russell <martyn lanedo com>
Date: Tue Aug 19 20:49:13 2014 +0100
libtracker-data: Fix tracker-backup unit test failures
tests/libtracker-data/tracker-backup-test.c | 104 +++++++++++++++++++--------
1 files changed, 75 insertions(+), 29 deletions(-)
---
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index 1b0c041..74228da 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -20,24 +20,35 @@
#include "config.h"
#include <string.h>
+#include <locale.h>
#include <glib.h>
#include <gio/gio.h>
#include <libtracker-common/tracker-common.h>
-
-#include <libtracker-data/tracker-data-backup.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-data.h>
-#include <libtracker-data/tracker-sparql-query.h>
+static gchar *tests_data_dir = NULL;
+static gchar *xdg_location = NULL;
static gint backup_calls = 0;
static GMainLoop *loop = NULL;
+typedef struct _TestInfo TestInfo;
+
+struct _TestInfo {
+ const gchar *test_name;
+ gboolean use_journal;
+};
+
+const TestInfo tests[] = {
+ { "journal_then_save_and_restore", TRUE },
+ { "save_and_resource", FALSE },
+ { NULL }
+};
+
static void
-backup_finished_cb (GError *error, gpointer user_data)
+backup_finished_cb (GError *error,
+ gpointer user_data)
{
g_assert (TRUE);
backup_calls += 1;
@@ -49,7 +60,8 @@ backup_finished_cb (GError *error, gpointer user_data)
}
static gboolean
-check_content_in_db (gint expected_instances, gint expected_relations)
+check_content_in_db (gint expected_instances,
+ gint expected_relations)
{
GError *error = NULL;
const gchar *query_instances_1 = "SELECT ?u WHERE { ?u a foo:class1. }";
@@ -79,6 +91,7 @@ check_content_in_db (gint expected_instances, gint expected_relations)
return TRUE;
}
+
/*
* Load ontology a few instances
* Run a couple of queries to check it is ok
@@ -95,7 +108,7 @@ test_backup_and_restore_helper (gboolean journal)
GFile *backup_file;
gchar *test_schemas[5] = { NULL, NULL, NULL, NULL, NULL };
- db_location = g_build_path (G_DIR_SEPARATOR_S, g_get_current_dir (), "tracker", NULL);
+ db_location = g_build_path (G_DIR_SEPARATOR_S, xdg_location, "tracker", NULL);
data_prefix = g_build_path (G_DIR_SEPARATOR_S,
TOP_SRCDIR, "tests", "libtracker-data", "backup", "backup",
NULL);
@@ -198,17 +211,60 @@ test_backup_and_restore_helper (gboolean journal)
}
static void
-test_backup_and_restore (void)
+test_backup_and_restore (TestInfo *info,
+ gconstpointer context)
{
- test_backup_and_restore_helper (FALSE);
+ gint index;
+
+ index = GPOINTER_TO_INT (context);
+ *info = tests[index];
+
+ test_backup_and_restore_helper (info->use_journal);
backup_calls = 0;
}
static void
-test_journal_then_backup_and_restore (void)
+setup (TestInfo *info,
+ gconstpointer context)
{
- test_backup_and_restore_helper (TRUE);
- backup_calls = 0;
+ gint i;
+
+ i = GPOINTER_TO_INT (context);
+ *info = tests[i];
+
+ /* Sadly, we can't use ONE location per test because GLib
+ * caches XDG env vars, so g_get_*dir() will not change if we
+ * update the environment, this sucks majorly.
+ */
+ if (!xdg_location) {
+ gchar *basename;
+
+ /* NOTE: g_test_build_filename() doesn't work env vars G_TEST_* are not defined?? */
+ basename = g_strdup_printf ("%d", g_test_rand_int_range (0, G_MAXINT));
+ xdg_location = g_build_path (G_DIR_SEPARATOR_S, tests_data_dir, basename, NULL);
+ g_free (basename);
+
+ g_assert_true (g_setenv ("XDG_DATA_HOME", xdg_location, TRUE));
+ g_assert_true (g_setenv ("XDG_CACHE_HOME", xdg_location, TRUE));
+ g_assert_true (g_setenv ("TRACKER_DB_ONTOLOGIES_DIR", TOP_SRCDIR "/data/ontologies/", TRUE));
+ }
+}
+
+static void
+teardown (TestInfo *info,
+ gconstpointer context)
+{
+ gchar *cleanup_command;
+
+ /* clean up */
+ g_print ("Removing temporary data (%s)\n", xdg_location);
+
+ cleanup_command = g_strdup_printf ("rm -Rf %s/", xdg_location);
+ g_spawn_command_line_sync (cleanup_command, NULL, NULL, NULL, NULL);
+ g_free (cleanup_command);
+
+ g_free (xdg_location);
+ xdg_location = NULL;
}
int
@@ -217,28 +273,18 @@ main (int argc, char **argv)
gint result;
gchar *current_dir;
- g_test_init (&argc, &argv, NULL);
+ setlocale (LC_COLLATE, "en_US.utf8");
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_ONTOLOGIES_DIR", TOP_SRCDIR "/data/ontologies/", TRUE);
-
+ tests_data_dir = g_build_path (G_DIR_SEPARATOR_S, current_dir, "test-data", NULL);
g_free (current_dir);
- g_test_add_func ("/tracker/libtracker-data/backup/journal_then_save_and_restore",
- test_journal_then_backup_and_restore);
+ g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/tracker/libtracker-data/backup/save_and_restore",
- test_backup_and_restore);
+ g_test_add ("/libtracker-data/backup/journal_then_save_and_restore", TestInfo, GINT_TO_POINTER(0),
setup, test_backup_and_restore, teardown);
+ g_test_add ("/libtracker-data/backup/save_and_restore", TestInfo, GINT_TO_POINTER(1), setup,
test_backup_and_restore, teardown);
- /* run tests */
result = g_test_run ();
- /* clean up */
- g_print ("Removing temporary data\n");
- g_spawn_command_line_sync ("rm -R tracker/", NULL, NULL, NULL, NULL);
-
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]