From 790fe22c52f15d4ba1c9e48d6f6847d286cb916f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 21 Feb 2013 13:56:21 -0800 Subject: [PATCH] Autotest: check that the plugin was actually unloaded in QPluginLoader Change-Id: I66d26da4e86add244d37ff670ad79ff2aff17ca1 Reviewed-by: Shawn Rutledge --- .../qpluginloader/tst_qpluginloader.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index f0be8cf6f15..e056fe2b95c 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -106,6 +106,8 @@ QT_FORWARD_DECLARE_CLASS(QPluginLoader) class tst_QPluginLoader : public QObject { Q_OBJECT +public slots: + void cleanup(); private slots: void errorString(); void loadHints(); @@ -119,6 +121,21 @@ private slots: void reloadPlugin(); }; +void tst_QPluginLoader::cleanup() +{ + // check if the library/plugin was leaked + // we can't use QPluginLoader::isLoaded here because on some platforms the plugin is always loaded by QPluginLoader. + // Also, if this test fails once, it will keep on failing because we can't force the unload, + // so we report it only once. + static bool failedAlready = false; + if (!failedAlready) { + QLibrary lib(sys_qualifiedLibraryName("theplugin")); + failedAlready = true; + QVERIFY2(!lib.isLoaded(), "Plugin was leaked - will not check again"); + failedAlready = false; + } +} + void tst_QPluginLoader::errorString() { #if defined(Q_OS_WINCE) @@ -334,6 +351,9 @@ void tst_QPluginLoader::reloadPlugin() PluginInterface *instance2 = qobject_cast(loader.instance()); QVERIFY(instance2); QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok")); + + QVERIFY(loader.unload()); +} } QTEST_MAIN(tst_QPluginLoader)