1#include "../sdl_prefs.hpp"
6#include <winpr/config.h>
7#include <winpr/winpr.h>
9#include "../filesystem.hpp"
11static std::shared_ptr<SdlPref> instance()
13#if !defined(TEST_SRC_AREA)
14#error "Please define TEST_SRC_AREA to the source directory of this test case"
16 fs::path src(TEST_SRC_AREA);
17 src /=
"sdl-freerdp.json";
20 std::cerr <<
"[ERROR] test configuration file '" << src <<
"' does not exist" << std::endl;
24 return SdlPref::instance(src.string());
27#if defined(WITH_WINPR_JSON)
28static std::string test_file(
const char* name)
30 fs::path src(TEST_SRC_AREA);
38static bool test_system_config()
40#if defined(WITH_WINPR_JSON)
42 SdlPref::instance(test_file(
"sdl-freerdp-user.json"), test_file(
"sdl-freerdp-system.json"));
43 if (prefs->get_string(
"string_key",
"x") !=
"user")
45 if (prefs->get_int(
"int_key", 0) != 1)
47 if (prefs->get_bool(
"bool_key",
true))
49 if (!prefs->get_bool(
"system_bool_key",
false))
51 if (prefs->get_string(
"string_key",
"x",
true) !=
"system")
54 if (!prefs->is_commandline_override_allowed())
57 prefs = SdlPref::instance(test_file(
"sdl-freerdp-user.json"),
58 test_file(
"sdl-freerdp-system-locked.json"));
59 if (prefs->get_string(
"string_key",
"x") !=
"system")
61 if (prefs->get_int(
"int_key", 0) != 0)
63 if (prefs->is_commandline_override_allowed())
69int TestSDLPrefs(
int argc,
char* argv[])
74#if defined(WITH_WINPR_JSON)
75 printf(
"implementation: json\n");
77 printf(
"implementation: fallback\n");
80#if defined(WITH_WINPR_JSON)
81 printf(
"config: %s\n", instance()->get_pref_file().c_str());
84 auto string_value = instance()->get_string(
"string_key",
"cba");
85#if defined(WITH_WINPR_JSON)
86 if (string_value !=
"abc")
89 if (string_value !=
"cba")
93 auto string_value_nonexistent = instance()->get_string(
"string_key_nonexistent",
"cba");
94 if (string_value_nonexistent !=
"cba")
97 auto int_value = instance()->get_int(
"int_key", 321);
98#if defined(WITH_WINPR_JSON)
102 if (int_value != 321)
106 auto int_value_nonexistent = instance()->get_int(
"int_key_nonexistent", 321);
107 if (int_value_nonexistent != 321)
110 auto bool_value = instance()->get_bool(
"bool_key",
false);
111#if defined(WITH_WINPR_JSON)
119 auto bool_value_nonexistent = instance()->get_bool(
"bool_key_nonexistent",
false);
120 if (bool_value_nonexistent)
123 auto array_value = instance()->get_array(
"array_key", {
"c",
"b",
"a" });
124 if (array_value.size() != 3)
126#if defined(WITH_WINPR_JSON)
127 if (array_value.at(0) !=
"a")
129 if (array_value.at(1) !=
"b")
131 if (array_value.at(2) !=
"c")
134 if (array_value.at(0) !=
"c")
136 if (array_value.at(1) !=
"b")
138 if (array_value.at(2) !=
"a")
142 auto array_value_nonexistent =
143 instance()->get_array(
"array_key_nonexistent", {
"c",
"b",
"a" });
144 if (array_value_nonexistent.size() != 3)
147 if (array_value_nonexistent.at(0) !=
"c")
149 if (array_value_nonexistent.at(1) !=
"b")
151 if (array_value_nonexistent.at(2) !=
"a")
154 if (!test_system_config())