diff options
-rw-r--r-- | src/corelib/plugin/qpluginloader.cpp | 19 | ||||
-rw-r--r-- | tests/auto/qpluginloader/tst_qpluginloader.cpp | 52 |
2 files changed, 70 insertions, 1 deletions
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index a911f1d..8d1c0f7 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -46,6 +46,7 @@ #include <qfileinfo.h> #include "qlibrary_p.h" #include "qdebug.h" +#include "qdir.h" #ifndef QT_NO_LIBRARY @@ -301,6 +302,24 @@ void QPluginLoader::setFileName(const QString &fileName) } QString fn = fi.canonicalFilePath(); + // If not found directly, check also all the available drives + if (!fn.length()) { + QString stubPath(fi.fileName().length() ? fi.absoluteFilePath() : QString()); + if (stubPath.length() > 1) { + if (stubPath.at(1).toAscii() == ':') + stubPath.remove(0,2); + QFileInfoList driveList(QDir::drives()); + foreach(const QFileInfo& drive, driveList) { + QString testFilePath(drive.absolutePath() + stubPath); + testFilePath = QDir::cleanPath(testFilePath); + if (QFile::exists(testFilePath)) { + fn = testFilePath; + break; + } + } + } + } + #else QString fn = QFileInfo(fileName).canonicalFilePath(); #endif diff --git a/tests/auto/qpluginloader/tst_qpluginloader.cpp b/tests/auto/qpluginloader/tst_qpluginloader.cpp index 20ca997..3b2cb66 100644 --- a/tests/auto/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/qpluginloader/tst_qpluginloader.cpp @@ -122,7 +122,7 @@ private slots: void errorString(); void loadHints(); void deleteinstanceOnUnload(); - + void checkingStubsFromDifferentDrives(); }; tst_QPluginLoader::tst_QPluginLoader() @@ -297,6 +297,56 @@ void tst_QPluginLoader::deleteinstanceOnUnload() } } +void tst_QPluginLoader::checkingStubsFromDifferentDrives() +{ +#if defined(Q_OS_SYMBIAN) + + // This test needs C-drive + some additional drive (driveForStubs) + + const QString driveForStubs("E:/");// != "C:/" + const QString stubDir("system/temp/stubtest/"); + const QString stubName("dummyStub.qtplugin"); + const QString fullStubFileName(stubDir + stubName); + QDir dir(driveForStubs); + bool test1(false); bool test2(false); + + // initial clean up + QFile::remove(driveForStubs + fullStubFileName); + dir.rmdir(driveForStubs + stubDir); + + // create a stub dir and do stub drive check + if (!dir.mkpath(stubDir)) + QSKIP("Required drive not available for this test", SkipSingle); + + {// test without stub, should not be found + QPluginLoader loader("C:/" + fullStubFileName); + test1 = !loader.fileName().length(); + } + + // create a stub to defined drive + QFile tempFile(driveForStubs + fullStubFileName); + tempFile.open(QIODevice::ReadWrite); + QFileInfo fileInfo(tempFile); + + {// now should be found even tried to find from C: + QPluginLoader loader("C:/" + fullStubFileName); + test2 = (loader.fileName() == fileInfo.absoluteFilePath()); + } + + // clean up + tempFile.close(); + if (!QFile::remove(driveForStubs + fullStubFileName)) + QWARN("Could not remove stub file"); + if (!dir.rmdir(driveForStubs + stubDir)) + QWARN("Could not remove stub directory"); + + // test after cleanup + QVERIFY(test1); + QVERIFY(test2); + +#endif//Q_OS_SYMBIAN +} + QTEST_APPLESS_MAIN(tst_QPluginLoader) #include "tst_qpluginloader.moc" |