10#include <boost/test/unit_test.hpp>
21#include <system_error>
28 return a.write() == b.
write();
37inline std::ostream&
operator<<(std::ostream&
os,
const std::pair<std::string, common::SettingsValue>&
kv)
40 out.pushKVEnd(
kv.first,
kv.second);
45inline void WriteText(
const fs::path& path,
const std::string& text)
48 file.open(path.std_path());
56 fs::path path = m_args.GetDataDirBase() /
"settings.json";
65 std::map<std::string, common::SettingsValue> expected{
73 std::map<std::string, common::SettingsValue>
values;
74 std::vector<std::string>
errors;
104 std::vector<std::string> fail_parse = {strprintf("Settings file %s does not contain valid JSON. This is probably caused by disk corruption or a crash, "
105 "and can be fixed by removing the file, which will reset settings to default values.",
115 for (
const auto&
item : GetSettingsList(
settings,
"section",
"name",
false)) {
127 settings.command_line_options[
"name"].emplace_back(
"val2");
128 settings.ro_config[
"section"][
"name"].emplace_back(2);
135 settings2.ro_config[
"section"][
"name"].emplace_back(
"val3");
150 settings.forced_settings[
"name"] = {};
166 template <
typename Fn>
194 if (!
out_file)
throw std::system_error(
errno, std::generic_category(),
"fopen failed");
206 std::vector<common::SettingsValue>& dest) {
208 for (
int i = 0; i < 2; ++i) {
212 }
else if (
action == NEGATE ||
action == SECTION_NEGATE) {
213 dest.emplace_back(
false);
220 desc +=
" " +
name +
"=forced";
239 if (OnlyHasDefaultSectionSetting(
settings, network,
name)) desc +=
" ignored";
249 if (fclose(
out_file))
throw std::system_error(
errno, std::generic_category(),
"fclose failed");
std::string ChainTypeToString(ChainType chain)
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
static const size_t OUTPUT_SIZE
void push_back(UniValue val)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static std::string PathToString(const path &path)
Convert path object to a byte string.
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
FILE * fopen(const fs::path &p, const char *mode)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
BOOST_AUTO_TEST_CASE(ReadWrite)
static void CheckValues(const common::Settings &settings, const std::string &single_val, const std::string &list_val)
Check settings struct contents against expected json strings.
void WriteText(const fs::path &path, const std::string &text)
BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup)
bool operator==(const common::SettingsValue &a, const common::SettingsValue &b)
std::ostream & operator<<(std::ostream &os, const common::SettingsValue &value)
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span{v}))
Like the std::span constructor, but for (const) unsigned char member types only.
void ForEachNoDup(CharType(&string)[StringLength], CharType min_char, CharType max_char, Fn &&fn)
Iterate over string values and call function for each string without successive duplicate characters.
void ForEachMergeSetup(Fn &&fn)
Enumerate all possible test configurations.
Action[MAX_ACTIONS] ActionList
static constexpr int MAX_ACTIONS
Max number of actions to sequence together.
std::map< std::string, std::map< std::string, std::vector< SettingsValue > > > ro_config
Map of config section name and setting name to list of config file values.
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
BOOST_CHECK_EQUAL_COLLECTIONS(R1L.begin(), R1L.end(), R1Array, R1Array+uint256::size())
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.