aboutsummaryrefslogtreecommitdiff
path: root/autotests
diff options
context:
space:
mode:
Diffstat (limited to 'autotests')
-rw-r--r--autotests/CMakeLists.txt5
-rw-r--r--autotests/kwindowstatesavertest.cpp90
2 files changed, 95 insertions, 0 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 7b5a73b1..458f8f97 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -82,3 +82,8 @@ if (NOT CMAKE_CROSSCOMPILING)
add_subdirectory(kconfig_compiler)
endif()
endif()
+
+find_package(Qt${QT_MAJOR_VERSION} OPTIONAL_COMPONENTS Widgets)
+if (TARGET Qt${QT_MAJOR_VERSION}::Widgets)
+ ecm_add_test(kwindowstatesavertest.cpp LINK_LIBRARIES KF5::ConfigGui Qt${QT_MAJOR_VERSION}::Test Qt${QT_MAJOR_VERSION}::Widgets)
+endif()
diff --git a/autotests/kwindowstatesavertest.cpp b/autotests/kwindowstatesavertest.cpp
new file mode 100644
index 00000000..a8b67218
--- /dev/null
+++ b/autotests/kwindowstatesavertest.cpp
@@ -0,0 +1,90 @@
+/*
+ SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
+ SPDX-License-Identifier: LGPL-2.0-or-later
+*/
+
+#include "kwindowstatesaver.h"
+#include "kconfiggroup.h"
+#include "ksharedconfig.h"
+
+#include <QSignalSpy>
+#include <QStandardPaths>
+#include <QTest>
+
+#include <QFontDialog>
+
+class KWindowStateSaverTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void initTestCase();
+ void testTopLevelDialog();
+ void testSubDialog();
+};
+
+void KWindowStateSaverTest::initTestCase()
+{
+ QStandardPaths::setTestModeEnabled(true);
+}
+
+void KWindowStateSaverTest::testTopLevelDialog()
+{
+ auto cfg = KSharedConfig::openStateConfig();
+ cfg->deleteGroup("topLevelDialogTest");
+ QSize dlgSize(720, 720);
+
+ {
+ QFontDialog dlg;
+ new KWindowStateSaver(&dlg, "topLevelDialogTest");
+ dlg.show();
+ QTest::qWait(10); // give the window time to show up, so we simulate a user-triggered resize
+ dlg.resize(dlgSize);
+ QTest::qWait(500); // give the state saver time to trigger
+ QCOMPARE(dlg.size(), dlgSize);
+ }
+
+ QVERIFY(cfg->hasGroup("topLevelDialogTest"));
+
+ {
+ QFontDialog dlg;
+ new KWindowStateSaver(&dlg, "topLevelDialogTest");
+ dlg.show();
+ QTest::qWait(100); // give the window time to show up properly
+ QCOMPARE(dlg.size(), dlgSize);
+ }
+}
+
+void KWindowStateSaverTest::testSubDialog()
+{
+ QWidget mainWindow;
+ mainWindow.show();
+ QTest::qWait(10);
+
+ auto cfg = KSharedConfig::openStateConfig();
+ cfg->deleteGroup("subDialogTest");
+ QSize dlgSize(700, 500);
+
+ {
+ auto dlg = new QFontDialog(&mainWindow);
+ new KWindowStateSaver(dlg, "subDialogTest");
+ dlg->show();
+ QTest::qWait(10); // give the window time to show up, so we simulate a user-triggered resize
+ dlg->resize(dlgSize);
+ QTest::qWait(500); // give the state saver time to trigger
+ QCOMPARE(dlg->size(), dlgSize);
+ delete dlg;
+ }
+
+ QVERIFY(cfg->hasGroup("subDialogTest"));
+
+ {
+ auto dlg = new QFontDialog(&mainWindow);
+ new KWindowStateSaver(dlg, "subDialogTest");
+ dlg->show();
+ QTest::qWait(100); // give the window time to show up properly
+ QCOMPARE(dlg->size(), dlgSize);
+ }
+}
+
+QTEST_MAIN(KWindowStateSaverTest)
+#include "kwindowstatesavertest.moc"