From 811505242197e25a0534ab2e2fd6812bf512d1b9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 9 Feb 2011 13:58:43 +0000 Subject: Implement test for XML logstore clear method --- tests/dbus/Makefile.am | 1 + tests/dbus/test-tpl-log-store-xml.c | 116 ++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/dbus/test-tpl-log-store-xml.c (limited to 'tests') diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am index 12111da..642325a 100644 --- a/tests/dbus/Makefile.am +++ b/tests/dbus/Makefile.am @@ -2,6 +2,7 @@ noinst_PROGRAMS = \ test-entity \ test-searches \ test-tpl-log-store-pidgin \ + test-tpl-log-store-xml \ $(NULL) TESTS = $(noinst_PROGRAMS) diff --git a/tests/dbus/test-tpl-log-store-xml.c b/tests/dbus/test-tpl-log-store-xml.c new file mode 100644 index 0000000..548fc26 --- /dev/null +++ b/tests/dbus/test-tpl-log-store-xml.c @@ -0,0 +1,116 @@ +#include "telepathy-logger/log-store-xml.c" + +#include "telepathy-logger/log-manager-internal.h" +#include "telepathy-logger/log-store-internal.h" + +#include + +typedef struct +{ + gchar *tmp_basedir; + TplLogStoreXml *store; +} XmlTestCaseFixture; + + +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); +} + + +static void +setup (XmlTestCaseFixture* fixture, + gconstpointer user_data) +{ + fixture->store = g_object_new (TPL_TYPE_LOG_STORE_XML, + "name", "testcase", + "testmode", TRUE, + NULL); + + if (fixture->tmp_basedir != NULL) + log_store_xml_set_basedir (fixture->store, fixture->tmp_basedir); +} + + +static void +setup_for_writing (XmlTestCaseFixture *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); + + copy_dir (readonly_dir, writable_dir); + fixture->tmp_basedir = writable_dir; + g_free (readonly_dir); + + setup (fixture, user_data); +} + + +static void +teardown (XmlTestCaseFixture *fixture, + gconstpointer user_data) +{ + if (fixture->tmp_basedir != NULL) + { + gchar *command = g_strdup_printf ("rm -rf %s", fixture->tmp_basedir); + system (command); + g_free (fixture->tmp_basedir); + } + + if (fixture->store == NULL) + g_object_unref (fixture->store); +} + + +static void +test_clear (XmlTestCaseFixture *fixture, + gconstpointer user_data) +{ + GList *hits; + hits = _tpl_log_store_search_new (TPL_LOG_STORE (fixture->store), + "1263405203"); + + g_assert (hits != NULL); + g_assert_cmpint (g_list_length (hits), ==, 1); + + tpl_log_manager_search_free (hits); + + _tpl_log_store_clear (TPL_LOG_STORE (fixture->store)); + + hits = _tpl_log_store_search_new (TPL_LOG_STORE (fixture->store), + "1263405203"); + + g_assert_cmpint (g_list_length (hits), ==, 0); +} + + +gint main (gint argc, gchar **argv) +{ + g_type_init (); + + g_test_init (&argc, &argv, NULL); + g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id="); + + g_test_add ("/log-store-xml/clear", + XmlTestCaseFixture, NULL, + setup_for_writing, test_clear, teardown); + + return g_test_run (); +} -- cgit v1.2.1