From 5614295aa1d06db90426a1418b0eb89494405e05 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 12 Aug 2014 08:15:39 -0700 Subject: [PATCH] Test 'l' specifier. --- test/printf-test.cc | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/test/printf-test.cc b/test/printf-test.cc index 28dbe86c..fc4b6234 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -289,15 +289,29 @@ SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong); template void TestLength(const char *length_spec, U value) { + fmt::LongLong signed_value = value; + fmt::ULongLong unsigned_value = value; + // Apply integer promotion to the argument. + U max = std::numeric_limits::max(); + if (max <= std::numeric_limits::max()) { + signed_value = static_cast(value); + unsigned_value = static_cast(value); + } else if (max <= std::numeric_limits::max()) { + signed_value = static_cast(value); + unsigned_value = static_cast(value); + } + using fmt::internal::MakeUnsigned; + if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) { + signed_value = unsigned_value = + static_cast::Type>(value); + } else { + signed_value = static_cast::Type>(value); + unsigned_value = static_cast::Type>(value); + } std::ostringstream os; - // Use LongLong instead of T, because std::ostream prints signed char as - // a character, not a number. - os << static_cast( - static_cast::Type>(value)); + os << signed_value; EXPECT_PRINTF(os.str(), fmt::format("%{}d", length_spec), value); EXPECT_PRINTF(os.str(), fmt::format("%{}i", length_spec), value); - fmt::ULongLong unsigned_value = - static_cast::Type>(value); os.str(""); os << unsigned_value; EXPECT_PRINTF(os.str(), fmt::format("%{}u", length_spec), value); @@ -339,8 +353,8 @@ TEST(PrintfTest, Length) { TestLength("hh"); TestLength("h"); TestLength("h"); - //TestLength("l"); - //TestLength("l"); + TestLength("l"); + TestLength("l"); // TODO: more tests //EXPECT_EQ("-1", sprintf_int("%hhd", UCHAR_MAX)); //EXPECT_EQ("255", sprintf_int("%hhu", UCHAR_MAX));