diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index a2917b7..450987a 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,58 +1,58 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII) include(ECMAddTests) ########### unittests ############### find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Concurrent Test) macro(KSERVICE_UNIT_TESTS) foreach(_testname ${ARGN}) ecm_add_test(${_testname}.cpp TEST_NAME ${_testname} LINK_LIBRARIES KF5::Service Qt5::Test Qt5::Concurrent Qt5::Xml) target_compile_definitions(${_testname} PRIVATE -DKBUILDSYCOCAEXE=\"$\") endforeach() endmacro(KSERVICE_UNIT_TESTS) kservice_unit_tests( ksycocatest ksycoca_xdgdirstest kautostarttest ksycocadicttest ksycocathreadtest kservicetest - pluginlocatortest + kplugintradertest kplugininfotest ) # the test plays with the timestamp of ~/.qttest/share/kservicetypes5, and with the ksycoca file, other tests can collide set_tests_properties(ksycocatest PROPERTIES RUN_SERIAL TRUE) # KServiceTest::testAllServices can fail if any service is deleted while the test runs set_tests_properties(kservicetest PROPERTIES RUN_SERIAL TRUE) target_sources(kservicetest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../src/services/ktraderparsetree.cpp ) add_library(fakeplugin MODULE nsaplugin.cpp) ecm_mark_as_test(fakeplugin) target_link_libraries(fakeplugin KF5::Service) # generate new-style and old-style JSON from the .desktop file file(COPY fakeplugin.desktop DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin.desktop ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin_json_old.desktop) kcoreaddons_desktop_to_json(fakeplugin ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin_json_old.desktop COMPAT_MODE) file(COPY fakeplugin.desktop DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin.desktop ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin_json_new.desktop) kcoreaddons_desktop_to_json(fakeplugin ${CMAKE_CURRENT_BINARY_DIR}/fakeplugin_json_new.desktop) ######### kmimeassociationstest ######## set(kmimeassociationstest_SRCS kmimeassociationstest.cpp ../src/sycoca/kmimeassociations.cpp) ecm_qt_declare_logging_category(kmimeassociationstest_SRCS HEADER sycocadebug.h IDENTIFIER SYCOCA CATEGORY_NAME kf5.kservice.sycoca) ecm_add_test(${kmimeassociationstest_SRCS} TEST_NAME kmimeassociationstest LINK_LIBRARIES KF5::Service Qt5::Test Qt5::Xml) diff --git a/autotests/pluginlocatortest.cpp b/autotests/kplugintradertest.cpp similarity index 92% rename from autotests/pluginlocatortest.cpp rename to autotests/kplugintradertest.cpp index 8417102..8e51a44 100644 --- a/autotests/pluginlocatortest.cpp +++ b/autotests/kplugintradertest.cpp @@ -1,85 +1,84 @@ /****************************************************************************** * Copyright 2013 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *******************************************************************************/ -#include "pluginlocatortest.h" +#include "kplugintradertest.h" #include "nsaplugin.h" -#include +#include #include #include -QTEST_MAIN(PluginTest) +QTEST_MAIN(PluginTraderTest) -void PluginTest::initTestCase() +void PluginTraderTest::initTestCase() { QCoreApplication::setLibraryPaths(QStringList() << QCoreApplication::applicationDirPath()); } -void PluginTest::findPlugin_data() +void PluginTraderTest::findPlugin_data() { QTest::addColumn("serviceType"); QTest::addColumn("constraint"); QTest::addColumn("expectedResult"); const QString _st = QStringLiteral("KService/NSA"); QString _c = ""; QTest::newRow("no constraints") << _st << _c << 1; _c = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(QStringLiteral("fakeplugin")); QTest::newRow("by pluginname") << _st << _c << 1; _c = QStringLiteral("[X-KDE-PluginInfo-Category] == '%1'").arg(QStringLiteral("Examples")); QTest::newRow("by category") << _st << _c << 1; _c = QStringLiteral("([X-KDE-PluginInfo-Category] == 'Examples') AND ([X-KDE-PluginInfo-Email] == 'sebas@kde.org')"); QTest::newRow("complex query") << _st << _c << 1; _c = QStringLiteral("([X-KDE-PluginInfo-Category] == 'Examples') AND ([X-KDE-PluginInfo-Email] == 'prrrrt')"); QTest::newRow("empty query") << _st << _c << 0; } -void PluginTest::findPlugin() +void PluginTraderTest::findPlugin() { QFETCH(QString, serviceType); QFETCH(QString, constraint); QFETCH(int, expectedResult); const KPluginInfo::List res = KPluginTrader::self()->query(QString(), serviceType, constraint); QCOMPARE(res.count(), expectedResult); } -void PluginTest::findSomething() +void PluginTraderTest::findSomething() { const KPluginInfo::List res = KPluginTrader::self()->query(QString()); QVERIFY(res.count() > 0); } -void PluginTest::loadPlugin() +void PluginTraderTest::loadPlugin() { const QString pluginName("fakeplugin"); const QString serviceType("KService/NSA"); const QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName); QObject *plugin = KPluginTrader::createInstanceFromQuery(QString(), serviceType, constraint, this); QVERIFY(plugin != nullptr); QCOMPARE(plugin->objectName(), QStringLiteral("Test Plugin Spy")); } -#include "moc_pluginlocatortest.cpp" diff --git a/autotests/pluginlocatortest.h b/autotests/kplugintradertest.h similarity index 93% rename from autotests/pluginlocatortest.h rename to autotests/kplugintradertest.h index 06d09fb..996d33d 100644 --- a/autotests/pluginlocatortest.h +++ b/autotests/kplugintradertest.h @@ -1,39 +1,39 @@ /****************************************************************************** * Copyright 2013 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *******************************************************************************/ -#ifndef PLUGINLOCATORTEST_H -#define PLUGINLOCATORTEST_H +#ifndef PLUGINTRADERTEST_H +#define PLUGINTRADERTEST_H #include -class PluginTest : public QObject +class PluginTraderTest : public QObject { Q_OBJECT public: - PluginTest() {} + PluginTraderTest() {} private Q_SLOTS: void initTestCase(); void findPlugin_data(); void findPlugin(); void findSomething(); void loadPlugin(); }; #endif diff --git a/tests/pluginlocator/main.cpp b/tests/pluginlocator/main.cpp index 997dac7..e32a129 100644 --- a/tests/pluginlocator/main.cpp +++ b/tests/pluginlocator/main.cpp @@ -1,41 +1,41 @@ /* * Copyright 2013 Sebastian Kügler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include "plugintest.h" int main(int argc, char **argv) { QCoreApplication app(argc, argv); QCommandLineParser parser; - const QString description = QStringLiteral("PluginLocator test app"); + const QString description = QStringLiteral("KPluginTrader test app"); const char version[] = "1.0"; app.setApplicationVersion(version); parser.addVersionOption(); parser.addHelpOption(); parser.setApplicationDescription(description); PluginTest test; return test.runMain(); } diff --git a/tests/pluginlocator/plugintest.cpp b/tests/pluginlocator/plugintest.cpp index 94dda16..a893d90 100644 --- a/tests/pluginlocator/plugintest.cpp +++ b/tests/pluginlocator/plugintest.cpp @@ -1,196 +1,196 @@ /****************************************************************************** * Copyright 2013 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *******************************************************************************/ #include "plugintest.h" #include #include #include #include #include #include #include #include #include static QTextStream cout(stdout); class PluginTestPrivate { public: QString pluginName; }; PluginTest::PluginTest() : QObject(nullptr) { d = new PluginTestPrivate; } PluginTest::~PluginTest() { delete d; } int PluginTest::runMain() { // measure performance QElapsedTimer timer; int runs = 1; QList timings; - cout << "-- PluginLocator Test --" << endl; + cout << "-- KPluginTrader Test --" << endl; bool ok = true; // KSycoca querying timer.start(); for (int _i = 0; _i < runs; _i++) { timer.restart(); if (!loadFromKService(QStringLiteral("time"))) { ok = false; } timings << timer.nsecsElapsed(); } report(timings, QStringLiteral("KServiceTypeTrader")); timings.clear(); // -- Metadata querying for (int _i = 0; _i < runs; _i++) { timer.restart(); if (!loadFromMetaData()) { ok = false; } //if (!loadFromMetaData2("Plasma/ContainmentActions")) ok = false; timings << timer.nsecsElapsed(); } report(timings, QStringLiteral("Metadata")); timings.clear(); findPlugins(); if (ok) { qDebug() << "All tests finished successfully"; return 0; } return 0; // We return successfully in any case, since plugins aren't installed for most people } void PluginTest::report(const QList timings, const QString &msg) { qulonglong totalTime = 0; int unitDiv = 1000; QString unit = QStringLiteral("microsec"); int i = 0; for (qint64 t : timings) { int msec = t / 1000000; qDebug() << " Run " << i << ": " << msec << " msec"; totalTime += t; i++; } QString av = QString::number((totalTime / timings.count() / unitDiv), 'f', 1); qDebug() << " Average: " << av << " " << unit << " (" << msg << ")" << endl; } bool PluginTest::loadFromKService(const QString &name) { bool ok = false; QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name); KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/DataEngine"), constraint); QString error; if (offers.isEmpty()) { qDebug() << "offers are empty for " << name << " with constraint " << constraint; } else { QVariantList allArgs; allArgs << offers.first()->storageId(); const QString _n = offers.first()->property(QStringLiteral("Name")).toString(); if (!_n.isEmpty()) { qDebug() << "Found Dataengine: " << _n << endl; ok = true; } else { qDebug() << "Nothing found. " << endl; } } return ok; } bool PluginTest::loadFromMetaData(const QString &serviceType) { bool ok = false; QString pluginName("time"); QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName); const KPluginInfo::List res = KPluginTrader::self()->query(QStringLiteral("kf5"), serviceType, QString()); qDebug() << "----------- Found " << res.count() << " Plugins" << constraint; ok = res.count() > 0; for (const KPluginInfo &info : res) { qDebug() << " file: " << info.libraryPath(); } return ok; } bool PluginTest::findPlugins() { QElapsedTimer timer; QList timings; const QString pluginDir("/media/storage/testdata/"); const QStringList sizes = QStringList() << QStringLiteral("50") << QStringLiteral("100") << QStringLiteral("150") << QStringLiteral("200") << QStringLiteral("250") << QStringLiteral("300") << QStringLiteral("400") << QStringLiteral("500") << QStringLiteral("600") << QStringLiteral("700") << QStringLiteral("800") << QStringLiteral("1000") << QStringLiteral("1500") << QStringLiteral("2000") << QStringLiteral("5000"); QStringList datadirs; for (const QString &_s : sizes) { datadirs << pluginDir + _s; } for (const QString &subdir : qAsConst(datadirs)) { const QString pluginName; const QString constraint; const QString serviceType; timer.restart(); KPluginInfo::List res = KPluginTrader::self()->query(subdir, serviceType, constraint); timings << timer.nsecsElapsed(); qDebug() << "Found " << res.count() << " Plugins in " << subdir; } report(timings, QStringLiteral("reading monsterdirs")); return true; } #include "moc_plugintest.cpp"