summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2011-09-26 07:46:53 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2011-09-26 08:01:13 (GMT)
commit8d9e63130767858287331d7e19d732919d620607 (patch)
tree9c6c2111e254d328a8d5c4535caa5562c48e4d68
parent930461946ce14051e56a3d7f49e2cd24742b8777 (diff)
downloadQt-8d9e63130767858287331d7e19d732919d620607.zip
Qt-8d9e63130767858287331d7e19d732919d620607.tar.gz
Qt-8d9e63130767858287331d7e19d732919d620607.tar.bz2
Fix plugin implicit loading when calling QPluginLoader::instance().
QPluginLoader::instance() didn't increase loading refcount if another QPluginLoader had already loaded the plugin. This meant that if the another QPluginLoader subsequently unloaded the plugin, the instance would be destroyed even if the second loader still wanted to use it. Also improved the tst_QPluginLoader::deleteinstanceOnUnload() test case to test more combinations of deletion order and explicit/implicit loading. Task-number: QT-5259 Reviewed-by: Sami Merila
-rw-r--r--src/corelib/plugin/qpluginloader.cpp2
-rw-r--r--tests/auto/qpluginloader/tst_qpluginloader.cpp29
2 files changed, 21 insertions, 10 deletions
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp
index bbb64e4..9f9ea1a 100644
--- a/src/corelib/plugin/qpluginloader.cpp
+++ b/src/corelib/plugin/qpluginloader.cpp
@@ -198,7 +198,7 @@ QPluginLoader::~QPluginLoader()
*/
QObject *QPluginLoader::instance()
{
- if (!isLoaded() && !load())
+ if (!load())
return 0;
if (!d->inst && d->instance)
d->inst = d->instance();
diff --git a/tests/auto/qpluginloader/tst_qpluginloader.cpp b/tests/auto/qpluginloader/tst_qpluginloader.cpp
index d2d92a5..152d1f4 100644
--- a/tests/auto/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/qpluginloader/tst_qpluginloader.cpp
@@ -272,10 +272,10 @@ void tst_QPluginLoader::loadHints()
void tst_QPluginLoader::deleteinstanceOnUnload()
{
- for (int pass = 0; pass < 2; ++pass) {
+ for (int pass = 0; pass < 4; ++pass) {
QPluginLoader loader1;
loader1.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin
- if (pass == 0)
+ if (pass < 2)
loader1.load(); // not recommended, instance() should do the job.
PluginInterface *instance1 = qobject_cast<PluginInterface*>(loader1.instance());
QVERIFY(instance1);
@@ -283,21 +283,32 @@ void tst_QPluginLoader::deleteinstanceOnUnload()
QPluginLoader loader2;
loader2.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin
- if (pass == 0)
+ if (pass < 2)
loader2.load(); // not recommended, instance() should do the job.
PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader2.instance());
QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));
QSignalSpy spy1(loader1.instance(), SIGNAL(destroyed()));
QSignalSpy spy2(loader2.instance(), SIGNAL(destroyed()));
- if (pass == 0) {
- QCOMPARE(loader2.unload(), false); // refcount not reached 0, not really unloaded
- QCOMPARE(spy1.count(), 0);
- QCOMPARE(spy2.count(), 0);
- }
+
+ // refcount not reached 0, not really unloaded
+ if (pass % 2)
+ QCOMPARE(loader1.unload(), false);
+ else
+ QCOMPARE(loader2.unload(), false);
+
+ QCOMPARE(spy1.count(), 0);
+ QCOMPARE(spy2.count(), 0);
+
QCOMPARE(instance1->pluginName(), QLatin1String("Plugin ok"));
QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));
- QVERIFY(loader1.unload()); // refcount reached 0, did really unload
+
+ // refcount reached 0, did really unload
+ if (pass % 2)
+ QVERIFY(loader2.unload());
+ else
+ QVERIFY(loader1.unload());
+
QCOMPARE(spy1.count(), 1);
QCOMPARE(spy2.count(), 1);
}