Skip to content

Commit

Permalink
Added checks for printing extremal values of the various signed and u…
Browse files Browse the repository at this point in the history
…nsigned integer types; regards issue mpaland#118.
  • Loading branch information
eyalroz committed Aug 2, 2021
1 parent 93b2678 commit d75320d
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <string.h>
#include <sstream>
#include <math.h>

#include <limits>

namespace test {
// use functions in own test namespace to avoid stdio conflicts
Expand Down Expand Up @@ -1055,6 +1055,53 @@ TEST_CASE("misc", "[]" ) {
#endif
}

TEST_CASE("extremal signed integer values", "[]" ) {
char buffer[100];
char expected[100];

std::sprintf(expected, "%hd", std::numeric_limits<short int>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%hd", std::numeric_limits<short int>::max());

std::sprintf(expected, "%hd", std::numeric_limits<short int>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%hd", std::numeric_limits<short int>::max());

std::sprintf(expected, "%d", std::numeric_limits<int>::min());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%d", std::numeric_limits<int>::min());

std::sprintf(expected, "%d", std::numeric_limits<int>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%d", std::numeric_limits<int>::max());

std::sprintf(expected, "%ld", std::numeric_limits<long int>::min());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%ld", std::numeric_limits<long int>::min());

std::sprintf(expected, "%ld", std::numeric_limits<long int>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%ld", std::numeric_limits<long int>::max());

std::sprintf(expected, "%lld", std::numeric_limits<long long int>::min());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%lld", std::numeric_limits<long long int>::min());

std::sprintf(expected, "%lld", std::numeric_limits<long long int>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%lld", std::numeric_limits<long long int>::max());
}

TEST_CASE("extremal unsigned integer values", "[]" ) {
char buffer[100];
char expected[100];

std::sprintf(expected, "%hu", std::numeric_limits<short unsigned>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%hu", std::numeric_limits<short unsigned>::max());

std::sprintf(expected, "%u", std::numeric_limits<unsigned>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%u", std::numeric_limits<unsigned>::max());

std::sprintf(expected, "%lu", std::numeric_limits<long unsigned>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%lu", std::numeric_limits<long unsigned>::max());

std::sprintf(expected, "%llu", std::numeric_limits<long long unsigned>::max());
PRINTING_CHECK(expected, ==, test::sprintf_, buffer, "%llu", std::numeric_limits<long long unsigned>::max());
}


#ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS
DISABLE_WARNING_POP
#endif
Expand Down

0 comments on commit d75320d

Please sign in to comment.