From a7a18fac89b12681f23bdc5acf5607139d1f4994 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 14 Jul 2014 07:17:58 -0700 Subject: [PATCH] Fix util-test. --- test/util-test.cc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/util-test.cc b/test/util-test.cc index fbd2492f..a0012858 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -111,8 +111,10 @@ TEST(UtilTest, ArgInfo) { CHECK_ARG_INFO(DOUBLE, double_value, 4.2); CHECK_ARG_INFO(LONG_DOUBLE, long_double_value, 4.2); CHECK_ARG_INFO(CHAR, int_value, 'x'); - CHECK_ARG_INFO(STRING, string.value, "abc"); - CHECK_ARG_INFO(WSTRING, wstring.value, L"abc"); + const char STR[] = "abc"; + CHECK_ARG_INFO(STRING, string.value, STR); + const wchar_t WSTR[] = L"abc"; + CHECK_ARG_INFO(WSTRING, wstring.value, WSTR); int p = 0; CHECK_ARG_INFO(POINTER, pointer_value, &p); Arg arg = {Arg::CUSTOM}; @@ -133,7 +135,6 @@ TEST(UtilTest, ArgInfo) { #define EXPECT_ARGW(type_code, Type, value) \ EXPECT_ARG_(wchar_t, type_code, Type, value) - TEST(UtilTest, MakeArg) { // Test bool. EXPECT_ARG(INT, bool, true); @@ -242,6 +243,7 @@ struct Result { template Result(const T& value) : arg(fmt::internal::MakeArg(value)) {} + Result(const wchar_t *s) : arg(fmt::internal::MakeArg(s)) {} }; struct TestVisitor : fmt::internal::ArgVisitor { @@ -251,14 +253,22 @@ struct TestVisitor : fmt::internal::ArgVisitor { Result visit_ulong_long(fmt::ULongLong value) { return value; } Result visit_double(double value) { return value; } Result visit_long_double(long double value) { return value; } + Result visit_char(int value) { return static_cast(value); } + Result visit_string(fmt::internal::StringValue s) { return s.value; } + Result visit_wstring(fmt::internal::StringValue s) { return s.value; } }; -#define EXPECT_RESULT(type_code, value) { \ - Result result = TestVisitor().visit(MakeArg(value)); \ +#define EXPECT_RESULT_(Char, type_code, value) { \ + Result result = TestVisitor().visit(MakeArg(value)); \ EXPECT_EQ(Arg::type_code, result.arg.type); \ EXPECT_EQ(value, ArgInfo::get(result.arg)); \ } +#define EXPECT_RESULT(type_code, value) \ + EXPECT_RESULT_(char, type_code, value) +#define EXPECT_RESULTW(type_code, value) \ + EXPECT_RESULT_(wchar_t, type_code, value) + TEST(UtilTest, ArgVisitor) { using fmt::internal::MakeArg; EXPECT_RESULT(INT, 42); @@ -266,7 +276,11 @@ TEST(UtilTest, ArgVisitor) { EXPECT_RESULT(LONG_LONG, 42ll); EXPECT_RESULT(ULONG_LONG, 42ull); EXPECT_RESULT(DOUBLE, 4.2); - // TODO + EXPECT_RESULT(LONG_DOUBLE, 4.2l); + EXPECT_RESULT(CHAR, 'x'); + EXPECT_RESULT(STRING, "abc"); + EXPECT_RESULTW(WSTRING, L"abc"); + // TODO: test pointer, custom } // Tests fmt::internal::CountDigits for integer type Int.