blob: a8b672183a7a732e8971fe5935c4ded770259f91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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"
|