gui/settings: Add gui_settings_has() function

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-26 18:36:26 -05:00
parent d292879837
commit c479042a86
3 changed files with 21 additions and 3 deletions

View File

@ -63,10 +63,16 @@ void gui_settings_set(const gchar *key, unsigned int value)
unsigned int gui_settings_get(const gchar *key)
{
unsigned int ret = 0;
if (gui_settings)
ret = GPOINTER_TO_UINT(g_hash_table_lookup(gui_settings, key));
return ret;
return GPOINTER_TO_UINT(g_hash_table_lookup(gui_settings, key));
return 0;
}
bool gui_settings_has(const gchar *key)
{
if (gui_settings)
return g_hash_table_contains(gui_settings, key);
return false;
}

View File

@ -20,6 +20,9 @@ void gui_settings_set(const gchar *, unsigned int);
/* Called to access a specific setting by key. */
unsigned int gui_settings_get(const gchar *);
/* Called to check if a specific settings exists. */
bool gui_settings_has(const gchar *);
#ifdef CONFIG_TESTING
GHashTable *test_get_gui_settings();

View File

@ -12,15 +12,20 @@ static void test_settings()
test_equal((void *)test_get_gui_settings(), NULL);
gui_settings_set("test.value1", 42);
gui_settings_set("test.value2", 84);
test_equal(gui_settings_has("test.value1"), (bool)false);
test_equal(gui_settings_get("test.value1"), 0);
test_equal(gui_settings_get("test.value2"), 0);
test_equal(file_exists(&f), (bool)false);
gui_settings_init();
test_not_equal((void *)test_get_gui_settings(), NULL);
test_equal(gui_settings_has("test.value1"), (bool)false);
gui_settings_set("test.value1", 42);
test_equal(gui_settings_has("test.value1"), (bool)true);
test_equal(gui_settings_has("test.value2"), (bool)false);
test_equal(file_exists(&f), (bool)true);
gui_settings_set("test.value2", 84);
test_equal(gui_settings_has("test.value2"), (bool)true);
test_equal(gui_settings_get("test.value1"), 42);
test_equal(gui_settings_get("test.value2"), 84);
@ -30,12 +35,16 @@ static void test_settings()
gui_settings_set("test.value2", 84);
test_equal(gui_settings_get("test.value1"), 0);
test_equal(gui_settings_get("test.value2"), 0);
test_equal(gui_settings_has("test.value1"), (bool)false);
test_equal(gui_settings_has("test.value2"), (bool)false);
test_equal(file_exists(&f), (bool)true);
gui_settings_init();
test_not_equal((void *)test_get_gui_settings(), NULL);
test_equal(gui_settings_get("test.value1"), 42);
test_equal(gui_settings_get("test.value2"), 84);
test_equal(gui_settings_has("test.value1"), (bool)true);
test_equal(gui_settings_has("test.value2"), (bool)true);
gui_settings_deinit();
}