Changeset View
Changeset View
Standalone View
Standalone View
src/test/util_tests.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && | ||||
result[2] == 0x56 && result[3] == 0x78); | result[2] == 0x56 && result[3] == 0x78); | ||||
// Stop parsing at invalid value | // Stop parsing at invalid value | ||||
result = ParseHex("1234 invalid 1234"); | result = ParseHex("1234 invalid 1234"); | ||||
BOOST_CHECK(result.size() == 2 && result[0] == 0x12 && result[1] == 0x34); | BOOST_CHECK(result.size() == 2 && result[0] == 0x12 && result[1] == 0x34); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(util_HexStr) { | BOOST_AUTO_TEST_CASE(util_HexStr) { | ||||
BOOST_CHECK_EQUAL(HexStr(ParseHex_expected, | BOOST_CHECK_EQUAL(HexStr(ParseHex_expected), | ||||
ParseHex_expected + sizeof(ParseHex_expected)), | |||||
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0" | "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0" | ||||
"ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d" | "ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d" | ||||
"578a4c702b6bf11d5f"); | "578a4c702b6bf11d5f"); | ||||
BOOST_CHECK_EQUAL(HexStr(ParseHex_expected + sizeof(ParseHex_expected), | BOOST_CHECK_EQUAL(HexStr(Span<const uint8_t>( | ||||
ParseHex_expected + sizeof(ParseHex_expected)), | ParseHex_expected + sizeof(ParseHex_expected), | ||||
""); | ParseHex_expected + sizeof(ParseHex_expected))), | ||||
BOOST_CHECK_EQUAL(HexStr(ParseHex_expected, ParseHex_expected), ""); | |||||
std::vector<uint8_t> ParseHex_vec(ParseHex_expected, ParseHex_expected + 5); | |||||
BOOST_CHECK_EQUAL(HexStr(ParseHex_vec.rbegin(), ParseHex_vec.rend()), | |||||
"b0fd8a6704"); | |||||
BOOST_CHECK_EQUAL( | |||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected), | |||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)), | |||||
""); | ""); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 1), | HexStr(Span<const uint8_t>(ParseHex_expected, ParseHex_expected)), ""); | ||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)), | |||||
"04"); | |||||
BOOST_CHECK_EQUAL( | std::vector<uint8_t> ParseHex_vec(ParseHex_expected, ParseHex_expected + 5); | ||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 5), | |||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)), | |||||
"b0fd8a6704"); | |||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL(HexStr(ParseHex_vec), "04678afdb0"); | ||||
HexStr(std::reverse_iterator<const uint8_t *>(ParseHex_expected + 65), | |||||
std::reverse_iterator<const uint8_t *>(ParseHex_expected)), | |||||
"5f1df16b2b704c8a578d0bbaf74d385cde12c11ee50455f3c438ef4c3fbcf649b6de61" | |||||
"1feae06279a60939e028a8d65c10b73071a6f16719274855feb0fd8a6704"); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(util_Join) { | BOOST_AUTO_TEST_CASE(util_Join) { | ||||
// Normal version | // Normal version | ||||
BOOST_CHECK_EQUAL(Join({}, ", "), ""); | BOOST_CHECK_EQUAL(Join({}, ", "), ""); | ||||
BOOST_CHECK_EQUAL(Join({"foo"}, ", "), "foo"); | BOOST_CHECK_EQUAL(Join({"foo"}, ", "), "foo"); | ||||
BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", "), "foo, bar"); | BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", "), "foo, bar"); | ||||
▲ Show 20 Lines • Show All 1,041 Lines • ▼ Show 20 Lines | if (out_file) { | ||||
throw std::system_error(errno, std::generic_category(), | throw std::system_error(errno, std::generic_category(), | ||||
"fclose failed"); | "fclose failed"); | ||||
} | } | ||||
out_file = nullptr; | out_file = nullptr; | ||||
} | } | ||||
uint8_t out_sha_bytes[CSHA256::OUTPUT_SIZE]; | uint8_t out_sha_bytes[CSHA256::OUTPUT_SIZE]; | ||||
out_sha.Finalize(out_sha_bytes); | out_sha.Finalize(out_sha_bytes); | ||||
std::string out_sha_hex = | std::string out_sha_hex = HexStr(out_sha_bytes); | ||||
HexStr(std::begin(out_sha_bytes), std::end(out_sha_bytes)); | |||||
// If check below fails, should manually dump the results with: | // If check below fails, should manually dump the results with: | ||||
// | // | ||||
// ARGS_MERGE_TEST_OUT=results.txt ./test_bitcoin | // ARGS_MERGE_TEST_OUT=results.txt ./test_bitcoin | ||||
// --run_test=util_tests/util_ArgsMerge | // --run_test=util_tests/util_ArgsMerge | ||||
// | // | ||||
// And verify diff against previous results to make sure the changes are | // And verify diff against previous results to make sure the changes are | ||||
// expected. | // expected. | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | if (out_file) { | ||||
throw std::system_error(errno, std::generic_category(), | throw std::system_error(errno, std::generic_category(), | ||||
"fclose failed"); | "fclose failed"); | ||||
} | } | ||||
out_file = nullptr; | out_file = nullptr; | ||||
} | } | ||||
uint8_t out_sha_bytes[CSHA256::OUTPUT_SIZE]; | uint8_t out_sha_bytes[CSHA256::OUTPUT_SIZE]; | ||||
out_sha.Finalize(out_sha_bytes); | out_sha.Finalize(out_sha_bytes); | ||||
std::string out_sha_hex = | std::string out_sha_hex = HexStr(out_sha_bytes); | ||||
HexStr(std::begin(out_sha_bytes), std::end(out_sha_bytes)); | |||||
// If check below fails, should manually dump the results with: | // If check below fails, should manually dump the results with: | ||||
// | // | ||||
// CHAIN_MERGE_TEST_OUT=results.txt ./test_bitcoin | // CHAIN_MERGE_TEST_OUT=results.txt ./test_bitcoin | ||||
// --run_test=util_tests/util_ChainMerge | // --run_test=util_tests/util_ChainMerge | ||||
// | // | ||||
// And verify diff against previous results to make sure the changes are | // And verify diff against previous results to make sure the changes are | ||||
// expected. | // expected. | ||||
▲ Show 20 Lines • Show All 1,179 Lines • Show Last 20 Lines |