Warning, file /frameworks/plasma-framework/autotests/pluginloadertest.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: 2013 Sebastian K├╝gler <sebas@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "pluginloadertest.h"
0008 
0009 #include <QDebug>
0010 #include <QSignalSpy>
0011 #include <qtest.h>
0012 
0013 #include <KPluginMetaData>
0014 
0015 #include <plasma/dataengineconsumer.h>
0016 #include <plasma/pluginloader.h>
0017 
0018 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 94)
0019 #include <KPluginInfo>
0020 #endif
0021 
0022 QTEST_MAIN(PluginTest)
0023 
0024 PluginTest::PluginTest()
0025     : m_buildonly(false)
0026 {
0027 }
0028 
0029 void PluginTest::listEngines()
0030 {
0031     QVector<KPluginMetaData> plugins = Plasma::PluginLoader::self()->listDataEngineMetaData();
0032     //     foreach (const KPluginInfo& info, plugins) {
0033     // qDebug() << " Found DataEngine: " << info.pluginName() << info.name();
0034     //     }
0035     qDebug() << " Found " << plugins.count() << " DataEngines";
0036     // Switch to true in order to let tests pass, this test usually will only
0037     // work with plugins installed, but there aren't any in plasma-framework
0038     m_buildonly = plugins.count() == 0;
0039     QVERIFY(plugins.count() > 0 || m_buildonly);
0040 }
0041 
0042 void PluginTest::listAppletCategories()
0043 {
0044     const QStringList cats = Plasma::PluginLoader::self()->listAppletCategories();
0045     qDebug() << "Categories" << cats;
0046     QVERIFY(cats.count() > 0 || m_buildonly);
0047 }
0048 
0049 void PluginTest::listContainmentActions()
0050 {
0051     const QVector<KPluginMetaData> plugins = Plasma::PluginLoader::self()->listContainmentActionsMetaData(QStringLiteral("plasma-shell"));
0052     qDebug() << "Categories: " << plugins.count();
0053     // QVERIFY(plugins.count() > 0 || m_buildonly);
0054 }
0055 
0056 void PluginTest::listContainmentsOfType()
0057 {
0058 #if PLASMA_BUILD_DEPRECATED_SINCE(5, 83)
0059     const KPluginInfo::List plugins = Plasma::PluginLoader::listContainmentsOfType(QStringLiteral("Desktop"));
0060     qDebug() << "Desktop Containments: " << plugins.count();
0061     QVERIFY(plugins.count() > 0 || m_buildonly);
0062 #endif
0063 
0064     const QList<KPluginMetaData> pluginsMetaData = Plasma::PluginLoader::listContainmentsMetaDataOfType(QStringLiteral("Desktop"));
0065     qDebug() << "Desktop Containments MetaData: " << pluginsMetaData.count();
0066     QVERIFY(pluginsMetaData.count() > 0 || m_buildonly);
0067 }
0068 
0069 static const auto source = QStringLiteral("Europe/Sofia");
0070 
0071 void EngineTest::dataUpdated(const QString &s, const Plasma::DataEngine::Data &data)
0072 {
0073     QVERIFY(source == s);
0074     QVERIFY(data["Timezone"] == source);
0075 }
0076 
0077 void PluginTest::loadDataEngine()
0078 {
0079     if (m_buildonly) {
0080         return;
0081     }
0082     QPointer<Plasma::DataEngine> engine;
0083     QPointer<Plasma::DataEngine> nullEngine;
0084     {
0085         Plasma::DataEngineConsumer consumer;
0086         engine = consumer.dataEngine(QStringLiteral("time"));
0087         nullEngine = consumer.dataEngine(QStringLiteral("noop"));
0088         QVERIFY(nullEngine && engine);
0089         QVERIFY(!nullEngine->isValid() && engine->isValid());
0090         {
0091             EngineTest test;
0092             engine->connectSource(source, &test);
0093             QSignalSpy spy(engine, SIGNAL(sourceAdded(QString)));
0094             spy.wait();
0095             QVERIFY(!engine->isEmpty());
0096         }
0097         QSignalSpy spy(engine, SIGNAL(sourceRemoved(QString)));
0098         spy.wait();
0099         QVERIFY(engine->isEmpty());
0100     }
0101     QVERIFY(!nullEngine.isNull() && engine.isNull());
0102 }
0103 
0104 #include "moc_pluginloadertest.cpp"