GCC Code Coverage Report


Directory: ./
File: autotests/testqscreenbackend.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 107 113 94.7%
Branches: 53 106 50.0%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
3 * Copyright 2012 by Sebastian K├╝gler <sebas@kde.org> *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Lesser General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2.1 of the License, or (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Lesser General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with this library; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18 *************************************************************************************/
19 #include <QElapsedTimer>
20 #include <QObject>
21 #include <QtTest>
22
23 #include "backendmanager_p.h"
24 #include "config.h"
25 #include "getconfigoperation.h"
26 #include "mode.h"
27 #include "output.h"
28
29 Q_LOGGING_CATEGORY(DISMAN_QSCREEN, "disman.qscreen")
30
31 using namespace Disman;
32
33 class testQScreenBackend : public QObject
34 {
35 Q_OBJECT
36
37 private Q_SLOTS:
38 void initTestCase();
39 void verifyConfig();
40 void verifyScreen();
41 void verifyOutputs();
42 void verifyModes();
43 void verifyFeatures();
44 void commonUsagePattern();
45 void cleanupTestCase();
46
47 private:
48 QProcess m_process;
49 ConfigPtr m_config;
50 QString m_backend;
51 };
52
53 1 void testQScreenBackend::initTestCase()
54 {
55 1 qputenv("DISMAN_LOGGING", "false");
56 1 qputenv("DISMAN_BACKEND", "qscreen");
57 1 qputenv("DISMAN_IN_PROCESS", "1");
58 1 Disman::BackendManager::instance()->shutdown_backend();
59
60 1 m_backend = QString::fromLocal8Bit(qgetenv("DISMAN_BACKEND"));
61
62 1 QElapsedTimer t;
63 1 t.start();
64 1 auto* op = new GetConfigOperation();
65 1 op->exec();
66 1 m_config = op->config();
67 1 const int n = t.nsecsElapsed();
68 1 qDebug() << "Test took: " << n << "ns";
69 1 }
70
71 1 void testQScreenBackend::verifyConfig()
72 {
73
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(m_config);
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!m_config) {
75 QSKIP("QScreenbackend invalid", SkipAll);
76 }
77 }
78
79 1 void testQScreenBackend::verifyScreen()
80 {
81 1 ScreenPtr screen = m_config->screen();
82
83
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->min_size().width() <= screen->max_size().width());
84
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->min_size().height() <= screen->max_size().height());
85
86
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->min_size().width() <= screen->current_size().width());
87
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->min_size().height() <= screen->current_size().height());
88
89
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->max_size().width() >= screen->current_size().width());
90
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 QVERIFY(screen->max_size().height() >= screen->current_size().height());
91
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QVERIFY(m_config->screen()->max_outputs_count() > 0);
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
93
94 1 void testQScreenBackend::verifyOutputs()
95 {
96
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(m_config->primary_output());
97
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (m_backend == QLatin1String("screen")) {
98 QCOMPARE(m_config->outputs().size(), QGuiApplication::screens().size());
99 }
100
101 1 const Disman::OutputPtr primary = m_config->primary_output();
102
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QVERIFY(primary->enabled());
103 // qDebug() << "Primary geometry? " << primary->geometry();
104 // qDebug() << " prim modes: " << primary->modes();
105
106 1 QList<int> ids;
107
2/2
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
2 for (auto const& [key, output] : m_config->outputs()) {
108 1 qDebug() << " _____________________ Output: " << output;
109 1 qDebug() << " output name: " << output->name().c_str();
110 1 qDebug() << " output modes: " << output->modes().size();
111
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
2 for (auto const& [key, mode] : output->modes()) {
112 1 qDebug() << " " << mode;
113 1 }
114 1 qDebug() << " output enabled: " << output->enabled();
115 1 qDebug() << " output physical_size : " << output->physical_size();
116
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(output->name().size());
117
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QVERIFY(output->id() > -1);
118
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QVERIFY(output->enabled());
119
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(output->geometry() != QRectF(1, 1, 1, 1));
120
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(output->geometry() != QRectF());
121
122 // Pass, but leave a note, when the x server doesn't report physical size
123
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (!output->physical_size().isValid()) {
124 QEXPECT_FAIL(
125 "", "The X server doesn't return a sensible physical output size", Continue);
126 QVERIFY(output->physical_size() != QSize());
127 }
128
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(output->rotation(), Output::None);
129
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!ids.contains(output->id()));
130 1 ids << output->id();
131
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
132
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
133
134 1 void testQScreenBackend::verifyModes()
135 {
136 1 const Disman::OutputPtr primary = m_config->primary_output();
137
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(primary);
138
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(primary->modes().size() > 0);
139
140
2/2
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
2 for (auto const& [output_key, output] : m_config->outputs()) {
141
2/2
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
2 for (auto const& [mode_key, mode] : output->modes()) {
142 1 qDebug() << " Mode : " << mode->name().c_str();
143
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(!mode->name().empty());
144
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QVERIFY(mode->refresh() > 0);
145
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(mode->size() != QSize());
146
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
147
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
148
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
149
150 1 void testQScreenBackend::commonUsagePattern()
151 {
152 1 auto* op = new GetConfigOperation();
153 1 op->exec();
154
155 1 auto outputs = op->config()->outputs();
156
157 1 QVariantList outputList;
158
2/2
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
2 for (auto const& [key, output] : outputs) {
159 1 QVariantMap info;
160 2 info[QStringLiteral("id")] = output->id();
161 2 info[QStringLiteral("enabled")] = output->enabled();
162 2 info[QStringLiteral("rotation")] = output->rotation();
163
164 1 QVariantMap pos;
165 2 pos[QStringLiteral("x")] = output->position().x();
166 2 pos[QStringLiteral("y")] = output->position().y();
167 2 info[QStringLiteral("pos")] = pos;
168
169
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (output->enabled()) {
170 1 const Disman::ModePtr mode = output->auto_mode();
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!mode) {
172 // qWarning() << "CurrentMode is null" << output->name();
173 return;
174 }
175
176 1 QVariantMap modeInfo;
177 2 modeInfo[QStringLiteral("refresh")] = mode->refresh();
178
179 1 QVariantMap modeSize;
180 2 modeSize[QStringLiteral("width")] = mode->size().width();
181 2 modeSize[QStringLiteral("height")] = mode->size().height();
182 2 modeInfo[QStringLiteral("size")] = modeSize;
183
184 2 info[QStringLiteral("mode")] = modeInfo;
185
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 }
186
187 1 outputList.append(info);
188
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
189
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
190
191 1 void testQScreenBackend::cleanupTestCase()
192 {
193 1 Disman::BackendManager::instance()->shutdown_backend();
194 1 qApp->exit(0);
195 1 }
196
197 1 void testQScreenBackend::verifyFeatures()
198 {
199 1 GetConfigOperation* op = new GetConfigOperation();
200 1 op->exec();
201 1 auto config = op->config();
202
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(config->supported_features().testFlag(Config::Feature::None));
203
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Config::Feature::Writable));
204
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(!config->supported_features().testFlag(Config::Feature::PrimaryDisplay));
205
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
206
207 1 QTEST_MAIN(testQScreenBackend)
208
209 #include "testqscreenbackend.moc"
210