GCC Code Coverage Report


Directory: ./
File: autotests/testscreenconfig.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 169 172 98.3%
Branches: 111 220 50.5%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this library; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
17 *************************************************************************************/
18 #include <QObject>
19 #include <QtTest>
20
21 #include "backendmanager_p.h"
22 #include "config.h"
23 #include "getconfigoperation.h"
24 #include "mode.h"
25 #include "output.h"
26 #include "screen.h"
27 #include "setconfigoperation.h"
28
29 using namespace Disman;
30
31 class testScreenConfig : public QObject
32 {
33 Q_OBJECT
34
35 private:
36 Disman::ConfigPtr getConfig();
37
38 private Q_SLOTS:
39 void initTestCase();
40 void singleOutput();
41 void singleOutputWithoutPreferred();
42 void multiOutput();
43 void configCanBeApplied();
44 void supported_features();
45 void testInvalidMode();
46 void cleanupTestCase();
47 void testOutputPositionNormalization();
48 };
49
50 8 ConfigPtr testScreenConfig::getConfig()
51 {
52 8 qputenv("DISMAN_IN_PROCESS", "1");
53 8 auto* op = new GetConfigOperation();
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (!op->exec()) {
55 qWarning("ConfigOperation error: %s", qPrintable(op->error_string()));
56 BackendManager::instance()->shutdown_backend();
57 return ConfigPtr();
58 }
59
60 8 BackendManager::instance()->shutdown_backend();
61
62 8 return op->config();
63 }
64
65 1 void testScreenConfig::initTestCase()
66 {
67 1 qputenv("DISMAN_LOGGING", "false");
68 1 qputenv("DISMAN_BACKEND", "fake");
69 1 }
70
71 1 void testScreenConfig::cleanupTestCase()
72 {
73 1 BackendManager::instance()->shutdown_backend();
74 1 }
75
76 1 void testScreenConfig::singleOutput()
77 {
78 // json file for the fake backend
79 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleoutput.json");
80
81 1 const ConfigPtr config = getConfig();
82
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(config);
83 1 const ScreenPtr screen = config->screen();
84
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(screen);
85
86
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->min_size(), QSize(320, 200));
87
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->max_size(), QSize(8192, 8192));
88
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->current_size(), QSize(1280, 800));
89
90
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(config->outputs().size(), 1);
91
92 1 const OutputPtr output = config->outputs().at(1);
93
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(output);
94
95
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(config->primary_output());
96
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
1 QCOMPARE(config->primary_output()->id(), output->id());
97
98
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->name(), "LVDS1");
99
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->type(), Output::Panel);
100
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(output->modes().size(), 3);
101
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->position(), QPoint(0, 0));
102
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->geometry(), QRect(0, 0, 1280, 800));
103
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QCOMPARE(output->auto_mode()->id(), "3");
104
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QCOMPARE(output->preferred_mode()->id(), "3");
105
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->rotation(), Output::None);
106
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->scale(), 1.0);
107
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->enabled(), true);
108 // QCOMPARE(output->isEmbedded(), true);
109
110 1 const ModePtr mode = output->auto_mode();
111
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(mode->size(), QSize(1280, 800));
112
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(mode->refresh(), 59900);
113
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
1 }
114
115 1 void testScreenConfig::singleOutputWithoutPreferred()
116 {
117 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleOutputWithoutPreferred.json");
118
119 1 const ConfigPtr config = getConfig();
120
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(config);
121 1 const OutputPtr output = config->outputs().at(1);
122
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(output);
123
124
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(output->preferred_modes().empty());
125
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QCOMPARE(output->preferred_mode()->id(), "3");
126
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
127
128 1 void testScreenConfig::multiOutput()
129 {
130 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "multipleoutput.json");
131
132 1 const ConfigPtr config = getConfig();
133
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(config);
134 1 const ScreenPtr screen = config->screen();
135
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(screen);
136
137
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->min_size(), QSize(320, 200));
138
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->max_size(), QSize(8192, 8192));
139
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(screen->current_size(), QSize(3200, 1880));
140
141
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(config->outputs().size(), 2);
142
143 1 const OutputPtr output = config->outputs().at(2);
144
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(output);
145
146
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(config->primary_output());
147
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
1 QVERIFY(config->primary_output()->id() != output->id());
148
149
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->name(), "HDMI1");
150
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->type(), Output::HDMI);
151
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(output->modes().size(), 4);
152
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->position(), QPoint(1280, 0));
153
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(output->geometry(), QRect(1280, 0, 1920 / 1.4, 1080 / 1.4));
154
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QCOMPARE(output->auto_mode()->id(), "4");
155
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QCOMPARE(output->preferred_mode()->id(), "4");
156
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->rotation(), Output::None);
157
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->scale(), 1.4);
158
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->enabled(), true);
159
160 1 const ModePtr mode = output->auto_mode();
161
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(mode);
162
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(mode->size(), QSize(1920, 1080));
163
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(mode->refresh(), 60000);
164
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
1 }
165
166 1 void testScreenConfig::configCanBeApplied()
167 {
168 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleoutputBroken.json");
169 1 const ConfigPtr brokenConfig = getConfig();
170
171 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleoutput.json");
172 1 const ConfigPtr currentConfig = getConfig();
173
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(currentConfig);
174 1 const OutputPtr primaryBroken = brokenConfig->outputs()[2];
175
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(primaryBroken);
176 1 const OutputPtr currentPrimary = currentConfig->outputs()[1];
177
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(currentPrimary);
178
179
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig));
180 1 primaryBroken->set_id(currentPrimary->id());
181
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig));
182
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig));
183 1 primaryBroken->set_mode(primaryBroken->mode("42"));
184
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig));
185 1 primaryBroken->set_mode(currentPrimary->auto_mode());
186
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig));
187
188 1 primaryBroken->mode("3")->set_size(QSize(1280, 800));
189
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(Config::can_be_applied(brokenConfig));
190
191 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "tooManyOutputs.json");
192 1 const ConfigPtr brokenConfig2 = getConfig();
193
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(brokenConfig2);
194
195 1 int enabledOutputsCount = 0;
196
2/2
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 times.
3 for (auto const& [key, output] : brokenConfig2->outputs()) {
197
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (output->enabled()) {
198 2 ++enabledOutputsCount;
199 }
200 1 }
201
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QVERIFY(brokenConfig2->screen()->max_outputs_count() < enabledOutputsCount);
202
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(brokenConfig2));
203
204 1 const ConfigPtr nulllConfig;
205
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!Config::can_be_applied(nulllConfig));
206
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 }
207
208 1 void testScreenConfig::supported_features()
209 {
210 1 ConfigPtr config = getConfig();
211
212
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::None));
213
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Disman::Config::Feature::Writable));
214
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Disman::Config::Feature::PrimaryDisplay));
215
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Disman::Config::Feature::PerOutputScaling));
216
217 2 config->set_supported_features(Disman::Config::Feature::Writable
218 1 | Disman::Config::Feature::PrimaryDisplay);
219
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::Writable));
220
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::PrimaryDisplay));
221
222 1 config->set_supported_features(Disman::Config::Feature::None);
223
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::None));
224
225 2 config->set_supported_features(Disman::Config::Feature::PerOutputScaling
226 1 | Disman::Config::Feature::Writable);
227
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Disman::Config::Feature::None));
228
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::Writable));
229
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::PerOutputScaling));
230
231 2 config->set_supported_features(Disman::Config::Feature::PerOutputScaling
232 1 | Disman::Config::Feature::Writable
233 1 | Disman::Config::Feature::PrimaryDisplay);
234
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Disman::Config::Feature::None));
235
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::Writable));
236
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::PrimaryDisplay));
237
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Disman::Config::Feature::PerOutputScaling));
238
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
239
240 1 void testScreenConfig::testInvalidMode()
241 {
242 1 auto output = new Disman::Output();
243 1 auto currentMode = output->auto_mode();
244
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!currentMode);
245
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete output;
246
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
247
248 1 void testScreenConfig::testOutputPositionNormalization()
249 {
250 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "multipleoutput.json");
251
252 1 const ConfigPtr config = getConfig();
253
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(config);
254 1 auto left = config->outputs().begin()->second;
255 1 auto right = config->outputs().rbegin()->second;
256
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(left);
257
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(right);
258 1 left->set_position(QPoint(-5000, 700));
259 1 right->set_position(QPoint(-3720, 666));
260
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(left->position(), QPoint(-5000, 700));
261
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(right->position(), QPoint(-3720, 666));
262
263 // start a set operation to fix up the positions
264 {
265 1 auto setop = new SetConfigOperation(config);
266 1 setop->exec();
267 }
268
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(left->position(), QPoint(0, 34));
269
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(right->position(), QPoint(1280, 0));
270
271 // make sure it doesn't touch a valid config
272 {
273 1 auto setop = new SetConfigOperation(config);
274 1 setop->exec();
275 }
276
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(left->position(), QPoint(0, 34));
277
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(right->position(), QPoint(1280, 0));
278
279 // positions of single outputs should be at 0, 0
280 1 left->set_enabled(false);
281 {
282 1 auto setop = new SetConfigOperation(config);
283 1 setop->exec();
284 }
285
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(right->position(), QPoint());
286
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 }
287
288 1 QTEST_MAIN(testScreenConfig)
289
290 #include "testscreenconfig.moc"
291