From 3f444fe3e2d43a92373f391c4cbaaca7634750dc Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 31 Jul 2014 06:47:24 -0700 Subject: [PATCH] Fix tests on MSVC. --- test/printf-test.cc | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/printf-test.cc b/test/printf-test.cc index 1f6afdad..cc86a1da 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -46,7 +46,7 @@ std::string make_positional(fmt::StringRef format) { #define EXPECT_PRINTF(expected_output, format, arg) \ EXPECT_EQ(expected_output, fmt::sprintf(format, arg)) \ - << "format:" << format; \ + << "format: " << format; \ EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg)) TEST(PrintfTest, NoArgs) { @@ -273,9 +273,10 @@ TEST(PrintfTest, DynamicPrecision) { } } -#define EXPECT_STD_PRINTF(format, arg) { \ +#define EXPECT_STD_PRINTF(format, Type, arg) { \ char buffer[BUFFER_SIZE]; \ - safe_sprintf(buffer, fmt::StringRef(format).c_str(), arg); \ + Type conv_arg = static_cast(arg); \ + safe_sprintf(buffer, fmt::StringRef(format).c_str(), conv_arg); \ EXPECT_PRINTF(buffer, format, arg); \ } @@ -285,19 +286,19 @@ void TestLength(const char *length_spec) { const char types[] = {'d', 'i', 'u', 'o', 'x', 'X'}; for (int i = 0; i < sizeof(types); ++i) { std::string format = fmt::format("%{}{}", length_spec, types[i]); - //EXPECT_STD_PRINTF(format, 42); - EXPECT_STD_PRINTF(format, min); - EXPECT_STD_PRINTF(format, max); - EXPECT_STD_PRINTF(format, fmt::LongLong(min) - 1); - EXPECT_STD_PRINTF(format, fmt::LongLong(max) + 1); - EXPECT_STD_PRINTF(format, std::numeric_limits::min()); - EXPECT_STD_PRINTF(format, std::numeric_limits::max()); - EXPECT_STD_PRINTF(format, std::numeric_limits::min()); - EXPECT_STD_PRINTF(format, std::numeric_limits::max()); - EXPECT_STD_PRINTF(format, std::numeric_limits::min()); - EXPECT_STD_PRINTF(format, std::numeric_limits::max()); - EXPECT_STD_PRINTF(format, std::numeric_limits::min()); - EXPECT_STD_PRINTF(format, std::numeric_limits::max()); + EXPECT_STD_PRINTF(format, T, 42); + EXPECT_STD_PRINTF(format, T, min); + EXPECT_STD_PRINTF(format, T, max); + EXPECT_STD_PRINTF(format, T, fmt::LongLong(min) - 1); + EXPECT_STD_PRINTF(format, T, fmt::LongLong(max) + 1); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::min()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::max()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::min()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::max()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::min()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::max()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::min()); + EXPECT_STD_PRINTF(format, T, std::numeric_limits::max()); } } @@ -306,6 +307,8 @@ TEST(PrintfTest, Length) { TestLength("h"); TestLength("hh"); TestLength("hh"); + //TestLength("l"); + //TestLength("l"); // TODO: more tests }