gui/settings: Add functions for setting and getting values
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
f23fb9e0f5
commit
92c1b64b1a
|
@ -18,6 +18,22 @@ void gui_settings_deinit()
|
|||
gui_settings = NULL;
|
||||
}
|
||||
|
||||
void gui_settings_set(const gchar *key, unsigned int value)
|
||||
{
|
||||
if (gui_settings)
|
||||
g_hash_table_replace(gui_settings, g_strdup(key),
|
||||
GUINT_TO_POINTER(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;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
GHashTable *test_get_gui_settings()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*
|
||||
* The settings layer is used to store values configured by the user.
|
||||
*/
|
||||
#ifndef OCARINA_GUI_SETTINGS_H
|
||||
#define OCARINA_GUI_SETTINGS_H
|
||||
|
@ -12,6 +14,12 @@ void gui_settings_init();
|
|||
/* Called to deinitialize GUI settings. */
|
||||
void gui_settings_deinit();
|
||||
|
||||
/* Called to configure a specific setting by key. */
|
||||
void gui_settings_set(const gchar *, unsigned int);
|
||||
|
||||
/* Called to access a specific setting by key. */
|
||||
unsigned int gui_settings_get(const gchar *);
|
||||
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
GHashTable *test_get_gui_settings();
|
||||
|
|
|
@ -7,12 +7,24 @@
|
|||
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_get("test.value1"), 0);
|
||||
test_equal(gui_settings_get("test.value2"), 0);
|
||||
|
||||
gui_settings_init();
|
||||
test_not_equal((void *)test_get_gui_settings(), NULL);
|
||||
gui_settings_set("test.value1", 42);
|
||||
gui_settings_set("test.value2", 84);
|
||||
test_equal(gui_settings_get("test.value1"), 42);
|
||||
test_equal(gui_settings_get("test.value2"), 84);
|
||||
|
||||
gui_settings_deinit();
|
||||
test_equal((void *)test_get_gui_settings(), NULL);
|
||||
gui_settings_set("test.value1", 42);
|
||||
gui_settings_set("test.value2", 84);
|
||||
test_equal(gui_settings_get("test.value1"), 0);
|
||||
test_equal(gui_settings_get("test.value2"), 0);
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
|
|
Loading…
Reference in New Issue