12#include <catch2/catch.hpp>
15bool IsSame(
const wxArrayString& arr, std::initializer_list<wxString> list,
bool compareWithCase =
true)
17 if(arr.size() != list.size())
24 [&](
const auto& value) { return str.IsSameAs(value, compareWithCase); }
45 return wxString::Format(
"%ld", obj.
value);
58 REQUIRE(
settings.Write(
"orange",
true));
59 REQUIRE(
settings.Read(
"orange", &orangeValue));
60 REQUIRE(orangeValue ==
true);
64 REQUIRE(
settings.Read(
"apple", &appleValue));
65 REQUIRE(appleValue == 3);
68 REQUIRE(
settings.Write(
"plum", std::numeric_limits<long long>::max()));
69 REQUIRE(
settings.Read(
"plum", &plumValue));
70 REQUIRE(plumValue == std::numeric_limits<long long>::max());
73 REQUIRE(
settings.Write(
"pear", std::numeric_limits<double>::epsilon()));
74 REQUIRE(
settings.Read(
"pear", &pearValue));
75 REQUIRE(std::abs(pearValue - std::numeric_limits<double>::epsilon()) <= 0.001);
77 wxString pineappleValue;
78 REQUIRE(
settings.Write(
"pineapple",
"Lorem Ipsum"));
79 REQUIRE(
settings.Read(
"pineapple", &pineappleValue));
80 REQUIRE(pineappleValue ==
"Lorem Ipsum");
84 REQUIRE(
settings.Read(
"mango", &mangoValue));
85 REQUIRE(mangoValue.value == 1431655765);
87 REQUIRE(
settings.Read(
"orange", &orangeValue,
false));
88 REQUIRE(orangeValue ==
true);
89 REQUIRE(
settings.Read(
"apple", &appleValue, 1000));
90 REQUIRE(appleValue == 3);
91 REQUIRE(
settings.Read(
"plum", &plumValue, 2000LL));
92 REQUIRE(plumValue == std::numeric_limits<long long>::max());
93 REQUIRE(
settings.Read(
"pear", &pearValue, 3000.0));
94 REQUIRE(std::abs(pearValue - std::numeric_limits<double>::epsilon()) <= 0.001);
95 REQUIRE(
settings.Read(
"pineapple", &pineappleValue, { }));
96 REQUIRE(pineappleValue ==
"Lorem Ipsum");
99 REQUIRE(!
settings.Read(
"orange1", &orange1, orangeValue));
100 REQUIRE(orange1 == orangeValue);
102 REQUIRE(!
settings.Read(
"apple1", &apple1, appleValue));
103 REQUIRE(apple1 == appleValue);
105 REQUIRE(!
settings.Read(
"plum1", &plum1, plumValue));
106 REQUIRE(plum1 == plumValue);
108 REQUIRE(!
settings.Read(
"pear1", &pear1, pearValue));
109 REQUIRE(std::abs(pearValue - pear1) <= 0.001);
111 REQUIRE(!
settings.Read(
"pineapple1", &pineapple1, pineappleValue));
112 REQUIRE(pineapple1 == pineappleValue);
114 REQUIRE(!
settings.Read(
"mango1", &mango1, mangoValue));
115 REQUIRE(mango1 == mangoValue);
117 REQUIRE(
settings.Read(
"pineapple") == pineappleValue);
118 REQUIRE(
settings.Read(
"pineapp").IsEmpty());
119 REQUIRE(
settings.Read(
"pineapp",
"not found") ==
"not found");
120 REQUIRE(
settings.Read(
"pineapp", L
"not found") == L
"not found");
122 REQUIRE(
settings.Read(
"orange",
false) == orangeValue);
123 REQUIRE(
settings.Read(
"apple", 0) == appleValue);
124 REQUIRE(
settings.Read(
"plum", 0LL) == plumValue);
125 REQUIRE(
settings.Read(
"pear", 0.0) == pearValue);
128 REQUIRE(
settings.Write(
"moon",
"full"));
129 REQUIRE(
settings.Read(
"moon") ==
"full");
131 REQUIRE(
settings.Write(
"star", L
"yellow"));
132 REQUIRE(
settings.Read(
"star") == L
"yellow");
138 REQUIRE(
settings.GetGroup().empty());
139 REQUIRE(
settings.GetChildKeys().empty());
140 REQUIRE(
settings.GetChildGroups().empty());
145 REQUIRE(
settings.HasEntry(
"apple"));
151 auto group =
settings.BeginGroup(
"group");
152 REQUIRE(
settings.GetGroup() ==
"group");
153 REQUIRE(
settings.GetChildKeys().empty());
154 REQUIRE(
settings.GetChildGroups().empty());
157 REQUIRE(
settings.GetGroup().empty());
159 REQUIRE(
settings.HasGroup(
"group"));
163 REQUIRE(
settings.Write(
"path/to/variable", 7));
165 REQUIRE(
settings.HasEntry(
"path/to/variable"));
167 REQUIRE(
settings.HasGroup(
"path/to"));
168 REQUIRE(!
settings.HasGroup(
"path/to/variable"));
169 REQUIRE(
settings.Read(
"path/to/variable", 0) == 7);
172 auto group =
settings.BeginGroup(
"group");
174 auto subgroup =
settings.BeginGroup(
"subgroup");
175 REQUIRE(
settings.GetGroup() ==
"group/subgroup");
176 REQUIRE(
settings.Write(
"number", 4));
178 REQUIRE(
settings.GetGroup() ==
"group");
181 REQUIRE(
settings.Write(
"parrot/color",
"red"));
182 REQUIRE(
IsSame(
settings.GetChildGroups(), {
"subgroup",
"parrot" }));
185 REQUIRE(
settings.Remove(
"subgroup"));
188 REQUIRE(
settings.Write(
"guess", 42));
192 REQUIRE(
settings.GetGroup() ==
"group");
193 REQUIRE(
settings.GetChildGroups().empty());
194 REQUIRE(
settings.GetChildKeys().empty());
197 REQUIRE(
settings.GetGroup().IsEmpty());
201 auto group1 =
settings.BeginGroup(
"group1");
202 REQUIRE(
settings.GetGroup() ==
"group1");
204 auto group2 =
settings.BeginGroup(
"group2");
205 REQUIRE(
settings.GetGroup() ==
"group1/group2");
208 auto group3 =
settings.BeginGroup(
"/group3");
209 REQUIRE(
settings.GetGroup() ==
"group3");
211 REQUIRE(
settings.HasGroup(
"/group1/group2"));
212 REQUIRE(!
settings.HasGroup(
"/group1/group3"));
214 REQUIRE(
settings.Write(
"/group1/value", 1));
215 REQUIRE(
settings.GetGroup() ==
"group3");
216 REQUIRE(
settings.Read(
"/group1/value", 0) == 1);
217 REQUIRE(
settings.HasEntry(
"/group1/value"));
219 REQUIRE(
settings.Exists(
"/group1/value"));
220 REQUIRE(
settings.Exists(
"/group1"));
222 REQUIRE(
settings.GetGroup() ==
"group1/group2");
226 REQUIRE(
settings.GetChildKeys().empty());
227 REQUIRE(
settings.GetChildGroups().empty());
bool IsSame(const wxArrayString &arr, std::initializer_list< wxString > list, bool compareWithCase=true)
void TestRW(audacity::BasicSettings &settings)
void TestGroups(audacity::BasicSettings &settings)
wxString wxToString(const Stringifyable &obj)
bool wxFromString(const wxString &str, Stringifyable *obj)
static Settings & settings()
Base class for objects that provide facility to store data persistently, and access it with string ke...
bool operator==(const Stringifyable &other) const