[grilo-plugins/0.2.x: 4/30] tests: new function to reset test environment



commit ad29eba1eb8c1af7a15d0b9fdd3f86840b8ef597
Author: Victor Toso <me victortoso com>
Date:   Fri Aug 28 16:50:52 2015 +0200

    tests: new function to reset test environment
    
    With commit b4cf71a18de08825006ed7e7c3b8545e736b1839 we are using
    temporary database for thetvdb tests. The goal of this patch is a way to
    reset test environment by removing the database and re-loading the
    plugin. If a test need a clean environment, it can call
    test_reset_thetvdb ().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748422

 tests/thetvdb/test_thetvdb_utils.c |   28 ++++++++++++++++++++++------
 tests/thetvdb/test_thetvdb_utils.h |    1 +
 2 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/tests/thetvdb/test_thetvdb_utils.c b/tests/thetvdb/test_thetvdb_utils.c
index 9131a74..db8f45f 100644
--- a/tests/thetvdb/test_thetvdb_utils.c
+++ b/tests/thetvdb/test_thetvdb_utils.c
@@ -34,11 +34,14 @@ test_setup_thetvdb (void)
   GrlRegistry *registry;
   GError *error = NULL;
 
-  tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
-  tmp_dir = g_mkdtemp (tmp_dir);
-  g_assert_nonnull (tmp_dir);
+  if (tmp_dir == NULL) {
+    /* Only create tmp dir and set the XDG_DATA_HOME once */
+    tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
+    tmp_dir = g_mkdtemp (tmp_dir);
+    g_assert_nonnull (tmp_dir);
 
-  g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
+    g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
+  }
 
   config = grl_config_new (THETVDB_ID, NULL);
   grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY");
@@ -61,8 +64,8 @@ GrlSource* test_get_source (void)
   return source;
 }
 
-void
-test_shutdown_thetvdb (void)
+static void
+test_unload (void)
 {
   GrlRegistry *registry;
   GError *error = NULL;
@@ -76,5 +79,18 @@ test_shutdown_thetvdb (void)
   db_path = g_build_filename (tmp_dir, "grilo-plugins", "grl-thetvdb.db", NULL);
   g_remove (db_path);
   g_free (db_path);
+}
+
+void
+test_reset_thetvdb (void)
+{
+  test_unload ();
+  test_setup_thetvdb ();
+}
+
+void
+test_shutdown_thetvdb (void)
+{
+  test_unload ();
   g_clear_pointer (&tmp_dir, g_free);
 }
diff --git a/tests/thetvdb/test_thetvdb_utils.h b/tests/thetvdb/test_thetvdb_utils.h
index 746bec2..77b0d85 100644
--- a/tests/thetvdb/test_thetvdb_utils.h
+++ b/tests/thetvdb/test_thetvdb_utils.h
@@ -30,6 +30,7 @@
 
 void test_setup_thetvdb (void);
 GrlSource* test_get_source (void);
+void test_reset_thetvdb (void);
 void test_shutdown_thetvdb (void);
 
 #endif /* _GRL_THETVDB_TEST_UTILS_H_ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]