// // logger_test.cxx // logger // // Created by Sam Jaffe on 3/31/19. // #include #include "logger/logger.hpp" struct MockLoggerImpl : public logging::logger_impl { MOCK_METHOD0(flush, void()); MOCK_METHOD1(write, void(logging::logpacket const &)); }; struct LoggerTest : public testing::Test { static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; static std::unique_ptr pimpl; }; std::unique_ptr LoggerTest::pimpl{}; using namespace logging; void LoggerTest::SetUpTestCase() { _binding bind([]() -> logger_impl& { return *pimpl; }); bind_logger_impl(bind); } void LoggerTest::SetUp() { pimpl.reset(new MockLoggerImpl); } void LoggerTest::TearDown() { pimpl.reset(); } TEST_F(LoggerTest, ImplCannotBeMadeTwice) { EXPECT_ANY_THROW(bind_logger_impl(nullptr)); } TEST_F(LoggerTest, LogsWithBraceFmtCode) { using testing::Field; EXPECT_CALL(*pimpl, write(Field(&logpacket::message, "5"))).Times(1); logger & LOG = logger::instance( ); LOG.log(LERROR, "{}", 5); }