diff --git a/src/util/log.cpp b/src/util/log.cpp index f89898b29..9cb3666fb 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -128,6 +128,7 @@ void Log::out(LogType type, const char *file, unsigned int line, const char *for cerr << "Failed to format log message: " << e.what() << '\n'; o << format << '\n'; } + o.flush(); va_end(args); } @@ -143,4 +144,5 @@ void Log::dbgPrintfMemImpl(const char *msg, const unsigned char *data, size_t si for(size_t i = 0; i < size; ++i) o << setw(2) << static_cast(data[i]) << ' '; o << dec << nouppercase << setfill(' ') << "}:" << size << '\n'; + o.flush(); } diff --git a/test/libdigidocpp_boost.cpp b/test/libdigidocpp_boost.cpp index 5a1327fce..9b0d9674a 100644 --- a/test/libdigidocpp_boost.cpp +++ b/test/libdigidocpp_boost.cpp @@ -30,6 +30,9 @@ #include #include #include +#include + +#include namespace digidoc { @@ -61,6 +64,35 @@ const string ASiCS::EXT = "asics"; BOOST_GLOBAL_FIXTURE(TestFixture); +BOOST_AUTO_TEST_SUITE(LogSuite) +BOOST_AUTO_TEST_CASE(logEntryIsWrittenImmediately) +{ + const string marker = "log entry is immediately available"; + const string path = Conf::instance()->logFile(); + const auto size = util::File::fileSize(path); + INFO("%s", marker.c_str()); + + BOOST_CHECK_GT(util::File::fileSize(path), size); + ifstream log{path}; + const string contents{istreambuf_iterator{log}, istreambuf_iterator{}}; + BOOST_CHECK_NE(contents.find(marker), string::npos); +} + +BOOST_AUTO_TEST_CASE(memoryLogEntryIsWrittenImmediately) +{ + const string marker = "memory log entry is immediately available"; + const string path = Conf::instance()->logFile(); + const auto size = util::File::fileSize(path); + const unsigned char data[] {0x01, 0x23, 0x45, 0x67}; + DEBUGMEM(marker.c_str(), data, sizeof(data)); + + BOOST_CHECK_GT(util::File::fileSize(path), size); + ifstream log{path}; + const string contents{istreambuf_iterator{log}, istreambuf_iterator{}}; + BOOST_CHECK_NE(contents.find(marker), string::npos); +} +BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_SUITE(SignerSuite) BOOST_AUTO_TEST_CASE(signerParameters) {