Changeset View
Changeset View
Standalone View
Standalone View
libcolorcorrect/autotests/nightcolortest.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program 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 | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | *********************************************************************/ | ||||
17 | #include "mock_kwin.h" | ||||
18 | #include "qtest_dbus.h" | ||||
19 | | ||||
20 | #include "../colorcorrectconstants.h" | ||||
21 | #include "../compositorcoloradaptor.h" | ||||
22 | | ||||
23 | #include <QtTest/QtTest> | ||||
24 | | ||||
25 | using namespace ColorCorrect; | ||||
26 | | ||||
27 | class TestNightColor : public QObject | ||||
28 | { | ||||
29 | Q_OBJECT | ||||
30 | private Q_SLOTS: | ||||
31 | void initTestCase(); | ||||
32 | void cleanupTestCase(); | ||||
33 | | ||||
34 | void testAdaptorInit(); | ||||
35 | void testStageData_data(); | ||||
36 | void testStageData(); | ||||
37 | void testAutoLocationUpdate(); | ||||
38 | private: | ||||
39 | void setCompBackToDefault() { | ||||
40 | m_comp->nightColorAvailable = true; | ||||
41 | | ||||
42 | m_comp->activeEnabled = true; | ||||
43 | m_comp->active = true; | ||||
44 | | ||||
45 | m_comp->modeEnabled = true; | ||||
46 | m_comp->mode = 0; | ||||
47 | | ||||
48 | m_comp->nightTemperatureEnabled = true; | ||||
49 | m_comp->nightTemperature = DEFAULT_NIGHT_TEMPERATURE; | ||||
50 | | ||||
51 | m_comp->running = false; | ||||
52 | m_comp->currentColorTemperature = NEUTRAL_TEMPERATURE; | ||||
53 | | ||||
54 | m_comp->latitudeAuto = 0; | ||||
55 | m_comp->longitudeAuto = 0; | ||||
56 | | ||||
57 | m_comp->locationEnabled = true; | ||||
58 | m_comp->latitudeFixed = 0; | ||||
59 | m_comp->longitudeFixed = 0; | ||||
60 | | ||||
61 | m_comp->timingsEnabled = true; | ||||
62 | m_comp->morningBeginFixed = QTime(6,0,0); | ||||
63 | m_comp->eveningBeginFixed = QTime(18,0,0); | ||||
64 | m_comp->transitionTime = FALLBACK_SLOW_UPDATE_TIME; | ||||
65 | } | ||||
66 | | ||||
67 | kwin_dbus *m_comp = nullptr; | ||||
68 | }; | ||||
69 | | ||||
70 | void TestNightColor::initTestCase() | ||||
71 | { | ||||
72 | m_comp = new kwin_dbus; | ||||
73 | QVERIFY(m_comp->registerDBus()); | ||||
74 | } | ||||
75 | | ||||
76 | void TestNightColor::cleanupTestCase() | ||||
77 | { | ||||
78 | QVERIFY(m_comp->unregisterDBus()); | ||||
79 | delete m_comp; | ||||
80 | m_comp = nullptr; | ||||
81 | } | ||||
82 | | ||||
83 | void TestNightColor::testAdaptorInit() | ||||
84 | { | ||||
85 | m_comp->nightColorAvailable = false; | ||||
86 | CompositorAdaptor *adaptor = new CompositorAdaptor(this); | ||||
87 | QVERIFY(!adaptor->nightColorAvailable()); | ||||
88 | delete adaptor; | ||||
89 | m_comp->nightColorAvailable = true; | ||||
90 | adaptor = new CompositorAdaptor(this); | ||||
91 | QVERIFY(adaptor->nightColorAvailable()); | ||||
92 | delete adaptor; | ||||
93 | } | ||||
94 | | ||||
95 | void TestNightColor::testStageData_data() | ||||
96 | { | ||||
97 | QTest::addColumn<bool>("active"); | ||||
98 | QTest::addColumn<int>("mode"); | ||||
99 | QTest::addColumn<int>("nightTemperature"); | ||||
100 | QTest::addColumn<double>("latitudeFixed"); | ||||
101 | QTest::addColumn<double>("longitudeFixed"); | ||||
102 | QTest::addColumn<QTime>("morningBeginFixed"); | ||||
103 | QTest::addColumn<QTime>("eveningBeginFixed"); | ||||
104 | QTest::addColumn<int>("transitionTime"); | ||||
105 | QTest::addColumn<bool>("isChange"); | ||||
106 | QTest::addColumn<bool>("isChangeAll"); | ||||
107 | QTest::addColumn<bool>("changeExpectFailure"); | ||||
108 | | ||||
109 | QTest::newRow("noChange") << true << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << false << false << false; | ||||
110 | QTest::newRow("wrongChange") << true << 0 << 9001 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true; | ||||
111 | QTest::newRow("temperature") << true << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false; | ||||
112 | QTest::newRow("deactivate+temperature") << false << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false; | ||||
113 | QTest::newRow("location+differentMode") << true << 2 << 0 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false; | ||||
114 | QTest::newRow("time+defaultMode") << true << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << false << true << false; | ||||
115 | QTest::newRow("location+mode") << true << 1 << DEFAULT_NIGHT_TEMPERATURE << 50. << -20. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false; | ||||
116 | QTest::newRow("time+mode") << false << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << true << true << false; | ||||
117 | } | ||||
118 | | ||||
119 | void TestNightColor::testStageData() | ||||
120 | { | ||||
121 | QFETCH(bool, active); | ||||
122 | QFETCH(int, mode); | ||||
123 | QFETCH(int, nightTemperature); | ||||
124 | QFETCH(double, latitudeFixed); | ||||
125 | QFETCH(double, longitudeFixed); | ||||
126 | QFETCH(QTime, morningBeginFixed); | ||||
127 | QFETCH(QTime, eveningBeginFixed); | ||||
128 | QFETCH(int, transitionTime); | ||||
129 | QFETCH(bool, isChange); | ||||
130 | QFETCH(bool, isChangeAll); | ||||
131 | QFETCH(bool, changeExpectFailure); | ||||
132 | | ||||
133 | setCompBackToDefault(); | ||||
134 | m_comp->configChangeExpectSuccess = !changeExpectFailure; | ||||
135 | | ||||
136 | CompositorAdaptor *aptr = new CompositorAdaptor(this); | ||||
137 | QSignalSpy *dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated())); | ||||
138 | QVERIFY(dataUpdateSpy->isValid()); | ||||
139 | | ||||
140 | QCOMPARE(aptr->checkStaged(), false); | ||||
141 | QCOMPARE(aptr->checkStagedAll(), false); | ||||
142 | | ||||
143 | auto setAdaptorStaged = [&aptr, | ||||
144 | &active, &mode, &nightTemperature, | ||||
145 | &latitudeFixed, &longitudeFixed, | ||||
146 | &morningBeginFixed, &eveningBeginFixed, &transitionTime]() { | ||||
147 | aptr->setActiveStaged(active); | ||||
148 | aptr->setModeStaged(mode); | ||||
149 | aptr->setNightTemperatureStaged(nightTemperature); | ||||
150 | aptr->setLatitudeFixedStaged(latitudeFixed); | ||||
151 | aptr->setLongitudeFixedStaged(longitudeFixed); | ||||
152 | aptr->setMorningBeginFixedStaged(morningBeginFixed); | ||||
153 | aptr->setEveningBeginFixedStaged(eveningBeginFixed); | ||||
154 | aptr->setTransitionTimeStaged(transitionTime); | ||||
155 | }; | ||||
156 | setAdaptorStaged(); | ||||
157 | QCOMPARE(aptr->checkStaged(), isChange); | ||||
158 | QCOMPARE(aptr->checkStagedAll(), isChangeAll); | ||||
159 | | ||||
160 | // send config relative to active and mode state | ||||
161 | aptr->sendConfiguration(); | ||||
162 | // give dbus communication time | ||||
163 | QTest::qWait(300); | ||||
164 | QCOMPARE(dataUpdateSpy->isEmpty(), changeExpectFailure); | ||||
165 | QCOMPARE(aptr->checkStaged(), changeExpectFailure); | ||||
166 | | ||||
167 | // reset compositor and adaptor - now send all data at once | ||||
168 | setCompBackToDefault(); | ||||
169 | delete aptr; | ||||
170 | aptr = new CompositorAdaptor(this); | ||||
171 | dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated())); | ||||
172 | QVERIFY(dataUpdateSpy->isValid()); | ||||
173 | | ||||
174 | QCOMPARE(aptr->checkStaged(), false); | ||||
175 | QCOMPARE(aptr->checkStagedAll(), false); | ||||
176 | | ||||
177 | setAdaptorStaged(); | ||||
178 | QCOMPARE(aptr->checkStaged(), isChange); | ||||
179 | QCOMPARE(aptr->checkStagedAll(), isChangeAll); | ||||
180 | // dump all config | ||||
181 | aptr->sendConfigurationAll(); | ||||
182 | // give dbus communication time | ||||
183 | QTest::qWait(300); | ||||
184 | QCOMPARE(dataUpdateSpy->isEmpty(), changeExpectFailure); | ||||
185 | QCOMPARE(aptr->checkStaged(), changeExpectFailure); | ||||
186 | QCOMPARE(aptr->checkStagedAll(), changeExpectFailure); | ||||
187 | } | ||||
188 | | ||||
189 | void TestNightColor::testAutoLocationUpdate() | ||||
190 | { | ||||
191 | setCompBackToDefault(); | ||||
192 | | ||||
193 | CompositorAdaptor *aptr = new CompositorAdaptor(this); | ||||
194 | QSignalSpy *dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated())); | ||||
195 | QVERIFY(dataUpdateSpy->isValid()); | ||||
196 | | ||||
197 | aptr->sendAutoLocationUpdate(10, 20); | ||||
198 | QTest::qWait(300); | ||||
199 | QCOMPARE(dataUpdateSpy->isEmpty(), false); | ||||
200 | } | ||||
201 | | ||||
202 | QTEST_GUILESS_MAIN_SYSTEM_DBUS(TestNightColor) | ||||
203 | | ||||
204 | #include "nightcolortest.moc" |