From 59536b154c7c0a789d9c3a3a0b4bdca0254910a2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 11 Dec 2012 20:48:49 -0800 Subject: [PATCH] Add more tests. --- format_test.cc | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/format_test.cc b/format_test.cc index e569fe4e..54a72cc5 100644 --- a/format_test.cc +++ b/format_test.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "format.h" @@ -560,23 +561,47 @@ TEST(FormatterTest, ArgInserter) { EXPECT_STREQ("12", c_str(format("{0}") << 2)); } -struct CallCheck { - bool &called; +struct CountCalls { + int &num_calls; - CallCheck(bool &called) : called(called) {} + CountCalls(int &num_calls) : num_calls(num_calls) {} void operator()(const Formatter &) const { - called = true; + ++num_calls; } }; TEST(ActiveFormatterTest, Action) { - bool called = false; + int num_calls = 0; { - fmt::ActiveFormatter af("test", CallCheck(called)); - EXPECT_FALSE(called); + fmt::ActiveFormatter af("test", CountCalls(num_calls)); + EXPECT_EQ(0, num_calls); } - EXPECT_TRUE(called); + EXPECT_EQ(1, num_calls); +} + +TEST(ActiveFormatterTest, Copy) { + int num_calls = 0; + typedef fmt::ActiveFormatter AF; + std::auto_ptr af(new AF("test", CountCalls(num_calls))); + EXPECT_EQ(0, num_calls); + { + AF copy(*af); + EXPECT_EQ(0, num_calls); + af.reset(); + EXPECT_EQ(0, num_calls); + } + EXPECT_EQ(1, num_calls); +} + +TEST(ActiveFormatterTest, ActionNotCalledOnError) { + int num_calls = 0; + { + EXPECT_THROW( + fmt::ActiveFormatter af("{0", CountCalls(num_calls)), + FormatError); + } + EXPECT_EQ(0, num_calls); } TEST(ActiveFormatterTest, ArgLifetime) {