Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/util/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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<int>(data[i]) << ' ';
o << dec << nouppercase << setfill(' ') << "}:" << size << '\n';
o.flush();
}
32 changes: 32 additions & 0 deletions test/libdigidocpp_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <crypto/PKCS12Signer.h>
#include <crypto/X509Crypto.h>
#include <util/DateTime.h>
#include <util/log.h>

#include <fstream>

namespace digidoc
{
Expand Down Expand Up @@ -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<char>{log}, istreambuf_iterator<char>{}};
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<char>{log}, istreambuf_iterator<char>{}};
BOOST_CHECK_NE(contents.find(marker), string::npos);
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(SignerSuite)
BOOST_AUTO_TEST_CASE(signerParameters)
{
Expand Down