Warning, file /plasma/plasma-workspace/shell/coronatesthelper.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "coronatesthelper.h"
0008 #include "debug.h"
0009 
0010 #include <PlasmaQuick/AppletQuickItem>
0011 #include <QGuiApplication>
0012 
0013 using namespace Plasma;
0014 
0015 CoronaTestHelper::CoronaTestHelper(Corona *parent)
0016     : QObject(parent)
0017     , m_corona(parent)
0018     , m_exitcode(0)
0019 {
0020     connect(m_corona, &Corona::startupCompleted, this, &CoronaTestHelper::initialize);
0021 }
0022 
0023 void CoronaTestHelper::processContainment(Plasma::Containment *containment)
0024 {
0025     foreach (Plasma::Applet *applet, containment->applets()) {
0026         processApplet(applet);
0027     }
0028     connect(containment, &Plasma::Containment::appletAdded, this, &CoronaTestHelper::processApplet);
0029 }
0030 
0031 void CoronaTestHelper::processApplet(Plasma::Applet *applet)
0032 {
0033     PlasmaQuick::AppletQuickItem *obj = PlasmaQuick::AppletQuickItem::itemForApplet(applet);
0034     if (applet->failedToLaunch()) {
0035         qCWarning(PLASMASHELL) << "cannot test an applet with a launch error" << applet->launchErrorMessage();
0036         qGuiApp->exit(1);
0037         return;
0038     }
0039     if (!obj) {
0040         qCWarning(PLASMASHELL) << "cannot get AppletQuickItem for applet";
0041         qGuiApp->exit(1);
0042         return;
0043     }
0044 
0045     auto testObject = obj->testItem();
0046     if (!testObject) {
0047         qCWarning(PLASMASHELL) << "no test for" << applet->title();
0048         return;
0049     }
0050     integrateTest(testObject);
0051 }
0052 
0053 void CoronaTestHelper::integrateTest(QObject *testObject)
0054 {
0055     if (m_registeredTests.contains(testObject))
0056         return;
0057 
0058     const int signal = testObject->metaObject()->indexOfSignal("done()");
0059     if (signal < 0) {
0060         qCWarning(PLASMASHELL) << "the test object should offer a 'done()' signal" << testObject;
0061         return;
0062     }
0063     if (testObject->metaObject()->indexOfProperty("failed") < 0) {
0064         qCWarning(PLASMASHELL) << "the test object should offer a 'bool failed' property" << testObject;
0065         return;
0066     }
0067 
0068     qCDebug(PLASMASHELL) << "Test registered" << testObject;
0069     m_tests.insert(testObject);
0070     m_registeredTests << testObject;
0071 
0072     connect(testObject, SIGNAL(done()), this, SLOT(testFinished()));
0073 }
0074 
0075 void CoronaTestHelper::testFinished()
0076 {
0077     QObject *testObject = sender();
0078 
0079     const bool failed = testObject->property("failed").toBool();
0080     m_exitcode += failed;
0081     m_tests.remove(testObject);
0082 
0083     qCWarning(PLASMASHELL) << "test finished" << testObject << failed << "remaining" << m_tests;
0084     if (m_tests.isEmpty()) {
0085         qGuiApp->exit(m_exitcode);
0086     }
0087 }
0088 
0089 void CoronaTestHelper::initialize()
0090 {
0091     foreach (Plasma::Containment *containment, m_corona->containments()) {
0092         processContainment(containment);
0093     }
0094     connect(m_corona, &Corona::containmentAdded, this, &CoronaTestHelper::processContainment);
0095 
0096     if (m_tests.isEmpty()) {
0097         qCWarning(PLASMASHELL) << "no tests found for the corona" << QCoreApplication::instance()->arguments();
0098         qGuiApp->exit();
0099         return;
0100     }
0101 }