From 9f48faf16866c549bf3d1aeadf17c258740fd255 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Fri, 4 Feb 2022 16:15:51 +0200 Subject: [PATCH] Fixes #111, #112: test suite now includes `printf_config.h` before `printf.c`; and separated cases of what's expected to be printed based on the value of `PRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL`. --- test/test_suite.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_suite.cpp b/test/test_suite.cpp index c88ccc8d..2a673e5f 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -29,6 +29,7 @@ /////////////////////////////////////////////////////////////////////////////// #define PRINTF_VISIBILITY static +#include #include // use the 'catch' test framework @@ -852,10 +853,17 @@ TEST_CASE("infinity and not-a-number values", "[]" ) { #if PRINTF_SUPPORT_DECIMAL_SPECIFIERS TEST_CASE("floating-point specifiers with 31-32 bit integer values", "[]" ) { char buffer[100]; +#if PRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL >= 10 + PRINTING_CHECK("2147483647", ==, sprintf_, buffer, "%.10f", 2147483647.0); // 2^31 - 1 + PRINTING_CHECK("2147483648", ==, sprintf_, buffer, "%.10f", 2147483648.0); // 2^31 + PRINTING_CHECK("4294967295", ==, sprintf_, buffer, "%.10f", 4294967295.0); // 2^32 - 1 + PRINTING_CHECK("4294967296", ==, sprintf_, buffer, "%.10f", 4294967296.0); // 2^32 +#else PRINTING_CHECK("2.1474836470e+09", ==, sprintf_, buffer, "%.10f", 2147483647.0); // 2^31 - 1 PRINTING_CHECK("2.1474836480e+09", ==, sprintf_, buffer, "%.10f", 2147483648.0); // 2^31 PRINTING_CHECK("4.2949672950e+09", ==, sprintf_, buffer, "%.10f", 4294967295.0); // 2^32 - 1 PRINTING_CHECK("4.2949672960e+09", ==, sprintf_, buffer, "%.10f", 4294967296.0); // 2^32 +#endif PRINTING_CHECK("2147483647", ==, sprintf_, buffer, "%.10g", 2147483647.0); // 2^31 - 1 PRINTING_CHECK("2147483648", ==, sprintf_, buffer, "%.10g", 2147483648.0); // 2^31 PRINTING_CHECK("4294967295", ==, sprintf_, buffer, "%.10g", 4294967295.0); // 2^32 - 1 @@ -863,6 +871,7 @@ TEST_CASE("floating-point specifiers with 31-32 bit integer values", "[]" ) { } #endif + #if PRINTF_SUPPORT_DECIMAL_SPECIFIERS TEST_CASE("fallback from decimal to exponential", "[]" ) { char buffer[100];