MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/test/settings_tests.cpp:188–267  ·  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

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

Callers

nothing calls this directly

Calls 15

fopenFunction · 0.85
ChainTypeToStringFunction · 0.85
GetSettingFunction · 0.85
GetSettingsListFunction · 0.85
MakeUCharSpanFunction · 0.85
ToStringFunction · 0.50
HexStrFunction · 0.50
emplace_backMethod · 0.45
backMethod · 0.45
writeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected