2016-03-29 08:39:00 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/file.h>
|
|
|
|
#include <core/settings.h>
|
|
|
|
#include <tests/test.h>
|
|
|
|
|
|
|
|
static void test_settings()
|
|
|
|
{
|
2016-08-17 14:17:52 -04:00
|
|
|
struct file f = FILE_INIT("settings", 0);
|
2016-03-29 08:39:00 -04:00
|
|
|
|
2016-09-26 10:52:44 -04:00
|
|
|
settings_set(NULL, 0);
|
|
|
|
g_assert_cmpuint(settings_get(NULL), ==, 0);
|
|
|
|
g_assert_false(settings_has(NULL));
|
|
|
|
|
2016-03-29 08:39:00 -04:00
|
|
|
g_assert_null(test_get_settings());
|
|
|
|
settings_set("test.value1", 42);
|
|
|
|
settings_set("test.value2", 84);
|
|
|
|
g_assert_false(settings_has("test.value1"));
|
|
|
|
g_assert_cmpuint(settings_get("test.value1"), ==, 0);
|
|
|
|
g_assert_cmpuint(settings_get("test.value2"), ==, 0);
|
|
|
|
g_assert_false(file_exists(&f));
|
|
|
|
|
|
|
|
settings_init();
|
|
|
|
g_assert_nonnull(test_get_settings());
|
|
|
|
g_assert_false(settings_has("test.value1"));
|
|
|
|
settings_set("test.value1", 42);
|
|
|
|
g_assert_true(settings_has("test.value1"));
|
|
|
|
g_assert_false(settings_has("test.value2"));
|
|
|
|
g_assert_true(file_exists(&f));
|
|
|
|
settings_set("test.value2", 84);
|
|
|
|
g_assert_true(settings_has("test.value2"));
|
|
|
|
g_assert_cmpuint(settings_get("test.value1"), ==, 42);
|
|
|
|
g_assert_cmpuint(settings_get("test.value2"), ==, 84);
|
|
|
|
|
|
|
|
settings_deinit();
|
|
|
|
g_assert_null(test_get_settings());
|
|
|
|
settings_set("test.value1", 42);
|
|
|
|
settings_set("test.value2", 84);
|
|
|
|
g_assert_cmpuint(settings_get("test.value1"), ==, 0);
|
|
|
|
g_assert_cmpuint(settings_get("test.value2"), ==, 0);
|
|
|
|
g_assert_false(settings_has("test.value1"));
|
|
|
|
g_assert_false(settings_has("test.value2"));
|
|
|
|
g_assert_true(file_exists(&f));
|
|
|
|
|
|
|
|
settings_init();
|
|
|
|
g_assert_nonnull(test_get_settings());
|
|
|
|
g_assert_cmpuint(settings_get("test.value1"), ==, 42);
|
|
|
|
g_assert_cmpuint(settings_get("test.value2"), ==, 84);
|
|
|
|
g_assert_true(settings_has("test.value1"));
|
|
|
|
g_assert_true(settings_has("test.value2"));
|
|
|
|
|
|
|
|
settings_deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Core/Settings", test_settings);
|
|
|
|
return g_test_run();
|
|
|
|
}
|