MCPcopy Create free account
hub / github.com/MEONMedical/Log4Qt / testBinaryFileAppender

Method testBinaryFileAppender

tests/binaryloggertest/binaryloggertest.cpp:246–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244}
245
246void BinaryLoggerTest::testBinaryFileAppender()
247{
248 auto blogger = Log4Qt::Logger::logger(binLogger);
249
250 QTemporaryFile file;
251 QVERIFY(file.open());
252 file.close();
253 Log4Qt::BinaryFileAppender *bfa = new Log4Qt::BinaryFileAppender(file.fileName(), blogger);
254 bfa->activateOptions();
255 blogger->addAppender(bfa);
256
257 auto _ = createScopeExitGuard([blogger, bfa] {blogger->removeAppender(bfa);});
258
259 blogger->debug(QStringLiteral("Hello world!"));
260 Log4Qt::BinaryLoggingEvent event(blogger, Log4Qt::Level::INFO_INT, QByteArray("\0\1\2\3", 4));
261 blogger->callAppenders(event);
262
263 char expected[] = {0x18, 0x00, 0x00, 0x00, 0x48, 0x00, 0x65, 0x00,
264 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00,
265 0x77, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x6c, 0x00,
266 0x64, 0x00, 0x21, 0x00, 0x04, 0x00, 0x00, 0x00,
267 0x00, 0x01, 0x02, 0x03
268 };
269
270 bfa->close();
271 QVERIFY(file.open());
272 QByteArray data = file.readAll();
273 QCOMPARE(data, QByteArray(expected, elementsInArray(expected)));
274}
275
276void BinaryLoggerTest::testBinaryLogStream()
277{

Callers

nothing calls this directly

Calls 9

createScopeExitGuardFunction · 0.85
elementsInArrayFunction · 0.85
addAppenderMethod · 0.80
removeAppenderMethod · 0.80
QByteArrayClass · 0.70
closeMethod · 0.45
activateOptionsMethod · 0.45
debugMethod · 0.45
callAppendersMethod · 0.45

Tested by

no test coverage detected