[dconf/wip/reorg] tests/: add test for system source



commit 2b182bb83a3fbaa72446f0f30f09b39a6f9c6c5f
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 12 22:58:26 2012 -0400

    tests/: add test for system source

 tests/engine.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/tests/engine.c b/tests/engine.c
index 6018cd1..84d7de5 100644
--- a/tests/engine.c
+++ b/tests/engine.c
@@ -324,6 +324,65 @@ test_user_source (void)
   dconf_mock_shm_reset ();
 }
 
+static void
+test_system_source (void)
+{
+  DConfEngineSource *source;
+  DConfMockGvdbTable *table;
+  gboolean reopened;
+
+  source = dconf_engine_source_new ("system-db:site");
+  g_assert (source != NULL);
+
+  /* Check to see that we get the warning about the missing file. */
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+    {
+      g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
+
+      /* Failing to open should return FALSE from refresh */
+      reopened = dconf_engine_source_refresh (source);
+      g_assert (!reopened);
+      g_assert (source->values == NULL);
+
+      /* Attempt the reopen to make sure we don't get two warnings.
+       * We should see FALSE again since we go from NULL to NULL.
+       */
+      reopened = dconf_engine_source_refresh (source);
+      g_assert (!reopened);
+
+      /* Create the file after the fact and make sure it opens properly */
+      table = dconf_mock_gvdb_table_new ();
+      dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+
+      reopened = dconf_engine_source_refresh (source);
+      g_assert (reopened);
+      g_assert (source->values != NULL);
+
+      dconf_engine_source_free (source);
+
+      exit (0);
+    }
+  g_test_trap_assert_passed ();
+  /* Check that we only saw the warning, but only one time. */
+  g_test_trap_assert_stderr ("*this gvdb does not exist; expect degraded performance*");
+  g_test_trap_assert_stderr_unmatched ("*degraded*degraded*");
+
+  /* Create the file before the first refresh attempt */
+  table = dconf_mock_gvdb_table_new ();
+  dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+
+  /* See that we get the database. */
+  reopened = dconf_engine_source_refresh (source);
+  g_assert (reopened);
+  g_assert (source->values != NULL);
+
+  /* Do a refresh, make sure there is no change. */
+  reopened = dconf_engine_source_refresh (source);
+  g_assert (!reopened);
+
+  dconf_engine_source_free (source);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -337,6 +396,7 @@ main (int argc, char **argv)
   g_test_add_func ("/engine/profile-parser", test_profile_parser);
   g_test_add_func ("/engine/signal-threadsafety", test_signal_threadsafety);
   g_test_add_func ("/engine/sources/user", test_user_source);
+  g_test_add_func ("/engine/sources/system", test_system_source);
 
   return g_test_run ();
 }



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