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:
Martin Leitner-Ankerl 2022-03-23 07:08:23 +01:00
parent 2074d7df20
commit 67c8411c37
No known key found for this signature in database
GPG key ID: FBEAAD7FC6FFFE81

View file

@ -198,6 +198,24 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp); BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
BOOST_CHECK_EQUAL(HexStr(in_b), 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) BOOST_AUTO_TEST_CASE(span_write_bytes)