summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-12-02 10:30:11 -0500
committerRyan Lortie <desrt@desrt.ca>2013-12-02 10:30:11 -0500
commit812ea54bd27bb61d9a38cc54d3405d370b75973e (patch)
tree08cf251872979354d461d6d29a4bd36498cf3a93
parent853c15b31ca3cd7896a86dd0337077790975add8 (diff)
downloaddconf-wip/varlib.tar.gz
tests: test the new file-db engine sourcewip/varlib
-rw-r--r--tests/engine.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/engine.c b/tests/engine.c
index 6becfa1..6c653be 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)
{
@@ -1746,6 +1802,7 @@ main (int argc, char **argv)
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/system/compat", test_system_source_compat);
+ 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);