File indexing completed on 2024-12-01 07:26:00
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2015 Jarosław Staniek <staniek@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include "PluginsTest.h" 0019 0020 #include <KReportPluginManager> 0021 #include <KReportPluginInterface> 0022 #include <KReportPluginMetaData> 0023 0024 #include <KAboutData> 0025 0026 #include <QTest> 0027 #include <QDebug> 0028 #include <QSet> 0029 #include <QList> 0030 0031 QTEST_MAIN(PluginsTest) 0032 0033 const struct Init { 0034 Init() 0035 { 0036 // Initialize before constructing QGuiApplication to avoid issue 0037 // "Qt WebEngine seems to be initialized from a plugin. Please set 0038 // Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute before constructing 0039 // QGuiApplication." 0040 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); 0041 } 0042 } initialize; 0043 0044 void PluginsTest::initTestCase() 0045 { 0046 //QCoreApplication::setLibraryPaths(QStringList() << QDir::currentPath()); 0047 } 0048 0049 void PluginsTest::listPlugins() 0050 { 0051 KReportPluginManager* manager = KReportPluginManager::self(); 0052 QStringList pluginIds = manager->pluginIds(); 0053 qDebug() << pluginIds; 0054 QCOMPARE(pluginIds.toSet().count(), pluginIds.count()); 0055 foreach(const QString &pluginId, pluginIds) { 0056 qDebug() << "Checking" << pluginId; 0057 QVERIFY2(!pluginId.isEmpty(), "Plugin id not empty"); 0058 KReportPluginInterface* iface = manager->plugin(pluginId); 0059 QVERIFY2(iface, "Plugin interface"); 0060 const KReportPluginMetaData *metaData = manager->pluginMetaData(pluginId); 0061 //! @todo info->priority() 0062 QVERIFY2(metaData, "Plugin metadata"); 0063 QCOMPARE(metaData, iface->metaData()); 0064 QVERIFY2(metaData->isValid(), "Plugin is valid"); 0065 QVERIFY(!metaData->id().isEmpty()); 0066 QCOMPARE(metaData->id(), pluginId); 0067 QVERIFY(!metaData->name().isEmpty()); 0068 QVERIFY(!metaData->description().isEmpty()); 0069 QVERIFY(!metaData->iconName().isEmpty()); 0070 QVERIFY(!metaData->authors().isEmpty()); 0071 QVERIFY(!metaData->version().isEmpty()); 0072 QVERIFY(!metaData->website().isEmpty()); 0073 QVERIFY(!metaData->license().isEmpty()); 0074 QCOMPARE(metaData->isStatic(), metaData->fileName().isEmpty()); 0075 } 0076 } 0077 0078 //! Compares @a actual and @a expected set, fails when not equal 0079 //! On failure, all elements are displayed. 0080 #define QCOMPARE_SET(type, actual, expected) \ 0081 do { \ 0082 if (actual == expected) { \ 0083 break; \ 0084 } \ 0085 QTest::qFail(#actual " != " #expected, __FILE__, __LINE__); \ 0086 QList<type> actualList = actual.toList(); \ 0087 QList<type> expectedList = expected.toList(); \ 0088 std::sort(actualList.begin(), actualList.end()); \ 0089 std::sort(expectedList.begin(), expectedList.end()); \ 0090 QList<type>::ConstIterator actualListIt = actualList.constBegin(); \ 0091 QList<type>::ConstIterator expectedListIt = expectedList.constBegin(); \ 0092 const int count = qMax(actualList.count(), expectedList.count()); \ 0093 int i = 0; \ 0094 bool stop; \ 0095 forever { \ 0096 stop = true; \ 0097 QByteArray sign = "!="; \ 0098 QString v1; \ 0099 if (actualListIt == actualList.constEnd()) { \ 0100 v1 = "<none>"; \ 0101 } \ 0102 else { \ 0103 v1 = QVariant(*actualListIt).toString(); \ 0104 stop = false; \ 0105 } \ 0106 QString v2; \ 0107 if (expectedListIt == expectedList.constEnd()) { \ 0108 v2 = "<none>"; \ 0109 } \ 0110 else { \ 0111 v2 = QVariant(*expectedListIt).toString(); \ 0112 stop = false; \ 0113 if (actualListIt != actualList.constEnd()) { \ 0114 if (*actualListIt == *expectedListIt) { \ 0115 sign = "=="; \ 0116 } \ 0117 } \ 0118 } \ 0119 if (stop) { \ 0120 break; \ 0121 } \ 0122 qDebug() << qPrintable(QString::fromLatin1("Actual/expected item %1 of %2: %3 %4 %5") \ 0123 .arg(i + 1).arg(count).arg(v1).arg(sign.constData()).arg(v2)); \ 0124 if (actualListIt != actualList.constEnd()) { \ 0125 ++actualListIt; \ 0126 } \ 0127 if (expectedListIt != expectedList.constEnd()) { \ 0128 ++expectedListIt; \ 0129 } \ 0130 ++i; \ 0131 } \ 0132 return; \ 0133 } while (0) 0134 0135 void PluginsTest::checkBuiltInPlugins() 0136 { 0137 KReportPluginManager* manager = KReportPluginManager::self(); 0138 QStringList pluginIds = manager->pluginIds(); 0139 QCOMPARE(pluginIds.toSet().count(), pluginIds.count()); 0140 QSet<QString> builtInPlugins( 0141 QSet<QString>() << "org.kde.kreport.checkbox" 0142 << "org.kde.kreport.field" 0143 << "org.kde.kreport.image" 0144 << "org.kde.kreport.label" 0145 << "org.kde.kreport.text"); 0146 QSet<QString> foundBuiltInPlugins; 0147 foreach(const QString &pluginId, pluginIds) { 0148 KReportPluginInterface* iface = manager->plugin(pluginId); 0149 QVERIFY(iface); 0150 if (iface->metaData()->isBuiltIn()) { 0151 foundBuiltInPlugins.insert(pluginId); 0152 } 0153 } 0154 QCOMPARE_SET(QString, builtInPlugins, foundBuiltInPlugins); 0155 }