diff options
author | Martin Leitner-Ankerl <martin.ankerl@gmail.com> | 2022-03-23 07:08:23 +0100 |
---|---|---|
committer | Martin Leitner-Ankerl <martin.ankerl@gmail.com> | 2022-04-17 14:29:14 +0200 |
commit | 67c8411c37b483caa2fe3f7f4f40b68ed2a9bcf7 (patch) | |
tree | 8b2af4a755b6c2a99c7b981ee751f07b392bfcfd /src/test | |
parent | 2074d7df20ebc100db6a7b2c3b784ef0bdb8753f (diff) |
test: Adds a test for HexStr that checks all 256 bytes
This makes sure the whole HexStr mapping table is checked.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/util_tests.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index b5d8411e1d..269f531a0d 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -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) |