From c479042a8677e6e69389781df08452cadcd345f2 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 26 Dec 2015 18:36:26 -0500 Subject: [PATCH] gui/settings: Add gui_settings_has() function Signed-off-by: Anna Schumaker --- gui/settings.c | 12 +++++++++--- include/gui/settings.h | 3 +++ tests/gui/settings.c | 9 +++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gui/settings.c b/gui/settings.c index e538c0cf..f9230dc1 100644 --- a/gui/settings.c +++ b/gui/settings.c @@ -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; } diff --git a/include/gui/settings.h b/include/gui/settings.h index 3698bc40..7665ec5f 100644 --- a/include/gui/settings.h +++ b/include/gui/settings.h @@ -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(); diff --git a/tests/gui/settings.c b/tests/gui/settings.c index d7f5108e..da90f114 100644 --- a/tests/gui/settings.c +++ b/tests/gui/settings.c @@ -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(); }