1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
* SPDX-FileCopyrightText: 2014 Daniel Vratil <dvratil@redhat.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#include <QObject>
#include <QSignalSpy>
#include <QTest>
#include "../src/backendmanager_p.h"
#include "../src/config.h"
#include "../src/configmonitor.h"
#include "../src/configoperation.h"
#include "../src/getconfigoperation.h"
#include "../src/output.h"
#include "../src/setconfigoperation.h"
#include <QSignalSpy>
#include "fakebackendinterface.h"
class TestConfigMonitor : public QObject
{
Q_OBJECT
public:
TestConfigMonitor()
{
}
KScreen::ConfigPtr getConfig()
{
auto op = new KScreen::GetConfigOperation();
if (!op->exec()) {
qWarning("Failed to retrieve backend: %s", qPrintable(op->errorString()));
return KScreen::ConfigPtr();
}
return op->config();
}
private Q_SLOTS:
void initTestCase()
{
qputenv("KSCREEN_LOGGING", "false");
qputenv("KSCREEN_BACKEND", "Fake");
// This particular test is only useful for out of process operation, so enforce that
qputenv("KSCREEN_BACKEND_INPROCESS", "0");
KScreen::BackendManager::instance()->shutdownBackend();
}
void cleanupTestCase()
{
KScreen::BackendManager::instance()->shutdownBackend();
}
void testChangeNotifyInProcess()
{
qputenv("KSCREEN_BACKEND_INPROCESS", "1");
KScreen::BackendManager::instance()->shutdownBackend();
KScreen::BackendManager::instance()->setMethod(KScreen::BackendManager::InProcess);
// json file for the fake backend
KScreen::BackendManager::instance()->setBackendArgs({{QStringLiteral("TEST_DATA"), TEST_DATA "singleoutput.json"}});
// Prepare monitor
KScreen::ConfigMonitor *monitor = KScreen::ConfigMonitor::instance();
QSignalSpy spy(monitor, SIGNAL(configurationChanged()));
// Get config and monitor it for changes
KScreen::ConfigPtr config = getConfig();
monitor->addConfig(config);
QSignalSpy enabledSpy(config->outputs().first().data(), SIGNAL(isEnabledChanged()));
auto output = config->outputs().first();
output->setEnabled(false);
auto setop = new KScreen::SetConfigOperation(config);
QVERIFY(!setop->hasError());
setop->exec();
QTRY_VERIFY(!spy.isEmpty());
QCOMPARE(spy.size(), 1);
QCOMPARE(enabledSpy.size(), 1);
QCOMPARE(config->output(1)->isEnabled(), false);
output->setEnabled(false);
auto setop2 = new KScreen::SetConfigOperation(config);
QVERIFY(!setop2->hasError());
setop2->exec();
QTRY_VERIFY(!spy.isEmpty());
QCOMPARE(spy.size(), 2);
}
};
QTEST_MAIN(TestConfigMonitor)
#include "testconfigmonitor.moc"
|