tests/auto/qlibrary/tst_qlibrary.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 #include <qdir.h>
       
    45 #include <qlibrary.h>
       
    46 #include <QtCore/QRegExp>
       
    47 
       
    48 
       
    49 // Helper macros to let us know if some suffixes and prefixes are valid
       
    50 #define bundle_VALID    false
       
    51 #define dylib_VALID     false
       
    52 #define sl_VALID        false
       
    53 #define a_VALID         false
       
    54 #define so_VALID        false
       
    55 #define dll_VALID       false
       
    56 
       
    57 #if defined(Q_OS_DARWIN)
       
    58 # undef bundle_VALID
       
    59 # undef dylib_VALID
       
    60 # undef so_VALID
       
    61 # define bundle_VALID   true
       
    62 # define dylib_VALID    true
       
    63 # define so_VALID       true
       
    64 # define SUFFIX         ".dylib"
       
    65 # define PREFIX         "lib"
       
    66 
       
    67 #elif defined(Q_OS_HPUX)
       
    68 # undef sl_VALID
       
    69 # define sl_VALID       true
       
    70 #  ifndef __ia64
       
    71 #   define SUFFIX         ".sl"
       
    72 #   define PREFIX         "lib"
       
    73 #  else
       
    74 #   undef so_VALID
       
    75 #   define so_VALID       true
       
    76 #   define SUFFIX         ".so"
       
    77 #   define PREFIX         "lib"
       
    78 #  endif
       
    79 
       
    80 #elif defined(Q_OS_AIX)
       
    81 # undef a_VALID
       
    82 # undef so_VALID
       
    83 # define a_VALID        true
       
    84 # define so_VALID       true
       
    85 # define SUFFIX         ".a"
       
    86 # define PREFIX         "lib"
       
    87 
       
    88 #elif defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
    89 # undef dll_VALID
       
    90 # define dll_VALID      true
       
    91 # define SUFFIX         ".dll"
       
    92 # define PREFIX         ""
       
    93 
       
    94 #else  // all other Unix
       
    95 # undef so_VALID
       
    96 # define so_VALID       true
       
    97 # define SUFFIX         ".so"
       
    98 # define PREFIX         "lib"
       
    99 #endif
       
   100 
       
   101 static QString sys_qualifiedLibraryName(const QString &fileName)
       
   102 {
       
   103 #if defined(Q_OS_SYMBIAN)
       
   104     return PREFIX + fileName + SUFFIX;
       
   105 #else
       
   106     QString currDir = QDir::currentPath();
       
   107     return currDir + "/" + PREFIX + fileName + SUFFIX;
       
   108 #endif
       
   109 }
       
   110 
       
   111 //TESTED_CLASS=
       
   112 //TESTED_FILES=
       
   113 
       
   114 QT_FORWARD_DECLARE_CLASS(QLibrary)
       
   115 class tst_QLibrary : public QObject
       
   116 {
       
   117     Q_OBJECT
       
   118 
       
   119 public:
       
   120     tst_QLibrary();
       
   121     virtual ~tst_QLibrary();
       
   122 
       
   123 enum QLibraryOperation {
       
   124     Load = 1,
       
   125     Unload = 2,
       
   126     Resolve = 3,
       
   127     OperationMask = 7,
       
   128     DontSetFileName = 0x100
       
   129 };
       
   130 private slots:
       
   131     void load();
       
   132     void load_data();
       
   133     void library_data();
       
   134     void resolve_data();
       
   135     void resolve();
       
   136     void unload_data();
       
   137     void unload();
       
   138     void unload_after_implicit_load();
       
   139     void isLibrary_data();
       
   140     void isLibrary();
       
   141     void version_data();
       
   142     void version();
       
   143     void errorString_data();
       
   144     void errorString();
       
   145     void loadHints();
       
   146     void loadHints_data();
       
   147     void fileName_data();
       
   148     void fileName();
       
   149     void multipleInstancesForOneLibrary();
       
   150 
       
   151 #ifdef Q_OS_WINCE
       
   152 private:
       
   153     QCoreApplication* app;
       
   154 #endif
       
   155 };
       
   156 
       
   157 tst_QLibrary::tst_QLibrary()
       
   158 
       
   159 {
       
   160 #ifdef Q_OS_WINCE
       
   161     char* argv = "app";
       
   162     int argc = 1;
       
   163     app = new QCoreApplication(argc,&argv);
       
   164 #endif
       
   165 }
       
   166 
       
   167 tst_QLibrary::~tst_QLibrary()
       
   168 {
       
   169 #ifdef Q_OS_WINCE
       
   170     app->quit();
       
   171 #endif
       
   172 }
       
   173 
       
   174 
       
   175 typedef int (*VersionFunction)(void);
       
   176 
       
   177 void tst_QLibrary::version_data()
       
   178 {
       
   179     QTest::addColumn<QString>("lib");
       
   180     QTest::addColumn<int>("loadversion");
       
   181     QTest::addColumn<int>("resultversion");
       
   182 
       
   183     QTest::newRow( "ok00, version 1" ) << "mylib" << 1 << 1;
       
   184     QTest::newRow( "ok00, version 2" ) << "mylib" << 2 << 2;
       
   185     QTest::newRow( "ok00, default to last version" ) << "mylib" << -1 << 2;
       
   186 }
       
   187 
       
   188 void tst_QLibrary::version()
       
   189 {
       
   190     QFETCH( QString, lib );
       
   191     QFETCH( int, loadversion );
       
   192     QFETCH( int, resultversion );
       
   193 
       
   194 #if !defined(Q_OS_AIX) && !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
       
   195     QString currDir = QDir::currentPath();
       
   196     QLibrary library( currDir + QLatin1Char('/') + lib, loadversion );
       
   197     bool ok = library.load();
       
   198     QVERIFY(ok);
       
   199 
       
   200     VersionFunction fnVersion = (VersionFunction)library.resolve("mylibversion");
       
   201     QVERIFY(fnVersion);
       
   202     QCOMPARE(fnVersion(), resultversion);
       
   203 #else
       
   204     Q_UNUSED(lib);
       
   205     Q_UNUSED(loadversion);
       
   206     Q_UNUSED(resultversion);
       
   207 #endif
       
   208 
       
   209 }
       
   210 
       
   211 void tst_QLibrary::load_data()
       
   212 {
       
   213     QTest::addColumn<QString>("lib");
       
   214     QTest::addColumn<bool>("result");
       
   215 
       
   216 #if defined(Q_OS_SYMBIAN)
       
   217     QString currDir;
       
   218 #else
       
   219     QString currDir = QDir::currentPath();
       
   220 #endif
       
   221     QTest::newRow( "ok00" ) << currDir + "/mylib" << (bool)true;
       
   222     QTest::newRow( "notexist" ) << currDir + "/nolib" << (bool)false;
       
   223     QTest::newRow( "badlibrary" ) << currDir + "/qlibrary.pro" << (bool)false;
       
   224 
       
   225 #ifdef Q_OS_MAC
       
   226     QTest::newRow("ok (libmylib ver. 1)") << currDir + "/libmylib" <<(bool)true;
       
   227 #endif
       
   228 
       
   229 # if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
       
   230     QTest::newRow( "ok01 (with suffix)" ) << currDir + "/mylib.dll" << (bool)true;
       
   231     QTest::newRow( "ok02 (with non-standard suffix)" ) << currDir + "/mylib.dl2" << (bool)true;
       
   232     QTest::newRow( "ok03 (with many dots)" ) << currDir + "/system.trolltech.test.mylib.dll" << (bool)true;
       
   233 # elif defined Q_OS_UNIX
       
   234     QTest::newRow( "ok01 (with suffix)" ) << currDir + "/libmylib" SUFFIX << (bool)true;
       
   235     QTest::newRow( "ok02 (with non-standard suffix)" ) << currDir + "/libmylib.so2" << (bool)true;
       
   236     QTest::newRow( "ok03 (with non-standard suffix)" ) << currDir + "/system.trolltech.test.mylib.so" << (bool)true;
       
   237 # endif  // Q_OS_UNIX
       
   238 }
       
   239 
       
   240 void tst_QLibrary::load()
       
   241 {
       
   242     QFETCH( QString, lib );
       
   243     QFETCH( bool, result );
       
   244 
       
   245     QLibrary library( lib );
       
   246     bool ok = library.load();
       
   247     if ( result ) {
       
   248 	QVERIFY( ok );
       
   249     } else {
       
   250 	QVERIFY( !ok );
       
   251     }
       
   252 }
       
   253 
       
   254 void tst_QLibrary::unload_data()
       
   255 {
       
   256     QTest::addColumn<QString>("lib");
       
   257     QTest::addColumn<bool>("result");
       
   258 
       
   259 #if defined(Q_OS_SYMBIAN)
       
   260     QString currDir;
       
   261 #else
       
   262     QString currDir = QDir::currentPath();
       
   263 #endif
       
   264 
       
   265     QTest::newRow( "mylib" ) << currDir + "/mylib" << (bool)TRUE;
       
   266 #ifdef Q_WS_MAC
       
   267     if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_3)
       
   268         QEXPECT_FAIL("mylib", "dlcompat cannot unload libraries", Continue);
       
   269 #endif
       
   270     QTest::newRow( "ok01" ) << currDir + "/nolib" << (bool)FALSE;
       
   271 }
       
   272 
       
   273 void tst_QLibrary::unload()
       
   274 {
       
   275     QFETCH( QString, lib );
       
   276     QFETCH( bool, result );
       
   277 
       
   278     QLibrary library( lib );
       
   279     library.load();
       
   280     bool ok = library.unload();
       
   281     if ( result ) {
       
   282 	QVERIFY( ok );
       
   283     } else {
       
   284 	QVERIFY( !ok );
       
   285     }
       
   286 }
       
   287 
       
   288 void tst_QLibrary::unload_after_implicit_load()
       
   289 {
       
   290 #if defined(Q_OS_SYMBIAN)
       
   291     QSKIP("SYMBIAN does not support symbols on non-STDDLL libraries.", SkipAll);
       
   292 #endif
       
   293 
       
   294     QLibrary library( "./mylib" );
       
   295     void *p = library.resolve("mylibversion");
       
   296     QVERIFY(p); // Check if it was loaded
       
   297     QVERIFY(library.isLoaded());
       
   298     QVERIFY(library.unload());
       
   299     QCOMPARE(library.isLoaded(), false);
       
   300 
       
   301 }
       
   302 
       
   303 void tst_QLibrary::resolve_data()
       
   304 {
       
   305     QTest::addColumn<QString>("lib");
       
   306     QTest::addColumn<QString>("symbol");
       
   307     QTest::addColumn<bool>("goodPointer");
       
   308 
       
   309 #if defined(Q_OS_SYMBIAN)
       
   310     QString currDir;
       
   311 #else
       
   312     QString currDir = QDir::currentPath();
       
   313 #endif
       
   314 
       
   315     QTest::newRow( "ok00" ) << currDir + "/mylib" << QString("mylibversion") << (bool)TRUE;
       
   316     QTest::newRow( "bad00" ) << currDir + "/mylib" << QString("nosym") << (bool)FALSE;
       
   317     QTest::newRow( "bad01" ) << currDir + "/nolib" << QString("nosym") << (bool)FALSE;
       
   318 }
       
   319 
       
   320 void tst_QLibrary::resolve()
       
   321 {
       
   322 #if defined(Q_OS_SYMBIAN)
       
   323     QSKIP("SYMBIAN does not support symbols on non-STDDLL libraries.", SkipAll);
       
   324 #endif
       
   325 
       
   326     typedef int (*testFunc)();
       
   327     QFETCH( QString, lib );
       
   328     QFETCH( QString, symbol );
       
   329     QFETCH( bool, goodPointer );
       
   330 
       
   331     QLibrary library( lib );
       
   332     testFunc func = (testFunc) library.resolve( symbol.toLatin1() );
       
   333     if ( goodPointer ) {
       
   334 	QVERIFY( func != 0 );
       
   335     } else {
       
   336 	QVERIFY( func == 0 );
       
   337     }
       
   338 }
       
   339 
       
   340 void tst_QLibrary::library_data()
       
   341 {
       
   342     QTest::addColumn<QString>("lib");
       
   343 }
       
   344 
       
   345 void tst_QLibrary::isLibrary_data()
       
   346 {
       
   347     QTest::addColumn<QString>("filename");
       
   348     QTest::addColumn<bool>("valid");
       
   349 
       
   350     // use the macros #defined at the top of the file
       
   351     QTest::newRow("bad") << QString("mylib.bad") << false;
       
   352     QTest::newRow(".a") << QString("mylib.a") << a_VALID;
       
   353     QTest::newRow(".bundle") << QString("mylib.bundle") << bundle_VALID;
       
   354     QTest::newRow(".dll") << QString("mylib.dll") << dll_VALID;
       
   355     QTest::newRow(".dl2" ) << QString("mylib.dl2") << false;
       
   356     QTest::newRow(".dylib") << QString("mylib.dylib") << dylib_VALID;
       
   357     QTest::newRow(".sl") << QString("mylib.sl") << sl_VALID;
       
   358     QTest::newRow(".so") << QString("mylib.so") << so_VALID;
       
   359     QTest::newRow(".so+version") << QString("mylib.so.0") << so_VALID;
       
   360 
       
   361     // special tests:
       
   362 #ifndef Q_OS_MAC
       
   363     QTest::newRow("version+.so") << QString("libc-2.7.so") << so_VALID;
       
   364     QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << so_VALID;
       
   365 #else
       
   366     QTest::newRow("version+.so") << QString("libc-2.7.so") << false;
       
   367     QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << false;
       
   368 #endif
       
   369 #ifdef Q_OS_MAC
       
   370     QTest::newRow("good (libmylib.1.0.0.dylib)") << QString("libmylib.1.0.0.dylib") << true;
       
   371     QTest::newRow("good (libmylib.dylib)") << QString("libmylib.dylib") << true;
       
   372     QTest::newRow("good (libmylib.so)") << QString("libmylib.so") << true;
       
   373     QTest::newRow("good (libmylib.so.1.0.0)") << QString("libmylib.so.1.0.0") << true;
       
   374 
       
   375     QTest::newRow("bad (libmylib.1.0.0.foo)") << QString("libmylib.1.0.0.foo") << false;
       
   376 #elif defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
   377     QTest::newRow("good (with many dots)" ) << "/system.trolltech.test.mylib.dll" << true;
       
   378 #endif
       
   379 }
       
   380 
       
   381 void tst_QLibrary::isLibrary()
       
   382 {
       
   383     QFETCH( QString, filename );
       
   384     QFETCH( bool, valid );
       
   385 
       
   386     QCOMPARE(QLibrary::isLibrary(filename), valid);
       
   387 }
       
   388 
       
   389 void tst_QLibrary::errorString_data()
       
   390 {
       
   391     QTest::addColumn<int>("operation");
       
   392     QTest::addColumn<QString>("fileName");
       
   393     QTest::addColumn<bool>("success");
       
   394     QTest::addColumn<QString>("errorString");
       
   395 
       
   396 #if defined(Q_OS_SYMBIAN)
       
   397     QString currDir;
       
   398 #else
       
   399     QString currDir = QDir::currentPath();
       
   400 
       
   401     QString srcDir = SRCDIR;
       
   402     if (srcDir.isEmpty())
       
   403         srcDir = currDir;
       
   404 #endif
       
   405 
       
   406     QTest::newRow("bad load()") << (int)Load << QString("nosuchlib") << false << QString("Cannot load library nosuchlib: .*");
       
   407     QTest::newRow("call errorString() on QLibrary with no d-pointer (crashtest)") << (int)(Load | DontSetFileName) << QString() << false << QString("Unknown error");
       
   408 #ifdef Q_OS_WINCE
       
   409     QTest::newRow("bad resolve") << (int)Resolve << currDir + "/mylib" << false << QString("Cannot resolve symbol \"nosuchsymbol\" in .*: .*");
       
   410 #else
       
   411     QTest::newRow("bad resolve") << (int)Resolve << currDir + "/mylib" << false << QString("Cannot resolve symbol \"nosuchsymbol\" in \\S+: .*");
       
   412 #endif
       
   413     QTest::newRow("good resolve") << (int)Resolve << currDir + "/mylib" << true << QString("Unknown error");
       
   414 
       
   415 #ifdef Q_OS_WIN
       
   416     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.");
       
   417 //    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.)");
       
   418 #elif defined Q_OS_MAC
       
   419 #elif defined Q_OS_SYMBIAN
       
   420     QTest::newRow("load invalid file") << (int)Load << "tst_qlibrary.exe" << false << QString("Cannot load library.*");
       
   421 #else
       
   422     QTest::newRow("load invalid file") << (int)Load << srcDir + "/library_path/invalid.so" << false << QString("Cannot load library.*");
       
   423 #endif
       
   424 }
       
   425 
       
   426 void tst_QLibrary::errorString()
       
   427 {
       
   428     QFETCH(int, operation);
       
   429     QFETCH(QString, fileName);
       
   430     QFETCH(bool, success);
       
   431     QFETCH(QString, errorString);
       
   432 
       
   433 #if defined(Q_OS_SYMBIAN)
       
   434     if ( success )
       
   435         {
       
   436         QSKIP("SYMBIAN does not support symbols on non-STDDLL libraries.", SkipSingle );
       
   437         }
       
   438 #endif
       
   439 
       
   440     QLibrary lib;
       
   441     if (!(operation & DontSetFileName)) {
       
   442         lib.setFileName(fileName);
       
   443     }
       
   444 
       
   445     bool ok = false;
       
   446     switch (operation & OperationMask) {
       
   447         case Load:
       
   448             ok = lib.load();
       
   449             break;
       
   450         case Unload:
       
   451             ok = lib.load();    //###
       
   452             ok = lib.unload();
       
   453             break;
       
   454         case Resolve: {
       
   455             ok = lib.load();
       
   456             QCOMPARE(ok, true);
       
   457             if (success) {
       
   458                 ok = lib.resolve("mylibversion");
       
   459             } else {
       
   460                 ok = lib.resolve("nosuchsymbol");
       
   461             }
       
   462             break;}
       
   463         default:
       
   464             Q_ASSERT(0);
       
   465             break;
       
   466     }
       
   467     QRegExp re(errorString);
       
   468     QVERIFY2(re.exactMatch(lib.errorString()), qPrintable(lib.errorString()));
       
   469     QCOMPARE(ok, success);
       
   470 }
       
   471 
       
   472 void tst_QLibrary::loadHints_data()
       
   473 {
       
   474     QTest::addColumn<QString>("lib");
       
   475     QTest::addColumn<int>("loadHints");
       
   476     QTest::addColumn<bool>("result");
       
   477 
       
   478     QLibrary::LoadHints lh;
       
   479 #if defined(Q_OS_AIX)
       
   480     if (QFile::exists("/usr/lib/libGL.a") || QFile::exists("/usr/X11R6/lib/libGL.a")) {
       
   481 # if QT_POINTER_SIZE == 4
       
   482         QTest::newRow( "ok03 (Archive member)" ) << "libGL.a(shr.o)" << int(QLibrary::LoadArchiveMemberHint) << (bool)TRUE;
       
   483 # else
       
   484         QTest::newRow( "ok03 (Archive member)" ) << "libGL.a(shr_64.o)" << int(QLibrary::LoadArchiveMemberHint) << (bool)TRUE;
       
   485 #endif
       
   486     }
       
   487 #endif
       
   488 
       
   489 #if defined(Q_OS_SYMBIAN)
       
   490     QString currDir;
       
   491 #else
       
   492     QString currDir = QDir::currentPath();
       
   493 #endif
       
   494 
       
   495     lh |= QLibrary::ResolveAllSymbolsHint;
       
   496 # if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
       
   497     QTest::newRow( "ok01 (with suffix)" ) << currDir + "/mylib.dll" << int(lh) << (bool)TRUE;
       
   498     QTest::newRow( "ok02 (with non-standard suffix)" ) << currDir + "/mylib.dl2" << int(lh) << (bool)TRUE;
       
   499     QTest::newRow( "ok03 (with many dots)" ) << currDir + "/system.trolltech.test.mylib.dll" << int(lh) << (bool)TRUE;
       
   500 # elif defined Q_OS_UNIX
       
   501     QTest::newRow( "ok01 (with suffix)" ) << currDir + "/libmylib" SUFFIX << int(lh) << (bool)TRUE;
       
   502     QTest::newRow( "ok02 (with non-standard suffix)" ) << currDir + "/libmylib.so2" << int(lh) << (bool)TRUE;
       
   503     QTest::newRow( "ok03 (with many dots)" ) << currDir + "/system.trolltech.test.mylib.so" << int(lh) << (bool)TRUE;
       
   504 # endif  // Q_OS_UNIX
       
   505 }
       
   506 
       
   507 void tst_QLibrary::loadHints()
       
   508 {
       
   509     QFETCH( QString, lib );
       
   510     QFETCH( int, loadHints);
       
   511     QFETCH( bool, result );
       
   512     //QLibrary library( lib );
       
   513     QLibrary library;
       
   514     QLibrary::LoadHints lh(loadHints);
       
   515     if (int(loadHints) != 0) {
       
   516         lh |= library.loadHints();
       
   517         library.setLoadHints(lh);
       
   518     }
       
   519     library.setFileName(lib);
       
   520     QCOMPARE(library.loadHints(), lh);
       
   521     bool ok = library.load();
       
   522     if ( result ) {
       
   523         QVERIFY( ok );
       
   524     } else {
       
   525         QVERIFY( !ok );
       
   526     }
       
   527 }
       
   528 
       
   529 void tst_QLibrary::fileName_data()
       
   530 {
       
   531     QTest::addColumn<QString>("libName");
       
   532     QTest::addColumn<QString>("expectedFilename");
       
   533 
       
   534     QTest::newRow( "ok02" ) << sys_qualifiedLibraryName(QLatin1String("mylib"))
       
   535                             << sys_qualifiedLibraryName(QLatin1String("mylib"));
       
   536 #ifdef Q_WS_WIN
       
   537 #ifndef Q_OS_WINCE
       
   538     QTest::newRow( "ok02" ) << "user32"
       
   539                             << "USER32.dll";
       
   540 #else
       
   541     QTest::newRow( "ok02" ) << "coredll"
       
   542                             << "coredll.dll";
       
   543 #endif
       
   544 #endif
       
   545 }
       
   546 
       
   547 void tst_QLibrary::fileName()
       
   548 {
       
   549     QFETCH( QString, libName);
       
   550     QFETCH( QString, expectedFilename);
       
   551 
       
   552     QLibrary lib(libName);
       
   553     bool ok = lib.load();
       
   554     if (!ok) {
       
   555         qDebug() << lib.errorString();
       
   556     }
       
   557 
       
   558     QVERIFY(ok);
       
   559     QCOMPARE(lib.fileName(), expectedFilename);
       
   560 
       
   561 }
       
   562 
       
   563 void tst_QLibrary::multipleInstancesForOneLibrary()
       
   564 {
       
   565 #if defined(Q_OS_SYMBIAN)
       
   566     QString lib = "/mylib";
       
   567 #else
       
   568     QString lib = QDir::currentPath() + "/mylib";
       
   569 #endif
       
   570 
       
   571     QLibrary lib1(lib);
       
   572     QLibrary lib2(lib);
       
   573     QCOMPARE(lib1.isLoaded(), false);
       
   574     QCOMPARE(lib2.isLoaded(), false);
       
   575     lib1.load();
       
   576     QCOMPARE(lib1.isLoaded(), true);
       
   577     QCOMPARE(lib2.isLoaded(), true);
       
   578     QCOMPARE(lib1.unload(), true);
       
   579     QCOMPARE(lib1.isLoaded(), false);
       
   580     QCOMPARE(lib2.isLoaded(), false);
       
   581     lib1.load();
       
   582     lib2.load();
       
   583     QCOMPARE(lib1.isLoaded(), true);
       
   584     QCOMPARE(lib2.isLoaded(), true);
       
   585     QCOMPARE(lib1.unload(), false);
       
   586     QCOMPARE(lib1.isLoaded(), true);
       
   587     QCOMPARE(lib2.isLoaded(), true);
       
   588     QCOMPARE(lib2.unload(), true);
       
   589     QCOMPARE(lib1.isLoaded(), false);
       
   590     QCOMPARE(lib2.isLoaded(), false);
       
   591 
       
   592     // Finally; unload on that is already unloaded
       
   593     QCOMPARE(lib1.unload(), false);
       
   594 
       
   595 /*
       
   596     lib1.setLoadHints(QLibrary::ResolveAllSymbolsHint);
       
   597     lib2.setLoadHints(QLibrary::ExportExternalSymbolHint);
       
   598 */
       
   599 }
       
   600 
       
   601 QTEST_APPLESS_MAIN(tst_QLibrary)
       
   602 #include "tst_qlibrary.moc"