Changeset View
Changeset View
Standalone View
Standalone View
tests/kded/configtest.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | |||||
110 | void TestConfig::initTestCase() | 110 | void TestConfig::initTestCase() | ||
111 | { | 111 | { | ||
112 | qputenv("KSCREEN_LOGGING", "false"); | 112 | qputenv("KSCREEN_LOGGING", "false"); | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | void TestConfig::testSimpleConfig() | 115 | void TestConfig::testSimpleConfig() | ||
116 | { | 116 | { | ||
117 | auto configWrapper = createConfig(true, false); | 117 | auto configWrapper = createConfig(true, false); | ||
118 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("simpleConfig.json"))); | 118 | configWrapper = configWrapper->readFile(QStringLiteral("simpleConfig.json")); | ||
119 | 119 | | |||
120 | auto config = configWrapper->data(); | 120 | auto config = configWrapper->data(); | ||
121 | QVERIFY(config); | 121 | QVERIFY(config); | ||
122 | QCOMPARE(config->connectedOutputs().count(), 1); | 122 | QCOMPARE(config->connectedOutputs().count(), 1); | ||
123 | 123 | | |||
124 | auto output = config->connectedOutputs().first(); | 124 | auto output = config->connectedOutputs().first(); | ||
125 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 125 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
126 | QCOMPARE(output->currentModeId(), QLatin1String("MODE-4")); | 126 | QCOMPARE(output->currentModeId(), QLatin1String("MODE-4")); | ||
127 | QCOMPARE(output->currentMode()->size(), QSize(1920, 1280)); | 127 | QCOMPARE(output->currentMode()->size(), QSize(1920, 1280)); | ||
128 | QCOMPARE(output->isEnabled(), true); | 128 | QCOMPARE(output->isEnabled(), true); | ||
129 | QCOMPARE(output->rotation(), KScreen::Output::None); | 129 | QCOMPARE(output->rotation(), KScreen::Output::None); | ||
130 | QCOMPARE(output->pos(), QPoint(0, 0)); | 130 | QCOMPARE(output->pos(), QPoint(0, 0)); | ||
131 | QCOMPARE(output->isPrimary(), true); | 131 | QCOMPARE(output->isPrimary(), true); | ||
132 | 132 | | |||
133 | auto screen = config->screen(); | 133 | auto screen = config->screen(); | ||
134 | QCOMPARE(screen->currentSize(), QSize(1920, 1280)); | 134 | QCOMPARE(screen->currentSize(), QSize(1920, 1280)); | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | void TestConfig::testTwoScreenConfig() | 137 | void TestConfig::testTwoScreenConfig() | ||
138 | { | 138 | { | ||
139 | auto configWrapper = createConfig(true, true); | 139 | auto configWrapper = createConfig(true, true); | ||
140 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("twoScreenConfig.json"))); | 140 | configWrapper = configWrapper->readFile(QStringLiteral("twoScreenConfig.json")); | ||
141 | 141 | | |||
142 | auto config = configWrapper->data(); | 142 | auto config = configWrapper->data(); | ||
143 | QVERIFY(config); | 143 | QVERIFY(config); | ||
144 | 144 | | |||
145 | QCOMPARE(config->connectedOutputs().count(), 2); | 145 | QCOMPARE(config->connectedOutputs().count(), 2); | ||
146 | 146 | | |||
147 | auto output = config->connectedOutputs().first(); | 147 | auto output = config->connectedOutputs().first(); | ||
148 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 148 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
Show All 15 Lines | |||||
164 | 164 | | |||
165 | auto screen = config->screen(); | 165 | auto screen = config->screen(); | ||
166 | QCOMPARE(screen->currentSize(), QSize(3200, 1280)); | 166 | QCOMPARE(screen->currentSize(), QSize(3200, 1280)); | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | void TestConfig::testRotatedScreenConfig() | 169 | void TestConfig::testRotatedScreenConfig() | ||
170 | { | 170 | { | ||
171 | auto configWrapper = createConfig(true, true); | 171 | auto configWrapper = createConfig(true, true); | ||
172 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("rotatedScreenConfig.json"))); | 172 | configWrapper = configWrapper->readFile(QStringLiteral("rotatedScreenConfig.json")); | ||
173 | 173 | | |||
174 | auto config = configWrapper->data(); | 174 | auto config = configWrapper->data(); | ||
175 | QVERIFY(config); | 175 | QVERIFY(config); | ||
176 | 176 | | |||
177 | QCOMPARE(config->connectedOutputs().count(), 2); | 177 | QCOMPARE(config->connectedOutputs().count(), 2); | ||
178 | 178 | | |||
179 | auto output = config->connectedOutputs().first(); | 179 | auto output = config->connectedOutputs().first(); | ||
180 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 180 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
Show All 15 Lines | |||||
196 | 196 | | |||
197 | auto screen = config->screen(); | 197 | auto screen = config->screen(); | ||
198 | QCOMPARE(screen->currentSize(), QSize(2944, 1280)); | 198 | QCOMPARE(screen->currentSize(), QSize(2944, 1280)); | ||
199 | } | 199 | } | ||
200 | 200 | | |||
201 | void TestConfig::testDisabledScreenConfig() | 201 | void TestConfig::testDisabledScreenConfig() | ||
202 | { | 202 | { | ||
203 | auto configWrapper = createConfig(true, true); | 203 | auto configWrapper = createConfig(true, true); | ||
204 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("disabledScreenConfig.json"))); | 204 | configWrapper = configWrapper->readFile(QStringLiteral("disabledScreenConfig.json")); | ||
205 | 205 | | |||
206 | auto config = configWrapper->data(); | 206 | auto config = configWrapper->data(); | ||
207 | QVERIFY(config); | 207 | QVERIFY(config); | ||
208 | 208 | | |||
209 | QCOMPARE(config->connectedOutputs().count(), 2); | 209 | QCOMPARE(config->connectedOutputs().count(), 2); | ||
210 | 210 | | |||
211 | auto output = config->connectedOutputs().first(); | 211 | auto output = config->connectedOutputs().first(); | ||
212 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 212 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
Show All 10 Lines | |||||
223 | 223 | | |||
224 | auto screen = config->screen(); | 224 | auto screen = config->screen(); | ||
225 | QCOMPARE(screen->currentSize(), QSize(1920, 1280)); | 225 | QCOMPARE(screen->currentSize(), QSize(1920, 1280)); | ||
226 | } | 226 | } | ||
227 | 227 | | |||
228 | void TestConfig::testConfig404() | 228 | void TestConfig::testConfig404() | ||
229 | { | 229 | { | ||
230 | auto configWrapper = createConfig(true, true); | 230 | auto configWrapper = createConfig(true, true); | ||
231 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("filenotfoundConfig.json"))); | 231 | configWrapper = configWrapper->readFile(QStringLiteral("filenotfoundConfig.json")); | ||
232 | 232 | | |||
233 | QVERIFY(!configWrapper); | 233 | QVERIFY(!configWrapper); | ||
234 | } | 234 | } | ||
235 | 235 | | |||
236 | void TestConfig::testCorruptConfig() | 236 | void TestConfig::testCorruptConfig() | ||
237 | { | 237 | { | ||
238 | auto configWrapper = createConfig(true, true); | 238 | auto configWrapper = createConfig(true, true); | ||
239 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("corruptConfig.json"))); | 239 | configWrapper = configWrapper->readFile(QStringLiteral("corruptConfig.json")); | ||
240 | auto config = configWrapper->data(); | 240 | auto config = configWrapper->data(); | ||
241 | 241 | | |||
242 | QVERIFY(config); | 242 | QVERIFY(config); | ||
243 | QCOMPARE(config->outputs().count(), 2); | 243 | QCOMPARE(config->outputs().count(), 2); | ||
244 | QVERIFY(config->isValid()); | 244 | QVERIFY(config->isValid()); | ||
245 | } | 245 | } | ||
246 | 246 | | |||
247 | void TestConfig::testCorruptEmptyConfig() | 247 | void TestConfig::testCorruptEmptyConfig() | ||
248 | { | 248 | { | ||
249 | auto configWrapper = createConfig(true, true); | 249 | auto configWrapper = createConfig(true, true); | ||
250 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("corruptEmptyConfig.json"))); | 250 | configWrapper = configWrapper->readFile(QStringLiteral("corruptEmptyConfig.json")); | ||
251 | auto config = configWrapper->data(); | 251 | auto config = configWrapper->data(); | ||
252 | 252 | | |||
253 | QVERIFY(config); | 253 | QVERIFY(config); | ||
254 | QCOMPARE(config->outputs().count(), 2); | 254 | QCOMPARE(config->outputs().count(), 2); | ||
255 | QVERIFY(config->isValid()); | 255 | QVERIFY(config->isValid()); | ||
256 | } | 256 | } | ||
257 | 257 | | |||
258 | void TestConfig::testCorruptUselessConfig() | 258 | void TestConfig::testCorruptUselessConfig() | ||
259 | { | 259 | { | ||
260 | auto configWrapper = createConfig(true, true); | 260 | auto configWrapper = createConfig(true, true); | ||
261 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("corruptUselessConfig.json"))); | 261 | configWrapper = configWrapper->readFile(QStringLiteral("corruptUselessConfig.json")); | ||
262 | auto config = configWrapper->data(); | 262 | auto config = configWrapper->data(); | ||
263 | 263 | | |||
264 | QVERIFY(config); | 264 | QVERIFY(config); | ||
265 | QCOMPARE(config->outputs().count(), 2); | 265 | QCOMPARE(config->outputs().count(), 2); | ||
266 | QVERIFY(config->isValid()); | 266 | QVERIFY(config->isValid()); | ||
267 | } | 267 | } | ||
268 | 268 | | |||
269 | void TestConfig::testNullConfig() | 269 | void TestConfig::testNullConfig() | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 286 | { | |||
376 | QHash<QString, QPoint> positions; | 376 | QHash<QString, QPoint> positions; | ||
377 | positions[QStringLiteral("DisplayPort-0")] = QPoint(0, 1080); | 377 | positions[QStringLiteral("DisplayPort-0")] = QPoint(0, 1080); | ||
378 | positions[QStringLiteral("DisplayPort-1")] = QPoint(2100, 30); | 378 | positions[QStringLiteral("DisplayPort-1")] = QPoint(2100, 30); | ||
379 | positions[QStringLiteral("DisplayPort-2")] = QPoint(2100, 1080); | 379 | positions[QStringLiteral("DisplayPort-2")] = QPoint(2100, 1080); | ||
380 | positions[QStringLiteral("DisplayPort-3")] = QPoint(4020, 0); | 380 | positions[QStringLiteral("DisplayPort-3")] = QPoint(4020, 0); | ||
381 | positions[QStringLiteral("DVI-0")] = QPoint(4020, 1080); | 381 | positions[QStringLiteral("DVI-0")] = QPoint(4020, 1080); | ||
382 | positions[QStringLiteral("DVI-1")] = QPoint(0, 0); | 382 | positions[QStringLiteral("DVI-1")] = QPoint(0, 0); | ||
383 | 383 | | |||
384 | auto configWrapper2 = std::move(configWrapper.readFile(QStringLiteral("outputgrid_2x3.json"))); | 384 | auto configWrapper2 = configWrapper.readFile(QStringLiteral("outputgrid_2x3.json")); | ||
385 | KScreen::ConfigPtr config2 = configWrapper2->data(); | 385 | KScreen::ConfigPtr config2 = configWrapper2->data(); | ||
386 | QVERIFY(config2); | 386 | QVERIFY(config2); | ||
387 | QVERIFY(config != config2); | 387 | QVERIFY(config != config2); | ||
388 | 388 | | |||
389 | QCOMPARE(config2->connectedOutputs().count(), 6); | 389 | QCOMPARE(config2->connectedOutputs().count(), 6); | ||
390 | Q_FOREACH (auto output, config2->connectedOutputs()) { | 390 | Q_FOREACH (auto output, config2->connectedOutputs()) { | ||
391 | QVERIFY(positions.keys().contains(output->name())); | 391 | QVERIFY(positions.keys().contains(output->name())); | ||
392 | QVERIFY(output->name() != output->hash()); | 392 | QVERIFY(output->name() != output->hash()); | ||
393 | QCOMPARE(positions[output->name()], output->pos()); | 393 | QCOMPARE(positions[output->name()], output->pos()); | ||
394 | QCOMPARE(output->currentMode()->size(), QSize(1920, 1080)); | 394 | QCOMPARE(output->currentMode()->size(), QSize(1920, 1080)); | ||
395 | QCOMPARE(output->currentMode()->refreshRate(), 60.0); | 395 | QCOMPARE(output->currentMode()->refreshRate(), 60.0); | ||
396 | QVERIFY(output->isEnabled()); | 396 | QVERIFY(output->isEnabled()); | ||
397 | } | 397 | } | ||
398 | QCOMPARE(config2->screen()->currentSize(), QSize(5940, 2160)); | 398 | QCOMPARE(config2->screen()->currentSize(), QSize(5940, 2160)); | ||
399 | } | 399 | } | ||
400 | 400 | | |||
401 | void TestConfig::testMoveConfig() | 401 | void TestConfig::testMoveConfig() | ||
402 | { | 402 | { | ||
403 | // Test if restoring a config using Serializer::moveConfig(src, dest) works | 403 | // Test if restoring a config using Serializer::moveConfig(src, dest) works | ||
404 | // https://bugs.kde.org/show_bug.cgi?id=353029 | 404 | // https://bugs.kde.org/show_bug.cgi?id=353029 | ||
405 | 405 | | |||
406 | // Load a dualhead config | 406 | // Load a dualhead config | ||
407 | auto configWrapper = createConfig(true, true); | 407 | auto configWrapper = createConfig(true, true); | ||
408 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("twoScreenConfig.json"))); | 408 | configWrapper = configWrapper->readFile(QStringLiteral("twoScreenConfig.json")); | ||
409 | 409 | | |||
410 | auto config = configWrapper->data(); | 410 | auto config = configWrapper->data(); | ||
411 | QVERIFY(config); | 411 | QVERIFY(config); | ||
412 | 412 | | |||
413 | // Make sure we don't write into TEST_DATA | 413 | // Make sure we don't write into TEST_DATA | ||
414 | QStandardPaths::setTestModeEnabled(true); | 414 | QStandardPaths::setTestModeEnabled(true); | ||
415 | Globals::setDirPath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QStringLiteral("/kscreen/")); | 415 | Globals::setDirPath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QStringLiteral("/kscreen/")); | ||
416 | // TODO: this needs setup of the control directory | 416 | // TODO: this needs setup of the control directory | ||
Show All 31 Lines | |||||
448 | const QString openedPath = closedPath % QStringLiteral("_lidOpened"); | 448 | const QString openedPath = closedPath % QStringLiteral("_lidOpened"); | ||
449 | 449 | | |||
450 | QFile openCfg(openedPath); | 450 | QFile openCfg(openedPath); | ||
451 | QFile closedCfg(closedPath); | 451 | QFile closedCfg(closedPath); | ||
452 | QVERIFY(openCfg.exists()); | 452 | QVERIFY(openCfg.exists()); | ||
453 | QVERIFY(closedCfg.exists()); | 453 | QVERIFY(closedCfg.exists()); | ||
454 | 454 | | |||
455 | // Switcheroolooloo... | 455 | // Switcheroolooloo... | ||
456 | configWrapper = std::move(configWrapper->readOpenLidFile()); | 456 | configWrapper = configWrapper->readOpenLidFile(); | ||
457 | QVERIFY(configWrapper); | 457 | QVERIFY(configWrapper); | ||
458 | 458 | | |||
459 | // Check actual files, src should be gone, dest must exist | 459 | // Check actual files, src should be gone, dest must exist | ||
460 | QVERIFY(!openCfg.exists()); | 460 | QVERIFY(!openCfg.exists()); | ||
461 | QVERIFY(closedCfg.exists()); | 461 | QVERIFY(closedCfg.exists()); | ||
462 | 462 | | |||
463 | // Make sure the laptop panel is enabled and primary again | 463 | // Make sure the laptop panel is enabled and primary again | ||
464 | config = configWrapper->data(); | 464 | config = configWrapper->data(); | ||
465 | 465 | | |||
466 | output = config->connectedOutputs().first(); | 466 | output = config->connectedOutputs().first(); | ||
467 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 467 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
468 | QCOMPARE(output->isEnabled(), true); | 468 | QCOMPARE(output->isEnabled(), true); | ||
469 | QCOMPARE(output->isPrimary(), true); | 469 | QCOMPARE(output->isPrimary(), true); | ||
470 | 470 | | |||
471 | output2 = config->connectedOutputs().last(); | 471 | output2 = config->connectedOutputs().last(); | ||
472 | QCOMPARE(output2->name(), QLatin1String("OUTPUT-2")); | 472 | QCOMPARE(output2->name(), QLatin1String("OUTPUT-2")); | ||
473 | QCOMPARE(output2->isEnabled(), true); | 473 | QCOMPARE(output2->isEnabled(), true); | ||
474 | QCOMPARE(output2->isPrimary(), false); | 474 | QCOMPARE(output2->isPrimary(), false); | ||
475 | 475 | | |||
476 | // Make sure we don't screw up when there's no _lidOpened config | 476 | // Make sure we don't screw up when there's no _lidOpened config | ||
477 | configWrapper = std::move(configWrapper->readOpenLidFile()); | 477 | configWrapper = configWrapper->readOpenLidFile(); | ||
478 | config = configWrapper->data(); | 478 | config = configWrapper->data(); | ||
479 | 479 | | |||
480 | output = config->connectedOutputs().first(); | 480 | output = config->connectedOutputs().first(); | ||
481 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | 481 | QCOMPARE(output->name(), QLatin1String("OUTPUT-1")); | ||
482 | QCOMPARE(output->isEnabled(), true); | 482 | QCOMPARE(output->isEnabled(), true); | ||
483 | QCOMPARE(output->isPrimary(), true); | 483 | QCOMPARE(output->isPrimary(), true); | ||
484 | 484 | | |||
485 | output2 = config->connectedOutputs().last(); | 485 | output2 = config->connectedOutputs().last(); | ||
486 | QCOMPARE(output2->name(), QLatin1String("OUTPUT-2")); | 486 | QCOMPARE(output2->name(), QLatin1String("OUTPUT-2")); | ||
487 | QCOMPARE(output2->isEnabled(), true); | 487 | QCOMPARE(output2->isEnabled(), true); | ||
488 | QCOMPARE(output2->isPrimary(), false); | 488 | QCOMPARE(output2->isPrimary(), false); | ||
489 | } | 489 | } | ||
490 | 490 | | |||
491 | void TestConfig::testFixedConfig() | 491 | void TestConfig::testFixedConfig() | ||
492 | { | 492 | { | ||
493 | // Load a dualhead config | 493 | // Load a dualhead config | ||
494 | auto configWrapper = createConfig(true, true); | 494 | auto configWrapper = createConfig(true, true); | ||
495 | configWrapper = std::move(configWrapper->readFile(QStringLiteral("twoScreenConfig.json"))); | 495 | configWrapper = configWrapper->readFile(QStringLiteral("twoScreenConfig.json")); | ||
496 | auto config = configWrapper->data(); | 496 | auto config = configWrapper->data(); | ||
497 | QVERIFY(config); | 497 | QVERIFY(config); | ||
498 | 498 | | |||
499 | // Make sure we don't write into TEST_DATA | 499 | // Make sure we don't write into TEST_DATA | ||
500 | QStandardPaths::setTestModeEnabled(true); | 500 | QStandardPaths::setTestModeEnabled(true); | ||
501 | Globals::setDirPath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QStringLiteral("/kscreen/")); | 501 | Globals::setDirPath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QStringLiteral("/kscreen/")); | ||
502 | // TODO: this needs setup of the control directory | 502 | // TODO: this needs setup of the control directory | ||
503 | 503 | | |||
Show All 13 Lines |