Skip to content

Commit 67c8411

Browse files
committed
test: Adds a test for HexStr that checks all 256 bytes
This makes sure the whole HexStr mapping table is checked.
1 parent 2074d7d commit 67c8411

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/util_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
198198
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
199199
BOOST_CHECK_EQUAL(HexStr(in_b), out_exp);
200200
}
201+
202+
{
203+
auto input = std::string();
204+
for (size_t i=0; i<256; ++i) {
205+
input.push_back(static_cast<char>(i));
206+
}
207+
208+
auto hex = HexStr(input);
209+
BOOST_TEST_REQUIRE(hex.size() == 512);
210+
static constexpr auto hexmap = std::string_view("0123456789abcdef");
211+
for (size_t i = 0; i < 256; ++i) {
212+
auto upper = hexmap.find(hex[i * 2]);
213+
auto lower = hexmap.find(hex[i * 2 + 1]);
214+
BOOST_TEST_REQUIRE(upper != std::string_view::npos);
215+
BOOST_TEST_REQUIRE(lower != std::string_view::npos);
216+
BOOST_TEST_REQUIRE(i == upper*16 + lower);
217+
}
218+
}
201219
}
202220

203221
BOOST_AUTO_TEST_CASE(span_write_bytes)

0 commit comments

Comments
 (0)