telepathy-logger: Make log-manager tests writable

Nicolas Dufresne nicolasd at kemper.freedesktop.org
Mon Apr 8 10:59:59 PDT 2013


Module: telepathy-logger
Branch: master
Commit: 253cbbba71629c6144c2440c0ab5f4bde975acc4
URL:    http://cgit.freedesktop.org/telepathy/telepathy-logger/commit/?id=253cbbba71629c6144c2440c0ab5f4bde975acc4

Author: Dan Vrátil <dvratil at redhat.com>
Date:   Mon Apr  8 19:36:23 2013 +0200

Make log-manager tests writable

---

 tests/dbus/test-log-manager.c       |   35 ++++++++++++++++++++++++++++++++++-
 tests/dbus/test-tpl-log-store-xml.c |   23 +----------------------
 tests/lib/util.c                    |   21 +++++++++++++++++++++
 tests/lib/util.h                    |    2 ++
 4 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/tests/dbus/test-log-manager.c b/tests/dbus/test-log-manager.c
index 875dd15..1f89cef 100644
--- a/tests/dbus/test-log-manager.c
+++ b/tests/dbus/test-log-manager.c
@@ -31,6 +31,8 @@ typedef struct
 
   GList *ret;
 
+  gchar *tmp_basedir;
+
   TplLogManager *manager;
 } TestCaseFixture;
 
@@ -123,6 +125,17 @@ static void
 teardown (TestCaseFixture* fixture,
     gconstpointer user_data)
 {
+  if (fixture->tmp_basedir != NULL)
+    {
+      gchar *command = g_strdup_printf ("rm -rf %s", fixture->tmp_basedir);
+
+      if (system (command) == -1)
+          g_warning ("Failed to cleanup tempory test log dir: %s",
+                  fixture->tmp_basedir);
+
+      g_free (fixture->tmp_basedir);
+    }
+
   g_object_unref (fixture->manager);
   fixture->manager = NULL;
 
@@ -216,6 +229,26 @@ setup (TestCaseFixture* fixture,
   DEBUG ("set up finished");
 }
 
+static void
+setup_for_writing (TestCaseFixture *fixture,
+    gconstpointer user_data)
+{
+  gchar *readonly_dir;
+  gchar *writable_dir;
+
+  readonly_dir = g_build_path (G_DIR_SEPARATOR_S,
+      g_getenv ("TPL_TEST_LOG_DIR"), "TpLogger", "logs", NULL);
+
+  writable_dir = g_build_path (G_DIR_SEPARATOR_S,
+      g_get_tmp_dir (), "logger-test-logs", NULL);
+
+  tp_tests_copy_dir (readonly_dir, writable_dir);
+  fixture->tmp_basedir = writable_dir;
+  g_setenv ("TPL_TEST_LOG_DIR", writable_dir, TRUE);
+  g_free (readonly_dir);
+
+  setup (fixture, user_data);
+}
 
 static void
 setup_debug (void)
@@ -711,7 +744,7 @@ main (int argc, char **argv)
 
   g_test_add ("/log-manager/ignorelist",
       TestCaseFixture, params,
-      setup, test_ignorelist, teardown);
+      setup_for_writing, test_ignorelist, teardown);
 
   retval = g_test_run ();
 
diff --git a/tests/dbus/test-tpl-log-store-xml.c b/tests/dbus/test-tpl-log-store-xml.c
index 35e3178..4351f73 100644
--- a/tests/dbus/test-tpl-log-store-xml.c
+++ b/tests/dbus/test-tpl-log-store-xml.c
@@ -25,27 +25,6 @@ typedef struct
 
 
 static void
-copy_dir (const gchar *from_dir, const gchar *to_dir)
-{
-  gchar *command;
-
-  // If destination directory exist erase it
-  command = g_strdup_printf ("rm -rf %s", to_dir);
-  g_assert (system (command) == 0);
-  g_free (command);
-
-  command = g_strdup_printf ("cp -r %s %s", from_dir, to_dir);
-  g_assert (system (command) == 0);
-  g_free (command);
-
-  // In distcheck mode the files and directory are read-only, fix that
-  command = g_strdup_printf ("chmod -R +w %s", to_dir);
-  g_assert (system (command) == 0);
-  g_free (command);
-}
-
-
-static void
 setup (XmlTestCaseFixture* fixture,
     gconstpointer user_data)
 {
@@ -81,7 +60,7 @@ setup_for_writing (XmlTestCaseFixture *fixture,
   writable_dir = g_build_path (G_DIR_SEPARATOR_S,
       g_get_tmp_dir (), "logger-test-logs", NULL);
 
-  copy_dir (readonly_dir, writable_dir);
+  tp_tests_copy_dir (readonly_dir, writable_dir);
   fixture->tmp_basedir = writable_dir;
   g_free (readonly_dir);
 
diff --git a/tests/lib/util.c b/tests/lib/util.c
index 690365c..b58227e 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -12,6 +12,7 @@
 
 #include "util.h"
 
+#include <stdlib.h>
 #ifdef G_OS_UNIX
 # include <unistd.h> /* for alarm() */
 #endif
@@ -210,6 +211,26 @@ _tp_tests_assert_strv_equals (const char *file,
 }
 
 void
+tp_tests_copy_dir (const gchar *from_dir, const gchar *to_dir)
+{
+  gchar *command;
+
+  // If destination directory exist erase it
+  command = g_strdup_printf ("rm -rf %s", to_dir);
+  g_assert (system (command) == 0);
+  g_free (command);
+
+  command = g_strdup_printf ("cp -r %s %s", from_dir, to_dir);
+  g_assert (system (command) == 0);
+  g_free (command);
+
+  // In distcheck mode the files and directory are read-only, fix that
+  command = g_strdup_printf ("chmod -R +w %s", to_dir);
+  g_assert (system (command) == 0);
+  g_free (command);
+}
+
+void
 tp_tests_create_and_connect_conn (GType conn_type,
     const gchar *account,
     TpBaseConnection **service_conn,
diff --git a/tests/lib/util.h b/tests/lib/util.h
index 7eab77d..ba96c7b 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -54,4 +54,6 @@ void tp_tests_result_ready_cb (GObject *object,
 
 void tp_tests_abort_after (guint sec);
 
+void tp_tests_copy_dir (const gchar *from_dir, const gchar *to_dir);
+
 #endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */



More information about the telepathy-commits mailing list