Skip to content

Commit fa3549a

Browse files
committed
test: Add hex parse unit tests
1 parent 437dfe1 commit fa3549a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/util_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ BOOST_AUTO_TEST_CASE(parse_hex)
149149
result = ParseHex(" 89 34 56 78");
150150
BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
151151

152+
// Mixed case and spaces are supported
153+
result = ParseHex(" Ff aA ");
154+
BOOST_CHECK(result.size() == 2 && result[0] == 0xff && result[1] == 0xaa);
155+
156+
// Empty string is supported
157+
result = ParseHex("");
158+
BOOST_CHECK(result.size() == 0);
159+
160+
// Spaces between nibbles is treated as end
161+
result = ParseHex("AAF F");
162+
BOOST_CHECK(result.size() == 1 && result[0] == 0xaa);
163+
152164
// Embedded null is treated as end
153165
const std::string with_embedded_null{" 11 "s
154166
" \0 "
@@ -160,6 +172,10 @@ BOOST_AUTO_TEST_CASE(parse_hex)
160172
// Stop parsing at invalid value
161173
result = ParseHex("1234 invalid 1234");
162174
BOOST_CHECK(result.size() == 2 && result[0] == 0x12 && result[1] == 0x34);
175+
176+
// Truncated input is treated as end
177+
result = ParseHex("12 3");
178+
BOOST_CHECK(result.size() == 1 && result[0] == 0x12);
163179
}
164180

165181
BOOST_AUTO_TEST_CASE(util_HexStr)

0 commit comments

Comments
 (0)