FreeRDP
Loading...
Searching...
No Matches
TestSDLPrefs.cpp
1#include "../sdl_prefs.hpp"
2
3#include <iostream>
4#include <fstream>
5
6#include <winpr/config.h>
7#include <winpr/winpr.h>
8
9#include "../filesystem.hpp"
10
11static std::shared_ptr<SdlPref> instance()
12{
13#if !defined(TEST_SRC_AREA)
14#error "Please define TEST_SRC_AREA to the source directory of this test case"
15#endif
16 fs::path src(TEST_SRC_AREA);
17 src /= "sdl-freerdp.json";
18 if (!fs::exists(src))
19 {
20 std::cerr << "[ERROR] test configuration file '" << src << "' does not exist" << std::endl;
21 return nullptr;
22 }
23
24 return SdlPref::instance(src.string());
25}
26
27int TestSDLPrefs(int argc, char* argv[])
28{
29 WINPR_UNUSED(argc);
30 WINPR_UNUSED(argv);
31
32#if defined(WITH_WINPR_JSON)
33 printf("implementation: json\n");
34#else
35 printf("implementation: fallback\n");
36#endif
37
38#if defined(WITH_WINPR_JSON)
39 printf("config: %s\n", instance()->get_pref_file().c_str());
40#endif
41
42 auto string_value = instance()->get_string("string_key", "cba");
43#if defined(WITH_WINPR_JSON)
44 if (string_value != "abc")
45 return -1;
46#else
47 if (string_value != "cba")
48 return -1;
49#endif
50
51 auto string_value_nonexistent = instance()->get_string("string_key_nonexistent", "cba");
52 if (string_value_nonexistent != "cba")
53 return -1;
54
55 auto int_value = instance()->get_int("int_key", 321);
56#if defined(WITH_WINPR_JSON)
57 if (int_value != 123)
58 return -1;
59#else
60 if (int_value != 321)
61 return -1;
62#endif
63
64 auto int_value_nonexistent = instance()->get_int("int_key_nonexistent", 321);
65 if (int_value_nonexistent != 321)
66 return -1;
67
68 auto bool_value = instance()->get_bool("bool_key", false);
69#if defined(WITH_WINPR_JSON)
70 if (!bool_value)
71 return -1;
72#else
73 if (bool_value)
74 return -1;
75#endif
76
77 auto bool_value_nonexistent = instance()->get_bool("bool_key_nonexistent", false);
78 if (bool_value_nonexistent)
79 return -1;
80
81 auto array_value = instance()->get_array("array_key", { "c", "b", "a" });
82 if (array_value.size() != 3)
83 return -1;
84#if defined(WITH_WINPR_JSON)
85 if (array_value.at(0) != "a")
86 return -1;
87 if (array_value.at(1) != "b")
88 return -1;
89 if (array_value.at(2) != "c")
90 return -1;
91#else
92 if (array_value.at(0) != "c")
93 return -1;
94 if (array_value.at(1) != "b")
95 return -1;
96 if (array_value.at(2) != "a")
97 return -1;
98#endif
99
100 auto array_value_nonexistent =
101 instance()->get_array("array_key_nonexistent", { "c", "b", "a" });
102 if (array_value_nonexistent.size() != 3)
103 return -1;
104
105 if (array_value_nonexistent.at(0) != "c")
106 return -1;
107 if (array_value_nonexistent.at(1) != "b")
108 return -1;
109 if (array_value_nonexistent.at(2) != "a")
110 return -1;
111
112 return 0;
113}