diff options
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r-- | src/test/util_tests.cpp | 84 |
1 files changed, 37 insertions, 47 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 5d1ad2ebf6..51707310a2 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1474,6 +1474,35 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32) BOOST_CHECK(!ParseInt32("32482348723847471234", nullptr)); } +template <typename T> +static void RunToIntegralTests() +{ + BOOST_CHECK(!ToIntegral<T>(STRING_WITH_EMBEDDED_NULL_CHAR)); + BOOST_CHECK(!ToIntegral<T>(" 1")); + BOOST_CHECK(!ToIntegral<T>("1 ")); + BOOST_CHECK(!ToIntegral<T>("1a")); + BOOST_CHECK(!ToIntegral<T>("1.1")); + BOOST_CHECK(!ToIntegral<T>("1.9")); + BOOST_CHECK(!ToIntegral<T>("+01.9")); + BOOST_CHECK(!ToIntegral<T>("-")); + BOOST_CHECK(!ToIntegral<T>("+")); + BOOST_CHECK(!ToIntegral<T>(" -1")); + BOOST_CHECK(!ToIntegral<T>("-1 ")); + BOOST_CHECK(!ToIntegral<T>(" -1 ")); + BOOST_CHECK(!ToIntegral<T>("+1")); + BOOST_CHECK(!ToIntegral<T>(" +1")); + BOOST_CHECK(!ToIntegral<T>(" +1 ")); + BOOST_CHECK(!ToIntegral<T>("+-1")); + BOOST_CHECK(!ToIntegral<T>("-+1")); + BOOST_CHECK(!ToIntegral<T>("++1")); + BOOST_CHECK(!ToIntegral<T>("--1")); + BOOST_CHECK(!ToIntegral<T>("")); + BOOST_CHECK(!ToIntegral<T>("aap")); + BOOST_CHECK(!ToIntegral<T>("0x1")); + BOOST_CHECK(!ToIntegral<T>("-32482348723847471234")); + BOOST_CHECK(!ToIntegral<T>("32482348723847471234")); +} + BOOST_AUTO_TEST_CASE(test_ToIntegral) { BOOST_CHECK_EQUAL(ToIntegral<int32_t>("1234").value(), 1'234); @@ -1486,27 +1515,14 @@ BOOST_AUTO_TEST_CASE(test_ToIntegral) BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-1234").value(), -1'234); BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-1").value(), -1); - BOOST_CHECK(!ToIntegral<int32_t>(" 1")); - BOOST_CHECK(!ToIntegral<int32_t>("1 ")); - BOOST_CHECK(!ToIntegral<int32_t>("1a")); - BOOST_CHECK(!ToIntegral<int32_t>("1.1")); - BOOST_CHECK(!ToIntegral<int32_t>("1.9")); - BOOST_CHECK(!ToIntegral<int32_t>("+01.9")); - BOOST_CHECK(!ToIntegral<int32_t>(" -1")); - BOOST_CHECK(!ToIntegral<int32_t>("-1 ")); - BOOST_CHECK(!ToIntegral<int32_t>(" -1 ")); - BOOST_CHECK(!ToIntegral<int32_t>("+1")); - BOOST_CHECK(!ToIntegral<int32_t>(" +1")); - BOOST_CHECK(!ToIntegral<int32_t>(" +1 ")); - BOOST_CHECK(!ToIntegral<int32_t>("+-1")); - BOOST_CHECK(!ToIntegral<int32_t>("-+1")); - BOOST_CHECK(!ToIntegral<int32_t>("++1")); - BOOST_CHECK(!ToIntegral<int32_t>("--1")); - BOOST_CHECK(!ToIntegral<int32_t>("")); - BOOST_CHECK(!ToIntegral<int32_t>("aap")); - BOOST_CHECK(!ToIntegral<int32_t>("0x1")); - BOOST_CHECK(!ToIntegral<int32_t>("-32482348723847471234")); - BOOST_CHECK(!ToIntegral<int32_t>("32482348723847471234")); + RunToIntegralTests<uint64_t>(); + RunToIntegralTests<int64_t>(); + RunToIntegralTests<uint32_t>(); + RunToIntegralTests<int32_t>(); + RunToIntegralTests<uint16_t>(); + RunToIntegralTests<int16_t>(); + RunToIntegralTests<uint8_t>(); + RunToIntegralTests<int8_t>(); BOOST_CHECK(!ToIntegral<int64_t>("-9223372036854775809")); BOOST_CHECK_EQUAL(ToIntegral<int64_t>("-9223372036854775808").value(), -9'223'372'036'854'775'807LL - 1LL); @@ -1785,32 +1801,6 @@ BOOST_AUTO_TEST_CASE(test_ParseUInt64) BOOST_CHECK(!ParseUInt64("-1234", &n)); } -BOOST_AUTO_TEST_CASE(test_ParseDouble) -{ - double n; - // Valid values - BOOST_CHECK(ParseDouble("1234", nullptr)); - BOOST_CHECK(ParseDouble("0", &n) && n == 0.0); - BOOST_CHECK(ParseDouble("1234", &n) && n == 1234.0); - BOOST_CHECK(ParseDouble("01234", &n) && n == 1234.0); // no octal - BOOST_CHECK(ParseDouble("2147483647", &n) && n == 2147483647.0); - BOOST_CHECK(ParseDouble("-2147483648", &n) && n == -2147483648.0); - BOOST_CHECK(ParseDouble("-1234", &n) && n == -1234.0); - BOOST_CHECK(ParseDouble("1e6", &n) && n == 1e6); - BOOST_CHECK(ParseDouble("-1e6", &n) && n == -1e6); - // Invalid values - BOOST_CHECK(!ParseDouble("", &n)); - BOOST_CHECK(!ParseDouble(" 1", &n)); // no padding inside - BOOST_CHECK(!ParseDouble("1 ", &n)); - BOOST_CHECK(!ParseDouble("1a", &n)); - BOOST_CHECK(!ParseDouble("aap", &n)); - BOOST_CHECK(!ParseDouble("0x1", &n)); // no hex - BOOST_CHECK(!ParseDouble(STRING_WITH_EMBEDDED_NULL_CHAR, &n)); - // Overflow and underflow - BOOST_CHECK(!ParseDouble("-1e10000", nullptr)); - BOOST_CHECK(!ParseDouble("1e10000", nullptr)); -} - BOOST_AUTO_TEST_CASE(test_FormatParagraph) { BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), ""); |