|
|
@@ -5,61 +5,17 @@
|
|
|
// Created by Sam Jaffe on 3/31/19.
|
|
|
//
|
|
|
|
|
|
-#include <gmock/gmock.h>
|
|
|
+#include "mock_logger.h"
|
|
|
|
|
|
#include "logger/logger.h"
|
|
|
-#include "logger/logger_impl.h"
|
|
|
-
|
|
|
-namespace logging {
|
|
|
- void PrintTo(location_info const & info, std::ostream * os) {
|
|
|
- if (info.line) {
|
|
|
- (*os) << "{\"" << info.filename << "\", \"" <<
|
|
|
- info.function << "\", " << info.line << "}";
|
|
|
- } else {
|
|
|
- (*os) << "NULL";
|
|
|
- }
|
|
|
- }
|
|
|
- void PrintTo(logpacket const & pkt, std::ostream * os) {
|
|
|
- (*os) << "{ " << pkt.level << ", ";
|
|
|
- PrintTo(pkt.info, os);
|
|
|
- (*os) << ", \"" << pkt.logger << "\", \"" << pkt.message << "\" }";
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-struct MockLoggerImpl : public logging::logger_impl {
|
|
|
- MockLoggerImpl() {
|
|
|
- SetLogLevel(logging::LTRACE);
|
|
|
- }
|
|
|
- void SetLogLevel(logging::log_level ll) {
|
|
|
- min_log_level = ll;
|
|
|
- }
|
|
|
- MOCK_METHOD0(flush, void());
|
|
|
- MOCK_METHOD1(write, void(logging::logpacket const &));
|
|
|
- MOCK_METHOD2(write, void(logging::log_level, std::string const &));
|
|
|
-};
|
|
|
-
|
|
|
-struct LoggerTest : public testing::Test {
|
|
|
- void SetUp() override;
|
|
|
- void TearDown() override;
|
|
|
-
|
|
|
- std::shared_ptr<MockLoggerImpl> pimpl;
|
|
|
-};
|
|
|
|
|
|
using namespace logging;
|
|
|
|
|
|
+namespace {
|
|
|
struct t_logger : public logger {
|
|
|
t_logger(std::string const & name, std::shared_ptr<logger_impl> impl)
|
|
|
: logger(name, impl) {}
|
|
|
};
|
|
|
-
|
|
|
-void LoggerTest::SetUp() {
|
|
|
- pimpl.reset(new MockLoggerImpl);
|
|
|
- using testing::AnyNumber;
|
|
|
- EXPECT_CALL(*pimpl, flush()).Times(AnyNumber());
|
|
|
-}
|
|
|
-
|
|
|
-void LoggerTest::TearDown() {
|
|
|
- pimpl.reset();
|
|
|
}
|
|
|
|
|
|
TEST_F(LoggerTest, LogsWithBraceFmtCode) {
|