diff --git a/src/lib/deskflow/Screen.h b/src/lib/deskflow/Screen.h index 30a0a8fc8..fc52de579 100644 --- a/src/lib/deskflow/Screen.h +++ b/src/lib/deskflow/Screen.h @@ -37,12 +37,6 @@ public: Screen &operator&(Screen const &) = delete; Screen &operator&(Screen &&) = delete; -#ifdef TEST_ENV - Screen() : m_mock(true) - { - } -#endif - //! @name manipulators //@{ diff --git a/src/test/shared/gui/TestQtCoreApp.h b/src/test/shared/gui/TestQtCoreApp.h deleted file mode 100644 index 8bb24f07d..000000000 --- a/src/test/shared/gui/TestQtCoreApp.h +++ /dev/null @@ -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 - -static int argc = 0; // NOLINT NOSONAR -static char **argv = nullptr; // NOLINT NOSONAR - -class TestQtCoreApp : public QCoreApplication -{ -public: - explicit TestQtCoreApp() : QCoreApplication(argc, argv) - { - } -}; diff --git a/src/test/unittests/gui/config/ScreenTests.cpp b/src/test/unittests/gui/config/ScreenTests.cpp deleted file mode 100644 index c305bed41..000000000 --- a/src/test/unittests/gui/config/ScreenTests.cpp +++ /dev/null @@ -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 -#include - -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 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 settings; - Screen screen; - screen.setName("stub"); - - EXPECT_CALL(settings, beginWriteArray(_)).Times(4); - - screen.saveSettings(settings); -} diff --git a/src/unittests/gui/CMakeLists.txt b/src/unittests/gui/CMakeLists.txt index 2146b5570..cdfa7143a 100644 --- a/src/unittests/gui/CMakeLists.txt +++ b/src/unittests/gui/CMakeLists.txt @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2025 Deskflow Developers # SPDX-License-Identifier: MIT +add_subdirectory(config) add_subdirectory(core) create_test( diff --git a/src/unittests/gui/config/CMakeLists.txt b/src/unittests/gui/config/CMakeLists.txt new file mode 100644 index 000000000..5a2600b3e --- /dev/null +++ b/src/unittests/gui/config/CMakeLists.txt @@ -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" +) diff --git a/src/unittests/gui/config/ScreenTests.cpp b/src/unittests/gui/config/ScreenTests.cpp new file mode 100644 index 000000000..3f1115429 --- /dev/null +++ b/src/unittests/gui/config/ScreenTests.cpp @@ -0,0 +1,38 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * 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) diff --git a/src/unittests/gui/config/ScreenTests.h b/src/unittests/gui/config/ScreenTests.h new file mode 100644 index 000000000..b92c98e62 --- /dev/null +++ b/src/unittests/gui/config/ScreenTests.h @@ -0,0 +1,20 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#include + +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); +};