MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/test/settings_tests.cpp:183–262  ·  view source on GitHub ↗

Regression test covering different ways config settings can be merged. The test parses and merges settings, representing the results as strings that get compared against an expected hash. To debug, the result strings can be dumped to a file (see comments below).

Source from the content-addressed store, hash-verified

181// compared against an expected hash. To debug, the result strings can be dumped
182// to a file (see comments below).
183BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup)
184{
185 CHash256 out_sha;
186 FILE* out_file = nullptr;
187 if (const char* out_path = getenv("SETTINGS_MERGE_TEST_OUT")) {
188 out_file = fsbridge::fopen(out_path, "w");
189 if (!out_file) throw std::system_error(errno, std::generic_category(), "fopen failed");
190 }
191
192 const std::string& network = CBaseChainParams::MAIN;
193 ForEachMergeSetup([&](const ActionList& arg_actions, const ActionList& conf_actions, bool force_set,
194 bool ignore_default_section_config) {
195 std::string desc;
196 int value_suffix = 0;
197 util::Settings settings;
198
199 const std::string& name = ignore_default_section_config ? "wallet" : "server";
200 auto push_values = [&](Action action, const char* value_prefix, const std::string& name_prefix,
201 std::vector<util::SettingsValue>& dest) {
202 if (action == SET || action == SECTION_SET) {
203 for (int i = 0; i < 2; ++i) {
204 dest.push_back(value_prefix + ToString(++value_suffix));
205 desc += " " + name_prefix + name + "=" + dest.back().get_str();
206 }
207 } else if (action == NEGATE || action == SECTION_NEGATE) {
208 dest.push_back(false);
209 desc += " " + name_prefix + "no" + name;
210 }
211 };
212
213 if (force_set) {
214 settings.forced_settings[name] = "forced";
215 desc += " " + name + "=forced";
216 }
217 for (Action arg_action : arg_actions) {
218 push_values(arg_action, "a", "-", settings.command_line_options[name]);
219 }
220 for (Action conf_action : conf_actions) {
221 bool use_section = conf_action == SECTION_SET || conf_action == SECTION_NEGATE;
222 push_values(conf_action, "c", use_section ? network + "." : "",
223 settings.ro_config[use_section ? network : ""][name]);
224 }
225
226 desc += " || ";
227 desc += GetSetting(settings, network, name, ignore_default_section_config, /* get_chain_name= */ false).write();
228 desc += " |";
229 for (const auto& s : GetSettingsList(settings, network, name, ignore_default_section_config)) {
230 desc += " ";
231 desc += s.write();
232 }
233 desc += " |";
234 if (OnlyHasDefaultSectionSetting(settings, network, name)) desc += " ignored";
235 desc += "\n";
236
237 out_sha.Write(MakeUCharSpan(desc));
238 if (out_file) {
239 BOOST_REQUIRE(fwrite(desc.data(), 1, desc.size(), out_file) == desc.size());
240 }

Callers

nothing calls this directly

Calls 13

fopenFunction · 0.85
GetSettingFunction · 0.85
GetSettingsListFunction · 0.85
MakeUCharSpanFunction · 0.85
ToStringFunction · 0.50
HexStrFunction · 0.50
push_backMethod · 0.45
writeMethod · 0.45
WriteMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected