2015-12-21 10:09:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-12-21 10:49:04 -05:00
|
|
|
#include <core/file.h>
|
2015-12-21 10:09:05 -05:00
|
|
|
#include <gui/settings.h>
|
|
|
|
#include <tests/test.h>
|
|
|
|
|
|
|
|
static void test_settings()
|
|
|
|
{
|
2016-03-30 11:25:14 -04:00
|
|
|
struct file f = FILE_INIT("settings", 0, 0);
|
2015-12-21 10:49:04 -05:00
|
|
|
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_null(test_get_gui_settings());
|
2015-12-21 10:35:32 -05:00
|
|
|
gui_settings_set("test.value1", 42);
|
|
|
|
gui_settings_set("test.value2", 84);
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_false(gui_settings_has("test.value1"));
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value1"), ==, 0);
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value2"), ==, 0);
|
|
|
|
g_assert_false(file_exists(&f));
|
2015-12-21 10:09:05 -05:00
|
|
|
|
|
|
|
gui_settings_init();
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_nonnull(test_get_gui_settings());
|
|
|
|
g_assert_false(gui_settings_has("test.value1"));
|
2015-12-21 10:35:32 -05:00
|
|
|
gui_settings_set("test.value1", 42);
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_true(gui_settings_has("test.value1"));
|
|
|
|
g_assert_false(gui_settings_has("test.value2"));
|
|
|
|
g_assert_true(file_exists(&f));
|
2015-12-21 10:35:32 -05:00
|
|
|
gui_settings_set("test.value2", 84);
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_true(gui_settings_has("test.value2"));
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value1"), ==, 42);
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value2"), ==, 84);
|
2015-12-21 10:09:05 -05:00
|
|
|
|
|
|
|
gui_settings_deinit();
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_null(test_get_gui_settings());
|
2015-12-21 10:35:32 -05:00
|
|
|
gui_settings_set("test.value1", 42);
|
|
|
|
gui_settings_set("test.value2", 84);
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_cmpuint(gui_settings_get("test.value1"), ==, 0);
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value2"), ==, 0);
|
|
|
|
g_assert_false(gui_settings_has("test.value1"));
|
|
|
|
g_assert_false(gui_settings_has("test.value2"));
|
|
|
|
g_assert_true(file_exists(&f));
|
2015-12-21 10:57:23 -05:00
|
|
|
|
|
|
|
gui_settings_init();
|
2016-03-22 08:19:19 -04:00
|
|
|
g_assert_nonnull(test_get_gui_settings());
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value1"), ==, 42);
|
|
|
|
g_assert_cmpuint(gui_settings_get("test.value2"), ==, 84);
|
|
|
|
g_assert_true(gui_settings_has("test.value1"));
|
|
|
|
g_assert_true(gui_settings_has("test.value2"));
|
2015-12-21 10:57:23 -05:00
|
|
|
|
|
|
|
gui_settings_deinit();
|
2015-12-21 10:09:05 -05:00
|
|
|
}
|
|
|
|
|
2016-03-22 08:19:19 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Gui/Settings", test_settings);
|
|
|
|
return g_test_run();
|
|
|
|
}
|