From fabdf81983e2542d60542b80fb94ccb1acdd204a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 9 Nov 2021 20:17:48 +0100 Subject: test: Add test for embedded null in hex string Also, fix style in the corresponding function. The style change can be reviewed with "--word-diff-regex=." --- src/test/util_tests.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/test/util_tests.cpp') diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 1ca20fd848..0b2f796078 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -153,7 +153,7 @@ static const unsigned char ParseHex_expected[65] = { 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f }; -BOOST_AUTO_TEST_CASE(util_ParseHex) +BOOST_AUTO_TEST_CASE(parse_hex) { std::vector result; std::vector expected(ParseHex_expected, ParseHex_expected + sizeof(ParseHex_expected)); @@ -169,6 +169,14 @@ BOOST_AUTO_TEST_CASE(util_ParseHex) result = ParseHex(" 89 34 56 78"); BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78); + // Embedded null is treated as end + const std::string with_embedded_null{" 11 "s + " \0 " + " 22 "s}; + BOOST_CHECK_EQUAL(with_embedded_null.size(), 11); + result = ParseHex(with_embedded_null); + BOOST_CHECK(result.size() == 1 && result[0] == 0x11); + // Stop parsing at invalid value result = ParseHex("1234 invalid 1234"); BOOST_CHECK(result.size() == 2 && result[0] == 0x12 && result[1] == 0x34); -- cgit v1.2.3