From f23fb9e0f5b9a7660fd3ce1ad481319d6742c3f6 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 21 Dec 2015 10:09:05 -0500 Subject: [PATCH] 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 --- gui/settings.c | 26 ++++++++++++++++++++++++++ include/gui/settings.h | 19 +++++++++++++++++++ tests/Sconscript | 1 + tests/gui/.gitignore | 1 + tests/gui/Sconscript | 29 +++++++++++++++++++++++++++++ tests/gui/settings.c | 20 ++++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 gui/settings.c create mode 100644 include/gui/settings.h create mode 100644 tests/gui/.gitignore create mode 100644 tests/gui/Sconscript create mode 100644 tests/gui/settings.c diff --git a/gui/settings.c b/gui/settings.c new file mode 100644 index 00000000..b916b040 --- /dev/null +++ b/gui/settings.c @@ -0,0 +1,26 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include + +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 */ diff --git a/include/gui/settings.h b/include/gui/settings.h new file mode 100644 index 00000000..02bc6a10 --- /dev/null +++ b/include/gui/settings.h @@ -0,0 +1,19 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_SETTINGS_H +#define OCARINA_GUI_SETTINGS_H +#include + + +/* 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 */ diff --git a/tests/Sconscript b/tests/Sconscript index ca2a1dce..d3cce3ea 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -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]) diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore new file mode 100644 index 00000000..a01c11a4 --- /dev/null +++ b/tests/gui/.gitignore @@ -0,0 +1 @@ +settings diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript new file mode 100644 index 00000000..7e249e1a --- /dev/null +++ b/tests/gui/Sconscript @@ -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") diff --git a/tests/gui/settings.c b/tests/gui/settings.c new file mode 100644 index 00000000..4a3d099d --- /dev/null +++ b/tests/gui/settings.c @@ -0,0 +1,20 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include +#include + +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), +);