diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-09 20:17:48 +0100 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-04-27 19:18:20 +0200 |
commit | fabdf81983e2542d60542b80fb94ccb1acdd204a (patch) | |
tree | f57cf4d2d0ea09976e8ce0256039740ba0f2ad1a /src/test/util_tests.cpp | |
parent | f0a834e2f10a0aa60c7cc76e9f3eb090168a32e5 (diff) |
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=."
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r-- | src/test/util_tests.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
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<unsigned char> result; std::vector<unsigned char> 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); |