| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // logger_test.cxx
- // logger
- //
- // Created by Sam Jaffe on 3/31/19.
- //
- #include "logger_test_obj.h"
- #include "logger/logger.h"
- using namespace logging;
- namespace {
- struct t_logger : public logger {
- t_logger(std::string const & name, std::shared_ptr<logger_impl> impl)
- : logger(name, impl) {}
- };
- }
- TEST_F(LoggerTest, FlushesOnClose) {
- EXPECT_CALL(*appender, flush()).Times(1);
- t_logger("", pimpl);
- }
- TEST_F(LoggerTest, FlushesOnFlushCall) {
- EXPECT_CALL(*appender, flush()).Times(2);
- t_logger("", pimpl).flush();
- }
- TEST_F(LoggerTest, LogsWithBraceFmtCode) {
- using testing::_;
- EXPECT_CALL(*appender, write(MessageEq("5"), _)).Times(1);
- t_logger("", pimpl).log(level::error, "{}", 5);
- }
- TEST_F(LoggerTest, DoesNotLogAboveLevel) {
- using testing::_;
- pimpl->min_log_level = level::fatal;
- EXPECT_CALL(*appender, write(_, _)).Times(0);
- t_logger("", pimpl).log(level::error, "{}", 5);
- }
- TEST_F(LoggerTest, LogCurlyBraceLiteralByDoubling) {
- using testing::_;
- EXPECT_CALL(*appender, write(MessageEq("{}"), _)).Times(1);
- t_logger("", pimpl).log(level::error, "{{}}", 5);
- }
- MATCHER_P3(LocationInfoNear, file, line, function, "") {
- return !strcmp(arg.info.filename, file) &&
- !strcmp(arg.info.function, function) &&
- std::abs(arg.info.line - line) < 5;
- }
- TEST_F(LoggerTest, LogMacroInjectsLocationInfo) {
- using testing::_;
- auto near_this_line = LocationInfoNear(__FILE__, __LINE__, __FUNCTION__);
- EXPECT_CALL(*appender, write(near_this_line, _)).Times(1);
- t_logger log("", pimpl);
- log_message(log, error, "{}", 5);
- }
|