Warning, file /plasma/kwin/autotests/integration/nightcolor_test.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "kwin_wayland_test.h" 0010 0011 #include "core/outputbackend.h" 0012 #include "plugins/nightcolor/constants.h" 0013 #include "plugins/nightcolor/nightcolormanager.h" 0014 #include "wayland_server.h" 0015 0016 #include <KConfigGroup> 0017 0018 using namespace KWin; 0019 0020 static const QString s_socketName = QStringLiteral("wayland_test_kwin_nightcolor-0"); 0021 0022 class NightColorTest : public QObject 0023 { 0024 Q_OBJECT 0025 private Q_SLOTS: 0026 void initTestCase(); 0027 void init(); 0028 void cleanup(); 0029 0030 void testConfigRead_data(); 0031 void testConfigRead(); 0032 }; 0033 0034 void NightColorTest::initTestCase() 0035 { 0036 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); 0037 QVERIFY(waylandServer()->init(s_socketName)); 0038 QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024))); 0039 0040 kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); 0041 0042 kwinApp()->start(); 0043 QVERIFY(applicationStartedSpy.wait()); 0044 0045 NightColorManager *manager = NightColorManager::self(); 0046 QVERIFY(manager); 0047 } 0048 0049 void NightColorTest::init() 0050 { 0051 QVERIFY(Test::setupWaylandConnection()); 0052 } 0053 0054 void NightColorTest::cleanup() 0055 { 0056 Test::destroyWaylandConnection(); 0057 } 0058 0059 void NightColorTest::testConfigRead_data() 0060 { 0061 QTest::addColumn<bool>("active"); 0062 QTest::addColumn<int>("mode"); 0063 0064 QTest::newRow("activeMode0") << true << 0; 0065 QTest::newRow("activeMode1") << true << 1; 0066 QTest::newRow("activeMode2") << true << 3; 0067 QTest::newRow("notActiveMode2") << false << 2; 0068 QTest::newRow("wrongData1") << false << 4; 0069 } 0070 0071 void NightColorTest::testConfigRead() 0072 { 0073 QFETCH(bool, active); 0074 QFETCH(int, mode); 0075 0076 const bool activeDefault = true; 0077 const int modeDefault = 0; 0078 0079 KConfigGroup cfgGroup = kwinApp()->config()->group("NightColor"); 0080 0081 cfgGroup.writeEntry("Active", activeDefault); 0082 cfgGroup.writeEntry("Mode", modeDefault); 0083 kwinApp()->config()->sync(); 0084 NightColorManager *manager = NightColorManager::self(); 0085 manager->reconfigure(); 0086 0087 QCOMPARE(manager->isEnabled(), activeDefault); 0088 QCOMPARE(manager->mode(), modeDefault); 0089 0090 cfgGroup.writeEntry("Active", active); 0091 cfgGroup.writeEntry("Mode", mode); 0092 kwinApp()->config()->sync(); 0093 0094 manager->reconfigure(); 0095 0096 QCOMPARE(manager->isEnabled(), active); 0097 if (mode > 3 || mode < 0) { 0098 QCOMPARE(manager->mode(), 0); 0099 } else { 0100 QCOMPARE(manager->mode(), mode); 0101 } 0102 } 0103 0104 WAYLANDTEST_MAIN(NightColorTest) 0105 #include "nightcolor_test.moc"