diff options
Diffstat (limited to 'tests/auto/corelib/plugin')
6 files changed, 91 insertions, 1 deletions
diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro index 3745782dfc..18c9c8d198 100644 --- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro +++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro @@ -3,6 +3,7 @@ TEMPLATE = subdirs tst.depends = lib theplugin SUBDIRS = lib \ + staticplugin \ theplugin \ tst !android:!win32:!darwin { diff --git a/tests/auto/corelib/plugin/qpluginloader/staticplugin/.gitignore b/tests/auto/corelib/plugin/qpluginloader/staticplugin/.gitignore new file mode 100644 index 0000000000..26f7ecd506 --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/staticplugin/.gitignore @@ -0,0 +1,3 @@ +*staticplugin.prl +libstaticplugin.a +staticplugin.lib diff --git a/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp b/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp new file mode 100644 index 0000000000..d891839b1e --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtPlugin> +#include <QObject> + +class StaticPlugin : public QObject +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "SomeIID") +public: + StaticPlugin() {} +}; + +#include "main.moc" diff --git a/tests/auto/corelib/plugin/qpluginloader/staticplugin/staticplugin.pro b/tests/auto/corelib/plugin/qpluginloader/staticplugin/staticplugin.pro new file mode 100644 index 0000000000..ff65ab728c --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/staticplugin/staticplugin.pro @@ -0,0 +1,7 @@ +TEMPLATE = lib +CONFIG += plugin static +SOURCES = main.cpp +QT = core + +# Add extra metadata to the plugin +QMAKE_MOC_OPTIONS += -M ExtraMetaData=StaticPlugin -M ExtraMetaData=foo diff --git a/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro b/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro index c20e56ba4c..a3885f4134 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro +++ b/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro @@ -8,9 +8,14 @@ HEADERS = ../theplugin/plugininterface.h win32 { CONFIG(debug, debug|release) { TARGET = ../../debug/tst_qpluginloader + LIBS += -L../staticplugin/debug } else { TARGET = ../../release/tst_qpluginloader + LIBS += -L../staticplugin/release } +} else { + LIBS += -L../staticplugin } +LIBS += -lstaticplugin TESTDATA += ../elftest ../machtest diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index c517c0809a..4316ea14ea 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2018 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -121,8 +121,11 @@ private slots: void reloadPlugin(); void preloadedPlugin_data(); void preloadedPlugin(); + void staticPlugins(); }; +Q_IMPORT_PLUGIN(StaticPlugin) + void tst_QPluginLoader::cleanup() { // check if the library/plugin was leaked @@ -520,5 +523,37 @@ void tst_QPluginLoader::preloadedPlugin() QVERIFY(lib.unload()); } +void tst_QPluginLoader::staticPlugins() +{ + const QObjectList instances = QPluginLoader::staticInstances(); + QVERIFY(instances.size()); + + bool found = false; + for (QObject *obj : instances) { + found = obj->metaObject()->className() == QLatin1String("StaticPlugin"); + if (found) + break; + } + QVERIFY(found); + + const auto plugins = QPluginLoader::staticPlugins(); + QCOMPARE(plugins.size(), instances.size()); + + // find the metadata + QJsonObject metaData; + for (const auto &p : plugins) { + metaData = p.metaData(); + found = metaData.value("className").toString() == QLatin1String("StaticPlugin"); + if (found) + break; + } + QVERIFY(found); + + QCOMPARE(metaData.value("version").toInt(), QT_VERSION); + QCOMPARE(metaData.value("IID").toString(), "SomeIID"); + QCOMPARE(metaData.value("ExtraMetaData"), QJsonArray({ "StaticPlugin", "foo" })); +} + + QTEST_MAIN(tst_QPluginLoader) #include "tst_qpluginloader.moc" |