summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-12-02 10:30:11 -0500
committerRyan Lortie <desrt@desrt.ca>2014-01-13 16:23:30 -0500
commit049c3fe0f4217d07e50281a337363972406c48fa (patch)
tree774d9de25fb1b39ef3cf9cc17e94ae48f3dced70
parent690821a22313982497f41b25940fa58a1c33e91b (diff)
downloaddconf-049c3fe0f4217d07e50281a337363972406c48fa.tar.gz
tests: test the new file-db engine source
-rw-r--r--tests/engine.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/engine.c b/tests/engine.c
index 0f85fdf..174417d 100644
--- a/tests/engine.c
+++ b/tests/engine.c
@@ -358,6 +358,63 @@ test_user_source (void)
dconf_mock_shm_reset ();
}
+static void
+test_file_source (void)
+{
+ DConfEngineSource *source;
+ gboolean reopened;
+ GvdbTable *table;
+ GVariant *value;
+
+ source = dconf_engine_source_new ("file-db:/path/to/db");
+ g_assert (source != NULL);
+ g_assert (source->values == NULL);
+ g_assert (source->locks == NULL);
+ g_test_expect_message ("dconf", G_LOG_LEVEL_WARNING, "*unable to open file '/path/to/db'*");
+ reopened = dconf_engine_source_refresh (source);
+ g_assert (source->values == NULL);
+ g_assert (source->locks == NULL);
+ dconf_engine_source_free (source);
+
+ source = dconf_engine_source_new ("file-db:/path/to/db");
+ g_assert (source != NULL);
+ g_assert (source->values == NULL);
+ g_assert (source->locks == NULL);
+
+ table = dconf_mock_gvdb_table_new ();
+ dconf_mock_gvdb_table_insert (table, "/value", g_variant_new_string ("first file"), NULL);
+ dconf_mock_gvdb_install ("/path/to/db", table);
+
+ reopened = dconf_engine_source_refresh (source);
+ g_assert (reopened);
+ g_assert (source->values);
+ g_assert (source->locks == NULL);
+ value = gvdb_table_get_value (source->values, "/value");
+ g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "first file");
+ g_variant_unref (value);
+
+ /* Of course this should do nothing... */
+ reopened = dconf_engine_source_refresh (source);
+ g_assert (!reopened);
+
+ /* Invalidate and replace */
+ dconf_mock_gvdb_table_invalidate (table);
+ table = dconf_mock_gvdb_table_new ();
+ dconf_mock_gvdb_table_insert (table, "/value", g_variant_new_string ("second file"), NULL);
+ dconf_mock_gvdb_install ("/path/to/db", table);
+
+ /* Even when invalidated, this should still do nothing... */
+ reopened = dconf_engine_source_refresh (source);
+ g_assert (!reopened);
+ value = gvdb_table_get_value (source->values, "/value");
+ g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "first file");
+ g_variant_unref (value);
+
+ dconf_mock_gvdb_install ("/path/to/db", NULL);
+ dconf_engine_source_free (source);
+}
+
+
static gboolean service_db_created;
static GvdbTable *service_db_table;
@@ -395,7 +452,6 @@ handle_service_request (GBusType bus_type,
}
}
-
static void
test_service_source (void)
{
@@ -1696,6 +1752,7 @@ main (int argc, char **argv)
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);
+ g_test_add_func ("/engine/sources/file", test_file_source);
g_test_add_func ("/engine/sources/service", test_service_source);
g_test_add_func ("/engine/read", test_read);
g_test_add_func ("/engine/watch/fast", test_watch_fast);