From 67c8411c37b483caa2fe3f7f4f40b68ed2a9bcf7 Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Wed, 23 Mar 2022 07:08:23 +0100 Subject: [PATCH] test: Adds a test for HexStr that checks all 256 bytes This makes sure the whole HexStr mapping table is checked. --- src/test/util_tests.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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(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)