mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
test: Adds a test for HexStr that checks all 256 bytes
This makes sure the whole HexStr mapping table is checked.
This commit is contained in:
parent
2074d7df20
commit
67c8411c37
1 changed files with 18 additions and 0 deletions
|
@ -198,6 +198,24 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
|
|||
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
|
||||
BOOST_CHECK_EQUAL(HexStr(in_b), out_exp);
|
||||
}
|
||||
|
||||
{
|
||||
auto input = std::string();
|
||||
for (size_t i=0; i<256; ++i) {
|
||||
input.push_back(static_cast<char>(i));
|
||||
}
|
||||
|
||||
auto hex = HexStr(input);
|
||||
BOOST_TEST_REQUIRE(hex.size() == 512);
|
||||
static constexpr auto hexmap = std::string_view("0123456789abcdef");
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
auto upper = hexmap.find(hex[i * 2]);
|
||||
auto lower = hexmap.find(hex[i * 2 + 1]);
|
||||
BOOST_TEST_REQUIRE(upper != std::string_view::npos);
|
||||
BOOST_TEST_REQUIRE(lower != std::string_view::npos);
|
||||
BOOST_TEST_REQUIRE(i == upper*16 + lower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(span_write_bytes)
|
||||
|
|
Loading…
Reference in a new issue