mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 18:09:47 +01:00
Merge #21488: test: add ParseUInt16() unit test and fuzz coverage
3d086f42ab
test: add ParseUInt16() test coverage (Jon Atack) Pull request description: `ParseUInt16()` was just added in #21328. ACKs for top commit: practicalswift: cr ACK3d086f42ab
: patch looks correct & more coverage is better than less coverage Tree-SHA512: bf7f96deb7c1531419565907f0ea8a8e32b368d4b823a3e80928b2c118edbf643ea06e357b4b5504a89f855caeed289daa9f823c740231ed6ad1b8ed00285ce8
This commit is contained in:
commit
d2a78ee928
@ -21,6 +21,9 @@ FUZZ_TARGET(parse_numbers)
|
||||
uint8_t u8;
|
||||
(void)ParseUInt8(random_string, &u8);
|
||||
|
||||
uint16_t u16;
|
||||
(void)ParseUInt16(random_string, &u16);
|
||||
|
||||
int32_t i32;
|
||||
(void)ParseInt32(random_string, &i32);
|
||||
(void)atoi(random_string);
|
||||
|
@ -1523,6 +1523,42 @@ BOOST_AUTO_TEST_CASE(test_ParseUInt8)
|
||||
BOOST_CHECK(!ParseUInt8("256", nullptr));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ParseUInt16)
|
||||
{
|
||||
uint16_t n;
|
||||
// Valid values
|
||||
BOOST_CHECK(ParseUInt16("1234", nullptr));
|
||||
BOOST_CHECK(ParseUInt16("0", &n) && n == 0);
|
||||
BOOST_CHECK(ParseUInt16("1234", &n) && n == 1234);
|
||||
BOOST_CHECK(ParseUInt16("01234", &n) && n == 1234); // no octal
|
||||
BOOST_CHECK(ParseUInt16("65535", &n) && n == static_cast<uint16_t>(65535));
|
||||
BOOST_CHECK(ParseUInt16("+65535", &n) && n == 65535);
|
||||
BOOST_CHECK(ParseUInt16("00000000000000000012", &n) && n == 12);
|
||||
BOOST_CHECK(ParseUInt16("00000000000000000000", &n) && n == 0);
|
||||
// Invalid values
|
||||
BOOST_CHECK(!ParseUInt16("-00000000000000000000", &n));
|
||||
BOOST_CHECK(!ParseUInt16("", &n));
|
||||
BOOST_CHECK(!ParseUInt16(" 1", &n)); // no padding inside
|
||||
BOOST_CHECK(!ParseUInt16(" -1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("++1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("+-1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("-+1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("--1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("-1", &n));
|
||||
BOOST_CHECK(!ParseUInt16("1 ", &n));
|
||||
BOOST_CHECK(!ParseUInt16("1a", &n));
|
||||
BOOST_CHECK(!ParseUInt16("aap", &n));
|
||||
BOOST_CHECK(!ParseUInt16("0x1", &n)); // no hex
|
||||
BOOST_CHECK(!ParseUInt16("0x1", &n)); // no hex
|
||||
BOOST_CHECK(!ParseUInt16(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
|
||||
// Overflow and underflow
|
||||
BOOST_CHECK(!ParseUInt16("-65535", &n));
|
||||
BOOST_CHECK(!ParseUInt16("65536", &n));
|
||||
BOOST_CHECK(!ParseUInt16("-123", &n));
|
||||
BOOST_CHECK(!ParseUInt16("-123", nullptr));
|
||||
BOOST_CHECK(!ParseUInt16("65536", nullptr));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ParseUInt32)
|
||||
{
|
||||
uint32_t n;
|
||||
|
Loading…
Reference in New Issue
Block a user