GCC Code Coverage Report


Directory: ./
File: autotests/testedid.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 122 122 100.0%
Branches: 39 70 55.7%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright 2018 by Frederik Gladhorn <gladhorn@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 <QCoreApplication>
19 #include <QObject>
20 #include <QtTest>
21 #include <memory>
22
23 #include "edid.h"
24
25 using namespace Disman;
26
27
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
1 Q_DECLARE_METATYPE(std::string)
28
29 class TestEdid : public QObject
30 {
31 Q_OBJECT
32
33 private Q_SLOTS:
34 void initTestCase();
35 void testInvalid();
36 void testEdidParser_data();
37 void testEdidParser();
38 };
39
40 1 void TestEdid::initTestCase()
41 {
42 1 qputenv("DISMAN_LOGGING", "false");
43 1 qputenv("DISMAN_IN_PROCESS", "1");
44 1 qputenv("DISMAN_BACKEND", "fake");
45 1 }
46
47 1 void TestEdid::testInvalid()
48 {
49 1 std::unique_ptr<Edid> e(new Edid("some random data"));
50
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(e->isValid(), false);
51
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(e->name().size(), 0);
52
53 1 std::unique_ptr<Edid> e2(new Edid(*e.get()));
54
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(e2->isValid(), false);
55
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(e2->name().size(), 0);
56
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
57
58 1 void TestEdid::testEdidParser_data()
59 {
60 // The raw edid data
61 1 QTest::addColumn<QByteArray>("raw_edid");
62 1 QTest::addColumn<std::string>("deviceId");
63 1 QTest::addColumn<std::string>("name");
64 1 QTest::addColumn<std::string>("pnpId");
65 // List of potential vendor names, this depends on the availablility
66 // of pnp.ids, otherwise it will be a three letter abbreviation.
67 1 QTest::addColumn<QStringList>("vendor");
68 1 QTest::addColumn<std::string>("serial");
69 1 QTest::addColumn<std::string>("eisaId");
70 1 QTest::addColumn<std::string>("hash");
71 1 QTest::addColumn<uint>("width");
72 1 QTest::addColumn<uint>("height");
73 1 QTest::addColumn<qreal>("gamma");
74
75 1 QTest::addColumn<QQuaternion>("red");
76 1 QTest::addColumn<QQuaternion>("green");
77 1 QTest::addColumn<QQuaternion>("blue");
78 1 QTest::addColumn<QQuaternion>("white");
79
80 2 QTest::addRow("cor") << QByteArray::fromBase64(
81 "AP///////"
82 "wAN8iw0AAAAABwVAQOAHRB4CoPVlFdSjCccUFQAAAABAQEBAQEBAQEBAQEBAQEBEhtWWlAAGTAwIDYAJaQQAAAYEht"
83 "WWlAAGTAwIDYAJaQQAAAYAAAA/gBBVU8KICAgICAgICAgAAAA/gBCMTMzWFcwMyBWNCAKAIc=")
84 // device-id
85 2 << std::string("xrandr-Corollary Inc")
86 // name
87 2 << std::string("")
88 // pnp-id, vendor
89 2 << std::string("COR")
90
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
5 << QStringList({QStringLiteral("COR"), QStringLiteral("Corollary Inc")})
91 // serial, eisa-id
92 2 << std::string("")
93 2 << std::string("B133XW03 V4")
94 // hash, width, height
95 2 << std::string("82266089b3f9da3a8c48de1ec81b09e1") << 29U
96 2 << 16U
97 // gamma
98 2 << 2.2
99 // colors: rgbw
100 1 << QQuaternion(1, QVector3D(0.580078, 0.339844, 0))
101 1 << QQuaternion(1, QVector3D(0.320313, 0.549805, 0))
102 1 << QQuaternion(1, QVector3D(0.155273, 0.110352, 0))
103 12 << QQuaternion(1, QVector3D(0.313477, 0.329102, 0));
104
105 2 QTest::addRow("dell") << QByteArray::fromBase64(
106 "AP///////"
107 "wAQrBbwTExLQQ4WAQOANCB46h7Frk80sSYOUFSlSwCBgKlA0QBxTwEBAQEBAQEBKDyAoHCwI0AwIDYABkQhAAAaAAA"
108 "A/wBGNTI1TTI0NUFLTEwKAAAA/ABERUxMIFUyNDEwCiAgAAAA/"
109 "QA4TB5REQAKICAgICAgAToCAynxUJAFBAMCBxYBHxITFCAVEQYjCQcHZwMMABAAOC2DAQAA4wUDAQI6gBhxOC1AWCx"
110 "FAAZEIQAAHgEdgBhxHBYgWCwlAAZEIQAAngEdAHJR0B4gbihVAAZEIQAAHowK0Iog4C0QED6WAAZEIQAAGAAAAAAAA"
111 "AAAAAAAAAAAPg==")
112 // device-id
113 2 << std::string("xrandr-Dell Inc.-DELL U2410-F525M245AKLL")
114 // name
115 2 << std::string("DELL U2410")
116 // pnp-id, vendor
117 2 << std::string("DEL")
118
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
5 << QStringList({QStringLiteral("DEL"), QStringLiteral("Dell Inc.")})
119 // serial, eisa-id
120 2 << std::string("F525M245AKLL")
121 2 << std::string("")
122 // hash, width, height
123 2 << std::string("be55eeb5fcc1e775f321c1ae3aa02ef0") << 52U
124 2 << 32U
125 // gamma
126 2 << 2.2
127 // colors: rgbw
128 1 << QQuaternion(1, QVector3D(0.679688, 0.308594, 0))
129 1 << QQuaternion(1, QVector3D(0.206055, 0.693359, 0))
130 1 << QQuaternion(1, QVector3D(0.151367, 0.0546875, 0))
131 12 << QQuaternion(1, QVector3D(0.313477, 0.329102, 0));
132
133 2 QTest::addRow("samsung") << QByteArray::fromBase64(
134 "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/"
135 "h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4=")
136 // device-id
137 2 << std::string("xrandr-Samsung Electric Company-SyncMaster-H9MZ302196")
138 // name
139 2 << std::string("SyncMaster")
140 // pnp-id, vendor
141 2 << std::string("SAM")
142
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
6 << QStringList({QStringLiteral("SAM"),
143 4 QStringLiteral("Samsung Electric Company")})
144 // serial, eisa-id
145 2 << std::string("H9MZ302196")
146 2 << std::string("")
147 // hash, width, height
148 2 << std::string("9384061b2b87ad193f841e07d60e9e1a") << 51U
149 2 << 29U
150 // gamma
151 2 << 2.2
152 // colors: rgbw
153 1 << QQuaternion(1, QVector3D(0.639648, 0.328125, 0))
154 1 << QQuaternion(1, QVector3D(0.299805, 0.599609, 0))
155 1 << QQuaternion(1, QVector3D(0.150391, 0.0595703, 0))
156 12 << QQuaternion(1, QVector3D(0.3125, 0.329102, 0));
157
158 2 QTest::newRow("sharp") << QByteArray::fromBase64(
159 "AP///////"
160 "wBNEEoUAAAAAB4ZAQSlHRF4Dt5Qo1RMmSYPUFQAAAABAQEBAQEBAQEBAQEBAQEBzZGAoMAINHAwIDUAJqUQAAAYpHS"
161 "AoMAINHAwIDUAJqUQAAAYAAAA/gBSWE40OYFMUTEzM1oxAAAAAAACQQMoABIAAAsBCiAgAMw=")
162 // device-id
163 2 << std::string("xrandr-Sharp Corporation")
164 // name, unsure why, this screen reports no name
165 2 << std::string("")
166 // pnp-id, vendor
167 2 << std::string("SHP")
168
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
5 << QStringList(
169 4 {QStringLiteral("SHP"), QStringLiteral("Sharp Corporation")})
170 // serial, eisa-id
171 2 << std::string("")
172 2 << std::string("RXN49-LQ133Z1")
173 // hash, width, height
174 2 << std::string("3627c3534e4c82871967b57237bf5b83") << 29U
175 2 << 17U
176 // gamma
177 2 << 2.2
178 // colors: rgbw
179 1 << QQuaternion(1, QVector3D(0.639648, 0.328125, 0))
180 1 << QQuaternion(1, QVector3D(0.299805, 0.599609, 0))
181 1 << QQuaternion(1, QVector3D(0.149414, 0.0595703, 0))
182 12 << QQuaternion(1, QVector3D(0.3125, 0.328125, 0));
183 1 }
184
185 4 void TestEdid::testEdidParser()
186 {
187 4 QFETCH(QByteArray, raw_edid);
188 4 QFETCH(std::string, deviceId);
189 4 QFETCH(std::string, name);
190 4 QFETCH(std::string, pnpId);
191 4 QFETCH(QStringList, vendor);
192 4 QFETCH(std::string, serial);
193 4 QFETCH(std::string, eisaId);
194 4 QFETCH(std::string, hash);
195 4 QFETCH(uint, width);
196 4 QFETCH(uint, height);
197 4 QFETCH(qreal, gamma);
198 4 QFETCH(QQuaternion, red);
199 4 QFETCH(QQuaternion, green);
200 4 QFETCH(QQuaternion, blue);
201 4 QFETCH(QQuaternion, white);
202
203 4 QScopedPointer<Edid> e(new Edid(raw_edid));
204
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 QCOMPARE(e->isValid(), true);
205
206 // FIXME: we hard-code all deviceIds as xrandr-something, that makes no sense
207
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->deviceId(), deviceId);
208
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->name(), name);
209
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->pnpId(), pnpId);
210 // FIXME: needs to return at least the short ID
211 // QVERIFY2(vendor.contains(e->vendor()),
212 // qPrintable(QString::fromLatin1("%1 not in list").arg(e->vendor())));
213
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->serial(), serial);
214
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->eisaId(), eisaId);
215
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QCOMPARE(e->hash(), hash);
216
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 QCOMPARE(e->width(), width);
217
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 QCOMPARE(e->height(), height);
218
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 QCOMPARE(e->gamma(), gamma);
219
220
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QVERIFY(qFuzzyCompare(e->red(), red));
221
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QVERIFY(qFuzzyCompare(e->green(), green));
222
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QVERIFY(qFuzzyCompare(e->blue(), blue));
223
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QVERIFY(qFuzzyCompare(e->white(), white));
224
9/18
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 4 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 4 times.
✗ Branch 26 not taken.
4 }
225
226 1 QTEST_GUILESS_MAIN(TestEdid)
227
228 #include "testedid.moc"
229