gui/settings: Add new settings file

The settings layer will track various configuration options set by the
user.  This belongs in the gui, and not core, because it controls
settings specific to this gui implementation.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-21 10:09:05 -05:00
parent 727752df08
commit f23fb9e0f5
6 changed files with 96 additions and 0 deletions

26
gui/settings.c Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <gui/settings.h>
static GHashTable *gui_settings = NULL;
void gui_settings_init()
{
gui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
}
void gui_settings_deinit()
{
g_hash_table_destroy(gui_settings);
gui_settings = NULL;
}
#ifdef CONFIG_TESTING
GHashTable *test_get_gui_settings()
{
return gui_settings;
}
#endif /* CONFIG_TESTING */

19
include/gui/settings.h Normal file
View File

@ -0,0 +1,19 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_SETTINGS_H
#define OCARINA_GUI_SETTINGS_H
#include <glib.h>
/* Called to initialize GUI settings. */
void gui_settings_init();
/* Called to deinitialize GUI settings. */
void gui_settings_deinit();
#ifdef CONFIG_TESTING
GHashTable *test_get_gui_settings();
#endif /* CONFIG_TESTING */
#endif /* OCARINA_GUI_SETTINGS_H */

View File

@ -37,6 +37,7 @@ SConscript("Music/Sconscript")
res = UnitTest("sanity", [ "sanity.c" ])
res += SConscript("core/Sconscript")
res += SConscript("gui/Sconscript")
if check_sanity == True:
for t in res[1:]:
Depends(t, res[0])

1
tests/gui/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
settings

29
tests/gui/Sconscript Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
import os
Import("env", "UnitTest", "testing_group")
res = []
gui_objs = []
ignore = open(".gitignore", "w")
def GuiTest(name):
global gui_objs
ignore.write("%s\n" % name)
source = "%s.c" % name
test = os.path.abspath(source)
gui = os.path.sep.join([x for x in test.split("/") if x != "tests"])
if os.path.exists(gui):
gui_objs += [ env.Object(gui) ]
run = UnitTest("gui/%s" % name, [ test ] + gui_objs)
Alias("tests/gui", run)
if len(res) > 0 and testing_group(["tests/gui"]):
Depends(run, res[-1])
return run
res += [ GuiTest("settings") ]
ignore.close()
Return("res")

20
tests/gui/settings.c Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <gui/settings.h>
#include <tests/test.h>
static void test_settings()
{
test_equal((void *)test_get_gui_settings(), NULL);
gui_settings_init();
test_not_equal((void *)test_get_gui_settings(), NULL);
gui_settings_deinit();
test_equal((void *)test_get_gui_settings(), NULL);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Settings", test_settings),
);