From c9091f03f4ef397fcf5c80e197f5fdb0f05dc028 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Fri, 30 Jul 2021 15:26:14 +0300 Subject: [PATCH] Fixes #21, mpaland/printf#112: Using some `catch2` internals to get the function called, the arguments used, and the resulting buffer contents. It's not ideal in terms of layout and reseness, but it does the job. Also, spacing tweaks for improved readability via alignment of arguments. --- test/test_suite.cpp | 1599 ++++++++++++------------------------------- 1 file changed, 439 insertions(+), 1160 deletions(-) diff --git a/test/test_suite.cpp b/test/test_suite.cpp index 7b799700..7bd071de 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -42,6 +42,29 @@ namespace test { } // namespace test +#define CAPTURE_AND_PRINT(printer_, ...) \ +do { \ + INFO( #printer_ << \ + " arguments (ignore the equations; interpret \"expr" \ + "\" := expr\" as just \"expr\"): "); \ + CAPTURE( __VA_ARGS__); \ + printer_(__VA_ARGS__); \ +} while(0) + +#define PRINTING_CHECK(expected_, dummy, printer_, buffer_, ...) \ +do { \ + INFO( #printer_ << " arguments, replicated ( \"arg := arg\" " \ + "):\n----"); \ + CAPTURE( __VA_ARGS__); \ + printer_(buffer_, __VA_ARGS__); \ + if (!strcmp(buffer_, expected_)) { \ + buffer_[strlen(expected_)] = '\0'; \ + } \ + INFO( "----"); \ + INFO( "Resulting buffer contents: " << '"' << buffer_ << '"'); \ + CHECK(!strcmp(buffer_, expected_)); \ +} while(0) + // Multi-compiler-compatible local warning suppression #if defined(_MSC_VER) @@ -95,9 +118,15 @@ void _out_fct(char character, void* arg) TEST_CASE("printf", "[]" ) { printf_idx = 0U; memset(printf_buffer, 0xCC, 100U); + INFO("test::printf_ format string and arguments: "); + CAPTURE("% d", 4232); CHECK(test::printf_("% d", 4232) == 5); + INFO("test::printf_ format string and arguments: "); + CAPTURE("% d", 4232); CHECK(printf_buffer[5] == (char)0xCC); printf_buffer[5] = 0; + INFO("test::printf_ format string and arguments: "); + CAPTURE("% d", 4232); CHECK(!strcmp(printf_buffer, " 4232")); } @@ -106,6 +135,8 @@ TEST_CASE("fctprintf", "[]" ) { printf_idx = 0U; memset(printf_buffer, 0xCC, 100U); test::fctprintf(&_out_fct, nullptr, "This is a test of %X", 0x12EFU); + INFO("test::fctprintf format string and arguments: "); + CAPTURE("This is a test of %X", 0x12EFU); CHECK(!strncmp(printf_buffer, "This is a test of 12EF", 22U)); CHECK(printf_buffer[22] == (char)0xCC); } @@ -118,7 +149,7 @@ static void vfctprintf_builder_1(out_fct_type f, char* buffer, ...) { va_list args; va_start(args, buffer); - test::vfctprintf(f, nullptr, "This is a test of %X", args); + CAPTURE_AND_PRINT(test::vfctprintf, f, nullptr, "This is a test of %X", args); va_end(args); } @@ -132,12 +163,8 @@ TEST_CASE("vfctprintf", "[]" ) { TEST_CASE("snprintf_", "[]" ) { char buffer[100]; - - test::snprintf_(buffer, 100U, "%d", -1000); - CHECK(!strcmp(buffer, "-1000")); - - test::snprintf_(buffer, 3U, "%d", -1000); - CHECK(!strcmp(buffer, "-1")); + PRINTING_CHECK("-1000", ==, test::snprintf_, buffer, 100U, "%d", -1000); + PRINTING_CHECK("-1", ==, test::snprintf_, buffer, 3U, "%d", -1000); } static void vprintf_builder_1(char* buffer, ...) @@ -152,7 +179,7 @@ static void vsprintf_builder_1(char* buffer, ...) { va_list args; va_start(args, buffer); - test::vsprintf_(buffer, "%d", args); + CAPTURE_AND_PRINT(test::vsprintf_, buffer, "%d", args); va_end(args); } @@ -160,7 +187,7 @@ static void vsnprintf_builder_1(char* buffer, ...) { va_list args; va_start(args, buffer); - test::vsnprintf_(buffer, 100U, "%d", args); + CAPTURE_AND_PRINT(test::vsnprintf_, buffer, 100U, "%d", args); va_end(args); } @@ -168,7 +195,7 @@ static void vsprintf_builder_3(char* buffer, ...) { va_list args; va_start(args, buffer); - test::vsprintf_(buffer, "%d %d %s", args); + CAPTURE_AND_PRINT(test::vsprintf_, buffer, "%d %d %s", args); va_end(args); } @@ -176,7 +203,7 @@ static void vsnprintf_builder_3(char* buffer, ...) { va_list args; va_start(args, buffer); - test::vsnprintf_(buffer, 100U, "%d %d %s", args); + CAPTURE_AND_PRINT(test::vsnprintf_, buffer, 100U, "%d %d %s", args); va_end(args); } @@ -216,267 +243,121 @@ TEST_CASE("vsnprintf_", "[]" ) { TEST_CASE("space flag", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "% d", 42); - CHECK(!strcmp(buffer, " 42")); - - test::sprintf_(buffer, "% d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "% 5d", 42); - CHECK(!strcmp(buffer, " 42")); - - test::sprintf_(buffer, "% 5d", -42); - CHECK(!strcmp(buffer, " -42")); - - test::sprintf_(buffer, "% 15d", 42); - CHECK(!strcmp(buffer, " 42")); - - test::sprintf_(buffer, "% 15d", -42); - CHECK(!strcmp(buffer, " -42")); - - test::sprintf_(buffer, "% 15d", -42); - CHECK(!strcmp(buffer, " -42")); - - test::sprintf_(buffer, "% 15.3f", -42.987); - CHECK(!strcmp(buffer, " -42.987")); - - test::sprintf_(buffer, "% 15.3f", 42.987); - CHECK(!strcmp(buffer, " 42.987")); - - test::sprintf_(buffer, "% d", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "% d", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "% i", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "% i", -1024); - CHECK(!strcmp(buffer, "-1024")); + PRINTING_CHECK(" 42", ==, test::sprintf_, buffer, "% d", 42); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "% d", -42); + PRINTING_CHECK(" 42", ==, test::sprintf_, buffer, "% 5d", 42); + PRINTING_CHECK(" -42", ==, test::sprintf_, buffer, "% 5d", -42); + PRINTING_CHECK(" 42", ==, test::sprintf_, buffer, "% 15d", 42); + PRINTING_CHECK(" -42", ==, test::sprintf_, buffer, "% 15d", -42); + PRINTING_CHECK(" -42", ==, test::sprintf_, buffer, "% 15d", -42); + PRINTING_CHECK(" -42.987", ==, test::sprintf_, buffer, "% 15.3f", -42.987); + PRINTING_CHECK(" 42.987", ==, test::sprintf_, buffer, "% 15.3f", 42.987); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "% d", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "% d", -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "% i", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "% i", -1024); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("space flag - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "% s", "Hello testing"); - CHECK(!strcmp(buffer, "Hello testing")); - - test::sprintf_(buffer, "% u", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "% u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272")); - - test::sprintf_(buffer, "% o", 511); - CHECK(!strcmp(buffer, "777")); - - test::sprintf_(buffer, "% o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001")); - - test::sprintf_(buffer, "% x", 305441741); - CHECK(!strcmp(buffer, "1234abcd")); - - test::sprintf_(buffer, "% x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433")); - - test::sprintf_(buffer, "% X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD")); - - test::sprintf_(buffer, "% X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433")); - - test::sprintf_(buffer, "% c", 'x'); - CHECK(!strcmp(buffer, "x")); + PRINTING_CHECK("Hello testing", ==, test::sprintf_, buffer, "% s", "Hello testing"); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "% u", 1024); + PRINTING_CHECK("4294966272", ==, test::sprintf_, buffer, "% u", 4294966272U); + PRINTING_CHECK("777", ==, test::sprintf_, buffer, "% o", 511); + PRINTING_CHECK("37777777001", ==, test::sprintf_, buffer, "% o", 4294966785U); + PRINTING_CHECK("1234abcd", ==, test::sprintf_, buffer, "% x", 305441741); + PRINTING_CHECK("edcb5433", ==, test::sprintf_, buffer, "% x", 3989525555U); + PRINTING_CHECK("1234ABCD", ==, test::sprintf_, buffer, "% X", 305441741); + PRINTING_CHECK("EDCB5433", ==, test::sprintf_, buffer, "% X", 3989525555U); + PRINTING_CHECK("x", ==, test::sprintf_, buffer, "% c", 'x'); } #endif TEST_CASE("+ flag", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%+d", 42); - CHECK(!strcmp(buffer, "+42")); - - test::sprintf_(buffer, "%+d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "%+5d", 42); - CHECK(!strcmp(buffer, " +42")); - - test::sprintf_(buffer, "%+5d", -42); - CHECK(!strcmp(buffer, " -42")); - - test::sprintf_(buffer, "%+15d", 42); - CHECK(!strcmp(buffer, " +42")); - - test::sprintf_(buffer, "%+15d", -42); - CHECK(!strcmp(buffer, " -42")); - - test::sprintf_(buffer, "%+d", 1024); - CHECK(!strcmp(buffer, "+1024")); - - test::sprintf_(buffer, "%+d", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%+i", 1024); - CHECK(!strcmp(buffer, "+1024")); - - test::sprintf_(buffer, "%+i", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%+.0d", 0); - CHECK(!strcmp(buffer, "+")); + PRINTING_CHECK("+42", ==, test::sprintf_, buffer, "%+d", 42); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "%+d", -42); + PRINTING_CHECK(" +42", ==, test::sprintf_, buffer, "%+5d", 42); + PRINTING_CHECK(" -42", ==, test::sprintf_, buffer, "%+5d", -42); + PRINTING_CHECK(" +42", ==, test::sprintf_, buffer, "%+15d", 42); + PRINTING_CHECK(" -42", ==, test::sprintf_, buffer, "%+15d", -42); + PRINTING_CHECK("+1024", ==, test::sprintf_, buffer, "%+d", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%+d", -1024); + PRINTING_CHECK("+1024", ==, test::sprintf_, buffer, "%+i", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%+i", -1024); + PRINTING_CHECK("+", ==, test::sprintf_, buffer, "%+.0d", 0); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("+ flag - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%+s", "Hello testing"); - CHECK(!strcmp(buffer, "Hello testing")); - - test::sprintf_(buffer, "%+u", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%+u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272")); - - test::sprintf_(buffer, "%+o", 511); - CHECK(!strcmp(buffer, "777")); - - test::sprintf_(buffer, "%+o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001")); - - test::sprintf_(buffer, "%+x", 305441741); - CHECK(!strcmp(buffer, "1234abcd")); - - test::sprintf_(buffer, "%+x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433")); - - test::sprintf_(buffer, "%+X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD")); - - test::sprintf_(buffer, "%+X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433")); - - test::sprintf_(buffer, "%+c", 'x'); - CHECK(!strcmp(buffer, "x")); + PRINTING_CHECK("Hello testing", ==, test::sprintf_, buffer, "%+s", "Hello testing"); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%+u", 1024); + PRINTING_CHECK("4294966272", ==, test::sprintf_, buffer, "%+u", 4294966272U); + PRINTING_CHECK("777", ==, test::sprintf_, buffer, "%+o", 511); + PRINTING_CHECK("37777777001", ==, test::sprintf_, buffer, "%+o", 4294966785U); + PRINTING_CHECK("1234abcd", ==, test::sprintf_, buffer, "%+x", 305441741); + PRINTING_CHECK("edcb5433", ==, test::sprintf_, buffer, "%+x", 3989525555U); + PRINTING_CHECK("1234ABCD", ==, test::sprintf_, buffer, "%+X", 305441741); + PRINTING_CHECK("EDCB5433", ==, test::sprintf_, buffer, "%+X", 3989525555U); + PRINTING_CHECK("x", ==, test::sprintf_, buffer, "%+c", 'x'); } #endif TEST_CASE("0 flag", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%0d", 42); - CHECK(!strcmp(buffer, "42")); - - test::sprintf_(buffer, "%0ld", 42L); - CHECK(!strcmp(buffer, "42")); - - test::sprintf_(buffer, "%0d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "%05d", 42); - CHECK(!strcmp(buffer, "00042")); - - test::sprintf_(buffer, "%05d", -42); - CHECK(!strcmp(buffer, "-0042")); - - test::sprintf_(buffer, "%015d", 42); - CHECK(!strcmp(buffer, "000000000000042")); - - test::sprintf_(buffer, "%015d", -42); - CHECK(!strcmp(buffer, "-00000000000042")); - - test::sprintf_(buffer, "%015.2f", 42.1234); - CHECK(!strcmp(buffer, "000000000042.12")); - - test::sprintf_(buffer, "%015.3f", 42.9876); - CHECK(!strcmp(buffer, "00000000042.988")); - - test::sprintf_(buffer, "%015.5f", -42.9876); - CHECK(!strcmp(buffer, "-00000042.98760")); + PRINTING_CHECK("42", ==, test::sprintf_, buffer, "%0d", 42); + PRINTING_CHECK("42", ==, test::sprintf_, buffer, "%0ld", 42L); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "%0d", -42); + PRINTING_CHECK("00042", ==, test::sprintf_, buffer, "%05d", 42); + PRINTING_CHECK("-0042", ==, test::sprintf_, buffer, "%05d", -42); + PRINTING_CHECK("000000000000042", ==, test::sprintf_, buffer, "%015d", 42); + PRINTING_CHECK("-00000000000042", ==, test::sprintf_, buffer, "%015d", -42); + PRINTING_CHECK("000000000042.12", ==, test::sprintf_, buffer, "%015.2f", 42.1234); + PRINTING_CHECK("00000000042.988", ==, test::sprintf_, buffer, "%015.3f", 42.9876); + PRINTING_CHECK("-00000042.98760", ==, test::sprintf_, buffer, "%015.5f", -42.9876); } TEST_CASE("- flag", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%-d", 42); - CHECK(!strcmp(buffer, "42")); - - test::sprintf_(buffer, "%-d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "%-5d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%-5d", -42); - CHECK(!strcmp(buffer, "-42 ")); - - test::sprintf_(buffer, "%-15d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%-15d", -42); - CHECK(!strcmp(buffer, "-42 ")); + PRINTING_CHECK("42", ==, test::sprintf_, buffer, "%-d", 42); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "%-d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%-5d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%-5d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%-15d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%-15d", -42); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("- flag - non-standard format", "[]" ) { char buffer[100]; + PRINTING_CHECK("42", ==, test::sprintf_, buffer, "%-0d", 42); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "%-0d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%-05d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%-05d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%-015d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%-015d", -42); + PRINTING_CHECK("42", ==, test::sprintf_, buffer, "%0-d", 42); + PRINTING_CHECK("-42", ==, test::sprintf_, buffer, "%0-d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%0-5d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%0-5d", -42); + PRINTING_CHECK("42 ", ==, test::sprintf_, buffer, "%0-15d", 42); + PRINTING_CHECK("-42 ", ==, test::sprintf_, buffer, "%0-15d", -42); - test::sprintf_(buffer, "%-0d", 42); - CHECK(!strcmp(buffer, "42")); - - test::sprintf_(buffer, "%-0d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "%-05d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%-05d", -42); - CHECK(!strcmp(buffer, "-42 ")); - - test::sprintf_(buffer, "%-015d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%-015d", -42); - CHECK(!strcmp(buffer, "-42 ")); - - test::sprintf_(buffer, "%0-d", 42); - CHECK(!strcmp(buffer, "42")); - - test::sprintf_(buffer, "%0-d", -42); - CHECK(!strcmp(buffer, "-42")); - - test::sprintf_(buffer, "%0-5d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%0-5d", -42); - CHECK(!strcmp(buffer, "-42 ")); - - test::sprintf_(buffer, "%0-15d", 42); - CHECK(!strcmp(buffer, "42 ")); - - test::sprintf_(buffer, "%0-15d", -42); - CHECK(!strcmp(buffer, "-42 ")); - - test::sprintf_(buffer, "%0-15.3e", -42.); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - CHECK(!strcmp(buffer, "-4.200e+01 ")); + PRINTING_CHECK("-4.200e+01 ", ==, test::sprintf_, buffer, "%0-15.3e", -42.); #else - CHECK(!strcmp(buffer, "e")); + PRINTING_CHECK("e", ==, test::sprintf_, buffer, "%0-15.3e", -42.); #endif - test::sprintf_(buffer, "%0-15.3g", -42.); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - CHECK(!strcmp(buffer, "-42.0 ")); + PRINTING_CHECK("-42.0 ", ==, test::sprintf_, buffer, "%0-15.3g", -42.); #else - CHECK(!strcmp(buffer, "g")); + PRINTING_CHECK("g", ==, test::sprintf_, buffer, "%0-15.3g", -42.); #endif } #endif @@ -484,583 +365,253 @@ TEST_CASE("- flag - non-standard format", "[]" ) { TEST_CASE("# flag", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%#o", 0); - CHECK(!strcmp(buffer, "0")); - test::sprintf_(buffer, "%#0o", 0); - CHECK(!strcmp(buffer, "0")); - test::sprintf_(buffer, "%#.0o", 0); - CHECK(!strcmp(buffer, "0")); - test::sprintf_(buffer, "%#.1o", 0); - CHECK(!strcmp(buffer, "0")); - test::sprintf_(buffer, "%#4o", 0); - CHECK(!strcmp(buffer, " 0")); - test::sprintf_(buffer, "%#.4o", 0); - CHECK(!strcmp(buffer, "0000")); - - test::sprintf_(buffer, "%#o", 1); - CHECK(!strcmp(buffer, "01")); - test::sprintf_(buffer, "%#0o", 1); - CHECK(!strcmp(buffer, "01")); - test::sprintf_(buffer, "%#.0o", 1); - CHECK(!strcmp(buffer, "01")); - test::sprintf_(buffer, "%#.1o", 1); - CHECK(!strcmp(buffer, "01")); - test::sprintf_(buffer, "%#4o", 1); - CHECK(!strcmp(buffer, " 01")); - test::sprintf_(buffer, "%#.4o", 1); - CHECK(!strcmp(buffer, "0001")); - - test::sprintf_(buffer, "%#04x", 0x1001); - CHECK(!strcmp(buffer, "0x1001")); - test::sprintf_(buffer, "%#04o", 01001); - CHECK(!strcmp(buffer, "01001")); - - test::sprintf_(buffer, "%#.0llx", (long long)0); - CHECK(!strcmp(buffer, "")); - test::sprintf_(buffer, "%#.8x", 0x614e); - CHECK(!strcmp(buffer, "0x0000614e")); + PRINTING_CHECK("0", ==, test::sprintf_, buffer, "%#o", 0 ); + PRINTING_CHECK("0", ==, test::sprintf_, buffer, "%#0o", 0 ); + PRINTING_CHECK("0", ==, test::sprintf_, buffer, "%#.0o", 0 ); + PRINTING_CHECK("0", ==, test::sprintf_, buffer, "%#.1o", 0 ); + PRINTING_CHECK(" 0", ==, test::sprintf_, buffer, "%#4o", 0 ); + PRINTING_CHECK("0000", ==, test::sprintf_, buffer, "%#.4o", 0 ); + PRINTING_CHECK("01", ==, test::sprintf_, buffer, "%#o", 1 ); + PRINTING_CHECK("01", ==, test::sprintf_, buffer, "%#0o", 1 ); + PRINTING_CHECK("01", ==, test::sprintf_, buffer, "%#.0o", 1 ); + PRINTING_CHECK("01", ==, test::sprintf_, buffer, "%#.1o", 1 ); + PRINTING_CHECK(" 01", ==, test::sprintf_, buffer, "%#4o", 1 ); + PRINTING_CHECK("0001", ==, test::sprintf_, buffer, "%#.4o", 1 ); + PRINTING_CHECK("0x1001", ==, test::sprintf_, buffer, "%#04x", 0x1001 ); + PRINTING_CHECK("01001", ==, test::sprintf_, buffer, "%#04o", 01001 ); + PRINTING_CHECK("", ==, test::sprintf_, buffer, "%#.0llx", (long long) 0); + PRINTING_CHECK("0x0000614e", ==, test::sprintf_, buffer, "%#.8x", 0x614e ); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("# flag - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer,"%#b", 6); - CHECK(!strcmp(buffer, "0b110")); + PRINTING_CHECK("0b110", ==, test::sprintf_, buffer, "%#b", 6); } #endif TEST_CASE("specifier", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "Hello testing"); - CHECK(!strcmp(buffer, "Hello testing")); - - test::sprintf_(buffer, "%s", "Hello testing"); - CHECK(!strcmp(buffer, "Hello testing")); + PRINTING_CHECK("Hello testing", ==, test::sprintf_, buffer, "Hello testing"); + PRINTING_CHECK("Hello testing", ==, test::sprintf_, buffer, "%s", "Hello testing"); DISABLE_WARNING_PUSH DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW - test::sprintf_(buffer, "%s", NULL); + PRINTING_CHECK( "(null)", ==, test::sprintf_, buffer, "%s", NULL); DISABLE_WARNING_POP - CHECK(!strcmp(buffer, "(null)")); - - test::sprintf_(buffer, "%d", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%d", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%i", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%i", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%u", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272")); - - test::sprintf_(buffer, "%o", 511); - CHECK(!strcmp(buffer, "777")); - - test::sprintf_(buffer, "%o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001")); - - test::sprintf_(buffer, "%x", 305441741); - CHECK(!strcmp(buffer, "1234abcd")); - - test::sprintf_(buffer, "%x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433")); - - test::sprintf_(buffer, "%X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD")); - - test::sprintf_(buffer, "%X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433")); - - test::sprintf_(buffer, "%%"); - CHECK(!strcmp(buffer, "%")); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%d", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%d", -1024); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%i", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%i", -1024); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%u", 1024); + PRINTING_CHECK("4294966272", ==, test::sprintf_, buffer, "%u", 4294966272U); + PRINTING_CHECK("777", ==, test::sprintf_, buffer, "%o", 511); + PRINTING_CHECK("37777777001", ==, test::sprintf_, buffer, "%o", 4294966785U); + PRINTING_CHECK("1234abcd", ==, test::sprintf_, buffer, "%x", 305441741); + PRINTING_CHECK("edcb5433", ==, test::sprintf_, buffer, "%x", 3989525555U); + PRINTING_CHECK("1234ABCD", ==, test::sprintf_, buffer, "%X", 305441741); + PRINTING_CHECK("EDCB5433", ==, test::sprintf_, buffer, "%X", 3989525555U); + PRINTING_CHECK("%", ==, test::sprintf_, buffer, "%%"); } TEST_CASE("width", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%1s", "Hello testing"); - CHECK(!strcmp(buffer, "Hello testing")); - - test::sprintf_(buffer, "%1d", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%1d", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%1i", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%1i", -1024); - CHECK(!strcmp(buffer, "-1024")); - - test::sprintf_(buffer, "%1u", 1024); - CHECK(!strcmp(buffer, "1024")); - - test::sprintf_(buffer, "%1u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272")); - - test::sprintf_(buffer, "%1o", 511); - CHECK(!strcmp(buffer, "777")); - - test::sprintf_(buffer, "%1o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001")); - - test::sprintf_(buffer, "%1x", 305441741); - CHECK(!strcmp(buffer, "1234abcd")); - - test::sprintf_(buffer, "%1x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433")); - - test::sprintf_(buffer, "%1X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD")); - - test::sprintf_(buffer, "%1X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433")); - - test::sprintf_(buffer, "%1c", 'x'); - CHECK(!strcmp(buffer, "x")); + PRINTING_CHECK("Hello testing", ==, test::sprintf_, buffer, "%1s", "Hello testing"); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%1d", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%1d", -1024); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%1i", 1024); + PRINTING_CHECK("-1024", ==, test::sprintf_, buffer, "%1i", -1024); + PRINTING_CHECK("1024", ==, test::sprintf_, buffer, "%1u", 1024); + PRINTING_CHECK("4294966272", ==, test::sprintf_, buffer, "%1u", 4294966272U); + PRINTING_CHECK("777", ==, test::sprintf_, buffer, "%1o", 511); + PRINTING_CHECK("37777777001", ==, test::sprintf_, buffer, "%1o", 4294966785U); + PRINTING_CHECK("1234abcd", ==, test::sprintf_, buffer, "%1x", 305441741); + PRINTING_CHECK("edcb5433", ==, test::sprintf_, buffer, "%1x", 3989525555U); + PRINTING_CHECK("1234ABCD", ==, test::sprintf_, buffer, "%1X", 305441741); + PRINTING_CHECK("EDCB5433", ==, test::sprintf_, buffer, "%1X", 3989525555U); + PRINTING_CHECK("x", ==, test::sprintf_, buffer, "%1c", 'x'); } TEST_CASE("width 20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%20s", "Hello"); - CHECK(!strcmp(buffer, " Hello")); - - test::sprintf_(buffer, "%20d", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20d", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%20i", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20i", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf(buffer, "%20i", 0); - CHECK(!strcmp(buffer, " 0")); - - test::sprintf_(buffer, "%20u", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20u", 4294966272U); - CHECK(!strcmp(buffer, " 4294966272")); - - test::sprintf_(buffer, "%20o", 511); - CHECK(!strcmp(buffer, " 777")); - - test::sprintf_(buffer, "%20o", 4294966785U); - CHECK(!strcmp(buffer, " 37777777001")); - - test::sprintf_(buffer, "%20x", 305441741); - CHECK(!strcmp(buffer, " 1234abcd")); - - test::sprintf_(buffer, "%20x", 3989525555U); - CHECK(!strcmp(buffer, " edcb5433")); - - test::sprintf_(buffer, "%20X", 305441741); - CHECK(!strcmp(buffer, " 1234ABCD")); - - test::sprintf_(buffer, "%20X", 3989525555U); - CHECK(!strcmp(buffer, " EDCB5433")); - - test::sprintf_(buffer, "%20X", 0); - CHECK(!strcmp(buffer, " 0")); - - test::sprintf_(buffer, "%20X", 0U); - CHECK(!strcmp(buffer, " 0")); - - test::sprintf_(buffer, "%20llX", 0U); - CHECK(!strcmp(buffer, " 0")); - - test::sprintf_(buffer, "%20c", 'x'); - CHECK(!strcmp(buffer, " x")); + PRINTING_CHECK(" Hello", ==, test::sprintf_, buffer, "%20s", "Hello"); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20d", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%20d", -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20i", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%20i", -1024); + PRINTING_CHECK(" 0", ==, test::sprintf_, buffer, "%20i", 0); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20u", 1024); + PRINTING_CHECK(" 4294966272", ==, test::sprintf_, buffer, "%20u", 4294966272U); + PRINTING_CHECK(" 777", ==, test::sprintf_, buffer, "%20o", 511); + PRINTING_CHECK(" 37777777001", ==, test::sprintf_, buffer, "%20o", 4294966785U); + PRINTING_CHECK(" 1234abcd", ==, test::sprintf_, buffer, "%20x", 305441741); + PRINTING_CHECK(" edcb5433", ==, test::sprintf_, buffer, "%20x", 3989525555U); + PRINTING_CHECK(" 1234ABCD", ==, test::sprintf_, buffer, "%20X", 305441741); + PRINTING_CHECK(" EDCB5433", ==, test::sprintf_, buffer, "%20X", 3989525555U); + PRINTING_CHECK(" 0", ==, test::sprintf_, buffer, "%20X", 0); + PRINTING_CHECK(" 0", ==, test::sprintf_, buffer, "%20X", 0U); + PRINTING_CHECK(" 0", ==, test::sprintf_, buffer, "%20llX", 0U); + PRINTING_CHECK(" x", ==, test::sprintf_, buffer, "%20c", 'x'); } TEST_CASE("width *20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%*s", 20, "Hello"); - CHECK(!strcmp(buffer, " Hello")); - - test::sprintf_(buffer, "%*d", 20, 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%*d", 20, -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%*i", 20, 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%*i", 20, -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%*u", 20, 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%*u", 20, 4294966272U); - CHECK(!strcmp(buffer, " 4294966272")); - - test::sprintf_(buffer, "%*o", 20, 511); - CHECK(!strcmp(buffer, " 777")); - - test::sprintf_(buffer, "%*o", 20, 4294966785U); - CHECK(!strcmp(buffer, " 37777777001")); - - test::sprintf_(buffer, "%*x", 20, 305441741); - CHECK(!strcmp(buffer, " 1234abcd")); - - test::sprintf_(buffer, "%*x", 20, 3989525555U); - CHECK(!strcmp(buffer, " edcb5433")); - - test::sprintf_(buffer, "%*X", 20, 305441741); - CHECK(!strcmp(buffer, " 1234ABCD")); - - test::sprintf_(buffer, "%*X", 20, 3989525555U); - CHECK(!strcmp(buffer, " EDCB5433")); - - test::sprintf_(buffer, "%*c", 20,'x'); - CHECK(!strcmp(buffer, " x")); + PRINTING_CHECK(" Hello", ==, test::sprintf_, buffer, "%*s", 20, "Hello"); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%*d", 20, 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%*d", 20, -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%*i", 20, 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%*i", 20, -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%*u", 20, 1024); + PRINTING_CHECK(" 4294966272", ==, test::sprintf_, buffer, "%*u", 20, 4294966272U); + PRINTING_CHECK(" 777", ==, test::sprintf_, buffer, "%*o", 20, 511); + PRINTING_CHECK(" 37777777001", ==, test::sprintf_, buffer, "%*o", 20, 4294966785U); + PRINTING_CHECK(" 1234abcd", ==, test::sprintf_, buffer, "%*x", 20, 305441741); + PRINTING_CHECK(" edcb5433", ==, test::sprintf_, buffer, "%*x", 20, 3989525555U); + PRINTING_CHECK(" 1234ABCD", ==, test::sprintf_, buffer, "%*X", 20, 305441741); + PRINTING_CHECK(" EDCB5433", ==, test::sprintf_, buffer, "%*X", 20, 3989525555U); + PRINTING_CHECK(" x", ==, test::sprintf_, buffer, "%*c", 20,'x'); } TEST_CASE("width -20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%-20s", "Hello"); - CHECK(!strcmp(buffer, "Hello ")); - - test::sprintf_(buffer, "%-20d", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%-20d", -1024); - CHECK(!strcmp(buffer, "-1024 ")); - - test::sprintf_(buffer, "%-20i", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%-20i", -1024); - CHECK(!strcmp(buffer, "-1024 ")); - - test::sprintf_(buffer, "%-20u", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%-20.4f", 1024.1234); - CHECK(!strcmp(buffer, "1024.1234 ")); - - test::sprintf_(buffer, "%-20u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272 ")); - - test::sprintf_(buffer, "%-20o", 511); - CHECK(!strcmp(buffer, "777 ")); - - test::sprintf_(buffer, "%-20o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001 ")); - - test::sprintf_(buffer, "%-20x", 305441741); - CHECK(!strcmp(buffer, "1234abcd ")); - - test::sprintf_(buffer, "%-20x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433 ")); - - test::sprintf_(buffer, "%-20X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD ")); - - test::sprintf_(buffer, "%-20X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433 ")); - - test::sprintf_(buffer, "%-20c", 'x'); - CHECK(!strcmp(buffer, "x ")); - - test::sprintf_(buffer, "|%5d| |%-2d| |%5d|", 9, 9, 9); - CHECK(!strcmp(buffer, "| 9| |9 | | 9|")); - - test::sprintf_(buffer, "|%5d| |%-2d| |%5d|", 10, 10, 10); - CHECK(!strcmp(buffer, "| 10| |10| | 10|")); - - test::sprintf_(buffer, "|%5d| |%-12d| |%5d|", 9, 9, 9); - CHECK(!strcmp(buffer, "| 9| |9 | | 9|")); - - test::sprintf_(buffer, "|%5d| |%-12d| |%5d|", 10, 10, 10); - CHECK(!strcmp(buffer, "| 10| |10 | | 10|")); + PRINTING_CHECK("Hello ", ==, test::sprintf_, buffer, "%-20s", "Hello"); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%-20d", 1024); + PRINTING_CHECK("-1024 ", ==, test::sprintf_, buffer, "%-20d", -1024); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%-20i", 1024); + PRINTING_CHECK("-1024 ", ==, test::sprintf_, buffer, "%-20i", -1024); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%-20u", 1024); + PRINTING_CHECK("1024.1234 ", ==, test::sprintf_, buffer, "%-20.4f", 1024.1234); + PRINTING_CHECK("4294966272 ", ==, test::sprintf_, buffer, "%-20u", 4294966272U); + PRINTING_CHECK("777 ", ==, test::sprintf_, buffer, "%-20o", 511); + PRINTING_CHECK("37777777001 ", ==, test::sprintf_, buffer, "%-20o", 4294966785U); + PRINTING_CHECK("1234abcd ", ==, test::sprintf_, buffer, "%-20x", 305441741); + PRINTING_CHECK("edcb5433 ", ==, test::sprintf_, buffer, "%-20x", 3989525555U); + PRINTING_CHECK("1234ABCD ", ==, test::sprintf_, buffer, "%-20X", 305441741); + PRINTING_CHECK("EDCB5433 ", ==, test::sprintf_, buffer, "%-20X", 3989525555U); + PRINTING_CHECK("x ", ==, test::sprintf_, buffer, "%-20c", 'x'); + PRINTING_CHECK("| 9| |9 | | 9|", ==, test::sprintf_, buffer, "|%5d| |%-2d| |%5d|", 9, 9, 9); + PRINTING_CHECK("| 10| |10| | 10|", ==, test::sprintf_, buffer, "|%5d| |%-2d| |%5d|", 10, 10, 10); + PRINTING_CHECK("| 9| |9 | | 9|", ==, test::sprintf_, buffer, "|%5d| |%-12d| |%5d|", 9, 9, 9); + PRINTING_CHECK("| 10| |10 | | 10|", ==, test::sprintf_, buffer, "|%5d| |%-12d| |%5d|", 10, 10, 10); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("width 0-20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%0-20s", "Hello"); - CHECK(!strcmp(buffer, "Hello ")); - - test::sprintf_(buffer, "%0-20d", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%0-20d", -1024); - CHECK(!strcmp(buffer, "-1024 ")); - - test::sprintf_(buffer, "%0-20i", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%0-20i", -1024); - CHECK(!strcmp(buffer, "-1024 ")); - - test::sprintf_(buffer, "%0-20u", 1024); - CHECK(!strcmp(buffer, "1024 ")); - - test::sprintf_(buffer, "%0-20u", 4294966272U); - CHECK(!strcmp(buffer, "4294966272 ")); - - test::sprintf_(buffer, "%0-20o", 511); - CHECK(!strcmp(buffer, "777 ")); - - test::sprintf_(buffer, "%0-20o", 4294966785U); - CHECK(!strcmp(buffer, "37777777001 ")); - - test::sprintf_(buffer, "%0-20x", 305441741); - CHECK(!strcmp(buffer, "1234abcd ")); - - test::sprintf_(buffer, "%0-20x", 3989525555U); - CHECK(!strcmp(buffer, "edcb5433 ")); - - test::sprintf_(buffer, "%0-20X", 305441741); - CHECK(!strcmp(buffer, "1234ABCD ")); - - test::sprintf_(buffer, "%0-20X", 3989525555U); - CHECK(!strcmp(buffer, "EDCB5433 ")); - - test::sprintf_(buffer, "%0-20c", 'x'); - CHECK(!strcmp(buffer, "x ")); + PRINTING_CHECK("Hello ", ==, test::sprintf_, buffer, "%0-20s", "Hello"); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%0-20d", 1024); + PRINTING_CHECK("-1024 ", ==, test::sprintf_, buffer, "%0-20d", -1024); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%0-20i", 1024); + PRINTING_CHECK("-1024 ", ==, test::sprintf_, buffer, "%0-20i", -1024); + PRINTING_CHECK("1024 ", ==, test::sprintf_, buffer, "%0-20u", 1024); + PRINTING_CHECK("4294966272 ", ==, test::sprintf_, buffer, "%0-20u", 4294966272U); + PRINTING_CHECK("777 ", ==, test::sprintf_, buffer, "%0-20o", 511); + PRINTING_CHECK("37777777001 ", ==, test::sprintf_, buffer, "%0-20o", 4294966785U); + PRINTING_CHECK("1234abcd ", ==, test::sprintf_, buffer, "%0-20x", 305441741); + PRINTING_CHECK("edcb5433 ", ==, test::sprintf_, buffer, "%0-20x", 3989525555U); + PRINTING_CHECK("1234ABCD ", ==, test::sprintf_, buffer, "%0-20X", 305441741); + PRINTING_CHECK("EDCB5433 ", ==, test::sprintf_, buffer, "%0-20X", 3989525555U); + PRINTING_CHECK("x ", ==, test::sprintf_, buffer, "%0-20c", 'x'); } #endif TEST_CASE("padding 20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%020d", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%020d", -1024); - CHECK(!strcmp(buffer, "-0000000000000001024")); - - test::sprintf_(buffer, "%020i", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%020i", -1024); - CHECK(!strcmp(buffer, "-0000000000000001024")); - - test::sprintf_(buffer, "%020u", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%020u", 4294966272U); - CHECK(!strcmp(buffer, "00000000004294966272")); - - test::sprintf_(buffer, "%020o", 511); - CHECK(!strcmp(buffer, "00000000000000000777")); - - test::sprintf_(buffer, "%020o", 4294966785U); - CHECK(!strcmp(buffer, "00000000037777777001")); - - test::sprintf_(buffer, "%020x", 305441741); - CHECK(!strcmp(buffer, "0000000000001234abcd")); - - test::sprintf_(buffer, "%020x", 3989525555U); - CHECK(!strcmp(buffer, "000000000000edcb5433")); - - test::sprintf_(buffer, "%020X", 305441741); - CHECK(!strcmp(buffer, "0000000000001234ABCD")); - - test::sprintf_(buffer, "%020X", 3989525555U); - CHECK(!strcmp(buffer, "000000000000EDCB5433")); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%020d", 1024); + PRINTING_CHECK("-0000000000000001024", ==, test::sprintf_, buffer, "%020d", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%020i", 1024); + PRINTING_CHECK("-0000000000000001024", ==, test::sprintf_, buffer, "%020i", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%020u", 1024); + PRINTING_CHECK("00000000004294966272", ==, test::sprintf_, buffer, "%020u", 4294966272U); + PRINTING_CHECK("00000000000000000777", ==, test::sprintf_, buffer, "%020o", 511); + PRINTING_CHECK("00000000037777777001", ==, test::sprintf_, buffer, "%020o", 4294966785U); + PRINTING_CHECK("0000000000001234abcd", ==, test::sprintf_, buffer, "%020x", 305441741); + PRINTING_CHECK("000000000000edcb5433", ==, test::sprintf_, buffer, "%020x", 3989525555U); + PRINTING_CHECK("0000000000001234ABCD", ==, test::sprintf_, buffer, "%020X", 305441741); + PRINTING_CHECK("000000000000EDCB5433", ==, test::sprintf_, buffer, "%020X", 3989525555U); } TEST_CASE("padding .20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%.20d", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%.20d", -1024); - CHECK(!strcmp(buffer, "-00000000000000001024")); - - test::sprintf_(buffer, "%.20i", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%.20i", -1024); - CHECK(!strcmp(buffer, "-00000000000000001024")); - - test::sprintf_(buffer, "%.20u", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%.20u", 4294966272U); - CHECK(!strcmp(buffer, "00000000004294966272")); - - test::sprintf_(buffer, "%.20o", 511); - CHECK(!strcmp(buffer, "00000000000000000777")); - - test::sprintf_(buffer, "%.20o", 4294966785U); - CHECK(!strcmp(buffer, "00000000037777777001")); - - test::sprintf_(buffer, "%.20x", 305441741); - CHECK(!strcmp(buffer, "0000000000001234abcd")); - - test::sprintf_(buffer, "%.20x", 3989525555U); - CHECK(!strcmp(buffer, "000000000000edcb5433")); - - test::sprintf_(buffer, "%.20X", 305441741); - CHECK(!strcmp(buffer, "0000000000001234ABCD")); - - test::sprintf_(buffer, "%.20X", 3989525555U); - CHECK(!strcmp(buffer, "000000000000EDCB5433")); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%.20d", 1024); + PRINTING_CHECK("-00000000000000001024", ==, test::sprintf_, buffer, "%.20d", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%.20i", 1024); + PRINTING_CHECK("-00000000000000001024", ==, test::sprintf_, buffer, "%.20i", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%.20u", 1024); + PRINTING_CHECK("00000000004294966272", ==, test::sprintf_, buffer, "%.20u", 4294966272U); + PRINTING_CHECK("00000000000000000777", ==, test::sprintf_, buffer, "%.20o", 511); + PRINTING_CHECK("00000000037777777001", ==, test::sprintf_, buffer, "%.20o", 4294966785U); + PRINTING_CHECK("0000000000001234abcd", ==, test::sprintf_, buffer, "%.20x", 305441741); + PRINTING_CHECK("000000000000edcb5433", ==, test::sprintf_, buffer, "%.20x", 3989525555U); + PRINTING_CHECK("0000000000001234ABCD", ==, test::sprintf_, buffer, "%.20X", 305441741); + PRINTING_CHECK("000000000000EDCB5433", ==, test::sprintf_, buffer, "%.20X", 3989525555U); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("padding #020 - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%#020d", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%#020d", -1024); - CHECK(!strcmp(buffer, "-0000000000000001024")); - - test::sprintf_(buffer, "%#020i", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%#020i", -1024); - CHECK(!strcmp(buffer, "-0000000000000001024")); - - test::sprintf_(buffer, "%#020u", 1024); - CHECK(!strcmp(buffer, "00000000000000001024")); - - test::sprintf_(buffer, "%#020u", 4294966272U); - CHECK(!strcmp(buffer, "00000000004294966272")); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%#020d", 1024); + PRINTING_CHECK("-0000000000000001024", ==, test::sprintf_, buffer, "%#020d", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%#020i", 1024); + PRINTING_CHECK("-0000000000000001024", ==, test::sprintf_, buffer, "%#020i", -1024); + PRINTING_CHECK("00000000000000001024", ==, test::sprintf_, buffer, "%#020u", 1024); + PRINTING_CHECK("00000000004294966272", ==, test::sprintf_, buffer, "%#020u", 4294966272U); } #endif TEST_CASE("padding #020", "[]" ) { char buffer[100]; - test::sprintf_(buffer, "%#020o", 511); - CHECK(!strcmp(buffer, "00000000000000000777")); - - test::sprintf_(buffer, "%#020o", 4294966785U); - CHECK(!strcmp(buffer, "00000000037777777001")); - - test::sprintf_(buffer, "%#020x", 305441741); - CHECK(!strcmp(buffer, "0x00000000001234abcd")); - - test::sprintf_(buffer, "%#020x", 3989525555U); - CHECK(!strcmp(buffer, "0x0000000000edcb5433")); - - test::sprintf_(buffer, "%#020X", 305441741); - CHECK(!strcmp(buffer, "0X00000000001234ABCD")); - - test::sprintf_(buffer, "%#020X", 3989525555U); - CHECK(!strcmp(buffer, "0X0000000000EDCB5433")); + PRINTING_CHECK("00000000000000000777", ==, test::sprintf_, buffer, "%#020o", 511); + PRINTING_CHECK("00000000037777777001", ==, test::sprintf_, buffer, "%#020o", 4294966785U); + PRINTING_CHECK("0x00000000001234abcd", ==, test::sprintf_, buffer, "%#020x", 305441741); + PRINTING_CHECK("0x0000000000edcb5433", ==, test::sprintf_, buffer, "%#020x", 3989525555U); + PRINTING_CHECK("0X00000000001234ABCD", ==, test::sprintf_, buffer, "%#020X", 305441741); + PRINTING_CHECK("0X0000000000EDCB5433", ==, test::sprintf_, buffer, "%#020X", 3989525555U); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("padding #20 - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%#20d", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%#20d", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%#20i", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%#20i", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%#20u", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%#20u", 4294966272U); - CHECK(!strcmp(buffer, " 4294966272")); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%#20d", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%#20d", -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%#20i", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%#20i", -1024); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%#20u", 1024); + PRINTING_CHECK(" 4294966272", ==, test::sprintf_, buffer, "%#20u", 4294966272U); } #endif TEST_CASE("padding #20", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%#20o", 511); - CHECK(!strcmp(buffer, " 0777")); - - test::sprintf_(buffer, "%#20o", 4294966785U); - CHECK(!strcmp(buffer, " 037777777001")); - - test::sprintf_(buffer, "%#20x", 305441741); - CHECK(!strcmp(buffer, " 0x1234abcd")); - - test::sprintf_(buffer, "%#20x", 3989525555U); - CHECK(!strcmp(buffer, " 0xedcb5433")); - - test::sprintf_(buffer, "%#20X", 305441741); - CHECK(!strcmp(buffer, " 0X1234ABCD")); - - test::sprintf_(buffer, "%#20X", 3989525555U); - CHECK(!strcmp(buffer, " 0XEDCB5433")); + PRINTING_CHECK(" 0777", ==, test::sprintf_, buffer, "%#20o", 511); + PRINTING_CHECK(" 037777777001", ==, test::sprintf_, buffer, "%#20o", 4294966785U); + PRINTING_CHECK(" 0x1234abcd", ==, test::sprintf_, buffer, "%#20x", 305441741); + PRINTING_CHECK(" 0xedcb5433", ==, test::sprintf_, buffer, "%#20x", 3989525555U); + PRINTING_CHECK(" 0X1234ABCD", ==, test::sprintf_, buffer, "%#20X", 305441741); + PRINTING_CHECK(" 0XEDCB5433", ==, test::sprintf_, buffer, "%#20X", 3989525555U); } TEST_CASE("padding 20.5", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%20.5d", 1024); - CHECK(!strcmp(buffer, " 01024")); - - test::sprintf_(buffer, "%20.5d", -1024); - CHECK(!strcmp(buffer, " -01024")); - - test::sprintf_(buffer, "%20.5i", 1024); - CHECK(!strcmp(buffer, " 01024")); - - test::sprintf_(buffer, "%20.5i", -1024); - CHECK(!strcmp(buffer, " -01024")); - - test::sprintf_(buffer, "%20.5u", 1024); - CHECK(!strcmp(buffer, " 01024")); - - test::sprintf_(buffer, "%20.5u", 4294966272U); - CHECK(!strcmp(buffer, " 4294966272")); - - test::sprintf_(buffer, "%20.5o", 511); - CHECK(!strcmp(buffer, " 00777")); - - test::sprintf_(buffer, "%20.5o", 4294966785U); - CHECK(!strcmp(buffer, " 37777777001")); - - test::sprintf_(buffer, "%20.5x", 305441741); - CHECK(!strcmp(buffer, " 1234abcd")); - - test::sprintf_(buffer, "%20.10x", 3989525555U); - CHECK(!strcmp(buffer, " 00edcb5433")); - - test::sprintf_(buffer, "%20.5X", 305441741); - CHECK(!strcmp(buffer, " 1234ABCD")); - - test::sprintf_(buffer, "%20.10X", 3989525555U); - CHECK(!strcmp(buffer, " 00EDCB5433")); + PRINTING_CHECK(" 01024", ==, test::sprintf_, buffer, "%20.5d", 1024); + PRINTING_CHECK(" -01024", ==, test::sprintf_, buffer, "%20.5d", -1024); + PRINTING_CHECK(" 01024", ==, test::sprintf_, buffer, "%20.5i", 1024); + PRINTING_CHECK(" -01024", ==, test::sprintf_, buffer, "%20.5i", -1024); + PRINTING_CHECK(" 01024", ==, test::sprintf_, buffer, "%20.5u", 1024); + PRINTING_CHECK(" 4294966272", ==, test::sprintf_, buffer, "%20.5u", 4294966272U); + PRINTING_CHECK(" 00777", ==, test::sprintf_, buffer, "%20.5o", 511); + PRINTING_CHECK(" 37777777001", ==, test::sprintf_, buffer, "%20.5o", 4294966785U); + PRINTING_CHECK(" 1234abcd", ==, test::sprintf_, buffer, "%20.5x", 305441741); + PRINTING_CHECK(" 00edcb5433", ==, test::sprintf_, buffer, "%20.10x", 3989525555U); + PRINTING_CHECK(" 1234ABCD", ==, test::sprintf_, buffer, "%20.5X", 305441741); + PRINTING_CHECK(" 00EDCB5433", ==, test::sprintf_, buffer, "%20.10X", 3989525555U); } @@ -1068,30 +619,16 @@ TEST_CASE("padding neg numbers", "[]" ) { char buffer[100]; // space padding - test::sprintf_(buffer, "% 1d", -5); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "% 2d", -5); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "% 3d", -5); - CHECK(!strcmp(buffer, " -5")); - - test::sprintf_(buffer, "% 4d", -5); - CHECK(!strcmp(buffer, " -5")); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "% 1d", -5); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "% 2d", -5); + PRINTING_CHECK(" -5", ==, test::sprintf_, buffer, "% 3d", -5); + PRINTING_CHECK(" -5", ==, test::sprintf_, buffer, "% 4d", -5); // zero padding - test::sprintf_(buffer, "%01d", -5); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "%02d", -5); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "%03d", -5); - CHECK(!strcmp(buffer, "-05")); - - test::sprintf_(buffer, "%04d", -5); - CHECK(!strcmp(buffer, "-005")); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "%01d", -5); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "%02d", -5); + PRINTING_CHECK("-05", ==, test::sprintf_, buffer, "%03d", -5); + PRINTING_CHECK("-005", ==, test::sprintf_, buffer, "%04d", -5); } @@ -1099,143 +636,66 @@ TEST_CASE("float padding neg numbers", "[]" ) { char buffer[100]; // space padding - test::sprintf_(buffer, "% 3.1f", -5.); - CHECK(!strcmp(buffer, "-5.0")); - - test::sprintf_(buffer, "% 4.1f", -5.); - CHECK(!strcmp(buffer, "-5.0")); - - test::sprintf_(buffer, "% 5.1f", -5.); - CHECK(!strcmp(buffer, " -5.0")); + PRINTING_CHECK("-5.0", ==, test::sprintf_, buffer, "% 3.1f", -5.); + PRINTING_CHECK("-5.0", ==, test::sprintf_, buffer, "% 4.1f", -5.); + PRINTING_CHECK(" -5.0", ==, test::sprintf_, buffer, "% 5.1f", -5.); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - test::sprintf_(buffer, "% 6.1g", -5.); - CHECK(!strcmp(buffer, " -5")); - - test::sprintf_(buffer, "% 6.1e", -5.); - CHECK(!strcmp(buffer, "-5.0e+00")); - - test::sprintf_(buffer, "% 10.1e", -5.); - CHECK(!strcmp(buffer, " -5.0e+00")); + PRINTING_CHECK(" -5", ==, test::sprintf_, buffer, "% 6.1g", -5.); + PRINTING_CHECK("-5.0e+00", ==, test::sprintf_, buffer, "% 6.1e", -5.); + PRINTING_CHECK(" -5.0e+00", ==, test::sprintf_, buffer, "% 10.1e", -5.); #endif // zero padding - test::sprintf_(buffer, "%03.1f", -5.); - CHECK(!strcmp(buffer, "-5.0")); - - test::sprintf_(buffer, "%04.1f", -5.); - CHECK(!strcmp(buffer, "-5.0")); - - test::sprintf_(buffer, "%05.1f", -5.); - CHECK(!strcmp(buffer, "-05.0")); + PRINTING_CHECK("-5.0", ==, test::sprintf_, buffer, "%03.1f", -5.); + PRINTING_CHECK("-5.0", ==, test::sprintf_, buffer, "%04.1f", -5.); + PRINTING_CHECK("-05.0", ==, test::sprintf_, buffer, "%05.1f", -5.); // zero padding no decimal point - test::sprintf_(buffer, "%01.0f", -5.); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "%02.0f", -5.); - CHECK(!strcmp(buffer, "-5")); - - test::sprintf_(buffer, "%03.0f", -5.); - CHECK(!strcmp(buffer, "-05")); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "%01.0f", -5.); + PRINTING_CHECK("-5", ==, test::sprintf_, buffer, "%02.0f", -5.); + PRINTING_CHECK("-05", ==, test::sprintf_, buffer, "%03.0f", -5.); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - test::sprintf_(buffer, "%010.1e", -5.); - CHECK(!strcmp(buffer, "-005.0e+00")); - - test::sprintf_(buffer, "%07.0E", -5.); - CHECK(!strcmp(buffer, "-05E+00")); - - test::sprintf_(buffer, "%03.0g", -5.); - CHECK(!strcmp(buffer, "-05")); + PRINTING_CHECK("-005.0e+00", ==, test::sprintf_, buffer, "%010.1e", -5.); + PRINTING_CHECK("-05E+00", ==, test::sprintf_, buffer, "%07.0E", -5.); + PRINTING_CHECK("-05", ==, test::sprintf_, buffer, "%03.0g", -5.); #endif } TEST_CASE("length", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%.0s", "Hello testing"); - CHECK(!strcmp(buffer, "")); - - test::sprintf_(buffer, "%20.0s", "Hello testing"); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%.s", "Hello testing"); - CHECK(!strcmp(buffer, "")); - - test::sprintf_(buffer, "%20.s", "Hello testing"); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.0d", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20.0d", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%20.d", 0); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.0i", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20.i", -1024); - CHECK(!strcmp(buffer, " -1024")); - - test::sprintf_(buffer, "%20.i", 0); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.u", 1024); - CHECK(!strcmp(buffer, " 1024")); - - test::sprintf_(buffer, "%20.0u", 4294966272U); - CHECK(!strcmp(buffer, " 4294966272")); - - test::sprintf_(buffer, "%20.u", 0U); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.o", 511); - CHECK(!strcmp(buffer, " 777")); - - test::sprintf_(buffer, "%20.0o", 4294966785U); - CHECK(!strcmp(buffer, " 37777777001")); - - test::sprintf_(buffer, "%20.o", 0U); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.x", 305441741); - CHECK(!strcmp(buffer, " 1234abcd")); - - test::sprintf_(buffer, "%50.x", 305441741); - CHECK(!strcmp(buffer, " 1234abcd")); - - test::sprintf_(buffer, "%50.x%10.u", 305441741, 12345); - CHECK(!strcmp(buffer, " 1234abcd 12345")); - - test::sprintf_(buffer, "%20.0x", 3989525555U); - CHECK(!strcmp(buffer, " edcb5433")); - - test::sprintf_(buffer, "%20.x", 0U); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%20.X", 305441741); - CHECK(!strcmp(buffer, " 1234ABCD")); - - test::sprintf_(buffer, "%20.0X", 3989525555U); - CHECK(!strcmp(buffer, " EDCB5433")); - - test::sprintf_(buffer, "%20.X", 0U); - CHECK(!strcmp(buffer, " ")); + PRINTING_CHECK("", ==, test::sprintf_, buffer, "%.0s", "Hello testing"); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.0s", "Hello testing"); + PRINTING_CHECK("", ==, test::sprintf_, buffer, "%.s", "Hello testing"); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.s", "Hello testing"); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20.0d", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%20.0d", -1024); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.d", 0); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20.0i", 1024); + PRINTING_CHECK(" -1024", ==, test::sprintf_, buffer, "%20.i", -1024); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.i", 0); + PRINTING_CHECK(" 1024", ==, test::sprintf_, buffer, "%20.u", 1024); + PRINTING_CHECK(" 4294966272", ==, test::sprintf_, buffer, "%20.0u", 4294966272U); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.u", 0U); + PRINTING_CHECK(" 777", ==, test::sprintf_, buffer, "%20.o", 511); + PRINTING_CHECK(" 37777777001", ==, test::sprintf_, buffer, "%20.0o", 4294966785U); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.o", 0U); + PRINTING_CHECK(" 1234abcd", ==, test::sprintf_, buffer, "%20.x", 305441741); + PRINTING_CHECK(" 1234abcd", ==, test::sprintf_, buffer, "%50.x", 305441741); + PRINTING_CHECK(" 1234abcd 12345", ==, test::sprintf_, buffer, "%50.x%10.u", 305441741, 12345); + PRINTING_CHECK(" edcb5433", ==, test::sprintf_, buffer, "%20.0x", 3989525555U); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.x", 0U); + PRINTING_CHECK(" 1234ABCD", ==, test::sprintf_, buffer, "%20.X", 305441741); + PRINTING_CHECK(" EDCB5433", ==, test::sprintf_, buffer, "%20.0X", 3989525555U); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%20.X", 0U); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("length - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%02.0u", 0U); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%02.0d", 0); - CHECK(!strcmp(buffer, " ")); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%02.0u", 0U); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "%02.0d", 0); } #endif @@ -1244,29 +704,19 @@ TEST_CASE("float", "[]" ) { char buffer[100]; // test special-case floats using math.h macros - test::sprintf_(buffer, "%8f", (double) NAN); - CHECK(!strcmp(buffer, " nan")); - - test::sprintf_(buffer, "%8f", (double) INFINITY); - CHECK(!strcmp(buffer, " inf")); - - test::sprintf_(buffer, "%-8f", (double) -INFINITY); - CHECK(!strcmp(buffer, "-inf ")); + PRINTING_CHECK(" nan", ==, test::sprintf_, buffer, "%8f", (double) NAN); + PRINTING_CHECK(" inf", ==, test::sprintf_, buffer, "%8f", (double) INFINITY); + PRINTING_CHECK("-inf ", ==, test::sprintf_, buffer, "%-8f", (double) -INFINITY); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - test::sprintf_(buffer, "%+8e", (double) INFINITY); - CHECK(!strcmp(buffer, " +inf")); + PRINTING_CHECK(" +inf", ==, test::sprintf_, buffer, "%+8e", (double) INFINITY); #endif - - test::sprintf_(buffer, "%.4f", 3.1415354); - CHECK(!strcmp(buffer, "3.1415")); - - test::sprintf_(buffer, "%.3f", 30343.1415354); - CHECK(!strcmp(buffer, "30343.142")); + PRINTING_CHECK("3.1415", ==, test::sprintf_, buffer, "%.4f", 3.1415354); + PRINTING_CHECK("30343.142", ==, test::sprintf_, buffer, "%.3f", 30343.1415354); // switch from decimal to exponential representation // - test::sprintf_(buffer, "%.0f", (double) ((int64_t)1 * 1000 ) ); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.0f", (double) ((int64_t)1 * 1000 ) ); if (PRINTF_FLOAT_NOTATION_THRESHOLD < 10e+2) { CHECK(!strcmp(buffer, "10e+2")); } @@ -1274,7 +724,7 @@ TEST_CASE("float", "[]" ) { CHECK(!strcmp(buffer, "1000")); } - test::sprintf_(buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 ) ); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 ) ); if (PRINTF_FLOAT_NOTATION_THRESHOLD < 10e+5) { CHECK(!strcmp(buffer, "10e+5")); } @@ -1282,7 +732,7 @@ TEST_CASE("float", "[]" ) { CHECK(!strcmp(buffer, "1000000")); } - test::sprintf_(buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 ) ); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 ) ); if (PRINTF_FLOAT_NOTATION_THRESHOLD < 10e+8) { CHECK(!strcmp(buffer, "10e+8")); } @@ -1290,7 +740,7 @@ TEST_CASE("float", "[]" ) { CHECK(!strcmp(buffer, "1000000000")); } - test::sprintf_(buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 * 1000) ); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 * 1000) ); if (PRINTF_FLOAT_NOTATION_THRESHOLD < 10e+11) { CHECK(!strcmp(buffer, "10e+11")); } @@ -1298,124 +748,59 @@ TEST_CASE("float", "[]" ) { CHECK(!strcmp(buffer, "1000000000000")); } - test::sprintf_(buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 * 1000 * 1000) ); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.0f", (double) ((int64_t)1 * 1000 * 1000 * 1000 * 1000 * 1000) ); if (PRINTF_FLOAT_NOTATION_THRESHOLD < 10e+14) { CHECK(!strcmp(buffer, "10e+14")); } else { CHECK(!strcmp(buffer, "1000000000000000")); } - - test::sprintf_(buffer, "%.0f", 34.1415354); - CHECK(!strcmp(buffer, "34")); - - test::sprintf_(buffer, "%.0f", 1.3); - CHECK(!strcmp(buffer, "1")); - - test::sprintf_(buffer, "%.0f", 1.55); - CHECK(!strcmp(buffer, "2")); - - test::sprintf_(buffer, "%.1f", 1.64); - CHECK(!strcmp(buffer, "1.6")); - - test::sprintf_(buffer, "%.2f", 42.8952); - CHECK(!strcmp(buffer, "42.90")); - - test::sprintf_(buffer, "%.9f", 42.8952); - CHECK(!strcmp(buffer, "42.895200000")); - - test::sprintf_(buffer, "%.10f", 42.895223); - CHECK(!strcmp(buffer, "42.8952230000")); + PRINTING_CHECK("34", ==, test::sprintf_, buffer, "%.0f", 34.1415354); + PRINTING_CHECK("1", ==, test::sprintf_, buffer, "%.0f", 1.3); + PRINTING_CHECK("2", ==, test::sprintf_, buffer, "%.0f", 1.55); + PRINTING_CHECK("1.6", ==, test::sprintf_, buffer, "%.1f", 1.64); + PRINTING_CHECK("42.90", ==, test::sprintf_, buffer, "%.2f", 42.8952); + PRINTING_CHECK("42.895200000", ==, test::sprintf_, buffer, "%.9f", 42.8952); + PRINTING_CHECK("42.8952230000", ==, test::sprintf_, buffer, "%.10f", 42.895223); // this testcase checks, that the precision is truncated to 9 digits. // a perfect working float should return the whole number - test::sprintf_(buffer, "%.12f", 42.89522312345678); - CHECK(!strcmp(buffer, "42.895223123000")); + PRINTING_CHECK("42.895223123000", ==, test::sprintf_, buffer, "%.12f", 42.89522312345678); // this testcase checks, that the precision is truncated AND rounded to 9 digits. // a perfect working float should return the whole number - test::sprintf_(buffer, "%.12f", 42.89522387654321); - CHECK(!strcmp(buffer, "42.895223877000")); - - test::sprintf_(buffer, "%6.2f", 42.8952); - CHECK(!strcmp(buffer, " 42.90")); - - test::sprintf_(buffer, "%+6.2f", 42.8952); - CHECK(!strcmp(buffer, "+42.90")); - - test::sprintf_(buffer, "%+5.1f", 42.9252); - CHECK(!strcmp(buffer, "+42.9")); - - test::sprintf_(buffer, "%f", 42.5); - CHECK(!strcmp(buffer, "42.500000")); - - test::sprintf_(buffer, "%.1f", 42.5); - CHECK(!strcmp(buffer, "42.5")); - - test::sprintf_(buffer, "%f", 42167.0); - CHECK(!strcmp(buffer, "42167.000000")); - - test::sprintf_(buffer, "%.9f", -12345.987654321); - CHECK(!strcmp(buffer, "-12345.987654321")); - - test::sprintf_(buffer, "%.1f", 3.999); - CHECK(!strcmp(buffer, "4.0")); - - test::sprintf_(buffer, "%.0f", 3.5); - CHECK(!strcmp(buffer, "4")); - - test::sprintf_(buffer, "%.0f", 4.5); - CHECK(!strcmp(buffer, "4")); - - test::sprintf_(buffer, "%.0f", 3.49); - CHECK(!strcmp(buffer, "3")); - - test::sprintf_(buffer, "%.1f", 3.49); - CHECK(!strcmp(buffer, "3.5")); - - test::sprintf_(buffer, "a%-5.1f", 0.5); - CHECK(!strcmp(buffer, "a0.5 ")); - - test::sprintf_(buffer, "a%-5.1fend", 0.5); - CHECK(!strcmp(buffer, "a0.5 end")); + PRINTING_CHECK("42.895223877000", ==, test::sprintf_, buffer, "%.12f", 42.89522387654321); + PRINTING_CHECK(" 42.90", ==, test::sprintf_, buffer, "%6.2f", 42.8952); + PRINTING_CHECK("+42.90", ==, test::sprintf_, buffer, "%+6.2f", 42.8952); + PRINTING_CHECK("+42.9", ==, test::sprintf_, buffer, "%+5.1f", 42.9252); + PRINTING_CHECK("42.500000", ==, test::sprintf_, buffer, "%f", 42.5); + PRINTING_CHECK("42.5", ==, test::sprintf_, buffer, "%.1f", 42.5); + PRINTING_CHECK("42167.000000", ==, test::sprintf_, buffer, "%f", 42167.0); + PRINTING_CHECK("-12345.987654321", ==, test::sprintf_, buffer, "%.9f", -12345.987654321); + PRINTING_CHECK("4.0", ==, test::sprintf_, buffer, "%.1f", 3.999); + PRINTING_CHECK("4", ==, test::sprintf_, buffer, "%.0f", 3.5); + PRINTING_CHECK("4", ==, test::sprintf_, buffer, "%.0f", 4.5); + PRINTING_CHECK("3", ==, test::sprintf_, buffer, "%.0f", 3.49); + PRINTING_CHECK("3.5", ==, test::sprintf_, buffer, "%.1f", 3.49); + PRINTING_CHECK("a0.5 ", ==, test::sprintf_, buffer, "a%-5.1f", 0.5); + PRINTING_CHECK("a0.5 end", ==, test::sprintf_, buffer, "a%-5.1fend", 0.5); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - test::sprintf_(buffer, "%.4g", 1.0); - CHECK(!strcmp(buffer, "1")); - - test::sprintf_(buffer, "%G", 12345.678); - CHECK(!strcmp(buffer, "12345.7")); - - test::sprintf_(buffer, "%.7G", 12345.678); - CHECK(!strcmp(buffer, "12345.68")); - - test::sprintf_(buffer, "%.5G", 123456789.); - CHECK(!strcmp(buffer, "1.2346E+08")); - - test::sprintf_(buffer, "%.6G", 12345.); - CHECK(!strcmp(buffer, "12345.0")); - - test::sprintf_(buffer, "%+12.4g", 123456789.); - CHECK(!strcmp(buffer, " +1.235e+08")); - - test::sprintf_(buffer, "%.2G", 0.001234); - CHECK(!strcmp(buffer, "0.0012")); - - test::sprintf_(buffer, "%+10.4G", 0.001234); - CHECK(!strcmp(buffer, " +0.001234")); - - test::sprintf_(buffer, "%+012.4g", 0.00001234); - CHECK(!strcmp(buffer, "+001.234e-05")); - - test::sprintf_(buffer, "%.3g", -1.2345e-308); - CHECK(!strcmp(buffer, "-1.23e-308")); - - test::sprintf_(buffer, "%+.3E", 1.23e+308); - CHECK(!strcmp(buffer, "+1.230E+308")); + PRINTING_CHECK("1", ==, test::sprintf_, buffer, "%.4g", 1.0); + PRINTING_CHECK("12345.7", ==, test::sprintf_, buffer, "%G", 12345.678); + PRINTING_CHECK("12345.68", ==, test::sprintf_, buffer, "%.7G", 12345.678); + PRINTING_CHECK("1.2346E+08", ==, test::sprintf_, buffer, "%.5G", 123456789.); + PRINTING_CHECK("12345.0", ==, test::sprintf_, buffer, "%.6G", 12345.); + PRINTING_CHECK(" +1.235e+08", ==, test::sprintf_, buffer, "%+12.4g", 123456789.); + PRINTING_CHECK("0.0012", ==, test::sprintf_, buffer, "%.2G", 0.001234); + PRINTING_CHECK(" +0.001234", ==, test::sprintf_, buffer, "%+10.4G", 0.001234); + PRINTING_CHECK("+001.234e-05", ==, test::sprintf_, buffer, "%+012.4g", 0.00001234); + PRINTING_CHECK("-1.23e-308", ==, test::sprintf_, buffer, "%.3g", -1.2345e-308); + PRINTING_CHECK("+1.230E+308", ==, test::sprintf_, buffer, "%+.3E", 1.23e+308); #endif // out of range for float: should switch to exp notation if supported, else empty - test::sprintf_(buffer, "%.1f", 1E20); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%.1f", 1E20); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS CHECK(!strcmp(buffer, "1.0e+20")); #else @@ -1451,117 +836,51 @@ TEST_CASE("float", "[]" ) { TEST_CASE("types", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%i", 0); - CHECK(!strcmp(buffer, "0")); - - test::sprintf_(buffer, "%i", 1234); - CHECK(!strcmp(buffer, "1234")); - - test::sprintf_(buffer, "%i", 32767); - CHECK(!strcmp(buffer, "32767")); - - test::sprintf_(buffer, "%i", -32767); - CHECK(!strcmp(buffer, "-32767")); - - test::sprintf_(buffer, "%li", 30L); - CHECK(!strcmp(buffer, "30")); - - test::sprintf_(buffer, "%li", -2147483647L); - CHECK(!strcmp(buffer, "-2147483647")); - - test::sprintf_(buffer, "%li", 2147483647L); - CHECK(!strcmp(buffer, "2147483647")); - - test::sprintf_(buffer, "%lli", 30LL); - CHECK(!strcmp(buffer, "30")); - - test::sprintf_(buffer, "%lli", -9223372036854775807LL); - CHECK(!strcmp(buffer, "-9223372036854775807")); - - test::sprintf_(buffer, "%lli", 9223372036854775807LL); - CHECK(!strcmp(buffer, "9223372036854775807")); - - test::sprintf_(buffer, "%lu", 100000L); - CHECK(!strcmp(buffer, "100000")); - - test::sprintf_(buffer, "%lu", 0xFFFFFFFFL); - CHECK(!strcmp(buffer, "4294967295")); - - test::sprintf_(buffer, "%llu", 281474976710656LLU); - CHECK(!strcmp(buffer, "281474976710656")); - - test::sprintf_(buffer, "%llu", 18446744073709551615LLU); - CHECK(!strcmp(buffer, "18446744073709551615")); - - test::sprintf_(buffer, "%zu", (size_t)2147483647UL); - CHECK(!strcmp(buffer, "2147483647")); - - test::sprintf_(buffer, "%zd", (size_t)2147483647UL); - CHECK(!strcmp(buffer, "2147483647")); - - test::sprintf_(buffer, "%zi", (ssize_t)-2147483647L); - CHECK(!strcmp(buffer, "-2147483647")); - - test::sprintf_(buffer, "%o", 60000); - CHECK(!strcmp(buffer, "165140")); - - test::sprintf_(buffer, "%lo", 12345678L); - CHECK(!strcmp(buffer, "57060516")); - - test::sprintf_(buffer, "%lx", 0x12345678L); - CHECK(!strcmp(buffer, "12345678")); - - test::sprintf_(buffer, "%llx", 0x1234567891234567LLU); - CHECK(!strcmp(buffer, "1234567891234567")); - - test::sprintf_(buffer, "%lx", 0xabcdefabL); - CHECK(!strcmp(buffer, "abcdefab")); - - test::sprintf_(buffer, "%lX", 0xabcdefabL); - CHECK(!strcmp(buffer, "ABCDEFAB")); - - test::sprintf_(buffer, "%c", 'v'); - CHECK(!strcmp(buffer, "v")); - - test::sprintf_(buffer, "%cv", 'w'); - CHECK(!strcmp(buffer, "wv")); - - test::sprintf_(buffer, "%s", "A Test"); - CHECK(!strcmp(buffer, "A Test")); - - test::sprintf_(buffer, "%hhu", (unsigned char) 0xFFU); - CHECK(!strcmp(buffer, "255")); - - test::sprintf_(buffer, "%hu", (unsigned short) 0x1234u); - CHECK(!strcmp(buffer, "4660")); - - test::sprintf_(buffer, "%s%hhi %hu", "Test", (char) 100, (unsigned short) 0xFFFF); - CHECK(!strcmp(buffer, "Test100 65535")); - - test::sprintf_(buffer, "%tx", &buffer[10] - &buffer[0]); - CHECK(!strcmp(buffer, "a")); - - test::sprintf_(buffer, "%ji", (intmax_t)-2147483647L); - CHECK(!strcmp(buffer, "-2147483647")); + PRINTING_CHECK("0", ==, test::sprintf_, buffer, "%i", 0); + PRINTING_CHECK("1234", ==, test::sprintf_, buffer, "%i", 1234); + PRINTING_CHECK("32767", ==, test::sprintf_, buffer, "%i", 32767); + PRINTING_CHECK("-32767", ==, test::sprintf_, buffer, "%i", -32767); + PRINTING_CHECK("30", ==, test::sprintf_, buffer, "%li", 30L); + PRINTING_CHECK("-2147483647", ==, test::sprintf_, buffer, "%li", -2147483647L); + PRINTING_CHECK("2147483647", ==, test::sprintf_, buffer, "%li", 2147483647L); + PRINTING_CHECK("30", ==, test::sprintf_, buffer, "%lli", 30LL); + PRINTING_CHECK("-9223372036854775807", ==, test::sprintf_, buffer, "%lli", -9223372036854775807LL); + PRINTING_CHECK("9223372036854775807", ==, test::sprintf_, buffer, "%lli", 9223372036854775807LL); + PRINTING_CHECK("100000", ==, test::sprintf_, buffer, "%lu", 100000L); + PRINTING_CHECK("4294967295", ==, test::sprintf_, buffer, "%lu", 0xFFFFFFFFL); + PRINTING_CHECK("281474976710656", ==, test::sprintf_, buffer, "%llu", 281474976710656LLU); + PRINTING_CHECK("18446744073709551615", ==, test::sprintf_, buffer, "%llu", 18446744073709551615LLU); + PRINTING_CHECK("2147483647", ==, test::sprintf_, buffer, "%zu", (size_t)2147483647UL); + PRINTING_CHECK("2147483647", ==, test::sprintf_, buffer, "%zd", (size_t)2147483647UL); + PRINTING_CHECK("-2147483647", ==, test::sprintf_, buffer, "%zi", (ssize_t)-2147483647L); + PRINTING_CHECK("165140", ==, test::sprintf_, buffer, "%o", 60000); + PRINTING_CHECK("57060516", ==, test::sprintf_, buffer, "%lo", 12345678L); + PRINTING_CHECK("12345678", ==, test::sprintf_, buffer, "%lx", 0x12345678L); + PRINTING_CHECK("1234567891234567", ==, test::sprintf_, buffer, "%llx", 0x1234567891234567LLU); + PRINTING_CHECK("abcdefab", ==, test::sprintf_, buffer, "%lx", 0xabcdefabL); + PRINTING_CHECK("ABCDEFAB", ==, test::sprintf_, buffer, "%lX", 0xabcdefabL); + PRINTING_CHECK("v", ==, test::sprintf_, buffer, "%c", 'v'); + PRINTING_CHECK("wv", ==, test::sprintf_, buffer, "%cv", 'w'); + PRINTING_CHECK("A Test", ==, test::sprintf_, buffer, "%s", "A Test"); + PRINTING_CHECK("255", ==, test::sprintf_, buffer, "%hhu", (unsigned char) 0xFFU); + PRINTING_CHECK("4660", ==, test::sprintf_, buffer, "%hu", (unsigned short) 0x1234u); + PRINTING_CHECK("Test100 65535", ==, test::sprintf_, buffer, "%s%hhi %hu", "Test", (char) 100, (unsigned short) 0xFFFF); + PRINTING_CHECK("a", ==, test::sprintf_, buffer, "%tx", &buffer[10] - &buffer[0]); + PRINTING_CHECK("-2147483647", ==, test::sprintf_, buffer, "%ji", (intmax_t)-2147483647L); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("types - non-standard format", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%b", 60000); - CHECK(!strcmp(buffer, "1110101001100000")); - - test::sprintf_(buffer, "%lb", 12345678L); - CHECK(!strcmp(buffer, "101111000110000101001110")); + PRINTING_CHECK("1110101001100000", ==, test::sprintf_, buffer, "%b", 60000); + PRINTING_CHECK("101111000110000101001110", ==, test::sprintf_, buffer, "%lb", 12345678L); } #endif TEST_CASE("pointer", "[]" ) { char buffer[100]; - test::sprintf_(buffer, "%p", (void*)0x1234U); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%p", (void*)0x1234U); if (sizeof(void*) == 4U) { CHECK(!strcmp(buffer, "0x00001234")); } @@ -1569,7 +888,7 @@ TEST_CASE("pointer", "[]" ) { CHECK(!strcmp(buffer, "0x0000000000001234")); } - test::sprintf_(buffer, "%p", (void*)0x12345678U); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%p", (void*)0x12345678U); if (sizeof(void*) == 4U) { CHECK(!strcmp(buffer, "0x12345678")); } @@ -1577,7 +896,7 @@ TEST_CASE("pointer", "[]" ) { CHECK(!strcmp(buffer, "0x0000000012345678")); } - test::sprintf_(buffer, "%p-%p", (void*)0x12345678U, (void*)0x7EDCBA98U); + CAPTURE_AND_PRINT(test::sprintf_, buffer, "%p-%p", (void*)0x12345678U, (void*)0x7EDCBA98U); if (sizeof(void*) == 4U) { CHECK(!strcmp(buffer, "0x12345678-0x7edcba98")); } @@ -1593,57 +912,36 @@ TEST_CASE("pointer", "[]" ) { test::sprintf_(buffer, "%p", (void*)(uintptr_t)0xFFFFFFFFU); CHECK(!strcmp(buffer, "0xffffffff")); } - - test::sprintf_(buffer, "%p", NULL); - CHECK(!strcmp(buffer, "(nil)")); + PRINTING_CHECK("(nil)", ==, test::sprintf_, buffer, "%p", NULL); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("unknown flag (non-standard format)", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%kmarco", 42, 37); - CHECK(!strcmp(buffer, "kmarco")); + PRINTING_CHECK("kmarco", ==, test::sprintf_, buffer, "%kmarco", 42, 37); } #endif TEST_CASE("string length", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%.4s", "This is a test"); - CHECK(!strcmp(buffer, "This")); - - test::sprintf_(buffer, "%.4s", "test"); - CHECK(!strcmp(buffer, "test")); - - test::sprintf_(buffer, "%.7s", "123"); - CHECK(!strcmp(buffer, "123")); - - test::sprintf_(buffer, "%.7s", ""); - CHECK(!strcmp(buffer, "")); - - test::sprintf_(buffer, "%.4s%.2s", "123456", "abcdef"); - CHECK(!strcmp(buffer, "1234ab")); - - test::sprintf_(buffer, "%.4.2s", "123456"); - CHECK(!strcmp(buffer, ".2s")); - - test::sprintf_(buffer, "%.*s", 3, "123456"); - CHECK(!strcmp(buffer, "123")); + PRINTING_CHECK("This", ==, test::sprintf_, buffer, "%.4s", "This is a test"); + PRINTING_CHECK("test", ==, test::sprintf_, buffer, "%.4s", "test"); + PRINTING_CHECK("123", ==, test::sprintf_, buffer, "%.7s", "123"); + PRINTING_CHECK("", ==, test::sprintf_, buffer, "%.7s", ""); + PRINTING_CHECK("1234ab", ==, test::sprintf_, buffer, "%.4s%.2s", "123456", "abcdef"); + PRINTING_CHECK(".2s", ==, test::sprintf_, buffer, "%.4.2s", "123456"); + PRINTING_CHECK("123", ==, test::sprintf_, buffer, "%.*s", 3, "123456"); DISABLE_WARNING_PUSH DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW - test::sprintf_(buffer, "%.*s", 3, NULL); + PRINTING_CHECK("(null)", ==, test::sprintf_, buffer, "%.*s", 3, NULL); DISABLE_WARNING_POP - CHECK(!strcmp(buffer, "(null)")); } #ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS TEST_CASE("string length (non-standard format)", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%.4.2s", "123456"); - CHECK(!strcmp(buffer, ".2s")); + PRINTING_CHECK(".2s", ==, test::sprintf_, buffer, "%.4.2s", "123456"); } #endif @@ -1665,15 +963,13 @@ TEST_CASE("buffer length", "[]" ) { buffer[0] = (char)0xCC; test::snprintf_(buffer, 1, "%s", "Test"); CHECK(buffer[0] == '\0'); - - test::snprintf_(buffer, 2, "%s", "Hello"); - CHECK(!strcmp(buffer, "H")); + PRINTING_CHECK("H", ==, test::snprintf_, buffer, 2, "%s", "Hello"); DISABLE_WARNING_PUSH DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW test::snprintf_(buffer, 2, "%s", NULL); -DISABLE_WARNING_POP CHECK(!strcmp(buffer, "(")); +DISABLE_WARNING_POP } @@ -1714,34 +1010,17 @@ DISABLE_WARNING_POP TEST_CASE("misc", "[]" ) { char buffer[100]; - - test::sprintf_(buffer, "%u%u%ctest%d %s", 5, 3000, 'a', -20, "bit"); - CHECK(!strcmp(buffer, "53000atest-20 bit")); - - test::sprintf_(buffer, "%.*f", 2, 0.33333333); - CHECK(!strcmp(buffer, "0.33")); - - test::sprintf_(buffer, "%.*d", -1, 1); - CHECK(!strcmp(buffer, "1")); - - test::sprintf_(buffer, "%.3s", "foobar"); - CHECK(!strcmp(buffer, "foo")); - - test::sprintf_(buffer, "% .0d", 0); - CHECK(!strcmp(buffer, " ")); - - test::sprintf_(buffer, "%10.5d", 4); - CHECK(!strcmp(buffer, " 00004")); - - test::sprintf_(buffer, "%*sx", -3, "hi"); - CHECK(!strcmp(buffer, "hi x")); + PRINTING_CHECK("53000atest-20 bit", ==, test::sprintf_, buffer, "%u%u%ctest%d %s", 5, 3000, 'a', -20, "bit"); + PRINTING_CHECK("0.33", ==, test::sprintf_, buffer, "%.*f", 2, 0.33333333); + PRINTING_CHECK("1", ==, test::sprintf_, buffer, "%.*d", -1, 1); + PRINTING_CHECK("foo", ==, test::sprintf_, buffer, "%.3s", "foobar"); + PRINTING_CHECK(" ", ==, test::sprintf_, buffer, "% .0d", 0); + PRINTING_CHECK(" 00004", ==, test::sprintf_, buffer, "%10.5d", 4); + PRINTING_CHECK("hi x", ==, test::sprintf_, buffer, "%*sx", -3, "hi"); #if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS - test::sprintf_(buffer, "%.*g", 2, 0.33333333); - CHECK(!strcmp(buffer, "0.33")); - - test::sprintf_(buffer, "%.*e", 2, 0.33333333); - CHECK(!strcmp(buffer, "3.33e-01")); + PRINTING_CHECK("0.33", ==, test::sprintf_, buffer, "%.*g", 2, 0.33333333); + PRINTING_CHECK("3.33e-01", ==, test::sprintf_, buffer, "%.*e", 2, 0.33333333); #endif }