GCC Code Coverage Report


Directory: ./
File: autotests/testmodelistchange.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 90 93 96.8%
Branches: 25 50 50.0%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright 2016 by Sebastian K├╝gler <sebas@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 "configmonitor.h"
24 #include "getconfigoperation.h"
25 #include "mode.h"
26 #include "output.h"
27 #include "setconfigoperation.h"
28
29 using namespace Disman;
30
31 class TestModeMapChange : public QObject
32 {
33 Q_OBJECT
34
35 private:
36 Disman::ConfigPtr getConfig();
37 Disman::ModeMap createModeMap();
38 bool compareModeMap(Disman::ModeMap before, Disman::ModeMap& after);
39
40 QSize s0 = QSize(1920, 1080);
41 QSize s1 = QSize(1600, 1200);
42 QSize s2 = QSize(1280, 1024);
43 QSize s3 = QSize(800, 600);
44 QSize snew = QSize(777, 888);
45 std::string idnew = "666";
46
47 private Q_SLOTS:
48 void initTestCase();
49 void cleanupTestCase();
50
51 void modeListChange();
52 };
53
54 1 ConfigPtr TestModeMapChange::getConfig()
55 {
56 1 qputenv("DISMAN_IN_PROCESS", "1");
57 1 auto* op = new GetConfigOperation();
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!op->exec()) {
59 qWarning("ConfigOperation error: %s", qPrintable(op->error_string()));
60 BackendManager::instance()->shutdown_backend();
61 return ConfigPtr();
62 }
63
64 1 BackendManager::instance()->shutdown_backend();
65
66 1 return op->config();
67 }
68
69 2 Disman::ModeMap TestModeMapChange::createModeMap()
70 {
71
72 2 Disman::ModeMap newmodes;
73 {
74 2 auto _id = std::to_string(11);
75 2 Disman::ModePtr dismanMode(new Disman::Mode);
76 2 dismanMode->set_id(_id);
77 2 dismanMode->set_name(_id);
78 2 dismanMode->set_size(s0);
79 2 dismanMode->set_refresh(60);
80 2 newmodes.insert({_id, dismanMode});
81 2 }
82 {
83 2 auto _id = std::to_string(22);
84 2 Disman::ModePtr dismanMode(new Disman::Mode);
85 2 dismanMode->set_id(_id);
86 2 dismanMode->set_name(_id);
87 2 dismanMode->set_size(s1);
88 2 dismanMode->set_refresh(60);
89 2 newmodes.insert({_id, dismanMode});
90 2 }
91 {
92 2 auto _id = std::to_string(33);
93 2 Disman::ModePtr dismanMode(new Disman::Mode);
94 2 dismanMode->set_id(_id);
95 2 dismanMode->set_name(_id);
96 2 dismanMode->set_size(s2);
97 2 dismanMode->set_refresh(60);
98 2 newmodes.insert({_id, dismanMode});
99 2 }
100 2 return newmodes;
101 }
102
103 1 void TestModeMapChange::initTestCase()
104 {
105 1 qputenv("DISMAN_LOGGING", "false");
106 1 qputenv("DISMAN_BACKEND", "Fake");
107 1 }
108
109 1 void TestModeMapChange::cleanupTestCase()
110 {
111 1 BackendManager::instance()->shutdown_backend();
112 1 }
113
114 1 void TestModeMapChange::modeListChange()
115 {
116 // json file for the fake backend
117 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleoutput.json");
118
119 1 const ConfigPtr config = getConfig();
120
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(config);
121
122 1 auto output = config->outputs().begin()->second;
123
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(output);
124 1 auto modelist = output->modes();
125
126 1 auto mode = modelist.begin()->second;
127 1 mode->set_id("44");
128 1 mode->set_size(QSize(880, 440));
129 1 output->set_modes(modelist);
130
131
1/2
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
1 QCOMPARE(output->modes().begin()->second->id(), "44");
132
1/2
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
1 QCOMPARE(output->modes().begin()->second->size(), QSize(880, 440));
133
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!modelist.empty());
134
135 1 ConfigMonitor::instance()->add_config(config);
136
137 1 auto before = createModeMap();
138 1 output->set_modes(before);
139 1 output->set_modes(before);
140 1 output->set_modes(before);
141
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
1 QCOMPARE(output->modes().begin()->second->size(), s0);
142
1/2
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
1 QCOMPARE(output->modes().begin()->second->id(), "11");
143
144 1 auto after = createModeMap();
145 1 auto firstmode = after.begin()->second;
146
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(firstmode);
147
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 QCOMPARE(firstmode->size(), s0);
148
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QCOMPARE(firstmode->id(), "11");
149 1 firstmode->set_size(snew);
150 1 firstmode->set_id(idnew);
151 1 output->set_modes(after);
152
153 1 auto _id = std::to_string(11);
154 1 Disman::ModePtr dismanMode(new Disman::Mode);
155 1 dismanMode->set_id(_id);
156 1 dismanMode->set_name(_id);
157 1 dismanMode->set_size(s0);
158 1 dismanMode->set_refresh(60);
159 1 before.insert({_id, dismanMode});
160 1 output->set_modes(before);
161
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(output->modes().size(), 3);
162
163 1 auto _id2 = std::to_string(999);
164 1 Disman::ModePtr dismanMode2(new Disman::Mode);
165 1 dismanMode2->set_id(_id2);
166 1 dismanMode2->set_name(_id2);
167 1 dismanMode2->set_size(s0);
168 1 dismanMode2->set_refresh(60);
169 1 before.insert({_id2, dismanMode2});
170 1 output->set_modes(before);
171
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QCOMPARE(output->modes().size(), 4);
172
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
1 QCOMPARE(output->modes()[_id2]->id(), _id2);
173
11/22
✓ 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.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
1 }
174
175 1 QTEST_MAIN(TestModeMapChange)
176
177 #include "testmodelistchange.moc"
178