mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
test: add ParseUInt8() unit and fuzz test coverage
This commit is contained in:
parent
3c631917f3
commit
24c6546946
2 changed files with 39 additions and 0 deletions
|
@ -18,6 +18,9 @@ FUZZ_TARGET(parse_numbers)
|
||||||
double d;
|
double d;
|
||||||
(void)ParseDouble(random_string, &d);
|
(void)ParseDouble(random_string, &d);
|
||||||
|
|
||||||
|
uint8_t u8;
|
||||||
|
(void)ParseUInt8(random_string, &u8);
|
||||||
|
|
||||||
int32_t i32;
|
int32_t i32;
|
||||||
(void)ParseInt32(random_string, &i32);
|
(void)ParseInt32(random_string, &i32);
|
||||||
(void)atoi(random_string);
|
(void)atoi(random_string);
|
||||||
|
|
|
@ -1490,6 +1490,42 @@ BOOST_AUTO_TEST_CASE(test_ParseInt64)
|
||||||
BOOST_CHECK(!ParseInt64("32482348723847471234", nullptr));
|
BOOST_CHECK(!ParseInt64("32482348723847471234", nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_ParseUInt8)
|
||||||
|
{
|
||||||
|
uint8_t n;
|
||||||
|
// Valid values
|
||||||
|
BOOST_CHECK(ParseUInt8("255", nullptr));
|
||||||
|
BOOST_CHECK(ParseUInt8("0", &n) && n == 0);
|
||||||
|
BOOST_CHECK(ParseUInt8("255", &n) && n == 255);
|
||||||
|
BOOST_CHECK(ParseUInt8("0255", &n) && n == 255); // no octal
|
||||||
|
BOOST_CHECK(ParseUInt8("255", &n) && n == static_cast<uint8_t>(255));
|
||||||
|
BOOST_CHECK(ParseUInt8("+255", &n) && n == 255);
|
||||||
|
BOOST_CHECK(ParseUInt8("00000000000000000012", &n) && n == 12);
|
||||||
|
BOOST_CHECK(ParseUInt8("00000000000000000000", &n) && n == 0);
|
||||||
|
// Invalid values
|
||||||
|
BOOST_CHECK(!ParseUInt8("-00000000000000000000", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8(" 1", &n)); // no padding inside
|
||||||
|
BOOST_CHECK(!ParseUInt8(" -1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("++1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("+-1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("-+1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("--1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("-1", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("1 ", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("1a", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("aap", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("0x1", &n)); // no hex
|
||||||
|
BOOST_CHECK(!ParseUInt8("0x1", &n)); // no hex
|
||||||
|
BOOST_CHECK(!ParseUInt8("1"s "\0" "1"s, &n)); // no embedded NULs
|
||||||
|
// Overflow and underflow
|
||||||
|
BOOST_CHECK(!ParseUInt8("-255", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("256", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("-123", &n));
|
||||||
|
BOOST_CHECK(!ParseUInt8("-123", nullptr));
|
||||||
|
BOOST_CHECK(!ParseUInt8("256", nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_ParseUInt32)
|
BOOST_AUTO_TEST_CASE(test_ParseUInt32)
|
||||||
{
|
{
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
|
|
Loading…
Reference in a new issue