diff --git a/autotests/testinprocess.cpp b/autotests/testinprocess.cpp --- a/autotests/testinprocess.cpp +++ b/autotests/testinprocess.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "../src/backendmanager_p.h" #include "../src/getconfigoperation.h" @@ -42,6 +43,8 @@ explicit TestInProcess(QObject *parent = nullptr); private Q_SLOTS: + void initTestCase(); + void init(); void cleanup(); @@ -57,6 +60,7 @@ private: ConfigPtr m_config; + bool m_backendServiceInstalled = false; }; @@ -66,6 +70,21 @@ { } +void TestInProcess::initTestCase() +{ + m_backendServiceInstalled = true; + + const QString kscreenServiceName = QStringLiteral("org.kde.KScreen"); + QDBusConnectionInterface *bus = QDBusConnection::sessionBus().interface(); + if (!bus->isServiceRegistered(kscreenServiceName)) { + auto reply = bus->startService(kscreenServiceName); + if (!reply.isValid()) { + qDebug() << "D-Bus service org.kde.KScreen could not be started, skipping out-of-process tests"; + m_backendServiceInstalled = false; + } + } +} + void TestInProcess::init() { qputenv("KSCREEN_LOGGING", "false"); @@ -118,18 +137,22 @@ QVERIFY(ic->isValid()); QVERIFY(ic->outputs().count()); + KScreen::ConfigPtr xc(nullptr); + if (m_backendServiceInstalled) { qDebug() << "TT xrandr out-of-process"; // Load the xrandr backend out-of-process qputenv("KSCREEN_BACKEND", "QScreen"); qputenv("KSCREEN_BACKEND_INPROCESS", "0"); BackendManager::instance()->setMethod(BackendManager::OutOfProcess); auto xp = new GetConfigOperation(); QCOMPARE(BackendManager::instance()->method(), BackendManager::OutOfProcess); QVERIFY(xp->exec()); - auto xc = xp->config(); + xc = xp->config(); QVERIFY(xc != nullptr); QVERIFY(xc->isValid()); QVERIFY(xc->outputs().count()); + } + qDebug() << "TT fake in-process"; qputenv("KSCREEN_BACKEND_INPROCESS", "1"); @@ -146,7 +169,9 @@ QVERIFY(oc->isValid()); QVERIFY(ic->isValid()); - QVERIFY(xc->isValid()); + if (xc) { + QVERIFY(xc->isValid()); + } QVERIFY(fc->isValid()); } @@ -194,6 +219,7 @@ // Check if all our configs are still valid after the backend is gone KScreen::BackendManager::instance()->shutdownBackend(); + if (m_backendServiceInstalled) { //qputenv("KSCREEN_BACKEND", "QScreen"); qputenv("KSCREEN_BACKEND_INPROCESS", "0"); BackendManager::instance()->setMethod(BackendManager::OutOfProcess); @@ -227,6 +253,7 @@ qDebug() << "cached oop: " << ((qreal)t_x_warm / 1000000); qDebug() << "cold in process: " << ((qreal)t_cold / 1000000); qDebug() << "cached in process: " << ((qreal)t_warm / 1000000); + } } void TestInProcess::testCreateJob() @@ -243,7 +270,7 @@ QVERIFY(cc != nullptr); QVERIFY(cc->isValid()); } - { + if (m_backendServiceInstalled) { BackendManager::instance()->setMethod(BackendManager::OutOfProcess); auto op = new GetConfigOperation(); auto _op = qobject_cast(op);