summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/plugin')
-rw-r--r--tests/auto/corelib/plugin/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/CMakeLists.txt10
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.cpp4
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.h4
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.json5
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/plugininterface1.h2
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin2/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.cpp4
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.h2
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin2/plugininterface2.h2
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/staticplugin/CMakeLists.txt14
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/staticplugin/main.cpp22
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/staticplugin/plugin.json3
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/test/CMakeLists.txt7
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/tst_qfactoryloader.cpp126
-rw-r--r--tests/auto/corelib/plugin/qlibrary/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt55
-rw-r--r--tests/auto/corelib/plugin/qlibrary/lib/mylib.c2
-rw-r--r--tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt66
-rw-r--r--tests/auto/corelib/plugin/qlibrary/lib2/mylib.c2
-rw-r--r--tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp225
-rw-r--r--tests/auto/corelib/plugin/qplugin/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/qplugin/debugplugin/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp2
-rw-r--r--tests/auto/corelib/plugin/qplugin/invalidplugin/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/plugin/qplugin/invalidplugin/main.cpp2
-rw-r--r--tests/auto/corelib/plugin/qplugin/releaseplugin/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp2
-rw-r--r--tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp14
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/BLACKLIST2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/almostplugin/CMakeLists.txt20
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/lib/CMakeLists.txt14
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/lib/mylib.c2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/machtest/CMakeLists.txt138
-rwxr-xr-xtests/auto/corelib/plugin/qpluginloader/machtest/ppcconverter.pl74
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/staticplugin/CMakeLists.txt4
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/CMakeLists.txt7
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.h2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp98
-rw-r--r--tests/auto/corelib/plugin/quuid/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/quuid/test/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp2
-rw-r--r--tests/auto/corelib/plugin/quuid/tst_quuid.cpp92
-rw-r--r--tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm4
57 files changed, 814 insertions, 332 deletions
diff --git a/tests/auto/corelib/plugin/CMakeLists.txt b/tests/auto/corelib/plugin/CMakeLists.txt
index 710d471e8a..5518231ace 100644
--- a/tests/auto/corelib/plugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from plugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
if(QT_BUILD_SHARED_LIBS)
add_subdirectory(qfactoryloader)
diff --git a/tests/auto/corelib/plugin/qfactoryloader/CMakeLists.txt b/tests/auto/corelib/plugin/qfactoryloader/CMakeLists.txt
index 6263be15a2..14174da173 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qfactoryloader/CMakeLists.txt
@@ -1,5 +1,13 @@
-# Generated from qfactoryloader.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfactoryloader LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(plugin1)
add_subdirectory(plugin2)
+add_subdirectory(staticplugin)
add_subdirectory(test)
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/CMakeLists.txt b/tests/auto/corelib/plugin/qfactoryloader/plugin1/CMakeLists.txt
index eec1abec3f..c7cedd7e0c 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin1/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from plugin1.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## plugin1 Generic Library:
@@ -10,7 +11,7 @@ qt_internal_add_cmake_library(tst_qfactoryloader_plugin1
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
plugin1.cpp plugin1.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.cpp b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.cpp
index 51825f0017..6731d560a7 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.cpp
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/qstring.h>
#include "plugin1.h"
@@ -7,3 +7,5 @@ QString Plugin1::pluginName() const
{
return QLatin1String("Plugin1 ok");
}
+
+#include "moc_plugin1.cpp"
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.h b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.h
index 8afb501f04..aba0b5c2f5 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.h
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef THEPLUGIN_H
#define THEPLUGIN_H
@@ -10,7 +10,7 @@
class Plugin1 : public QObject, public PluginInterface1
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface1")
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface1" FILE "plugin1.json")
Q_INTERFACES(PluginInterface1)
public:
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.json b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.json
new file mode 100644
index 0000000000..ce67846d48
--- /dev/null
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.json
@@ -0,0 +1,5 @@
+{
+ "Keys": [
+ "plugin1"
+ ]
+}
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugininterface1.h b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugininterface1.h
index b7251db358..a652273eb5 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugininterface1.h
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugininterface1.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PLUGININTERFACE1_H
#define PLUGININTERFACE1_H
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin2/CMakeLists.txt b/tests/auto/corelib/plugin/qfactoryloader/plugin2/CMakeLists.txt
index 765ad0b262..259d6fb739 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin2/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin2/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from plugin2.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## plugin2 Generic Library:
@@ -10,7 +11,7 @@ qt_internal_add_cmake_library(tst_qfactoryloader_plugin2
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
plugin2.cpp plugin2.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.cpp b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.cpp
index 88a34ac73e..c2ac873317 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.cpp
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/qstring.h>
#include "plugin2.h"
@@ -7,3 +7,5 @@ QString Plugin2::pluginName() const
{
return QLatin1String("Plugin2 ok");
}
+
+#include "moc_plugin2.cpp"
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.h b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.h
index a2ccae198e..02ef062b77 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.h
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef THEPLUGIN_H
#define THEPLUGIN_H
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugininterface2.h b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugininterface2.h
index e332e80b89..df30f2ffd3 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugininterface2.h
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugininterface2.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PLUGININTERFACE2_H
#define PLUGININTERFACE2_H
diff --git a/tests/auto/corelib/plugin/qfactoryloader/staticplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/CMakeLists.txt
new file mode 100644
index 0000000000..c43a69c707
--- /dev/null
+++ b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_cmake_library(tst_qfactoryloader_staticplugin
+ STATIC
+ SOURCES
+ main.cpp
+ LIBRARIES
+ Qt::Core
+)
+
+qt_autogen_tools_initial_setup(tst_qfactoryloader_staticplugin)
+
+target_compile_definitions(tst_qfactoryloader_staticplugin PRIVATE QT_STATICPLUGIN)
diff --git a/tests/auto/corelib/plugin/qfactoryloader/staticplugin/main.cpp b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/main.cpp
new file mode 100644
index 0000000000..6506f9cf9b
--- /dev/null
+++ b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/main.cpp
@@ -0,0 +1,22 @@
+// Copyright (C) 2018 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#include <QtPlugin>
+#include <QObject>
+
+class StaticPlugin1 : public QObject
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "StaticPlugin1" FILE "plugin.json")
+public:
+ StaticPlugin1() {}
+};
+
+class StaticPlugin2 : public QObject
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "StaticPlugin2" FILE "plugin.json")
+public:
+ StaticPlugin2() {}
+};
+
+#include "main.moc"
diff --git a/tests/auto/corelib/plugin/qfactoryloader/staticplugin/plugin.json b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/plugin.json
new file mode 100644
index 0000000000..7321080fb4
--- /dev/null
+++ b/tests/auto/corelib/plugin/qfactoryloader/staticplugin/plugin.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "Value" ]
+}
diff --git a/tests/auto/corelib/plugin/qfactoryloader/test/CMakeLists.txt b/tests/auto/corelib/plugin/qfactoryloader/test/CMakeLists.txt
index 2869fca045..fb3b6f5acb 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/test/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qfactoryloader/test/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfactoryloader Test:
@@ -12,11 +13,9 @@ qt_internal_add_test(tst_qfactoryloader
../tst_qfactoryloader.cpp
LIBRARIES
Qt::CorePrivate
+ tst_qfactoryloader_staticplugin
)
-## Scopes:
-#####################################################################
-
qt_internal_extend_target(tst_qfactoryloader CONDITION NOT QT_FEATURE_library
LIBRARIES
tst_qfactoryloader_plugin1
diff --git a/tests/auto/corelib/plugin/qfactoryloader/tst_qfactoryloader.cpp b/tests/auto/corelib/plugin/qfactoryloader/tst_qfactoryloader.cpp
index a3ee6fa3d4..faec311f2d 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/tst_qfactoryloader.cpp
+++ b/tests/auto/corelib/plugin/qfactoryloader/tst_qfactoryloader.cpp
@@ -1,11 +1,13 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/qtest.h>
#include <QtCore/qdir.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qplugin.h>
+#include <QtCore/qversionnumber.h>
#include <private/qfactoryloader_p.h>
+#include <private/qlibrary_p.h>
#include "plugin1/plugininterface1.h"
#include "plugin2/plugininterface2.h"
@@ -18,10 +20,6 @@ class tst_QFactoryLoader : public QObject
{
Q_OBJECT
-#ifdef Q_OS_ANDROID
- QSharedPointer<QTemporaryDir> directory;
-#endif
-
QString binFolder;
public slots:
void initTestCase();
@@ -29,6 +27,9 @@ public slots:
private slots:
void usingTwoFactoriesFromSameDir();
void extraSearchPath();
+ void multiplePaths();
+ void staticPlugin_data();
+ void staticPlugin();
};
static const char binFolderC[] = "bin";
@@ -48,21 +49,61 @@ void tst_QFactoryLoader::usingTwoFactoriesFromSameDir()
// set the library path to contain the directory where the 'bin' dir is located
QCoreApplication::setLibraryPaths( { QFileInfo(binFolder).absolutePath() });
#endif
+ auto versionNumber = [](const QCborValue &value) {
+ // Qt plugins only store major & minor versions in the metadata, so
+ // the low 8 bits are always zero.
+ qint64 v = value.toInteger();
+ return QVersionNumber(v >> 16, uchar(v >> 8));
+ };
+ QVersionNumber qtVersion(QT_VERSION_MAJOR, 0);
const QString suffix = QLatin1Char('/') + QLatin1String(binFolderC);
QFactoryLoader loader1(PluginInterface1_iid, suffix);
+ const QFactoryLoader::MetaDataList list1 = loader1.metaData();
+ const QList<QCborArray> keys1 = loader1.metaDataKeys();
+ QCOMPARE(list1.size(), 1);
+ QCOMPARE(keys1.size(), 1);
+ QCOMPARE_GE(versionNumber(list1[0].value(QtPluginMetaDataKeys::QtVersion)), qtVersion);
+ QCOMPARE(list1[0].value(QtPluginMetaDataKeys::IID), PluginInterface1_iid);
+ QCOMPARE(list1[0].value(QtPluginMetaDataKeys::ClassName), "Plugin1");
+
+ // plugin1's Q_PLUGIN_METADATA has FILE "plugin1.json"
+ QCborValue metadata1 = list1[0].value(QtPluginMetaDataKeys::MetaData);
+ QCOMPARE(metadata1.type(), QCborValue::Map);
+ QCOMPARE(metadata1["Keys"], QCborArray{ "plugin1" });
+ QCOMPARE(keys1[0], QCborArray{ "plugin1" });
+ QCOMPARE(loader1.indexOf("Plugin1"), 0);
+ QCOMPARE(loader1.indexOf("PLUGIN1"), 0);
+ QCOMPARE(loader1.indexOf("Plugin2"), -1);
- PluginInterface1 *plugin1 = qobject_cast<PluginInterface1 *>(loader1.instance(0));
+ QFactoryLoader loader2(PluginInterface2_iid, suffix);
+ const QFactoryLoader::MetaDataList list2 = loader2.metaData();
+ const QList<QCborArray> keys2 = loader2.metaDataKeys();
+ QCOMPARE(list2.size(), 1);
+ QCOMPARE(keys2.size(), 1);
+ QCOMPARE_GE(versionNumber(list2[0].value(QtPluginMetaDataKeys::QtVersion)), qtVersion);
+ QCOMPARE(list2[0].value(QtPluginMetaDataKeys::IID), PluginInterface2_iid);
+ QCOMPARE(list2[0].value(QtPluginMetaDataKeys::ClassName), "Plugin2");
+
+ // plugin2's Q_PLUGIN_METADATA does not have FILE
+ QCOMPARE(list2[0].value(QtPluginMetaDataKeys::MetaData), QCborValue());
+ QCOMPARE(keys2[0], QCborArray());
+ QCOMPARE(loader2.indexOf("Plugin1"), -1);
+ QCOMPARE(loader2.indexOf("Plugin2"), -1);
+
+ QObject *obj1 = loader1.instance(0);
+ PluginInterface1 *plugin1 = qobject_cast<PluginInterface1 *>(obj1);
QVERIFY2(plugin1,
qPrintable(QString::fromLatin1("Cannot load plugin '%1'")
.arg(QLatin1String(PluginInterface1_iid))));
+ QCOMPARE(obj1->metaObject()->className(), "Plugin1");
- QFactoryLoader loader2(PluginInterface2_iid, suffix);
-
- PluginInterface2 *plugin2 = qobject_cast<PluginInterface2 *>(loader2.instance(0));
+ QObject *obj2 = loader2.instance(0);
+ PluginInterface2 *plugin2 = qobject_cast<PluginInterface2 *>(obj2);
QVERIFY2(plugin2,
qPrintable(QString::fromLatin1("Cannot load plugin '%1'")
.arg(QLatin1String(PluginInterface2_iid))));
+ QCOMPARE(obj2->metaObject()->className(), "Plugin2");
QCOMPARE(plugin1->pluginName(), QLatin1String("Plugin1 ok"));
QCOMPARE(plugin2->pluginName(), QLatin1String("Plugin2 ok"));
@@ -109,5 +150,72 @@ void tst_QFactoryLoader::extraSearchPath()
#endif
}
+void tst_QFactoryLoader::multiplePaths()
+{
+#if !QT_CONFIG(library) || !(defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)) || defined(Q_OS_ANDROID)
+ QSKIP("Test not applicable in this configuration.");
+#else
+ QTemporaryDir dir;
+ QVERIFY(dir.isValid());
+
+ QString pluginsPath = QFileInfo(binFolder, binFolderC).absolutePath();
+ QString linkPath = dir.filePath(binFolderC);
+ QVERIFY(QFile::link(pluginsPath, linkPath));
+
+ QCoreApplication::setLibraryPaths({ QFileInfo(binFolder).absolutePath(), dir.path() });
+
+ const QString suffix = QLatin1Char('/') + QLatin1String(binFolderC);
+ QFactoryLoader loader1(PluginInterface1_iid, suffix);
+
+ QLibraryPrivate *library1 = loader1.library("plugin1");
+ QVERIFY(library1);
+ QCOMPARE(library1->loadHints(), QLibrary::PreventUnloadHint);
+#endif
+}
+
+Q_IMPORT_PLUGIN(StaticPlugin1)
+Q_IMPORT_PLUGIN(StaticPlugin2)
+constexpr bool IsDebug =
+#ifdef QT_NO_DEBUG
+ false &&
+#endif
+ true;
+
+void tst_QFactoryLoader::staticPlugin_data()
+{
+ QTest::addColumn<QString>("iid");
+ auto addRow = [](const char *iid) {
+ QTest::addRow("%s", iid) << QString(iid);
+ };
+ addRow("StaticPlugin1");
+ addRow("StaticPlugin2");
+}
+
+void tst_QFactoryLoader::staticPlugin()
+{
+ QFETCH(QString, iid);
+ QFactoryLoader loader(iid.toLatin1(), "/irrelevant");
+ QFactoryLoader::MetaDataList list = loader.metaData();
+ QCOMPARE(list.size(), 1);
+
+ QCborMap map = list.at(0).toCbor();
+ QCOMPARE(map[int(QtPluginMetaDataKeys::QtVersion)],
+ QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, 0));
+ QCOMPARE(map[int(QtPluginMetaDataKeys::IID)], iid);
+ QCOMPARE(map[int(QtPluginMetaDataKeys::ClassName)], iid);
+ QCOMPARE(map[int(QtPluginMetaDataKeys::IsDebug)], IsDebug);
+
+ QCborValue metaData = map[int(QtPluginMetaDataKeys::MetaData)];
+ QVERIFY(metaData.isMap());
+ QCOMPARE(metaData["Keys"], QCborArray{ "Value" });
+ QCOMPARE(loader.metaDataKeys(), QList{ QCborArray{ "Value" } });
+ QCOMPARE(loader.indexOf("Value"), 0);
+
+ // instantiate
+ QObject *instance = loader.instance(0);
+ QVERIFY(instance);
+ QCOMPARE(instance->metaObject()->className(), iid);
+}
+
QTEST_MAIN(tst_QFactoryLoader)
#include "tst_qfactoryloader.moc"
diff --git a/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt
index c0faebc91d..b8f4af5aa8 100644
--- a/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qlibrary.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qlibrary LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(lib)
add_subdirectory(lib2)
diff --git a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt
index 25292c0cc5..1a318e1483 100644
--- a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from lib.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## mylib Generic Library:
@@ -7,14 +8,12 @@
qt_internal_add_cmake_library(mylib
SHARED
INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/tst_qlibrary"
- #OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
SOURCES
mylib.c
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-# special case begin
set_target_properties(mylib PROPERTIES
VERSION 1.0.0
SOVERSION 1
@@ -27,27 +26,27 @@ if(WIN32)
set_property(TARGET mylib PROPERTY PREFIX "")
endif()
-
-if (MACOS)
- add_custom_command(TARGET mylib POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- $<TARGET_FILE:mylib>
- "${CMAKE_CURRENT_BINARY_DIR}/../"
+if(UNIX)
+ if(APPLE)
+ add_custom_command(TARGET mylib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${CMAKE_CURRENT_BINARY_DIR}/*dylib"
- "${CMAKE_CURRENT_BINARY_DIR}/../")
-elseif (UNIX)
- if (NOT ANDROID)
+ $<TARGET_FILE:mylib>
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.1.0.0.dylib"
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "libmylib.1.0.0.dylib"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.1.dylib"
+ VERBATIM)
+ elseif(NOT ANDROID)
add_custom_command(TARGET mylib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
- $<TARGET_FILE:mylib>
- "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1.0.0"
+ $<TARGET_FILE:mylib>
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1.0.0"
COMMAND ${CMAKE_COMMAND} -E create_symlink
- "libmylib.so.1.0.0"
- "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1"
+ "libmylib.so.1.0.0"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1"
COMMAND ${CMAKE_COMMAND} -E create_symlink
- "libmylib.so.1.0.0"
- "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so1"
+ "libmylib.so.1.0.0"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so1"
VERBATIM)
else()
# Android does not use symlinks. Also, according to our conventions,
@@ -61,17 +60,11 @@ elseif (UNIX)
endif()
else() #Win32
add_custom_command(TARGET mylib POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib>
"${CMAKE_CURRENT_BINARY_DIR}/../mylib.dll"
- VERBATIM)
+ VERBATIM)
endif()
-# special case end
-
-#### Keys ignored in scope 1:.:.:lib.pro:<TRUE>:
-# INSTALLS = "target"
-# TEMPLATE = "lib"
-# target.path = "$$[QT_INSTALL_TESTS]/tst_qlibrary"
## Scopes:
#####################################################################
@@ -80,9 +73,3 @@ qt_internal_extend_target(mylib CONDITION MSVC
DEFINES
WIN32_MSVC
)
-
-#### Keys ignored in scope 4:.:.:lib.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# DESTDIR = "../debug/"
-
-#### Keys ignored in scope 5:.:.:lib.pro:else:
-# DESTDIR = "../release/"
diff --git a/tests/auto/corelib/plugin/qlibrary/lib/mylib.c b/tests/auto/corelib/plugin/qlibrary/lib/mylib.c
index 63622bdf1a..61fe52d182 100644
--- a/tests/auto/corelib/plugin/qlibrary/lib/mylib.c
+++ b/tests/auto/corelib/plugin/qlibrary/lib/mylib.c
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qglobal.h>
diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt
index 902c53ea84..f6bdeb453a 100644
--- a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt
@@ -1,20 +1,20 @@
-# Generated from lib2.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## mylib Generic Library:
#####################################################################
-qt_internal_add_cmake_library(mylib2 # special case
+qt_internal_add_cmake_library(mylib2
SHARED
INSTALL_DIRECTORY "${INSTALL_TESTSDIR}tst_qlibrary"
- #OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
+ #OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
mylib.c
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-# special case begin
# This test is very "annoying" to get working with CMake as it involves having
# two targets with the same name on the parent scope, which is not possible with
# CMake. Furthermore, on UNIX, this version of the library should override the
@@ -39,8 +39,28 @@ if(WIN32)
set_property(TARGET mylib2 PROPERTY PREFIX "")
endif()
-if (UNIX)
- if(NOT ANDROID)
+if(UNIX)
+ if(APPLE)
+ add_custom_command(TARGET mylib2 POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ $<TARGET_FILE:mylib2>
+ "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so.dylib"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ $<TARGET_FILE:mylib2>
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.2.0.0.dylib"
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "libmylib.2.0.0.dylib"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.2.dylib"
+ COMMAND ${CMAKE_COMMAND} -E remove
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.dylib"
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "libmylib.2.0.0.dylib"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.dylib"
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "libmylib.2.0.0.dylib"
+ "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2.dylib"
+ VERBATIM)
+ elseif(NOT ANDROID)
add_custom_command(TARGET mylib2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib2>
@@ -80,41 +100,11 @@ else() #Win32
"${CMAKE_CURRENT_BINARY_DIR}/../mylib.dl2"
VERBATIM)
endif()
-# special case end
-
-#### Keys ignored in scope 1:.:.:lib2.pro:<TRUE>:
-# INSTALLS = "target" "renamed_target"
-# QMAKE_POST_LINK = "$$member(QMAKE_POST_LINK, 0, -2)"
-# TEMPLATE = "lib"
-# VERSION = "2"
-# renamed_target.extra = "$$member(renamed_target.extra, 0, -2)"
-# renamed_target.path = "$$target.path"
-# target.path = "$$[QT_INSTALL_TESTS]$${QMAKE_DIR_SEP}tst_qlibrary"
## Scopes:
#####################################################################
-qt_internal_extend_target(mylib2 CONDITION MSVC # special case
+qt_internal_extend_target(mylib2 CONDITION MSVC
DEFINES
WIN32_MSVC
)
-
-#### Keys ignored in scope 3:.:.:lib2.pro:WIN32:
-# DESTDIR = "../$$BUILD_FOLDER/"
-# files = "$$BUILD_FOLDER$${QMAKE_DIR_SEP}mylib.dl2" "$$BUILD_FOLDER$${QMAKE_DIR_SEP}system.qt.test.mylib.dll"
-
-#### Keys ignored in scope 4:.:.:lib2.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# BUILD_FOLDER = "debug"
-
-#### Keys ignored in scope 5:.:.:lib2.pro:else:
-# BUILD_FOLDER = "release"
-
-#### Keys ignored in scope 6:.:.:lib2.pro:TEMPLATE___contains___vc._x_:
-# src = "$(TargetPath)"
-
-#### Keys ignored in scope 7:.:.:lib2.pro:else:
-# src = "$(DESTDIR_TARGET)"
-
-#### Keys ignored in scope 8:.:.:lib2.pro:else:
-# files = "libmylib.so2" "system.qt.test.mylib.so"
-# src = "$(DESTDIR)$(TARGET)"
diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c b/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c
index d036a1ae93..5312a9355b 100644
--- a/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c
+++ b/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qglobal.h>
diff --git a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt
index ee50a7f581..fc452f37f5 100644
--- a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from tst.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qlibrary Test:
@@ -12,7 +13,7 @@ qt_internal_add_test(tst_qlibrary
SOURCES
../tst_qlibrary.cpp
TESTDATA ${test_data}
- LIBRARIES mylib mylib2 # special case
+ LIBRARIES mylib mylib2
)
add_dependencies(tst_qlibrary mylib mylib2)
diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
index d36ca0f8d8..28f4581997 100644
--- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
+++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -81,19 +81,25 @@ enum QLibraryOperation {
QString directory;
private slots:
void initTestCase();
+ void cleanup();
- void load();
void load_data();
- void library_data();
+ void load();
void resolve_data();
void resolve();
void unload_data();
void unload();
void unload_after_implicit_load();
+ void setFilenameAfterFailedLoad();
+ void loadAfterFailedLoad();
void isLibrary_data();
void isLibrary();
void version_data();
void version();
+ void loadTwoVersions();
+ void setFileNameAndVersionTwice();
+ void setFileNameAndVersionAfterFailedLoad_data() { version_data(); }
+ void setFileNameAndVersionAfterFailedLoad();
void errorString_data();
void errorString();
void loadHints();
@@ -124,6 +130,38 @@ void tst_QLibrary::initTestCase()
#endif
}
+void tst_QLibrary::cleanup()
+{
+ // unload the libraries, if they are still loaded after the test ended
+ // (probably in a failure)
+
+ static struct {
+ QString name;
+ int version = -1;
+ } libs[] = {
+ { directory + "/mylib" },
+ { directory + "/mylib", 1 },
+ { directory + "/mylib", 2 },
+ { sys_qualifiedLibraryName("mylib") },
+
+ // stuff that load_data() succeeds with
+ { directory + "/" PREFIX "mylib" },
+ { directory + "/" PREFIX "mylib" SUFFIX },
+#if defined(Q_OS_WIN32)
+ { directory + "/mylib.dl2" },
+ { directory + "/system.qt.test.mylib.dll" },
+#elif !defined(Q_OS_ANDROID)
+ // .so even on macOS
+ { directory + "/libmylib.so2" },
+ { directory + "/system.qt.test.mylib.so" },
+#endif
+
+ };
+ for (const auto &entry : libs) {
+ do {} while (QLibrary(entry.name, entry.version).unload());
+ }
+}
+
void tst_QLibrary::version_data()
{
#ifdef Q_OS_ANDROID
@@ -160,6 +198,70 @@ void tst_QLibrary::version()
#endif
}
+void tst_QLibrary::loadTwoVersions()
+{
+#if defined(Q_OS_ANDROID) || defined(Q_OS_WIN)
+ QSKIP("Versioned files are not generated for this OS, so this test is not applicable.");
+#endif
+
+ QLibrary lib1(directory + "/mylib", 1);
+ QLibrary lib2(directory + "/mylib", 2);
+ QVERIFY(!lib1.isLoaded());
+ QVERIFY(!lib2.isLoaded());
+
+ // load the first one
+ QVERIFY(lib1.load());
+ QVERIFY(lib1.isLoaded());
+
+ // let's see if we can load the second one too
+ QVERIFY(lib2.load());
+ QVERIFY(lib2.isLoaded());
+
+ auto p1 = (VersionFunction)lib1.resolve("mylibversion");
+ QVERIFY(p1);
+
+ auto p2 = (VersionFunction)lib2.resolve("mylibversion");
+ QVERIFY(p2);
+
+ QCOMPARE_NE(p1(), p2());
+
+ lib2.unload();
+ lib1.unload();
+}
+
+void tst_QLibrary::setFileNameAndVersionTwice()
+{
+#if defined(Q_OS_ANDROID) || defined(Q_OS_WIN)
+ QSKIP("Versioned files are not generated for this OS, so this test is not applicable.");
+#endif
+
+ QLibrary library(directory + "/mylib", 1);
+ QVERIFY(library.load());
+ QVERIFY(library.isLoaded());
+
+ auto p1 = (VersionFunction)library.resolve("mylibversion");
+ QVERIFY(p1);
+ // don't .unload()
+
+ library.setFileNameAndVersion(directory + "/mylib", 2);
+ QVERIFY(!library.isLoaded());
+ QVERIFY(library.load());
+ QVERIFY(library.isLoaded());
+
+ auto p2 = (VersionFunction)library.resolve("mylibversion");
+ QVERIFY(p2);
+ QCOMPARE_NE(p1(), p2());
+
+ QVERIFY(library.unload());
+ QVERIFY(!library.isLoaded());
+
+ // set back
+ // it'll look like it isn't loaded, but it is and we can't unload it!
+ library.setFileNameAndVersion(directory + "/mylib", 1);
+ QVERIFY(!library.isLoaded());
+ QVERIFY(!library.unload());
+}
+
void tst_QLibrary::load_data()
{
QTest::addColumn<QString>("lib");
@@ -171,7 +273,7 @@ void tst_QLibrary::load_data()
QTest::newRow( "notexist" ) << appDir + "/nolib" << false;
QTest::newRow( "badlibrary" ) << appDir + "/qlibrary.pro" << false;
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
QTest::newRow("ok (libmylib ver. 1)") << appDir + "/libmylib" <<true;
#endif
@@ -240,6 +342,76 @@ void tst_QLibrary::unload_after_implicit_load()
QCOMPARE(library.isLoaded(), false);
}
+void tst_QLibrary::setFilenameAfterFailedLoad()
+{
+#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+ QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt");
+#endif
+
+ QLibrary library(directory + "/nolib");
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+
+ library.setFileName(directory + "/mylib");
+ QVERIFY(library.load());
+ QVERIFY(library.isLoaded());
+ auto p = (VersionFunction)library.resolve("mylibversion");
+ QVERIFY(p);
+ QCOMPARE(p(), 2);
+ library.unload();
+}
+
+void tst_QLibrary::setFileNameAndVersionAfterFailedLoad()
+{
+ QLibrary library(directory + "/nolib");
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+
+#if !defined(Q_OS_AIX) && !defined(Q_OS_WIN)
+ QFETCH(QString, lib);
+ QFETCH(int, loadversion);
+ QFETCH(int, resultversion);
+
+ library.setFileNameAndVersion(directory + '/' + lib, loadversion);
+ QVERIFY(library.load());
+ QVERIFY(library.isLoaded());
+ auto p = (VersionFunction)library.resolve("mylibversion");
+ QVERIFY(p);
+ QCOMPARE(p(), resultversion);
+ library.unload();
+#endif
+}
+
+void tst_QLibrary::loadAfterFailedLoad()
+{
+#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+ QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt");
+#endif
+
+ QTemporaryDir dir;
+ QLibrary library(dir.path() + "/mylib");
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+ QVERIFY(!library.load());
+ QVERIFY(!library.isLoaded());
+
+ // now copy the actual lib file into our dir
+ QString actualLib = PREFIX "mylib" SUFFIX;
+ QVERIFY(QFile::copy(directory + '/' + actualLib, dir.filePath(actualLib)));
+
+ // try again, must succeed now
+ QVERIFY(library.load());
+ QVERIFY(library.isLoaded());
+ auto p = (VersionFunction)library.resolve("mylibversion");
+ QVERIFY(p);
+ QCOMPARE(p(), 2);
+ library.unload();
+}
+
void tst_QLibrary::resolve_data()
{
QTest::addColumn<QString>("lib");
@@ -260,21 +432,27 @@ void tst_QLibrary::resolve()
QFETCH( QString, symbol );
QFETCH( bool, goodPointer );
- QLibrary library( lib );
- testFunc func = (testFunc) library.resolve( symbol.toLatin1() );
- if ( goodPointer ) {
- QVERIFY( func != 0 );
+ QLibrary library(lib);
+ QVERIFY(!library.isLoaded());
+ testFunc func = (testFunc) library.resolve(symbol.toLatin1());
+
+ if (goodPointer) {
+ QVERIFY(library.isLoaded());
+ QVERIFY(func);
+
+ QLibrary lib2(lib);
+ QVERIFY(!lib2.isLoaded());
+ QVERIFY(lib2.load());
+
+ // this unload() won't unload and it must still be loaded
+ QVERIFY(!lib2.unload());
+ func(); // doesn't crash
} else {
- QVERIFY( func == 0 );
+ QVERIFY(func == nullptr);
}
library.unload();
}
-void tst_QLibrary::library_data()
-{
- QTest::addColumn<QString>("lib");
-}
-
void tst_QLibrary::isLibrary_data()
{
QTest::addColumn<QString>("filename");
@@ -295,7 +473,7 @@ void tst_QLibrary::isLibrary_data()
QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << so_VALID;
// special tests:
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
QTest::newRow("good (libmylib.1.0.0.dylib)") << QString("libmylib.1.0.0.dylib") << true;
QTest::newRow("good (libmylib.dylib)") << QString("libmylib.dylib") << true;
QTest::newRow("good (libmylib.so)") << QString("libmylib.so") << true;
@@ -332,7 +510,7 @@ void tst_QLibrary::errorString_data()
#ifdef Q_OS_WIN
QTest::newRow("bad load() with .dll suffix") << (int)Load << QString("nosuchlib.dll") << false << QString("Cannot load library nosuchlib.dll: The specified module could not be found.");
// QTest::newRow("bad unload") << (int)Unload << QString("nosuchlib.dll") << false << QString("QLibrary::unload_sys: Cannot unload nosuchlib.dll (The specified module could not be found.)");
-#elif defined Q_OS_MAC
+#elif defined Q_OS_DARWIN
#else
QTest::newRow("load invalid file") << (int)Load << QFINDTESTDATA("library_path/invalid.so") << false << QString("Cannot load library.*");
#endif
@@ -480,7 +658,7 @@ void tst_QLibrary::multipleInstancesForOneLibrary()
QCOMPARE(lib2.isLoaded(), false);
lib1.load();
QCOMPARE(lib1.isLoaded(), true);
- QCOMPARE(lib2.isLoaded(), true);
+ QCOMPARE(lib2.isLoaded(), false); // lib2 didn't call load()
QCOMPARE(lib1.unload(), true);
QCOMPARE(lib1.isLoaded(), false);
QCOMPARE(lib2.isLoaded(), false);
@@ -489,7 +667,7 @@ void tst_QLibrary::multipleInstancesForOneLibrary()
QCOMPARE(lib1.isLoaded(), true);
QCOMPARE(lib2.isLoaded(), true);
QCOMPARE(lib1.unload(), false);
- QCOMPARE(lib1.isLoaded(), true);
+ QCOMPARE(lib1.isLoaded(), false); // lib1 did call unload()
QCOMPARE(lib2.isLoaded(), true);
QCOMPARE(lib2.unload(), true);
QCOMPARE(lib1.isLoaded(), false);
@@ -498,17 +676,6 @@ void tst_QLibrary::multipleInstancesForOneLibrary()
// Finally; unload on that is already unloaded
QCOMPARE(lib1.unload(), false);
}
-
- //now let's try with a 3rd one that will go out of scope
- {
- QLibrary lib1(lib);
- QCOMPARE(lib1.isLoaded(), false);
- lib1.load();
- QCOMPARE(lib1.isLoaded(), true);
- }
- QLibrary lib2(lib);
- //lib2 should be loaded because lib1 was loaded and never unloaded
- QCOMPARE(lib2.isLoaded(), true);
}
QTEST_MAIN(tst_QLibrary)
diff --git a/tests/auto/corelib/plugin/qplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qplugin/CMakeLists.txt
index 1713f8c2af..d0e8736e09 100644
--- a/tests/auto/corelib/plugin/qplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qplugin/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qplugin LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(invalidplugin)
add_subdirectory(debugplugin)
diff --git a/tests/auto/corelib/plugin/qplugin/debugplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qplugin/debugplugin/CMakeLists.txt
index ee4c0cf33c..230282f175 100644
--- a/tests/auto/corelib/plugin/qplugin/debugplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qplugin/debugplugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from debugplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## debugplugin Generic Library:
@@ -9,11 +10,8 @@ qt_internal_add_cmake_library(debugplugin
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../plugins"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-#### Keys ignored in scope 1:.:.:debugplugin.pro:<TRUE>:
-# TEMPLATE = "lib"
-
qt_autogen_tools_initial_setup(debugplugin)
diff --git a/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp b/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp
index 635dbd7856..fe25c44d87 100644
--- a/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp
+++ b/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtPlugin>
#include <QObject>
diff --git a/tests/auto/corelib/plugin/qplugin/invalidplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qplugin/invalidplugin/CMakeLists.txt
index b9cdf2af05..0b12e9c0f0 100644
--- a/tests/auto/corelib/plugin/qplugin/invalidplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qplugin/invalidplugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from invalidplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## invalidplugin Generic Library:
@@ -9,11 +10,10 @@ qt_internal_add_cmake_library(invalidplugin
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../plugins"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-#### Keys ignored in scope 1:.:.:invalidplugin.pro:<TRUE>:
# TEMPLATE = "lib"
qt_autogen_tools_initial_setup(invalidplugin)
diff --git a/tests/auto/corelib/plugin/qplugin/invalidplugin/main.cpp b/tests/auto/corelib/plugin/qplugin/invalidplugin/main.cpp
index 083f3ad14f..10b6131857 100644
--- a/tests/auto/corelib/plugin/qplugin/invalidplugin/main.cpp
+++ b/tests/auto/corelib/plugin/qplugin/invalidplugin/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qplugin.h>
diff --git a/tests/auto/corelib/plugin/qplugin/releaseplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qplugin/releaseplugin/CMakeLists.txt
index abf3ae2a4d..3ec89eb4c6 100644
--- a/tests/auto/corelib/plugin/qplugin/releaseplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qplugin/releaseplugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from releaseplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## releaseplugin Generic Library:
@@ -9,11 +10,8 @@ qt_internal_add_cmake_library(releaseplugin
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../plugins"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-#### Keys ignored in scope 1:.:.:releaseplugin.pro:<TRUE>:
-# TEMPLATE = "lib"
-
qt_autogen_tools_initial_setup(releaseplugin)
diff --git a/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp b/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp
index edb2340a7d..ee14da8384 100644
--- a/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp
+++ b/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtPlugin>
#include <QObject>
diff --git a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp
index e96204c471..3d3cb8330d 100644
--- a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp
+++ b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2020 The Qt Company Ltd.
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QCoreApplication>
@@ -57,7 +57,7 @@ void tst_QPlugin::loadDebugPlugin()
if (!QLibrary::isLibrary(fileName))
continue;
QPluginLoader loader(dir.filePath(fileName));
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
// we can always load a plugin on unix
QVERIFY(loader.load());
QObject *object = loader.instance();
@@ -90,7 +90,7 @@ void tst_QPlugin::loadReleasePlugin()
if (!QLibrary::isLibrary(fileName))
continue;
QPluginLoader loader(dir.filePath(fileName));
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
// we can always load a plugin on unix
QVERIFY(loader.load());
QObject *object = loader.instance();
@@ -152,8 +152,8 @@ void tst_QPlugin::scanInvalidPlugin_data()
<< " Unexpected metadata contents";
++cprefix[MagicLen + 0];
- QTest::newRow("cbor-major-too-new") << (cprefix + cborValid) << false
- << " Invalid metadata version";
+ QTest::newRow("cbor-major-too-new-invalid")
+ << (cprefix + cborValid) << false << " Invalid metadata version";
}
static const char invalidPluginSignature[] = "qplugin testfile";
@@ -224,10 +224,6 @@ void tst_QPlugin::scanInvalidPlugin()
// now try to load this
QFETCH(bool, loads);
QFETCH(QString, errMsg);
- if (!errMsg.isEmpty())
- QTest::ignoreMessage(QtWarningMsg,
- "Found invalid metadata in lib " + QFile::encodeName(newName) +
- ":" + errMsg.toUtf8());
QPluginLoader loader(newName);
QCOMPARE(loader.load(), loads);
if (loads)
diff --git a/tests/auto/corelib/plugin/qpluginloader/BLACKLIST b/tests/auto/corelib/plugin/qpluginloader/BLACKLIST
deleted file mode 100644
index bfcfdff61b..0000000000
--- a/tests/auto/corelib/plugin/qpluginloader/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-[loadMachO]
-macos cmake
diff --git a/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt
index a051bb3ea6..592b8632fa 100644
--- a/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qpluginloader.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpluginloader LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(lib)
add_subdirectory(staticplugin)
diff --git a/tests/auto/corelib/plugin/qpluginloader/almostplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/almostplugin/CMakeLists.txt
index fe5d6295aa..15ae79dfb1 100644
--- a/tests/auto/corelib/plugin/qpluginloader/almostplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/almostplugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from almostplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## almostplugin Generic Library:
@@ -10,23 +11,8 @@ qt_internal_add_cmake_library(almostplugin
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
almostplugin.cpp almostplugin.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-#### Keys ignored in scope 1:.:.:almostplugin.pro:<TRUE>:
-# INSTALLS = "target"
-# TEMPLATE = "lib"
-# target.path = "$$[QT_INSTALL_TESTS]/tst_qpluginloader/bin"
-
-## Scopes:
-#####################################################################
-
qt_autogen_tools_initial_setup(almostplugin)
-# special case begin
-# We want the opposite of this
-#qt_internal_extend_target(almostplugin CONDITION GCC
-# LINK_OPTIONS
-# "--Wl,--no-undefined"
-#)
-# special case end
diff --git a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp
index afb77d8f3a..29b6df2683 100644
--- a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QString>
#include "almostplugin.h"
#include <QtCore/qplugin.h>
diff --git a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h
index 88592d9bbf..dea26875c2 100644
--- a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h
+++ b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef ALMOSTPLUGIN_H
#define ALMOSTPLUGIN_H
diff --git a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
index e52206579e..e84bfa6dbc 100644
--- a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QT_VERSION_MAJOR
# include <QtCore/qglobal.h>
#endif
diff --git a/tests/auto/corelib/plugin/qpluginloader/lib/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/lib/CMakeLists.txt
index 7914f07c0d..283bdb1352 100644
--- a/tests/auto/corelib/plugin/qpluginloader/lib/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/lib/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from lib.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpluginloaderlib Generic Library:
@@ -10,21 +11,14 @@ qt_internal_add_cmake_library(tst_qpluginloaderlib
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
mylib.c
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
-# special case begin
if(WIN32)
# CMake sets for Windows-GNU platforms the suffix "lib"
set_property(TARGET tst_qpluginloaderlib PROPERTY PREFIX "")
endif()
-# special case begin
-
-#### Keys ignored in scope 1:.:.:lib.pro:<TRUE>:
-# INSTALLS = "target"
-# TEMPLATE = "lib"
-# target.path = "$$[QT_INSTALL_TESTS]/tst_qpluginloader/bin"
## Scopes:
#####################################################################
@@ -34,9 +28,7 @@ qt_internal_extend_target(tst_qpluginloaderlib CONDITION MSVC
WIN32_MSVC
)
-# special case begin
set_target_properties(tst_qpluginloaderlib PROPERTIES
C_VISIBILITY_PRESET "default"
CXX_VISIBILITY_PRESET "default"
)
-# special case end
diff --git a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
index 087fc5aa31..3f1fe03114 100644
--- a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
+++ b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qglobal.h>
diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/machtest/CMakeLists.txt
index 05cd044aa3..6cb69fc46d 100644
--- a/tests/auto/corelib/plugin/qpluginloader/machtest/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/machtest/CMakeLists.txt
@@ -1,2 +1,138 @@
-# Generated from machtest.pro.
+set_directory_properties(PROPERTIES
+ _qt_good_targets ""
+ _qt_stub_targets ""
+)
+function(add_plugin_binary)
+ set(no_value_options "")
+ set(single_value_options NAME ARCH OUT_TARGET)
+ set(multi_value_options SOURCES)
+ cmake_parse_arguments(PARSE_ARGV 0 arg
+ "${no_value_options}" "${single_value_options}" "${multi_value_options}"
+ )
+
+ set(output_name ${arg_NAME}.${arg_ARCH})
+ set(target tst_qpluginloader.${output_name})
+ set(${arg_OUT_TARGET} ${target} PARENT_SCOPE)
+ set_property(DIRECTORY APPEND PROPERTY _qt_${arg_NAME}_targets ${target})
+ add_library(${target} MODULE ${arg_SOURCES})
+ add_dependencies(tst_qpluginloader ${target})
+ set_target_properties(${target} PROPERTIES
+ OUTPUT_NAME ${output_name}
+ PREFIX ""
+ SUFFIX ".dylib"
+ DEBUG_POSTFIX ""
+ OSX_ARCHITECTURES ${arg_ARCH}
+ )
+endfunction()
+
+function(add_good_binary)
+ set(no_value_options "")
+ set(single_value_options ARCH)
+ set(multi_value_options "")
+ cmake_parse_arguments(PARSE_ARGV 0 arg
+ "${no_value_options}" "${single_value_options}" "${multi_value_options}"
+ )
+
+ add_plugin_binary(
+ NAME good
+ ARCH ${arg_ARCH}
+ SOURCES ../fakeplugin.cpp
+ OUT_TARGET target
+ )
+
+ # We cannot link against Qt6::Core, because the architecture might not match.
+ # Extract the include directories from Qt6::Core.
+ get_target_property(incdirs Qt6::Core INTERFACE_INCLUDE_DIRECTORIES)
+ target_include_directories(${target} PRIVATE ${incdirs})
+
+ # Extract the compile definitions from Qt6::Core and disable version tagging.
+ get_target_property(compdefs Qt6::Core INTERFACE_COMPILE_DEFINITIONS)
+ target_compile_definitions(${target} PRIVATE
+ ${compdefs}
+ QT_NO_VERSION_TAGGING
+ )
+endfunction()
+
+function(add_stub_binary)
+ set(no_value_options "")
+ set(single_value_options ARCH)
+ set(multi_value_options "")
+ cmake_parse_arguments(PARSE_ARGV 0 arg
+ "${no_value_options}" "${single_value_options}" "${multi_value_options}"
+ )
+
+ add_plugin_binary(
+ NAME stub
+ ARCH ${arg_ARCH}
+ SOURCES stub.cpp
+ )
+endfunction()
+
+function(add_fat_binary)
+ set(no_value_options "")
+ set(single_value_options NAME OUT_TARGET)
+ set(multi_value_options TARGETS)
+ cmake_parse_arguments(PARSE_ARGV 0 arg
+ "${no_value_options}" "${single_value_options}" "${multi_value_options}"
+ )
+
+ set(arch_args "")
+ foreach(dependency IN LISTS arg_TARGETS)
+ get_target_property(arch ${dependency} OSX_ARCHITECTURES)
+ list(APPEND arch_args -arch ${arch} $<TARGET_FILE_NAME:${dependency}>)
+ endforeach()
+
+ set(output_name good.fat.${arg_NAME})
+ set(output_file ${output_name}.dylib)
+ set(target tst_qpluginloader.${output_name})
+ set(${arg_OUT_TARGET} ${target} PARENT_SCOPE)
+ add_custom_command(
+ OUTPUT ${output_file}
+ COMMAND lipo -create -output ${output_file} ${arch_args}
+ DEPENDS ${arg_TARGETS}
+ )
+ add_custom_target(${target}
+ DEPENDS ${output_file}
+ )
+ add_dependencies(tst_qpluginloader ${target})
+endfunction()
+
+set(archs_to_test arm64 x86_64)
+foreach(arch IN LISTS archs_to_test)
+ add_good_binary(ARCH ${arch})
+ add_stub_binary(ARCH ${arch})
+endforeach()
+
+get_directory_property(good_targets _qt_good_targets)
+add_fat_binary(NAME all TARGETS ${good_targets})
+
+set(targets ${good_targets})
+list(FILTER targets EXCLUDE REGEX "\\.arm64$")
+add_fat_binary(NAME no-arm64 TARGETS ${targets})
+
+set(targets ${good_targets})
+list(FILTER targets EXCLUDE REGEX "\\.x86_64$")
+add_fat_binary(NAME no-x86_64 TARGETS ${targets})
+
+get_directory_property(stub_targets _qt_stub_targets)
+set(targets ${stub_targets})
+list(FILTER targets INCLUDE REGEX "\\.arm64$")
+add_fat_binary(NAME stub-arm64 TARGETS ${targets})
+
+set(targets ${stub_targets})
+list(FILTER targets INCLUDE REGEX "\\.x86_64$")
+add_fat_binary(NAME stub-x86_64 TARGETS ${targets})
+
+set(bad_binary_names "")
+foreach(i RANGE 1 13)
+ list(APPEND bad_binary_names "bad${i}.dylib")
+endforeach()
+add_custom_command(
+ OUTPUT ${bad_binary_names}
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-bad.pl
+)
+add_custom_target(tst_qpluginloader_generate_bad_binaries
+ DEPENDS ${bad_binary_names}
+)
+add_dependencies(tst_qpluginloader tst_qpluginloader_generate_bad_binaries)
diff --git a/tests/auto/corelib/plugin/qpluginloader/machtest/ppcconverter.pl b/tests/auto/corelib/plugin/qpluginloader/machtest/ppcconverter.pl
deleted file mode 100755
index 64b937991a..0000000000
--- a/tests/auto/corelib/plugin/qpluginloader/machtest/ppcconverter.pl
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/perl
-# Copyright (C) 2016 Intel Corporation.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-# Changes the Mach-O file type header to PowerPC.
-#
-# The header is (from mach-o/loader.h):
-# struct mach_header {
-# uint32_t magic; /* mach magic number identifier */
-# cpu_type_t cputype; /* cpu specifier */
-# cpu_subtype_t cpusubtype; /* machine specifier */
-# uint32_t filetype; /* type of file */
-# uint32_t ncmds; /* number of load commands */
-# uint32_t sizeofcmds; /* the size of all the load commands */
-# uint32_t flags; /* flags */
-# };
-#
-# The 64-bit header is identical in the first three fields, except for a different
-# magic number. We will not touch the magic number, we'll just reset the cputype
-# field to the PowerPC type and the subtype field to zero.
-#
-# We will not change the file's endianness. That means we might create a little-endian
-# PowerPC binary, which could not be run in real life.
-#
-# We will also not change the 64-bit ABI flag, which is found in the cputype's high
-# byte. That means we'll create a PPC64 binary if fed a 64-bit input.
-#
-use strict;
-use constant MH_MAGIC => 0xfeedface;
-use constant MH_CIGAM => 0xcefaedfe;
-use constant MH_MAGIC_64 => 0xfeedfacf;
-use constant MH_CIGAM_64 => 0xcffaedfe;
-use constant CPU_TYPE_POWERPC => 18;
-use constant CPU_SUBTYPE_POWERPC_ALL => 0;
-
-my $infile = shift @ARGV or die("Missing input filename");
-my $outfile = shift @ARGV or die("Missing output filename");
-
-open IN, "<$infile" or die("Can't open $infile for reading: $!\n");
-open OUT, ">$outfile" or die("Can't open $outfile for writing: $!\n");
-
-binmode IN;
-binmode OUT;
-
-# Read the first 12 bytes, which includes the interesting fields of the header
-my $buffer;
-read(IN, $buffer, 12);
-
-my $magic = vec($buffer, 0, 32);
-if ($magic == MH_MAGIC || $magic == MH_MAGIC_64) {
- # Big endian
- # The low byte of cputype is at offset 7
- vec($buffer, 7, 8) = CPU_TYPE_POWERPC;
-} elsif ($magic == MH_CIGAM || $magic == MH_CIGAM_64) {
- # Little endian
- # The low byte of cpytype is at offset 4
- vec($buffer, 4, 8) = CPU_TYPE_POWERPC;
-} else {
- $magic = '';
- $magic .= sprintf("%02X ", $_) for unpack("CCCC", $buffer);
- die("Invalid input. Unknown magic $magic\n");
-}
-vec($buffer, 2, 32) = CPU_SUBTYPE_POWERPC_ALL;
-
-print OUT $buffer;
-
-# Copy the rest
-while (!eof(IN)) {
- read(IN, $buffer, 4096) and
- print OUT $buffer or
- die("Problem copying: $!\n");
-}
-close(IN);
-close(OUT);
diff --git a/tests/auto/corelib/plugin/qpluginloader/staticplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/staticplugin/CMakeLists.txt
index 68d9a5da0a..647c8ac207 100644
--- a/tests/auto/corelib/plugin/qpluginloader/staticplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/staticplugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from staticplugin.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## staticplugin Generic Library:
@@ -17,7 +18,6 @@ qt_internal_add_cmake_library(staticplugin
"ExtraMetaData=foo"
)
-#### Keys ignored in scope 1:.:.:staticplugin.pro:<TRUE>:
# TEMPLATE = "lib"
qt_autogen_tools_initial_setup(staticplugin)
diff --git a/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp b/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp
index d0d9d5f59d..208096b425 100644
--- a/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/staticplugin/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtPlugin>
#include <QObject>
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/theplugin/CMakeLists.txt
index 1e7754a167..dfce9d6a52 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/CMakeLists.txt
@@ -1,10 +1,13 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
qt_internal_add_cmake_library(theplugin
MODULE
INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/tst_qpluginloader/bin"
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
theplugin.cpp theplugin.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
qt_autogen_tools_initial_setup(theplugin)
@@ -16,7 +19,7 @@ if (UNIX AND NOT APPLE)
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin"
SOURCES
theoldplugin.cpp theoldplugin.h
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
)
qt_autogen_tools_initial_setup(theoldplugin)
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h b/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h
index d139919a07..3fd6c384a4 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.cpp
index 59f180b0e8..20e65b4bb0 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "theoldplugin.h"
#include <QtCore/QString>
#include <QtCore/qplugin.h>
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.h b/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.h
index 781fdefa2c..786ce3f618 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.h
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theoldplugin.h
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Intel Corportaion.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef THEOLDPLUGIN_H
#define THEOLDPLUGIN_H
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
index 1656718de3..bfa45c7c48 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QString>
#include "theplugin.h"
#include <QtCore/qplugin.h>
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h
index 3a2f0d09fd..a6b7e4a083 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef THEPLUGIN_H
#define THEPLUGIN_H
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
index ca27cef44b..16dd1cf9cf 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from tst.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpluginloader Test:
@@ -55,16 +56,16 @@ qt_internal_extend_target(tst_qpluginloader CONDITION QT_FEATURE_private_tests
)
qt_internal_extend_target(tst_qpluginloader CONDITION CMAKE_BUILD_TYPE STREQUAL Debug AND WIN32 AND debug_and_release
- PUBLIC_LIBRARIES
+ LIBRARIES
# Remove: L../staticplugin/debug
)
qt_internal_extend_target(tst_qpluginloader CONDITION WIN32 AND debug_and_release AND NOT CMAKE_BUILD_TYPE STREQUAL Debug
- PUBLIC_LIBRARIES
+ LIBRARIES
# Remove: L../staticplugin/release
)
qt_internal_extend_target(tst_qpluginloader CONDITION UNIX OR NOT debug_and_release
- PUBLIC_LIBRARIES
+ LIBRARIES
# Remove: L../staticplugin
)
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
index 2c2b24acee..f4ecf5bfb3 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2020 The Qt Company Ltd.
// Copyright (C) 2021 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -16,6 +16,8 @@
# include <QtCore/private/qmachparser_p.h>
#endif
+using namespace Qt::StringLiterals;
+
// Helper macros to let us know if some suffixes are valid
#define bundle_VALID false
#define dylib_VALID false
@@ -128,7 +130,7 @@ static std::unique_ptr<QTemporaryFile> patchElf(const QString &source, ElfPatche
const char *basename = QTest::currentDataTag();
if (!basename)
basename = QTest::currentTestFunction();
- tmplib.reset(new QTemporaryFile(basename + QString(".XXXXXX" SUFFIX)));
+ tmplib.reset(new QTemporaryFile(QDir::currentPath() + u'/' + basename + u".XXXXXX" SUFFIX ""_s));
QVERIFY2(tmplib->open(), qPrintable(tmplib->errorString()));
// sanity-check
@@ -206,6 +208,7 @@ private slots:
void preloadedPlugin_data();
void preloadedPlugin();
void staticPlugins();
+ void reregisteredStaticPlugins();
};
Q_IMPORT_PLUGIN(StaticPlugin)
@@ -277,7 +280,9 @@ void tst_QPluginLoader::errorString()
QVERIFY(!unloaded);
}
-#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) && !defined(Q_OS_HPUX)
+// A bug in QNX causes the test to crash on exit after attempting to load
+// a shared library with undefined symbols (tracked as QTBUG-114682).
+#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) && !defined(Q_OS_HPUX) && !defined(Q_OS_QNX)
{
QPluginLoader loader( sys_qualifiedLibraryName("almostplugin")); //a plugin with unresolved symbols
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
@@ -337,16 +342,34 @@ void tst_QPluginLoader::loadHints()
QCOMPARE(loader.loadHints(), QLibrary::PreventUnloadHint); //Do not crash
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
+ // We can clear load hints when file name is not set.
+ loader.setLoadHints(QLibrary::LoadHints{});
+ QCOMPARE(loader.loadHints(), QLibrary::LoadHints{});
+ // Set the hints again
+ loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
+ QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
loader.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin
QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
+ QPluginLoader loader4;
+ QCOMPARE(loader4.loadHints(), QLibrary::PreventUnloadHint);
+ loader4.setLoadHints(QLibrary::LoadHints{});
+ QCOMPARE(loader4.loadHints(), QLibrary::LoadHints{});
+ loader4.setFileName(sys_qualifiedLibraryName("theplugin"));
+ // Hints are merged with hints from the previous loader.
+ QCOMPARE(loader4.loadHints(), QLibrary::ResolveAllSymbolsHint);
+ // We cannot clear load hints after associating the loader with a file.
+ loader.setLoadHints(QLibrary::LoadHints{});
+ QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
+
QPluginLoader loader2;
QCOMPARE(loader2.loadHints(), QLibrary::PreventUnloadHint);
loader2.setFileName(sys_qualifiedLibraryName("theplugin"));
- QCOMPARE(loader2.loadHints(), QLibrary::PreventUnloadHint);
+ // Hints are merged with hints from previous loaders.
+ QCOMPARE(loader2.loadHints(), QLibrary::PreventUnloadHint | QLibrary::ResolveAllSymbolsHint);
QPluginLoader loader3(sys_qualifiedLibraryName("theplugin"));
- QCOMPARE(loader3.loadHints(), QLibrary::PreventUnloadHint);
+ QCOMPARE(loader3.loadHints(), QLibrary::PreventUnloadHint | QLibrary::ResolveAllSymbolsHint);
}
void tst_QPluginLoader::deleteinstanceOnUnload()
@@ -376,14 +399,14 @@ void tst_QPluginLoader::deleteinstanceOnUnload()
QVERIFY(spy2.isValid());
if (pass == 0) {
QCOMPARE(loader2.unload(), false); // refcount not reached 0, not really unloaded
- QCOMPARE(spy1.count(), 0);
- QCOMPARE(spy2.count(), 0);
+ QCOMPARE(spy1.size(), 0);
+ QCOMPARE(spy2.size(), 0);
}
QCOMPARE(instance1->pluginName(), QLatin1String("Plugin ok"));
QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));
QVERIFY(loader1.unload()); // refcount reached 0, did really unload
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
+ QCOMPARE(spy1.size(), 1);
+ QCOMPARE(spy2.size(), 1);
}
}
@@ -451,7 +474,7 @@ static void loadCorruptElfCommonRows()
memcpy(h, &o, sizeof(o));
});
newRow("invalid-word-size", "file is for a different word size", [](H h) {
- h->e_ident[EI_CLASS] = ELFCLASSNONE;;
+ h->e_ident[EI_CLASS] = ELFCLASSNONE;
});
newRow("unknown-word-size", "file is for a different word size", [](H h) {
h->e_ident[EI_CLASS] |= 0x40;
@@ -837,26 +860,23 @@ void tst_QPluginLoader::loadMachO_data()
# ifdef Q_PROCESSOR_X86_64
QTest::newRow("machtest/good.x86_64.dylib") << true;
- QTest::newRow("machtest/good.i386.dylib") << false;
+ QTest::newRow("machtest/good.arm64.dylib") << false;
QTest::newRow("machtest/good.fat.no-x86_64.dylib") << false;
- QTest::newRow("machtest/good.fat.no-i386.dylib") << true;
-# elif defined(Q_PROCESSOR_X86_32)
- QTest::newRow("machtest/good.i386.dylib") << true;
+ QTest::newRow("machtest/good.fat.no-arm64.dylib") << true;
+# elif defined(Q_PROCESSOR_ARM)
+ QTest::newRow("machtest/good.arm64.dylib") << true;
QTest::newRow("machtest/good.x86_64.dylib") << false;
- QTest::newRow("machtest/good.fat.no-i386.dylib") << false;
+ QTest::newRow("machtest/good.fat.no-arm64.dylib") << false;
QTest::newRow("machtest/good.fat.no-x86_64.dylib") << true;
# endif
-# ifndef Q_PROCESSOR_POWER_64
- QTest::newRow("machtest/good.ppc64.dylib") << false;
-# endif
QTest::newRow("machtest/good.fat.all.dylib") << true;
QTest::newRow("machtest/good.fat.stub-x86_64.dylib") << false;
- QTest::newRow("machtest/good.fat.stub-i386.dylib") << false;
+ QTest::newRow("machtest/good.fat.stub-arm64.dylib") << false;
QDir d(QFINDTESTDATA("machtest"));
- QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
- foreach (const QString &bad, badlist)
+ const QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
+ for (const QString &bad : badlist)
QTest::newRow(qPrintable("machtest/" + bad)) << false;
#endif
}
@@ -880,12 +900,7 @@ void tst_QPluginLoader::loadMachO()
}
QVERIFY(r.pos > 0);
- QVERIFY(size_t(r.length) >= sizeof(void*));
QVERIFY(r.pos + r.length < data.size());
- QCOMPARE(r.pos & (sizeof(void*) - 1), 0UL);
-
- void *value = *(void**)(data.constData() + r.pos);
- QCOMPARE(value, sizeof(void*) > 4 ? (void*)(0xc0ffeec0ffeeL) : (void*)0xc0ffee);
// now that we know it's valid, let's try to make it invalid
ulong offeredlen = r.pos;
@@ -969,7 +984,7 @@ void tst_QPluginLoader::reloadPlugin()
QSignalSpy spy(loader.instance(), &QObject::destroyed);
QVERIFY(spy.isValid());
QVERIFY(loader.unload()); // refcount reached 0, did really unload
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
// reload plugin
QVERIFY(loader.load());
@@ -984,6 +999,10 @@ void tst_QPluginLoader::reloadPlugin()
void tst_QPluginLoader::loadSectionTableStrippedElf()
{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 24)
+ QSKIP("Android 7+ (API 24+) linker doesn't allow missing or bad section header");
+#endif
#if !defined(QT_SHARED)
QSKIP("This test requires a shared build of Qt, as QPluginLoader::setFileName is a no-op in static builds");
#elif !defined(Q_OF_ELF)
@@ -1076,19 +1095,18 @@ 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);
+ // ensure the our plugin only shows up once
+ int foundCount = std::count_if(instances.begin(), instances.end(), [](QObject *obj) {
+ return obj->metaObject()->className() == QLatin1String("StaticPlugin");
+ });
+ QCOMPARE(foundCount, 1);
const auto plugins = QPluginLoader::staticPlugins();
QCOMPARE(plugins.size(), instances.size());
// find the metadata
QJsonObject metaData;
+ bool found = false;
for (const auto &p : plugins) {
metaData = p.metaData();
found = metaData.value("className").toString() == QLatin1String("StaticPlugin");
@@ -1104,6 +1122,18 @@ void tst_QPluginLoader::staticPlugins()
QCOMPARE(metaData.value("URI").toString(), "qt.test.pluginloader.staticplugin");
}
+void tst_QPluginLoader::reregisteredStaticPlugins()
+{
+ // the Q_IMPORT_PLUGIN macro will have already done this
+ qRegisterStaticPluginFunction(qt_static_plugin_StaticPlugin());
+ staticPlugins();
+ if (QTest::currentTestFailed())
+ return;
+
+ qRegisterStaticPluginFunction(qt_static_plugin_StaticPlugin());
+ staticPlugins();
+}
+
QTEST_MAIN(tst_QPluginLoader)
#include "tst_qpluginloader.moc"
diff --git a/tests/auto/corelib/plugin/quuid/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/CMakeLists.txt
index 91e75fe0ae..be90dc1849 100644
--- a/tests/auto/corelib/plugin/quuid/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from quuid.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_quuid LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(testProcessUniqueness)
add_subdirectory(test)
diff --git a/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
index 233a410db6..1e1e820b14 100644
--- a/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## tst_quuid Test:
#####################################################################
@@ -13,7 +16,8 @@ qt_internal_add_test(tst_quuid
qt_internal_extend_target(tst_quuid CONDITION APPLE
SOURCES
../tst_quuid_darwin.mm
- PUBLIC_LIBRARIES
+ LIBRARIES
+ Qt::CorePrivate
${FWFoundation}
)
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
index 0bdf32a207..f207cdaa3a 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from testProcessUniqueness.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## testProcessUniqueness Binary:
@@ -11,6 +12,4 @@ qt_internal_add_executable(testProcessUniqueness
main.cpp
)
-# special case begin
set_target_properties(testProcessUniqueness PROPERTIES MACOSX_BUNDLE TRUE)
-# special case end
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
index 07109afabf..93d1201631 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <stdio.h>
#include <QUuid>
diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
index eb0ce46502..c5ce490b61 100644
--- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
+++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -25,6 +25,8 @@ private slots:
void fromByteArray();
void toRfc4122();
void fromRfc4122();
+ void id128();
+ void uint128();
void createUuidV3OrV5();
void check_QDataStream();
void isNull();
@@ -98,7 +100,7 @@ void tst_QUuid::fromChar()
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34-"));
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34"));
QCOMPARE(QUuid(), QUuid("cc34"));
- QCOMPARE(QUuid(), QUuid(NULL));
+ QCOMPARE(QUuid(), QUuid(nullptr));
QCOMPARE(uuidB, QUuid(QString("{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}")));
}
@@ -135,7 +137,7 @@ void tst_QUuid::fromString_data()
ROW(uuidA, "{fc69b59e-cc34-4436-a43c-ee95d128b8c56"); // too long (not an error!)
ROW(invalid, "{fc69b59e-cc34-4436-a43c-ee95d128b8c" ); // premature end (within length limits)
ROW(invalid, " fc69b59e-cc34-4436-a43c-ee95d128b8c5}"); // leading space
- ROW(uuidA, "{fc69b59e-cc34-4436-a43c-ee95d128b8c5 "); // trailing space (not an error!)
+ ROW(uuidB, "{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b "); // trailing space (not an error!)
ROW(invalid, "{gc69b59e-cc34-4436-a43c-ee95d128b8c5}"); // non-hex digit in 1st group
ROW(invalid, "{fc69b59e-cp34-4436-a43c-ee95d128b8c5}"); // non-hex digit in 2nd group
ROW(invalid, "{fc69b59e-cc34-44r6-a43c-ee95d128b8c5}"); // non-hex digit in 3rd group
@@ -217,6 +219,78 @@ void tst_QUuid::fromRfc4122()
QCOMPARE(uuidB, QUuid::fromRfc4122(QByteArray::fromHex("1ab6e93ab1cb4a87ba47ec7e99039a7b")));
}
+void tst_QUuid::id128()
+{
+ constexpr QUuid::Id128Bytes bytesA = { {
+ 0xfc, 0x69, 0xb5, 0x9e,
+ 0xcc, 0x34,
+ 0x44, 0x36,
+ 0xa4, 0x3c, 0xee, 0x95, 0xd1, 0x28, 0xb8, 0xc5,
+ } };
+ constexpr QUuid::Id128Bytes bytesB = { {
+ 0x1a, 0xb6, 0xe9, 0x3a,
+ 0xb1, 0xcb,
+ 0x4a, 0x87,
+ 0xba, 0x47, 0xec, 0x7e, 0x99, 0x03, 0x9a, 0x7b,
+ } };
+
+ QCOMPARE(QUuid(bytesA), uuidA);
+ QCOMPARE(QUuid(bytesB), uuidB);
+ QVERIFY(memcmp(uuidA.toBytes().data, bytesA.data, sizeof(QUuid::Id128Bytes)) == 0);
+ QVERIFY(memcmp(uuidB.toBytes().data, bytesB.data, sizeof(QUuid::Id128Bytes)) == 0);
+
+ QUuid::Id128Bytes leBytesA = {};
+ for (int i = 0; i < 16; i++)
+ leBytesA.data[15 - i] = bytesA.data[i];
+ QCOMPARE(QUuid(leBytesA, QSysInfo::LittleEndian), uuidA);
+ QVERIFY(memcmp(uuidA.toBytes(QSysInfo::LittleEndian).data, leBytesA.data, sizeof(leBytesA)) == 0);
+
+ // check the new q{To,From}{Big,Little}Endian() overloads
+ QUuid::Id128Bytes roundtrip = qFromLittleEndian(qToLittleEndian(bytesA));
+ QVERIFY(memcmp(roundtrip.data, bytesA.data, sizeof(bytesA)) == 0);
+ roundtrip = qFromBigEndian(qToBigEndian(bytesA));
+ QVERIFY(memcmp(roundtrip.data, bytesA.data, sizeof(bytesA)) == 0);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ const QUuid::Id128Bytes beBytesA = qToBigEndian(leBytesA);
+ QVERIFY(memcmp(beBytesA.data, bytesA.data, sizeof(beBytesA)) == 0);
+ const QUuid::Id128Bytes otherLeBytesA = qFromBigEndian(bytesA);
+ QVERIFY(memcmp(otherLeBytesA.data, leBytesA.data, sizeof(leBytesA)) == 0);
+#else // Q_BIG_ENDIAN
+ const QUuid::Id128Bytes otherLeBytesA = qToLittleEndian(bytesA);
+ QVERIFY(memcmp(otherLeBytesA.data, leBytesA.data, sizeof(leBytesA)) == 0);
+ const QUuid::Id128Bytes beBytesA = qFromLittleEndian(leBytesA);
+ QVERIFY(memcmp(beBytesA.data, bytesA.data, sizeof(beBytesA)) == 0);
+#endif // Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+}
+
+void tst_QUuid::uint128()
+{
+#ifdef QT_SUPPORTS_INT128
+ constexpr quint128 u = Q_UINT128_C(0xfc69b59e'cc344436'a43cee95'd128b8c5); // This is LE
+ constexpr quint128 be = qToBigEndian(u);
+ constexpr QUuid uuid = QUuid::fromUInt128(be);
+ static_assert(uuid.toUInt128() == be, "Round-trip through QUuid failed");
+
+ QCOMPARE(uuid, uuidA);
+ QCOMPARE(uuid.toUInt128(), be);
+
+ quint128 le = qFromBigEndian(be);
+ QCOMPARE(uuid.toUInt128(QSysInfo::LittleEndian), le);
+ QCOMPARE(QUuid::fromUInt128(le, QSysInfo::LittleEndian), uuidA);
+
+ QUuid::Id128Bytes bytes = { .data128 = { qToBigEndian(u) } };
+ QUuid uuid2(bytes);
+ QCOMPARE(uuid2, uuid);
+
+ // verify that toBytes() and toUInt128() provide bytewise similar result
+ constexpr quint128 val = uuid.toUInt128();
+ bytes = uuid.toBytes();
+ QVERIFY(memcmp(&val, bytes.data, sizeof(val)) == 0);
+#else
+ QSKIP("This platform has no support for 128-bit integer");
+#endif
+}
+
void tst_QUuid::createUuidV3OrV5()
{
//"www.widgets.com" is also from RFC4122
@@ -372,13 +446,13 @@ public:
void tst_QUuid::threadUniqueness()
{
QList<UuidThread *> threads(qMax(2, QThread::idealThreadCount()));
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
threads[i] = new UuidThread;
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
threads[i]->start();
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
QVERIFY(threads[i]->wait(1000));
- for (int i = 1; i < threads.count(); ++i)
+ for (int i = 1; i < threads.size(); ++i)
QVERIFY(threads[0]->uuid != threads[i]->uuid);
qDeleteAll(threads);
}
@@ -396,7 +470,7 @@ void tst_QUuid::processUniqueness()
QString processTwoOutput;
// Start it once
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
process.start("testProcessUniqueness/testProcessUniqueness.app");
#elif defined(Q_OS_ANDROID)
process.start("libtestProcessUniqueness.so");
@@ -407,7 +481,7 @@ void tst_QUuid::processUniqueness()
processOneOutput = process.readAllStandardOutput();
// Start it twice
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
process.start("testProcessUniqueness/testProcessUniqueness.app");
#elif defined(Q_OS_ANDROID)
process.start("libtestProcessUniqueness.so");
diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm b/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
index a1f040fb4f..c3fc809b1f 100644
--- a/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
+++ b/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
@@ -1,9 +1,11 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QUuid>
#include <QTest>
+#include <QtCore/private/qcore_mac_p.h>
+
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>