KWin
Loading...
Searching...
No Matches
windowquadlisttest.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
10#include <QTest>
11
13
14class WindowQuadListTest : public QObject
15{
16 Q_OBJECT
17private Q_SLOTS:
18 void testMakeGrid_data();
19 void testMakeGrid();
20 void testMakeRegularGrid_data();
21 void testMakeRegularGrid();
22
23private:
24 KWin::WindowQuad makeQuad(const QRectF &rect);
25};
26
27KWin::WindowQuad WindowQuadListTest::makeQuad(const QRectF &r)
28{
30 quad[0] = KWin::WindowVertex(r.x(), r.y(), r.x(), r.y());
31 quad[1] = KWin::WindowVertex(r.x() + r.width(), r.y(), r.x() + r.width(), r.y());
32 quad[2] = KWin::WindowVertex(r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height());
33 quad[3] = KWin::WindowVertex(r.x(), r.y() + r.height(), r.x(), r.y() + r.height());
34 return quad;
35}
36
37void WindowQuadListTest::testMakeGrid_data()
38{
39 QTest::addColumn<KWin::WindowQuadList>("orig");
40 QTest::addColumn<int>("quadSize");
41 QTest::addColumn<int>("expectedCount");
42 QTest::addColumn<KWin::WindowQuadList>("expected");
43
45 KWin::WindowQuadList expected;
46
47 QTest::newRow("empty") << orig << 10 << 0 << expected;
48
49 orig.append(makeQuad(QRectF(0, 0, 10, 10)));
50 expected.append(makeQuad(QRectF(0, 0, 10, 10)));
51 QTest::newRow("quadSizeTooLarge") << orig << 10 << 1 << expected;
52
53 expected.clear();
54 expected.append(makeQuad(QRectF(0, 0, 5, 5)));
55 expected.append(makeQuad(QRectF(0, 5, 5, 5)));
56 expected.append(makeQuad(QRectF(5, 0, 5, 5)));
57 expected.append(makeQuad(QRectF(5, 5, 5, 5)));
58 QTest::newRow("regularGrid") << orig << 5 << 4 << expected;
59
60 expected.clear();
61 expected.append(makeQuad(QRectF(0, 0, 9, 9)));
62 expected.append(makeQuad(QRectF(0, 9, 9, 1)));
63 expected.append(makeQuad(QRectF(9, 0, 1, 9)));
64 expected.append(makeQuad(QRectF(9, 9, 1, 1)));
65 QTest::newRow("irregularGrid") << orig << 9 << 4 << expected;
66
67 orig.append(makeQuad(QRectF(0, 10, 4, 3)));
68 expected.clear();
69 expected.append(makeQuad(QRectF(0, 0, 4, 4)));
70 expected.append(makeQuad(QRectF(0, 4, 4, 4)));
71 expected.append(makeQuad(QRectF(0, 8, 4, 2)));
72 expected.append(makeQuad(QRectF(0, 10, 4, 2)));
73 expected.append(makeQuad(QRectF(0, 12, 4, 1)));
74 expected.append(makeQuad(QRectF(4, 0, 4, 4)));
75 expected.append(makeQuad(QRectF(4, 4, 4, 4)));
76 expected.append(makeQuad(QRectF(4, 8, 4, 2)));
77 expected.append(makeQuad(QRectF(8, 0, 2, 4)));
78 expected.append(makeQuad(QRectF(8, 4, 2, 4)));
79 expected.append(makeQuad(QRectF(8, 8, 2, 2)));
80 QTest::newRow("irregularGrid2") << orig << 4 << 11 << expected;
81}
82
83void WindowQuadListTest::testMakeGrid()
84{
85 QFETCH(KWin::WindowQuadList, orig);
86 QFETCH(int, quadSize);
87 QFETCH(int, expectedCount);
88 KWin::WindowQuadList actual = orig.makeGrid(quadSize);
89 QCOMPARE(actual.count(), expectedCount);
90
91 QFETCH(KWin::WindowQuadList, expected);
92 for (auto it = actual.constBegin(); it != actual.constEnd(); ++it) {
93 bool found = false;
94 const KWin::WindowQuad &actualQuad = (*it);
95 for (auto it2 = expected.constBegin(); it2 != expected.constEnd(); ++it2) {
96 const KWin::WindowQuad &expectedQuad = (*it2);
97 auto vertexTest = [actualQuad, expectedQuad](int index) {
98 const KWin::WindowVertex &actualVertex = actualQuad[index];
99 const KWin::WindowVertex &expectedVertex = expectedQuad[index];
100 if (actualVertex.x() != expectedVertex.x()) {
101 return false;
102 }
103 if (actualVertex.y() != expectedVertex.y()) {
104 return false;
105 }
106 if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) {
107 return false;
108 }
109 if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) {
110 return false;
111 }
112 return true;
113 };
114 found = vertexTest(0) && vertexTest(1) && vertexTest(2) && vertexTest(3);
115 if (found) {
116 break;
117 }
118 }
119 QVERIFY2(found, qPrintable(QStringLiteral("%0, %1 / %2, %3").arg(QString::number(actualQuad.left()), QString::number(actualQuad.top()), QString::number(actualQuad.right()), QString::number(actualQuad.bottom()))));
120 }
121}
122
123void WindowQuadListTest::testMakeRegularGrid_data()
124{
125 QTest::addColumn<KWin::WindowQuadList>("orig");
126 QTest::addColumn<int>("xSubdivisions");
127 QTest::addColumn<int>("ySubdivisions");
128 QTest::addColumn<int>("expectedCount");
129 QTest::addColumn<KWin::WindowQuadList>("expected");
130
132 KWin::WindowQuadList expected;
133
134 QTest::newRow("empty") << orig << 1 << 1 << 0 << expected;
135
136 orig.append(makeQuad(QRectF(0, 0, 10, 10)));
137 expected.append(makeQuad(QRectF(0, 0, 10, 10)));
138 QTest::newRow("noSplit") << orig << 1 << 1 << 1 << expected;
139
140 expected.clear();
141 expected.append(makeQuad(QRectF(0, 0, 5, 10)));
142 expected.append(makeQuad(QRectF(5, 0, 5, 10)));
143 QTest::newRow("xSplit") << orig << 2 << 1 << 2 << expected;
144
145 expected.clear();
146 expected.append(makeQuad(QRectF(0, 0, 10, 5)));
147 expected.append(makeQuad(QRectF(0, 5, 10, 5)));
148 QTest::newRow("ySplit") << orig << 1 << 2 << 2 << expected;
149
150 expected.clear();
151 expected.append(makeQuad(QRectF(0, 0, 5, 5)));
152 expected.append(makeQuad(QRectF(5, 0, 5, 5)));
153 expected.append(makeQuad(QRectF(0, 5, 5, 5)));
154 expected.append(makeQuad(QRectF(5, 5, 5, 5)));
155 QTest::newRow("xySplit") << orig << 2 << 2 << 4 << expected;
156
157 orig.append(makeQuad(QRectF(0, 10, 4, 2)));
158 expected.clear();
159 expected.append(makeQuad(QRectF(0, 0, 5, 3)));
160 expected.append(makeQuad(QRectF(5, 0, 5, 3)));
161 expected.append(makeQuad(QRectF(0, 3, 5, 3)));
162 expected.append(makeQuad(QRectF(5, 3, 5, 3)));
163 expected.append(makeQuad(QRectF(0, 6, 5, 3)));
164 expected.append(makeQuad(QRectF(5, 6, 5, 3)));
165 expected.append(makeQuad(QRectF(0, 9, 5, 1)));
166 expected.append(makeQuad(QRectF(0, 10, 4, 2)));
167 expected.append(makeQuad(QRectF(5, 9, 5, 1)));
168 QTest::newRow("multipleQuads") << orig << 2 << 4 << 9 << expected;
169}
170
171void WindowQuadListTest::testMakeRegularGrid()
172{
173 QFETCH(KWin::WindowQuadList, orig);
174 QFETCH(int, xSubdivisions);
175 QFETCH(int, ySubdivisions);
176 QFETCH(int, expectedCount);
177 KWin::WindowQuadList actual = orig.makeRegularGrid(xSubdivisions, ySubdivisions);
178 QCOMPARE(actual.count(), expectedCount);
179
180 QFETCH(KWin::WindowQuadList, expected);
181 for (auto it = actual.constBegin(); it != actual.constEnd(); ++it) {
182 bool found = false;
183 const KWin::WindowQuad &actualQuad = (*it);
184 for (auto it2 = expected.constBegin(); it2 != expected.constEnd(); ++it2) {
185 const KWin::WindowQuad &expectedQuad = (*it2);
186 auto vertexTest = [actualQuad, expectedQuad](int index) {
187 const KWin::WindowVertex &actualVertex = actualQuad[index];
188 const KWin::WindowVertex &expectedVertex = expectedQuad[index];
189 if (actualVertex.x() != expectedVertex.x()) {
190 return false;
191 }
192 if (actualVertex.y() != expectedVertex.y()) {
193 return false;
194 }
195 if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) {
196 return false;
197 }
198 if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) {
199 return false;
200 }
201 return true;
202 };
203 found = vertexTest(0) && vertexTest(1) && vertexTest(2) && vertexTest(3);
204 if (found) {
205 break;
206 }
207 }
208 QVERIFY2(found, qPrintable(QStringLiteral("%0, %1 / %2, %3").arg(QString::number(actualQuad.left()), QString::number(actualQuad.top()), QString::number(actualQuad.right()), QString::number(actualQuad.bottom()))));
209 }
210}
211
213
214#include "windowquadlisttest.moc"
Class representing one area of a window.
double left() const
double bottom() const
double right() const
double top() const
WindowQuadList makeGrid(int maxquadsize) const
WindowQuadList makeRegularGrid(int xSubdivisions, int ySubdivisions) const
Vertex class.
double x() const
double u() const
double v() const
double y() const
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
QTEST_MAIN(OnScreenNotificationTest)