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/qpluginloader/lib/mylib.c6
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp6
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp49
3 files changed, 60 insertions, 1 deletions
diff --git a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
index 324dce5b0c..a9abe471b1 100644
--- a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
+++ b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
@@ -53,6 +53,12 @@
# define BORLAND_STDCALL
#endif
+static int pluginVariable = 0xc0ffee;
+LIB_EXPORT int *pointerAddress()
+{
+ return &pluginVariable;
+}
+
LIB_EXPORT int BORLAND_STDCALL version()
{
return 1;
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
index 6abb9b6c20..b26b24f454 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
@@ -46,3 +46,9 @@ QString ThePlugin::pluginName() const
{
return QLatin1String("Plugin ok");
}
+
+static int pluginVariable = 0xc0ffee;
+extern "C" Q_DECL_EXPORT int *pointerAddress()
+{
+ return &pluginVariable;
+}
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
index e056fe2b95..cef4f53101 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
@@ -99,7 +99,11 @@
static QString sys_qualifiedLibraryName(const QString &fileName)
{
- return QFINDTESTDATA(QString("bin/%1%2%3").arg(PREFIX).arg(fileName).arg(SUFFIX));
+ QString libname = QFINDTESTDATA(QString("bin/%1%2%3").arg(PREFIX).arg(fileName).arg(SUFFIX));
+ QFileInfo fi(libname);
+ if (fi.exists())
+ return fi.canonicalFilePath();
+ return libname;
}
QT_FORWARD_DECLARE_CLASS(QPluginLoader)
@@ -119,6 +123,8 @@ private slots:
#endif
void relativePath();
void reloadPlugin();
+ void preloadedPlugin_data();
+ void preloadedPlugin();
};
void tst_QPluginLoader::cleanup()
@@ -354,6 +360,47 @@ void tst_QPluginLoader::reloadPlugin()
QVERIFY(loader.unload());
}
+
+void tst_QPluginLoader::preloadedPlugin_data()
+{
+ QTest::addColumn<bool>("doLoad");
+ QTest::addColumn<QString>("libname");
+ QTest::newRow("create-plugin") << false << sys_qualifiedLibraryName("theplugin");
+ QTest::newRow("load-plugin") << true << sys_qualifiedLibraryName("theplugin");
+ QTest::newRow("create-non-plugin") << false << sys_qualifiedLibraryName("tst_qpluginloaderlib");
+ QTest::newRow("load-non-plugin") << true << sys_qualifiedLibraryName("tst_qpluginloaderlib");
+}
+
+void tst_QPluginLoader::preloadedPlugin()
+{
+ // check that using QPluginLoader does not interfere with QLibrary
+ QFETCH(QString, libname);
+ QLibrary lib(libname);
+ QVERIFY(lib.load());
+
+ typedef int *(*pf_t)();
+ pf_t pf = (pf_t)lib.resolve("pointerAddress");
+ QVERIFY(pf);
+
+ int *pluginVariable = pf();
+ QVERIFY(pluginVariable);
+ QCOMPARE(*pluginVariable, 0xc0ffee);
+
+ {
+ // load the plugin
+ QPluginLoader loader(libname);
+ QFETCH(bool, doLoad);
+ if (doLoad && loader.load()) {
+ // unload() returns false because QLibrary has it loaded
+ QVERIFY(!loader.unload());
+ }
+ }
+
+ QVERIFY(lib.isLoaded());
+
+ // if the library was unloaded behind our backs, the following will crash:
+ QCOMPARE(*pluginVariable, 0xc0ffee);
+ QVERIFY(lib.unload());
}
QTEST_MAIN(tst_QPluginLoader)