summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson <arichardson.kde@gmail.com>2015-04-22 12:10:03 (GMT)
committerAlex Richardson <arichardson.kde@gmail.com>2015-05-22 15:33:09 (GMT)
commit8059e5b686cef4b4a8aab1f62d92255556a3ec09 (patch)
tree02e1272b297a5721fc53b4cc92bcdf4597348962
parent0ef5903c73fbf074317620ef739cf6fb026969a6 (diff)
Add a test to see whether generators can be loaded
REVIEW: 123466
-rw-r--r--autotests/CMakeLists.txt6
-rw-r--r--autotests/generatorstest.cpp73
2 files changed, 79 insertions, 0 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index f27f479..31f9986 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -62,3 +62,9 @@ ecm_add_test(mainshelltest.cpp ../shell/okular_main.cpp ../shell/shellutils.cpp
TEST_NAME "mainshelltest"
LINK_LIBRARIES Qt5::Test KF5::Activities okularpart okularcore
)
+
+ecm_add_test(generatorstest.cpp
+ TEST_NAME "generatorstest"
+ LINK_LIBRARIES Qt5::Test KF5::CoreAddons okularcore
+)
+target_compile_definitions(generatorstest PRIVATE GENERATORS_BUILD_DIR="${CMAKE_BINARY_DIR}/generators")
diff --git a/autotests/generatorstest.cpp b/autotests/generatorstest.cpp
new file mode 100644
index 0000000..22b85fe
--- /dev/null
+++ b/autotests/generatorstest.cpp
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Alex Richardson <arichardson.kde@gmail.com> *
+ * *
+ * 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 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+
+#include <QtTest/QTest>
+#include <QDirIterator>
+#include <QDebug>
+#include <QStringList>
+#include <KPluginFactory>
+#include <KPluginLoader>
+
+#include "../generator.h"
+
+class GeneratorsTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testLoadsCorrectly();
+};
+
+void GeneratorsTest::testLoadsCorrectly()
+{
+ QVERIFY2(QDir(GENERATORS_BUILD_DIR).exists(), GENERATORS_BUILD_DIR);
+ // find all possible generators in $CMAKE_BINARY_DIR/generators
+ // We can't simply hardcore the list of generators since some might not be built
+ // depending on which dependencies were found by CMake
+ QStringList generatorLibs;
+ QDirIterator it(GENERATORS_BUILD_DIR, QDir::Files | QDir::Executable, QDirIterator::Subdirectories);
+ while (it.hasNext()) {
+ it.next();
+ if (QLibrary::isLibrary(it.fileName())) {
+ if (it.fileName().startsWith(QLatin1String("kio_"))) {
+ continue; // don't check kio_msits.so
+ }
+ generatorLibs << it.fileName();
+ }
+ }
+ int failures = 0;
+ int successful = 0;
+ foreach (const QString& lib, generatorLibs) {
+ KPluginLoader loader(lib);
+ QVERIFY(!loader.fileName().isEmpty());
+ auto factory = loader.factory();
+ if (!factory) {
+ qWarning() << "Could not get KPluginFactory for" << lib;
+ failures++;
+ continue;
+ }
+ Okular::Generator* generator = factory->create<Okular::Generator>();
+ if (!generator) {
+ qWarning() << "Failed to cast" << lib << "to Okular::Generator";
+ // without the necessary Q_INTERFACES() qobject_cast fails!
+ auto obj = factory->create<QObject>();
+ qDebug() << "Object is of type " << obj->metaObject()->className();
+ qDebug() << "dynamic_cast:" << dynamic_cast<Okular::Generator*>(obj);
+ qDebug() << "qobject_cast:" << qobject_cast<Okular::Generator*>(obj);
+ failures++;
+ continue;
+ }
+ successful++;
+ }
+ qDebug() << "Successfully loaded" << successful << "generators";
+ QCOMPARE(failures, 0);
+}
+
+QTEST_MAIN(GeneratorsTest)
+
+#include "generatorstest.moc"