refactor: Logger is now a proper singleton
This commit is contained in:
parent
8256a3ba43
commit
ec9f7efcff
2 changed files with 8 additions and 7 deletions
|
|
@ -25,6 +25,10 @@ public:
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void newLine(const QString &line);
|
void newLine(const QString &line);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit Logger() = default;
|
||||||
|
~Logger() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace deskflow::gui
|
} // namespace deskflow::gui
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,11 @@ void LoggerTests::initTestCase()
|
||||||
|
|
||||||
void LoggerTests::newLine()
|
void LoggerTests::newLine()
|
||||||
{
|
{
|
||||||
Logger logger;
|
QSignalSpy spy(Logger::instance(), &Logger::newLine);
|
||||||
|
|
||||||
QSignalSpy spy(&logger, &Logger::newLine);
|
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
|
|
||||||
Settings::setValue(Settings::Log::GuiDebug, true);
|
Settings::setValue(Settings::Log::GuiDebug, true);
|
||||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
Logger::instance()->handleMessage(QtDebugMsg, "stub", "test");
|
||||||
|
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QVERIFY(qvariant_cast<QString>(spy.takeFirst().at(0)).contains("test"));
|
QVERIFY(qvariant_cast<QString>(spy.takeFirst().at(0)).contains("test"));
|
||||||
|
|
@ -45,14 +43,13 @@ void LoggerTests::newLine()
|
||||||
|
|
||||||
void LoggerTests::noNewLine()
|
void LoggerTests::noNewLine()
|
||||||
{
|
{
|
||||||
Logger logger;
|
|
||||||
bool newLineEmitted = false;
|
bool newLineEmitted = false;
|
||||||
|
|
||||||
QSignalSpy spy(&logger, &Logger::newLine);
|
QSignalSpy spy(Logger::instance(), &Logger::newLine);
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
|
|
||||||
Settings::setValue(Settings::Log::GuiDebug, false);
|
Settings::setValue(Settings::Log::GuiDebug, false);
|
||||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
Logger::instance()->handleMessage(QtDebugMsg, "stub", "test");
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
QVERIFY(!newLineEmitted);
|
QVERIFY(!newLineEmitted);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue