Skip to content

Commit

Permalink
Fixes #111, #112: test suite now includes printf_config.h before `p…
Browse files Browse the repository at this point in the history
…rintf.c`; and separated cases of what's expected to be printed based on the value of `PRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL`.
  • Loading branch information
eyalroz committed Feb 4, 2022
1 parent 3d25f8d commit 9f48faf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
///////////////////////////////////////////////////////////////////////////////

#define PRINTF_VISIBILITY static
#include <printf_config.h>
#include <printf/printf.c>

// use the 'catch' test framework
Expand Down Expand Up @@ -852,17 +853,25 @@ 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
PRINTING_CHECK("4294967296", ==, sprintf_, buffer, "%.10g", 4294967296.0); // 2^32
}
#endif


#if PRINTF_SUPPORT_DECIMAL_SPECIFIERS
TEST_CASE("fallback from decimal to exponential", "[]" ) {
char buffer[100];
Expand Down

0 comments on commit 9f48faf

Please sign in to comment.