refactor: port gui/ScreenTest to QtTests
remove TEST_ENV items from Screen
This commit is contained in:
parent
b8c6d1b58f
commit
632be4b240
7 changed files with 68 additions and 82 deletions
|
|
@ -37,12 +37,6 @@ public:
|
|||
Screen &operator&(Screen const &) = delete;
|
||||
Screen &operator&(Screen &&) = delete;
|
||||
|
||||
#ifdef TEST_ENV
|
||||
Screen() : m_mock(true)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
static int argc = 0; // NOLINT NOSONAR
|
||||
static char **argv = nullptr; // NOLINT NOSONAR
|
||||
|
||||
class TestQtCoreApp : public QCoreApplication
|
||||
{
|
||||
public:
|
||||
explicit TestQtCoreApp() : QCoreApplication(argc, argv)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "gui/config/Screen.h"
|
||||
|
||||
#include "common/QSettingsProxy.h"
|
||||
#include "shared/gui/TestQtCoreApp.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing;
|
||||
|
||||
class QSettingsProxyMock : public QSettingsProxy
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD(int, beginReadArray, (const QString &prefix), (override));
|
||||
MOCK_METHOD(void, beginWriteArray, (const QString &prefix), (override));
|
||||
MOCK_METHOD(void, setArrayIndex, (int i), (override));
|
||||
MOCK_METHOD(QVariant, value, (const QString &key), (const, override));
|
||||
MOCK_METHOD(QVariant, value, (const QString &key, const QVariant &defaultValue), (const, override));
|
||||
MOCK_METHOD(void, endArray, (), (override));
|
||||
MOCK_METHOD(void, setValue, (const QString &key, const QVariant &value), (override));
|
||||
MOCK_METHOD(void, beginGroup, (const QString &prefix), (override));
|
||||
MOCK_METHOD(void, endGroup, (), (override));
|
||||
MOCK_METHOD(void, remove, (const QString &key), (override));
|
||||
MOCK_METHOD(bool, isWritable, (), (const, override));
|
||||
MOCK_METHOD(bool, contains, (const QString &key), (const, override));
|
||||
};
|
||||
|
||||
TEST(ScreenTests, loadSettings_whenHasSetting_readsArray)
|
||||
{
|
||||
TestQtCoreApp app;
|
||||
NiceMock<QSettingsProxyMock> settings;
|
||||
Screen screen;
|
||||
ON_CALL(settings, value(_)).WillByDefault(Return("stub"));
|
||||
|
||||
EXPECT_CALL(settings, beginReadArray(_)).Times(4);
|
||||
|
||||
screen.loadSettings(settings);
|
||||
}
|
||||
|
||||
TEST(ScreenTests, saveSettings_whenNameIsSet_writesArray)
|
||||
{
|
||||
TestQtCoreApp app;
|
||||
NiceMock<QSettingsProxyMock> settings;
|
||||
Screen screen;
|
||||
screen.setName("stub");
|
||||
|
||||
EXPECT_CALL(settings, beginWriteArray(_)).Times(4);
|
||||
|
||||
screen.saveSettings(settings);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2025 Deskflow Developers
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(core)
|
||||
|
||||
create_test(
|
||||
|
|
|
|||
9
src/unittests/gui/config/CMakeLists.txt
Normal file
9
src/unittests/gui/config/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# SPDX-FileCopyrightText: 2025 Deskflow Developers
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
create_test(
|
||||
NAME ScreenTests
|
||||
DEPENDS gui
|
||||
SOURCE ScreenTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
||||
)
|
||||
38
src/unittests/gui/config/ScreenTests.cpp
Normal file
38
src/unittests/gui/config/ScreenTests.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 "ScreenTests.h"
|
||||
|
||||
#include "../../../lib/common/Settings.h"
|
||||
#include "../../../lib/gui/config/Screen.h"
|
||||
|
||||
void ScreenTests::initTestCase()
|
||||
{
|
||||
QDir dir;
|
||||
QVERIFY(dir.mkpath(m_settingsPath));
|
||||
|
||||
QFile oldSettings(m_settingsFile);
|
||||
if (oldSettings.exists())
|
||||
oldSettings.remove();
|
||||
|
||||
Settings::setSettingFile(m_settingsFile);
|
||||
}
|
||||
|
||||
void ScreenTests::basicFunctionality()
|
||||
{
|
||||
Screen screen;
|
||||
QVERIFY(screen.isNull());
|
||||
|
||||
screen.setName("stub");
|
||||
QVERIFY(!screen.isNull());
|
||||
|
||||
screen.saveSettings(Settings::proxy());
|
||||
screen.loadSettings(Settings::proxy());
|
||||
QCOMPARE("stub", screen.name());
|
||||
}
|
||||
|
||||
QTEST_MAIN(ScreenTests)
|
||||
20
src/unittests/gui/config/ScreenTests.h
Normal file
20
src/unittests/gui/config/ScreenTests.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class ScreenTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
// Test are run in order top to bottom
|
||||
void initTestCase();
|
||||
void basicFunctionality();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
inline static const QString m_settingsFile = QStringLiteral("%1/Deskflow.conf").arg(m_settingsPath);
|
||||
};
|
||||
Loading…
Reference in a new issue