Warning, file /frameworks/kservice/autotests/kplugintradertest.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 "kplugintradertest.h"
0008 #include "nsaplugin.h"
0009 
0010 #include <QTest>
0011 
0012 #include <kplugininfo.h>
0013 #include <kplugintrader.h>
0014 
0015 QTEST_MAIN(PluginTraderTest)
0016 
0017 QT_WARNING_PUSH
0018 QT_WARNING_DISABLE_DEPRECATED
0019 
0020 void PluginTraderTest::initTestCase()
0021 {
0022     QCoreApplication::setLibraryPaths(QStringList() << QCoreApplication::applicationDirPath());
0023 }
0024 
0025 void PluginTraderTest::findPlugin_data()
0026 {
0027     QTest::addColumn<QString>("serviceType");
0028     QTest::addColumn<QString>("constraint");
0029     QTest::addColumn<int>("expectedResult");
0030 
0031     const QString _st = QStringLiteral("KService/NSA");
0032     QString _c;
0033     QTest::newRow("no constraints") << _st << _c << 1;
0034 
0035     _c = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(QStringLiteral("fakeplugin"));
0036     QTest::newRow("by pluginname") << _st << _c << 1;
0037 
0038     _c = QStringLiteral("[X-KDE-PluginInfo-Category] == '%1'").arg(QStringLiteral("Examples"));
0039     QTest::newRow("by category") << _st << _c << 1;
0040 
0041     _c = QStringLiteral("([X-KDE-PluginInfo-Category] == 'Examples') AND ([X-KDE-PluginInfo-Email] == 'sebas@kde.org')");
0042     QTest::newRow("complex query") << _st << _c << 1;
0043 
0044     _c = QStringLiteral("([X-KDE-PluginInfo-Category] == 'Examples') AND ([X-KDE-PluginInfo-Email] == 'prrrrt')");
0045     QTest::newRow("empty query") << _st << _c << 0;
0046 }
0047 
0048 void PluginTraderTest::findPlugin()
0049 {
0050     QFETCH(QString, serviceType);
0051     QFETCH(QString, constraint);
0052     QFETCH(int, expectedResult);
0053     const KPluginInfo::List res = KPluginTrader::self()->query(QString(), serviceType, constraint);
0054     QCOMPARE(res.count(), expectedResult);
0055 }
0056 
0057 void PluginTraderTest::findSomething()
0058 {
0059     const KPluginInfo::List res = KPluginTrader::self()->query(QString());
0060     QVERIFY(res.count() > 0);
0061 }
0062 
0063 void PluginTraderTest::loadPlugin()
0064 {
0065     const QString pluginName(QStringLiteral("fakeplugin"));
0066     const QString serviceType(QStringLiteral("KService/NSA"));
0067     const QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName);
0068 
0069     QObject *plugin = KPluginTrader::createInstanceFromQuery<QObject>(QString(), serviceType, constraint, this);
0070     QVERIFY(plugin != nullptr);
0071     QCOMPARE(plugin->objectName(), QStringLiteral("Test Plugin Spy"));
0072 }