Changeset View
Changeset View
Standalone View
Standalone View
src/test/settings_tests.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), | ||||
fail_parse.begin(), fail_parse.end()); | fail_parse.begin(), fail_parse.end()); | ||||
} | } | ||||
//! Check settings struct contents against expected json strings. | //! Check settings struct contents against expected json strings. | ||||
static void CheckValues(const util::Settings &settings, | static void CheckValues(const util::Settings &settings, | ||||
const std::string &single_val, | const std::string &single_val, | ||||
const std::string &list_val) { | const std::string &list_val) { | ||||
util::SettingsValue single_value = | util::SettingsValue single_value = | ||||
GetSetting(settings, "section", "name", false, false); | GetSetting(settings, "section", "name", false, false, false); | ||||
util::SettingsValue list_value(util::SettingsValue::VARR); | util::SettingsValue list_value(util::SettingsValue::VARR); | ||||
for (const auto &item : | for (const auto &item : | ||||
GetSettingsList(settings, "section", "name", false)) { | GetSettingsList(settings, "section", "name", false)) { | ||||
list_value.push_back(item); | list_value.push_back(item); | ||||
} | } | ||||
BOOST_CHECK_EQUAL(single_value.write().c_str(), single_val); | BOOST_CHECK_EQUAL(single_value.write().c_str(), single_val); | ||||
BOOST_CHECK_EQUAL(list_value.write().c_str(), list_val); | BOOST_CHECK_EQUAL(list_value.write().c_str(), list_val); | ||||
}; | }; | ||||
Show All 18 Lines | |||||
// Confirm that a high priority setting overrides a lower priority setting even | // Confirm that a high priority setting overrides a lower priority setting even | ||||
// if the high priority setting is null. This behavior is useful for a high | // if the high priority setting is null. This behavior is useful for a high | ||||
// priority setting source to be able to effectively reset any setting back to | // priority setting source to be able to effectively reset any setting back to | ||||
// its default value. | // its default value. | ||||
BOOST_AUTO_TEST_CASE(NullOverride) { | BOOST_AUTO_TEST_CASE(NullOverride) { | ||||
util::Settings settings; | util::Settings settings; | ||||
settings.command_line_options["name"].push_back("value"); | settings.command_line_options["name"].push_back("value"); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL(R"("value")", GetSetting(settings, "section", "name", | ||||
R"("value")", | false, false, false) | ||||
GetSetting(settings, "section", "name", false, false).write().c_str()); | .write() | ||||
.c_str()); | |||||
settings.forced_settings["name"] = {}; | settings.forced_settings["name"] = {}; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
R"(null)", | R"(null)", GetSetting(settings, "section", "name", false, false, false) | ||||
GetSetting(settings, "section", "name", false, false).write().c_str()); | .write() | ||||
.c_str()); | |||||
} | } | ||||
// Test different ways settings can be merged, and verify results. This test can | // Test different ways settings can be merged, and verify results. This test can | ||||
// be used to confirm that updates to settings code don't change behavior | // be used to confirm that updates to settings code don't change behavior | ||||
// unintentionally. | // unintentionally. | ||||
struct MergeTestingSetup : public BasicTestingSetup { | struct MergeTestingSetup : public BasicTestingSetup { | ||||
//! Max number of actions to sequence together. Can decrease this when | //! Max number of actions to sequence together. Can decrease this when | ||||
//! debugging to make test results easier to understand. | //! debugging to make test results easier to understand. | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | ForEachMergeSetup([&](const ActionList &arg_actions, | ||||
conf_action == SECTION_SET || conf_action == SECTION_NEGATE; | conf_action == SECTION_SET || conf_action == SECTION_NEGATE; | ||||
push_values(conf_action, "c", use_section ? network + "." : "", | push_values(conf_action, "c", use_section ? network + "." : "", | ||||
settings.ro_config[use_section ? network : ""][name]); | settings.ro_config[use_section ? network : ""][name]); | ||||
} | } | ||||
desc += " || "; | desc += " || "; | ||||
desc += | desc += | ||||
GetSetting(settings, network, name, ignore_default_section_config, | GetSetting(settings, network, name, ignore_default_section_config, | ||||
/* get_chain_name= */ false) | /*ignore_nonpersistent=*/false, /*get_chain_name=*/false) | ||||
.write(); | .write(); | ||||
desc += " |"; | desc += " |"; | ||||
for (const auto &s : GetSettingsList(settings, network, name, | for (const auto &s : GetSettingsList(settings, network, name, | ||||
ignore_default_section_config)) { | ignore_default_section_config)) { | ||||
desc += " "; | desc += " "; | ||||
desc += s.write(); | desc += s.write(); | ||||
} | } | ||||
desc += " |"; | desc += " |"; | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |