2025-04-08 22:22:19 +00:00
|
|
|
/*
|
|
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "LoggerTests.h"
|
2025-11-04 16:27:52 +00:00
|
|
|
#include "common/Settings.h"
|
2025-04-08 22:22:19 +00:00
|
|
|
|
2025-05-10 03:23:46 +00:00
|
|
|
#include "gui/Logger.h"
|
2025-04-08 22:22:19 +00:00
|
|
|
|
2025-11-04 16:27:52 +00:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
2025-04-08 22:22:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
|
|
|
|
|
|
using namespace deskflow::gui;
|
|
|
|
|
|
2025-11-04 16:27:52 +00:00
|
|
|
void LoggerTests::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
QDir dir;
|
|
|
|
|
QVERIFY(dir.mkpath(m_settingsPath));
|
|
|
|
|
|
|
|
|
|
QFile oldSettings(m_settingsFile);
|
|
|
|
|
if (oldSettings.exists())
|
|
|
|
|
oldSettings.remove();
|
|
|
|
|
|
|
|
|
|
Settings::setSettingsFile(m_settingsFile);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 22:22:19 +00:00
|
|
|
void LoggerTests::newLine()
|
|
|
|
|
{
|
|
|
|
|
Logger logger;
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(&logger, &Logger::newLine);
|
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
|
|
2025-11-04 16:27:52 +00:00
|
|
|
Settings::setValue(Settings::Log::GuiDebug, true);
|
2025-04-08 22:22:19 +00:00
|
|
|
logger.handleMessage(QtDebugMsg, "stub", "test");
|
|
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
QVERIFY(qvariant_cast<QString>(spy.takeFirst().at(0)).contains("test"));
|
2025-11-04 16:27:52 +00:00
|
|
|
Settings::setValue(Settings::Log::GuiDebug, false);
|
2025-04-08 22:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoggerTests::noNewLine()
|
|
|
|
|
{
|
|
|
|
|
Logger logger;
|
|
|
|
|
bool newLineEmitted = false;
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(&logger, &Logger::newLine);
|
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
|
|
2025-11-04 16:27:52 +00:00
|
|
|
Settings::setValue(Settings::Log::GuiDebug, false);
|
2025-04-08 22:22:19 +00:00
|
|
|
logger.handleMessage(QtDebugMsg, "stub", "test");
|
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
|
QVERIFY(!newLineEmitted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(LoggerTests)
|