瀏覽代碼

More test coverage.

Sam Jaffe 5 年之前
父節點
當前提交
bb98910948
共有 2 個文件被更改,包括 40 次插入0 次删除
  1. 26 0
      test/file_appender_test.cxx
  2. 14 0
      test/logger_test.cxx

+ 26 - 0
test/file_appender_test.cxx

@@ -108,3 +108,29 @@ TEST_F(FileAppenderTest, OverwritesFileWithSetting) {
   }
   EXPECT_THAT(slurp(filename()), Eq("Test"));
 }
+
+TEST_F(FileAppenderTest, CanWriteBufferedData) {
+  using namespace logging;
+  using namespace logging::property;
+  properties props{_obj({
+    {"immediateFlush", _v(false)},
+    {"filename", _v(filename())},
+    {"bufferedIO", _v(true)},
+    {"bufferSize", _v(256)}
+  })};
+  
+  using testing::Eq;
+  logpacket pkt{{}, level::error, {}, {}, "Test"};
+  EXPECT_NO_THROW(get(props)->write(pkt));
+  // We can't really test the results here, because the standard library is in
+  // control of the actual writes...
+}
+
+TEST_F(FileAppenderTest, WillThrowIfCannotOpenFile) {
+  using namespace logging;
+  using namespace logging::property;
+  properties props{_obj({
+    {"filename", _v("./fake_directory_for_testing/file.log")}
+  })};
+  EXPECT_THROW(get(props), std::runtime_error);
+}

+ 14 - 0
test/logger_test.cxx

@@ -46,3 +46,17 @@ TEST_F(LoggerTest, LogCurlyBraceLiteralByDoubling) {
   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);
+}