tests/auto/qdir/tst_qdir.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
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 
       
    45 #include <qcoreapplication.h>
       
    46 #include <qdebug.h>
       
    47 #include <qdir.h>
       
    48 #include <qfileinfo.h>
       
    49 #include <qregexp.h>
       
    50 #include <qstringlist.h>
       
    51 #include "../network-settings.h"
       
    52 
       
    53 #if defined(Q_OS_SYMBIAN)
       
    54 # define STRINGIFY(x) #x
       
    55 # define TOSTRING(x) STRINGIFY(x)
       
    56 # define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/"
       
    57 #elif defined(Q_OS_UNIX)
       
    58 # include <unistd.h>
       
    59 #endif
       
    60 
       
    61 #if defined(Q_OS_VXWORKS)
       
    62 #define Q_NO_SYMLINKS
       
    63 #endif
       
    64 
       
    65 #if defined(Q_OS_SYMBIAN)
       
    66 // Open C in Symbian doesn't support symbolic links to directories
       
    67 #define Q_NO_SYMLINKS_TO_DIRS
       
    68 #endif
       
    69 
       
    70 
       
    71 //TESTED_CLASS=
       
    72 //TESTED_FILES=
       
    73 
       
    74 class tst_QDir : public QObject
       
    75 {
       
    76 Q_OBJECT
       
    77 
       
    78 public:
       
    79     tst_QDir();
       
    80     virtual ~tst_QDir();
       
    81 
       
    82 private slots:
       
    83     void getSetCheck();
       
    84     void construction();
       
    85 
       
    86     void setPath_data();
       
    87     void setPath();
       
    88 
       
    89     void entryList_data();
       
    90     void entryList();
       
    91 
       
    92     void entryListSimple_data();
       
    93     void entryListSimple();
       
    94 
       
    95     void entryListWithSymLinks();
       
    96 
       
    97     void mkdir_data();
       
    98     void mkdir();
       
    99 
       
   100     void rmdir_data();
       
   101     void rmdir();
       
   102 
       
   103     void exists_data();
       
   104     void exists();
       
   105 
       
   106     void isRelativePath_data();
       
   107     void isRelativePath();
       
   108 
       
   109     void canonicalPath_data();
       
   110     void canonicalPath();
       
   111 
       
   112     void current_data();
       
   113     void current();
       
   114 
       
   115     void cd_data();
       
   116     void cd();
       
   117 
       
   118     void setNameFilters_data();
       
   119     void setNameFilters();
       
   120 
       
   121     void cleanPath_data();
       
   122     void cleanPath();
       
   123 
       
   124     void compare();
       
   125     void QDir_default();
       
   126 
       
   127     void filePath_data();
       
   128     void filePath();
       
   129 
       
   130     void absoluteFilePath_data();
       
   131     void absoluteFilePath();
       
   132 
       
   133     void absolutePath_data();
       
   134     void absolutePath();
       
   135 
       
   136     void relativeFilePath_data();
       
   137     void relativeFilePath();
       
   138 
       
   139     void remove();
       
   140     void rename();
       
   141 
       
   142     void exists2_data();
       
   143     void exists2();
       
   144 
       
   145     void dirName_data();
       
   146     void dirName();
       
   147 
       
   148     void operator_eq();
       
   149 
       
   150     void dotAndDotDot();
       
   151 #ifdef QT3_SUPPORT
       
   152     void matchAllDirs();
       
   153 #endif
       
   154     void homePath();
       
   155     void tempPath();
       
   156     void rootPath();
       
   157 
       
   158     void nativeSeparators();
       
   159 
       
   160     void searchPaths();
       
   161     void searchPaths_data();
       
   162 
       
   163     void entryListWithSearchPaths();
       
   164 
       
   165     void longFileName_data();
       
   166     void longFileName();
       
   167 };
       
   168 
       
   169 // Testing get/set functions
       
   170 void tst_QDir::getSetCheck()
       
   171 {
       
   172     QDir obj1;
       
   173     // Filters QDir::filter()
       
   174     // void QDir::setFilter(Filters)
       
   175     obj1.setFilter(QDir::Filters(QDir::Dirs));
       
   176     QCOMPARE(QDir::Filters(QDir::Dirs), obj1.filter());
       
   177     obj1.setFilter(QDir::Filters(QDir::Dirs | QDir::Files));
       
   178     QCOMPARE(QDir::Filters(QDir::Dirs | QDir::Files), obj1.filter());
       
   179     obj1.setFilter(QDir::Filters(QDir::NoFilter));
       
   180     QCOMPARE(QDir::Filters(QDir::NoFilter), obj1.filter());
       
   181 
       
   182     // SortFlags QDir::sorting()
       
   183     // void QDir::setSorting(SortFlags)
       
   184     obj1.setSorting(QDir::SortFlags(QDir::Name));
       
   185     QCOMPARE(QDir::SortFlags(QDir::Name), obj1.sorting());
       
   186     obj1.setSorting(QDir::SortFlags(QDir::Name | QDir::IgnoreCase));
       
   187     QCOMPARE(QDir::SortFlags(QDir::Name | QDir::IgnoreCase), obj1.sorting());
       
   188     obj1.setSorting(QDir::SortFlags(QDir::NoSort));
       
   189     QCOMPARE(QDir::SortFlags(QDir::NoSort), obj1.sorting());
       
   190 }
       
   191 
       
   192 tst_QDir::tst_QDir()
       
   193 {
       
   194 #ifdef Q_OS_SYMBIAN
       
   195     // Can't deploy empty test dir, so create it here
       
   196     QDir dir(SRCDIR);
       
   197     dir.mkdir("testData");
       
   198 #endif
       
   199 }
       
   200 
       
   201 tst_QDir::~tst_QDir()
       
   202 {
       
   203 #ifdef Q_OS_SYMBIAN
       
   204     // Remove created test dir
       
   205     QDir dir(SRCDIR);
       
   206     dir.rmdir("testData");
       
   207 #endif
       
   208 }
       
   209 
       
   210 void tst_QDir::construction()
       
   211 {
       
   212     QFileInfo myFileInfo("/machine/share/dir1/file1");
       
   213     QDir myDir(myFileInfo.absoluteDir()); // this asserted
       
   214     QCOMPARE(myFileInfo.absoluteDir().absolutePath(), myDir.absolutePath());
       
   215 }
       
   216 
       
   217 void tst_QDir::setPath_data()
       
   218 {
       
   219     QTest::addColumn<QString>("dir1");
       
   220     QTest::addColumn<QString>("dir2");
       
   221 
       
   222     QTest::newRow("data0") << QString(".") << QString("..");
       
   223 #if (defined(Q_WS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
       
   224     QTest::newRow("data1") << QString("c:/") << QDir::currentPath();
       
   225 #endif
       
   226 }
       
   227 
       
   228 void tst_QDir::setPath()
       
   229 {
       
   230     QFETCH(QString, dir1);
       
   231     QFETCH(QString, dir2);
       
   232 
       
   233     QDir shared;
       
   234     QDir qDir1(dir1);
       
   235     QStringList entries1 = qDir1.entryList();
       
   236     shared.setPath(dir1);
       
   237     QCOMPARE(shared.entryList(), entries1);
       
   238 
       
   239     QDir qDir2(dir2);
       
   240     QStringList entries2 = qDir2.entryList();
       
   241     shared.setPath(dir2);
       
   242     QCOMPARE(shared.entryList(), entries2);
       
   243 }
       
   244 
       
   245 void tst_QDir::mkdir_data()
       
   246 {
       
   247     QTest::addColumn<QString>("path");
       
   248     QTest::addColumn<bool>("recurse");
       
   249 
       
   250     QStringList dirs;
       
   251     dirs << QDir::currentPath() + "/testdir/one/two/three"
       
   252          << QDir::currentPath() + "/testdir/two"
       
   253          << QDir::currentPath() + "/testdir/two/three";
       
   254     QTest::newRow("data0") << dirs.at(0) << true;
       
   255     QTest::newRow("data1") << dirs.at(1) << false;
       
   256     QTest::newRow("data2") << dirs.at(2) << false;
       
   257 
       
   258     // Ensure that none of these directories already exist
       
   259     QDir dir;
       
   260     for (int i = 0; i < dirs.count(); ++i)
       
   261         dir.rmpath(dirs.at(i));
       
   262 }
       
   263 
       
   264 void tst_QDir::mkdir()
       
   265 {
       
   266     QFETCH(QString, path);
       
   267     QFETCH(bool, recurse);
       
   268 
       
   269     QDir dir;
       
   270     dir.rmdir(path);
       
   271     if (recurse)
       
   272         QVERIFY(dir.mkpath(path));
       
   273     else
       
   274         QVERIFY(dir.mkdir(path));
       
   275 
       
   276     //make sure it really exists (ie that mkdir returns the right value)
       
   277     QFileInfo fi(path);
       
   278     QVERIFY(fi.exists() && fi.isDir());
       
   279 }
       
   280 
       
   281 void tst_QDir::rmdir_data()
       
   282 {
       
   283     QTest::addColumn<QString>("path");
       
   284     QTest::addColumn<bool>("recurse");
       
   285 
       
   286     QTest::newRow("data0") << QDir::currentPath() + "/testdir/one/two/three" << true;
       
   287     QTest::newRow("data1") << QDir::currentPath() + "/testdir/two/three" << false;
       
   288     QTest::newRow("data2") << QDir::currentPath() + "/testdir/two" << false;
       
   289 }
       
   290 
       
   291 void tst_QDir::rmdir()
       
   292 {
       
   293     QFETCH(QString, path);
       
   294     QFETCH(bool, recurse);
       
   295 
       
   296     QDir dir;
       
   297     if (recurse)
       
   298         QVERIFY(dir.rmpath(path));
       
   299     else
       
   300         QVERIFY(dir.rmdir(path));
       
   301 
       
   302     //make sure it really doesn't exist (ie that rmdir returns the right value)
       
   303     QFileInfo fi(path);
       
   304     QVERIFY(!fi.exists());
       
   305 }
       
   306 
       
   307 void tst_QDir::exists_data()
       
   308 {
       
   309     QTest::addColumn<QString>("path");
       
   310     QTest::addColumn<bool>("expected");
       
   311 
       
   312     QTest::newRow("data0") << QDir::currentPath() << true;
       
   313     QTest::newRow("data0.1") << QDir::currentPath() + "/" << true;
       
   314     QTest::newRow("data1") << QString("/I/Do_not_expect_this_path_to_exist/") << false;
       
   315     QTest::newRow("resource0") << QString(":/tst_qdir/") << true;
       
   316     QTest::newRow("resource1") << QString(":/I/Do_not_expect_this_resource_to_exist/") << false;
       
   317 
       
   318     QTest::newRow("simple dir") << SRCDIR "resources" << true;
       
   319     QTest::newRow("simple dir with slash") << SRCDIR "resources/" << true;
       
   320 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
       
   321     QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
       
   322     QTest::newRow("unc 2") << "//"  + QtNetworkSettings::winServerName() + "/" << true;
       
   323     QTest::newRow("unc 3") << "//"  + QtNetworkSettings::winServerName() + "/testshare" << true;
       
   324     QTest::newRow("unc 4") << "//"  + QtNetworkSettings::winServerName() + "/testshare/" << true;
       
   325     QTest::newRow("unc 5") << "//"  + QtNetworkSettings::winServerName() + "/testshare/tmp" << true;
       
   326     QTest::newRow("unc 6") << "//"  + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true;
       
   327     QTest::newRow("unc 7") << "//"  + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false;
       
   328     QTest::newRow("unc 8") << "//"  + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false;
       
   329     QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false;
       
   330 #endif
       
   331 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
       
   332     QTest::newRow("This drive should exist") <<  "C:/" << true;
       
   333     // find a non-existing drive and check if it does not exist
       
   334     QFileInfoList drives = QFSFileEngine::drives();
       
   335     QStringList driveLetters;
       
   336     for (int i = 0; i < drives.count(); ++i) {
       
   337         driveLetters+=drives.at(i).absoluteFilePath();
       
   338     }
       
   339     char drive = 'Z';
       
   340     QString driv;
       
   341     do {
       
   342         driv = QString::fromAscii("%1:/").arg(drive);
       
   343         if (!driveLetters.contains(driv)) break;
       
   344         --drive;
       
   345     } while (drive >= 'A');
       
   346     if (drive >= 'A') {
       
   347         QTest::newRow("This drive should not exist") <<  driv << false;
       
   348     }
       
   349 #endif
       
   350 }
       
   351 
       
   352 void tst_QDir::exists()
       
   353 {
       
   354     QFETCH(QString, path);
       
   355     QFETCH(bool, expected);
       
   356 
       
   357     QDir dir(path);
       
   358     QCOMPARE(dir.exists(), expected);
       
   359 }
       
   360 
       
   361 void tst_QDir::isRelativePath_data()
       
   362 {
       
   363     QTest::addColumn<QString>("path");
       
   364     QTest::addColumn<bool>("relative");
       
   365 
       
   366     QTest::newRow("data0") << "../somedir" << true;
       
   367 #if (defined(Q_WS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
       
   368     QTest::newRow("data1") << "C:/sOmedir" << false;
       
   369 #endif
       
   370     QTest::newRow("data2") << "somedir" << true;
       
   371     QTest::newRow("data3") << "/somedir" << false;
       
   372 }
       
   373 
       
   374 void tst_QDir::isRelativePath()
       
   375 {
       
   376     QFETCH(QString, path);
       
   377     QFETCH(bool, relative);
       
   378 
       
   379     QCOMPARE(QDir::isRelativePath(path),relative);
       
   380 }
       
   381 
       
   382 
       
   383 void tst_QDir::QDir_default()
       
   384 {
       
   385     //default constructor QDir();
       
   386     QDir dir; // according to documentation should be currentDirPath
       
   387     QCOMPARE(dir.absolutePath(), QDir::currentPath());
       
   388 }
       
   389 
       
   390 void tst_QDir::compare()
       
   391 {
       
   392     // operator==
       
   393     QDir dir;
       
   394     dir.makeAbsolute();
       
   395     QVERIFY(dir == QDir::currentPath());
       
   396 }
       
   397 
       
   398 static QStringList filterLinks(const QStringList &list)
       
   399 {
       
   400 #ifndef Q_NO_SYMLINKS
       
   401     return list;
       
   402 #else
       
   403     QStringList result;
       
   404     foreach (QString str, list) {
       
   405         if (!str.endsWith(QLatin1String(".lnk")))
       
   406             result.append(str);
       
   407     }
       
   408     return result;
       
   409 #endif
       
   410 }
       
   411 
       
   412 void tst_QDir::entryList_data()
       
   413 {
       
   414     QTest::addColumn<QString>("dirName"); // relative from current path or abs
       
   415     QTest::addColumn<QStringList>("nameFilters");
       
   416     QTest::addColumn<int>("filterspec");
       
   417     QTest::addColumn<int>("sortspec");
       
   418     QTest::addColumn<QStringList>("expected");
       
   419     QTest::newRow("spaces1") << SRCDIR "testdir/spaces" << QStringList("*. bar")
       
   420               << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   421               << QStringList("foo. bar"); // notice how spaces5 works
       
   422     QTest::newRow("spaces2") << SRCDIR "testdir/spaces" << QStringList("*.bar")
       
   423               << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   424               << QStringList("foo.bar");
       
   425     QTest::newRow("spaces3") << SRCDIR "testdir/spaces" << QStringList("foo.*")
       
   426               << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   427               << QString("foo. bar,foo.bar").split(',');
       
   428     QTest::newRow("files1")  << SRCDIR "testdir/dir" << QString("*r.cpp *.pro").split(" ")
       
   429               << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   430               << QString("qdir.pro,qrc_qdir.cpp,tst_qdir.cpp").split(',');
       
   431     QTest::newRow("testdir1")  << SRCDIR "testdir" << QStringList()
       
   432               << (int)(QDir::AllDirs) << (int)(QDir::NoSort)
       
   433               << QString(".,..,dir,spaces").split(',');
       
   434 // #### this test uses filenames that cannot be represented on all filesystems we test, in
       
   435 // particular HFS+ on the Mac. When checking out the files with perforce it silently ignores the
       
   436 // error that it cannot represent the file names stored in the repository and the test fails. That
       
   437 // is why the test is marked as 'skip' for the mac. When checking out the files with git on the mac
       
   438 // the error of not being able to represent the files stored in the repository is not silently
       
   439 // ignored but git reports an error. The test only tried to prevent QDir from _hanging_ when listing
       
   440 // the directory.
       
   441 //    QTest::newRow("unprintablenames")  << SRCDIR "unprintablenames" << QStringList("*")
       
   442 //              << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   443 //              << QString(".,..").split(",");
       
   444     QTest::newRow("resources1") << QString(":/tst_qdir/resources/entryList") << QStringList("*.data")
       
   445                              << (int)(QDir::NoFilter) << (int)(QDir::NoSort)
       
   446                              << QString("file1.data,file2.data,file3.data").split(',');
       
   447     QTest::newRow("resources2") << QString(":/tst_qdir/resources/entryList") << QStringList("*.data")
       
   448                              << (int)(QDir::Files) << (int)(QDir::NoSort)
       
   449                              << QString("file1.data,file2.data,file3.data").split(',');
       
   450 
       
   451     QTest::newRow("nofilter") << SRCDIR "entrylist/" << QStringList("*")
       
   452                               << int(QDir::NoFilter) << int(QDir::Name)
       
   453                               << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   454     QTest::newRow("QDir::AllEntries") << SRCDIR "entrylist/" << QStringList("*")
       
   455                               << int(QDir::AllEntries) << int(QDir::Name)
       
   456                               << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   457     QTest::newRow("QDir::Files") << SRCDIR "entrylist/" << QStringList("*")
       
   458                                  << int(QDir::Files) << int(QDir::Name)
       
   459                                  << filterLinks(QString("file,linktofile.lnk,writable").split(','));
       
   460     QTest::newRow("QDir::Dirs") << SRCDIR "entrylist/" << QStringList("*")
       
   461                                 << int(QDir::Dirs) << int(QDir::Name)
       
   462                                 << filterLinks(QString(".,..,directory,linktodirectory.lnk").split(','));
       
   463     QTest::newRow("QDir::Dirs | QDir::NoDotAndDotDot") << SRCDIR "entrylist/" << QStringList("*")
       
   464                                                        << int(QDir::Dirs | QDir::NoDotAndDotDot) << int(QDir::Name)
       
   465                                 << filterLinks(QString("directory,linktodirectory.lnk").split(','));
       
   466     QTest::newRow("QDir::AllDirs") << SRCDIR "entrylist/" << QStringList("*")
       
   467                                    << int(QDir::AllDirs) << int(QDir::Name)
       
   468                                    << filterLinks(QString(".,..,directory,linktodirectory.lnk").split(','));
       
   469     QTest::newRow("QDir::AllDirs | QDir::Dirs") << SRCDIR "entrylist/" << QStringList("*")
       
   470                                                 << int(QDir::AllDirs | QDir::Dirs) << int(QDir::Name)
       
   471                                                 << filterLinks(QString(".,..,directory,linktodirectory.lnk").split(','));
       
   472     QTest::newRow("QDir::AllDirs | QDir::Files") << SRCDIR "entrylist/" << QStringList("*")
       
   473                                                  << int(QDir::AllDirs | QDir::Files) << int(QDir::Name)
       
   474                                                  << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   475     QTest::newRow("QDir::AllEntries | QDir::NoSymLinks") << SRCDIR "entrylist/" << QStringList("*")
       
   476                                       << int(QDir::AllEntries | QDir::NoSymLinks) << int(QDir::Name)
       
   477                                       << filterLinks(QString(".,..,directory,file,writable").split(','));
       
   478     QTest::newRow("QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot") << SRCDIR "entrylist/" << QStringList("*")
       
   479                                       << int(QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot) << int(QDir::Name)
       
   480                                       << filterLinks(QString("directory,file,writable").split(','));
       
   481     QTest::newRow("QDir::Files | QDir::NoSymLinks") << SRCDIR "entrylist/" << QStringList("*")
       
   482                                                     << int(QDir::Files | QDir::NoSymLinks) << int(QDir::Name)
       
   483                                                     << filterLinks(QString("file,writable").split(','));
       
   484     QTest::newRow("QDir::Dirs | QDir::NoSymLinks") << SRCDIR "entrylist/" << QStringList("*")
       
   485                                                    << int(QDir::Dirs | QDir::NoSymLinks) << int(QDir::Name)
       
   486                                                    << filterLinks(QString(".,..,directory").split(','));
       
   487     QTest::newRow("QDir::Drives | QDir::Files | QDir::NoDotAndDotDot") << SRCDIR "entrylist/" << QStringList("*")
       
   488                                                    << int(QDir::Drives | QDir::Files | QDir::NoDotAndDotDot) << int(QDir::Name)
       
   489                                                    << filterLinks(QString("file,linktofile.lnk,writable").split(','));
       
   490     QTest::newRow("QDir::System") << SRCDIR "entrylist/" << QStringList("*")
       
   491                                   << int(QDir::System) << int(QDir::Name)
       
   492                                   << filterLinks(QStringList("brokenlink.lnk"));
       
   493     QTest::newRow("QDir::Hidden") << SRCDIR "entrylist/" << QStringList("*")
       
   494                                   << int(QDir::Hidden) << int(QDir::Name)
       
   495                                   << QStringList();
       
   496     QTest::newRow("QDir::System | QDir::Hidden") << SRCDIR "entrylist/" << QStringList("*")
       
   497                                   << int(QDir::System | QDir::Hidden) << int(QDir::Name)
       
   498                                   << filterLinks(QStringList("brokenlink.lnk"));
       
   499     QTest::newRow("QDir::AllDirs | QDir::NoSymLinks") << SRCDIR "entrylist/" << QStringList("*")
       
   500                                                       << int(QDir::AllDirs | QDir::NoSymLinks) << int(QDir::Name)
       
   501                                                       << filterLinks(QString(".,..,directory").split(','));
       
   502 #ifdef QT3_SUPPORT
       
   503     QTest::newRow("QDir::All | QDir::Hidden | QDir::System") << SRCDIR "entrylist/" << QStringList("*")
       
   504                                   << int(QDir::All | QDir::Hidden | QDir::System) << int(QDir::Name)
       
   505                                   << filterLinks(QString(".,..,brokenlink.lnk,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   506     QTest::newRow("QDir::All | QDir::Readable") << SRCDIR "entrylist/" << QStringList("*")
       
   507                                   << int(QDir::All | QDir::Readable) << int(QDir::Name)
       
   508                                                 << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   509     QTest::newRow("QDir::All | QDir::Writable") << SRCDIR "entrylist/" << QStringList("*")
       
   510                                   << int(QDir::All | QDir::Writable) << int(QDir::Name)
       
   511                                   << filterLinks(QString(".,..,directory,linktodirectory.lnk,writable").split(','));
       
   512 #else
       
   513     QTest::newRow("QDir::AllEntries | QDir::Hidden | QDir::System") << SRCDIR "entrylist/" << QStringList("*")
       
   514                                   << int(QDir::AllEntries | QDir::Hidden | QDir::System) << int(QDir::Name)
       
   515                                   << filterLinks(QString(".,..,brokenlink.lnk,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   516     QTest::newRow("QDir::AllEntries | QDir::Readable") << SRCDIR "entrylist/" << QStringList("*")
       
   517                                   << int(QDir::AllEntries | QDir::Readable) << int(QDir::Name)
       
   518                                                 << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   519     QTest::newRow("QDir::AllEntries | QDir::Writable") << SRCDIR "entrylist/" << QStringList("*")
       
   520                                   << int(QDir::AllEntries | QDir::Writable) << int(QDir::Name)
       
   521                                   << filterLinks(QString(".,..,directory,linktodirectory.lnk,writable").split(','));
       
   522 #endif
       
   523     QTest::newRow("Namefilters b*") << SRCDIR "entrylist/" << QStringList("d*")
       
   524                                   << int(QDir::NoFilter) << int(QDir::Name)
       
   525                                   << filterLinks(QString("directory").split(','));
       
   526     QTest::newRow("Namefilters f*") << SRCDIR "entrylist/" << QStringList("f*")
       
   527                                   << int(QDir::NoFilter) << int(QDir::Name)
       
   528                                   << filterLinks(QString("file").split(','));
       
   529     QTest::newRow("Namefilters link*") << SRCDIR "entrylist/" << QStringList("link*")
       
   530                                   << int(QDir::NoFilter) << int(QDir::Name)
       
   531                                   << filterLinks(QString("linktodirectory.lnk,linktofile.lnk").split(','));
       
   532     QTest::newRow("Namefilters *to*") << SRCDIR "entrylist/" << QStringList("*to*")
       
   533                                   << int(QDir::NoFilter) << int(QDir::Name)
       
   534                                   << filterLinks(QString("directory,linktodirectory.lnk,linktofile.lnk").split(','));
       
   535     QTest::newRow("Sorting QDir::Name") << SRCDIR "entrylist/" << QStringList("*")
       
   536                                   << int(QDir::NoFilter) << int(QDir::Name)
       
   537                                   << filterLinks(QString(".,..,directory,file,linktodirectory.lnk,linktofile.lnk,writable").split(','));
       
   538     QTest::newRow("Sorting QDir::Name | QDir::Reversed") << SRCDIR "entrylist/" << QStringList("*")
       
   539                                   << int(QDir::NoFilter) << int(QDir::Name | QDir::Reversed)
       
   540                                   << filterLinks(QString("writable,linktofile.lnk,linktodirectory.lnk,file,directory,..,.").split(','));
       
   541 
       
   542     QTest::newRow("Sorting QDir::Type") << SRCDIR "types/" << QStringList("*")
       
   543                                   << int(QDir::NoFilter) << int(QDir::Type)
       
   544                                   << QString(".,..,a,b,c,d,e,f,a.a,b.a,c.a,d.a,e.a,f.a,a.b,b.b,c.b,d.b,e.b,f.b,a.c,b.c,c.c,d.c,e.c,f.c").split(',');
       
   545     QTest::newRow("Sorting QDir::Type | QDir::Reversed") << SRCDIR "types/" << QStringList("*")
       
   546                                   << int(QDir::NoFilter) << int(QDir::Type | QDir::Reversed)
       
   547                                   << QString("f.c,e.c,d.c,c.c,b.c,a.c,f.b,e.b,d.b,c.b,b.b,a.b,f.a,e.a,d.a,c.a,b.a,a.a,f,e,d,c,b,a,..,.").split(',');
       
   548     QTest::newRow("Sorting QDir::Type | QDir::DirsLast") << SRCDIR "types/" << QStringList("*")
       
   549                                   << int(QDir::NoFilter) << int(QDir::Type | QDir::DirsLast)
       
   550                                   << QString("a,b,c,a.a,b.a,c.a,a.b,b.b,c.b,a.c,b.c,c.c,.,..,d,e,f,d.a,e.a,f.a,d.b,e.b,f.b,d.c,e.c,f.c").split(',');
       
   551     QTest::newRow("Sorting QDir::Type | QDir::DirsFirst") << SRCDIR "types/" << QStringList("*")
       
   552                                   << int(QDir::NoFilter) << int(QDir::Type | QDir::DirsFirst)
       
   553                                   << QString(".,..,d,e,f,d.a,e.a,f.a,d.b,e.b,f.b,d.c,e.c,f.c,a,b,c,a.a,b.a,c.a,a.b,b.b,c.b,a.c,b.c,c.c").split(',');
       
   554     QTest::newRow("Sorting QDir::Size") << SRCDIR "types/" << QStringList("*")
       
   555                                   << int(QDir::AllEntries|QDir::NoDotAndDotDot) << int(QDir::Size | QDir::DirsFirst)
       
   556                                   << QString("d,d.a,d.b,d.c,e,e.a,e.b,e.c,f,f.a,f.b,f.c,c.a,c.b,c.c,b.a,b.c,b.b,a.c,a.b,a.a,a,b,c").split(',');
       
   557     QTest::newRow("Sorting QDir::Size | QDir::Reversed") << SRCDIR "types/" << QStringList("*")
       
   558                                   << int(QDir::AllEntries|QDir::NoDotAndDotDot) << int(QDir::Size | QDir::Reversed | QDir::DirsLast)
       
   559                                   << QString("c,b,a,a.a,a.b,a.c,b.b,b.c,b.a,c.c,c.b,c.a,f.c,f.b,f.a,f,e.c,e.b,e.a,e,d.c,d.b,d.a,d").split(',');
       
   560 }
       
   561 
       
   562 void tst_QDir::entryList()
       
   563 {
       
   564     QFETCH(QString, dirName);
       
   565     QFETCH(QStringList, nameFilters);
       
   566     QFETCH(int, filterspec);
       
   567     QFETCH(int, sortspec);
       
   568     QFETCH(QStringList, expected);
       
   569 
       
   570     QFile(SRCDIR "entrylist/writable").open(QIODevice::ReadWrite);
       
   571     QFile(SRCDIR "entrylist/file").setPermissions(QFile::ReadOwner | QFile::ReadUser);
       
   572     QFile::remove(SRCDIR "entrylist/linktofile");
       
   573     QFile::remove(SRCDIR "entrylist/linktodirectory");
       
   574     QFile::remove(SRCDIR "entrylist/linktofile.lnk");
       
   575     QFile::remove(SRCDIR "entrylist/linktodirectory.lnk");
       
   576     QFile::remove(SRCDIR "entrylist/brokenlink.lnk");
       
   577     QFile::remove(SRCDIR "entrylist/brokenlink");
       
   578 
       
   579     // WinCE/Symbian does not have . and .. in the directory listing
       
   580 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
       
   581     expected.removeAll(".");
       
   582     expected.removeAll("..");
       
   583 #endif
       
   584 
       
   585 #if defined(Q_OS_WIN)
       
   586     // ### Sadly, this is a platform difference right now.
       
   587     QFile::link(SRCDIR "entryList/file", SRCDIR "entrylist/linktofile.lnk");
       
   588     QFile::link(SRCDIR "entryList/directory", SRCDIR "entrylist/linktodirectory.lnk");
       
   589     QFile::link(SRCDIR "entryList/nothing", SRCDIR "entrylist/brokenlink.lnk");
       
   590 #elif defined(Q_OS_SYMBIAN)
       
   591     // Symbian doesn't support links to directories
       
   592       expected.removeAll("linktodirectory.lnk");
       
   593 
       
   594     // Expecting failures from a couple of OpenC bugs. Do checks only once.
       
   595     static int xFailChecked = false;
       
   596     static int expectedFail1 = false;
       
   597     static int expectedFail2 = false;
       
   598 
       
   599     if (!expectedFail1) {
       
   600         // Can't create link if file doesn't exist in symbian, so create file temporarily,
       
   601         // But only if testing for
       
   602         QFile tempFile(SRCDIR "entryList/nothing");
       
   603         tempFile.open(QIODevice::WriteOnly);
       
   604         tempFile.link(SRCDIR "entryList/brokenlink.lnk");
       
   605         tempFile.remove();
       
   606     }
       
   607 
       
   608     if (!expectedFail2) {
       
   609         QFile::link(SRCDIR "entryList/file", SRCDIR "entrylist/linktofile.lnk");
       
   610     }
       
   611 
       
   612     if (!xFailChecked) {
       
   613         // ### Until OpenC supports stat correctly for symbolic links, expect them to fail.
       
   614         expectedFail1 = QFileInfo(SRCDIR "entryList/brokenlink.lnk").exists();
       
   615         expectedFail2 = !(QFileInfo(SRCDIR "entryList/linktofile.lnk").isFile());
       
   616 
       
   617         QEXPECT_FAIL("", "OpenC bug, stat for broken links returns normally, when it should return error.", Continue);
       
   618         QVERIFY(!expectedFail1);
       
   619 
       
   620         QEXPECT_FAIL("", "OpenC bug, stat for file links doesn't indicate them as such.", Continue);
       
   621         QVERIFY(!expectedFail2);
       
   622         xFailChecked = true;
       
   623     }
       
   624 
       
   625     if (expectedFail1) {
       
   626         expected.removeAll("brokenlink.lnk");
       
   627         QFile::remove(SRCDIR "entrylist/brokenlink.lnk");
       
   628     }
       
   629 
       
   630     if (expectedFail2) {
       
   631         expected.removeAll("linktofile.lnk");
       
   632         QFile::remove(SRCDIR "entrylist/linktofile.lnk");
       
   633     }
       
   634 #else
       
   635     QFile::link("file", SRCDIR "entrylist/linktofile.lnk");
       
   636     QFile::link("directory", SRCDIR "entrylist/linktodirectory.lnk");
       
   637     QFile::link("nothing", SRCDIR "entrylist/brokenlink.lnk");
       
   638 #endif
       
   639 
       
   640 #ifdef Q_WS_MAC
       
   641     if (qstrcmp(QTest::currentDataTag(), "unprintablenames") == 0)
       
   642         QSKIP("p4 doesn't sync the files with the unprintable names properly on Mac",SkipSingle);
       
   643 #endif
       
   644     QDir dir(dirName);
       
   645     QVERIFY(dir.exists());
       
   646 
       
   647     QStringList actual = dir.entryList(nameFilters, (QDir::Filters)filterspec,
       
   648                                        (QDir::SortFlags)sortspec);
       
   649 
       
   650     int max = qMin(actual.count(), expected.count());
       
   651 
       
   652     if (qstrcmp(QTest::currentDataTag(), "unprintablenames") == 0) {
       
   653         // The purpose of this entry is to check that QDir doesn't
       
   654         // lock up. The actual result depends on the file system.
       
   655         return;
       
   656     }
       
   657     bool doContentCheck = true;
       
   658 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
       
   659     if (qstrcmp(QTest::currentDataTag(), "QDir::AllEntries | QDir::Writable") == 0) {
       
   660         // for root, everything is writeable
       
   661         if (::getuid() == 0)
       
   662             doContentCheck = false;
       
   663     }
       
   664 #endif
       
   665 
       
   666     if (doContentCheck) {
       
   667         for (int i=0; i<max; ++i)
       
   668             QCOMPARE(actual[i], expected[i]);
       
   669 
       
   670         QCOMPARE(actual.count(), expected.count());
       
   671     }
       
   672 
       
   673 #if defined(Q_OS_SYMBIAN)
       
   674     // Test cleanup on device requires setting the permissions back to normal
       
   675     QFile(SRCDIR "entrylist/file").setPermissions(QFile::WriteUser | QFile::ReadUser);
       
   676 #endif
       
   677 
       
   678     QFile::remove(SRCDIR "entrylist/writable");
       
   679     QFile::remove(SRCDIR "entrylist/linktofile");
       
   680     QFile::remove(SRCDIR "entrylist/linktodirectory");
       
   681     QFile::remove(SRCDIR "entrylist/linktofile.lnk");
       
   682     QFile::remove(SRCDIR "entrylist/linktodirectory.lnk");
       
   683     QFile::remove(SRCDIR "entrylist/brokenlink.lnk");
       
   684     QFile::remove(SRCDIR "entrylist/brokenlink");
       
   685 }
       
   686 
       
   687 void tst_QDir::entryListSimple_data()
       
   688 {
       
   689     QTest::addColumn<QString>("dirName");
       
   690     QTest::addColumn<int>("countMin");
       
   691 
       
   692     QTest::newRow("data2") << "do_not_expect_this_path_to_exist/" << 0;
       
   693 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
       
   694     QTest::newRow("simple dir") << SRCDIR "resources" << 0;
       
   695     QTest::newRow("simple dir with slash") << SRCDIR "resources/" << 0;
       
   696 #else
       
   697     QTest::newRow("simple dir") << SRCDIR "resources" << 2;
       
   698     QTest::newRow("simple dir with slash") << SRCDIR "resources/" << 2;
       
   699 #endif
       
   700 
       
   701 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
       
   702     QTest::newRow("unc 1") << "//"  + QtNetworkSettings::winServerName() << 2;
       
   703     QTest::newRow("unc 2") << "//"  + QtNetworkSettings::winServerName() + "/" << 2;
       
   704     QTest::newRow("unc 3") << "//"  + QtNetworkSettings::winServerName() + "/testshare" << 2;
       
   705     QTest::newRow("unc 4") << "//"  + QtNetworkSettings::winServerName() + "/testshare/" << 2;
       
   706     QTest::newRow("unc 5") << "//"  + QtNetworkSettings::winServerName() + "/testshare/tmp" << 2;
       
   707     QTest::newRow("unc 6") << "//"  + QtNetworkSettings::winServerName() + "/testshare/tmp/" << 2;
       
   708     QTest::newRow("unc 7") << "//"  + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << 0;
       
   709     QTest::newRow("unc 8") << "//"  + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << 0;
       
   710     QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << 0;
       
   711 #endif
       
   712 }
       
   713 
       
   714 void tst_QDir::entryListSimple()
       
   715 {
       
   716     QFETCH(QString, dirName);
       
   717     QFETCH(int, countMin);
       
   718 
       
   719     QDir dir(dirName);
       
   720     QStringList actual = dir.entryList();
       
   721     QVERIFY(actual.count() >= countMin);
       
   722 }
       
   723 
       
   724 void tst_QDir::entryListWithSymLinks()
       
   725 {
       
   726 #ifndef Q_NO_SYMLINKS
       
   727 #  ifndef Q_NO_SYMLINKS_TO_DIRS
       
   728     QFile::remove("myLinkToDir.lnk");
       
   729 #  endif
       
   730     QFile::remove("myLinkToFile.lnk");
       
   731     QFile::remove("testfile.cpp");
       
   732     QDir dir;
       
   733     dir.mkdir("myDir");
       
   734     QFile("testfile.cpp").open(QIODevice::WriteOnly);
       
   735 #  ifndef Q_NO_SYMLINKS_TO_DIRS
       
   736     QVERIFY(QFile::link("myDir", "myLinkToDir.lnk"));
       
   737 #  endif
       
   738     QVERIFY(QFile::link("testfile.cpp", "myLinkToFile.lnk"));
       
   739 
       
   740     {
       
   741         QStringList entryList = QDir().entryList();
       
   742         QVERIFY(entryList.contains("myDir"));
       
   743 #  ifndef Q_NO_SYMLINKS_TO_DIRS
       
   744         QVERIFY(entryList.contains("myLinkToDir.lnk"));
       
   745 #endif
       
   746         QVERIFY(entryList.contains("myLinkToFile.lnk"));
       
   747     }
       
   748     {
       
   749         QStringList entryList = QDir().entryList(QDir::Dirs);
       
   750         QVERIFY(entryList.contains("myDir"));
       
   751 #  ifndef Q_NO_SYMLINKS_TO_DIRS
       
   752         QVERIFY(entryList.contains("myLinkToDir.lnk"));
       
   753 #endif
       
   754 #if defined(Q_OS_SYMBIAN)
       
   755     QEXPECT_FAIL("", "OpenC stat for symlinks is buggy.", Continue);
       
   756 #endif
       
   757         QVERIFY(!entryList.contains("myLinkToFile.lnk"));
       
   758     }
       
   759     {
       
   760         QStringList entryList = QDir().entryList(QDir::Dirs | QDir::NoSymLinks);
       
   761         QVERIFY(entryList.contains("myDir"));
       
   762         QVERIFY(!entryList.contains("myLinkToDir.lnk"));
       
   763         QVERIFY(!entryList.contains("myLinkToFile.lnk"));
       
   764     }
       
   765 
       
   766     QFile::remove("myLinkToDir.lnk");
       
   767     QFile::remove("myLinkToFile.lnk");
       
   768     QFile::remove("testfile.cpp");
       
   769     dir.rmdir("myDir");
       
   770 #endif
       
   771 }
       
   772 
       
   773 void tst_QDir::canonicalPath_data()
       
   774 {
       
   775     QTest::addColumn<QString>("path");
       
   776     QTest::addColumn<QString>("canonicalPath");
       
   777     QString appPath = SRCDIR;
       
   778     if (appPath.isEmpty())
       
   779         appPath = QCoreApplication::instance()->applicationDirPath();
       
   780     else
       
   781         appPath.chop(1);        // remove the ending slash
       
   782 
       
   783 #if defined Q_WS_WIN
       
   784     if (appPath.endsWith("release", Qt::CaseInsensitive) || appPath.endsWith("debug", Qt::CaseInsensitive)) {
       
   785         QDir appDir(appPath);
       
   786         QVERIFY(appDir.cdUp());
       
   787         appPath = appDir.absolutePath();
       
   788     }
       
   789 #endif
       
   790 
       
   791     QTest::newRow("relative") << "." << appPath;
       
   792     QTest::newRow("relativeSubDir") << "./testData/../testData" << appPath + "/testData";
       
   793 
       
   794 #ifndef Q_WS_WIN
       
   795     QTest::newRow("absPath") << appPath + "/testData/../testData" << appPath + "/testData";
       
   796 #else
       
   797     QTest::newRow("absPath") << appPath + "\\testData\\..\\testData" << appPath + "/testData";
       
   798 #endif
       
   799     QTest::newRow("nonexistant") << "testd" << QString();
       
   800 }
       
   801 
       
   802 void tst_QDir::canonicalPath()
       
   803 {
       
   804     QDir srcPath;
       
   805     if (strlen(SRCDIR) > 0)
       
   806         srcPath = QDir(SRCDIR);
       
   807     else
       
   808         srcPath = QDir(".");
       
   809     if (srcPath.absolutePath() != srcPath.canonicalPath())
       
   810         QSKIP("This test does not work if this directory path consists of symlinks.", SkipAll);
       
   811 
       
   812     QString oldpwd = QDir::currentPath();
       
   813     QDir::setCurrent(srcPath.absolutePath());
       
   814 
       
   815     QFETCH(QString, path);
       
   816     QFETCH(QString, canonicalPath);
       
   817 
       
   818     QDir dir(path);
       
   819 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
   820     QCOMPARE(dir.canonicalPath().toLower(), canonicalPath.toLower());
       
   821 #else
       
   822     QCOMPARE(dir.canonicalPath(), canonicalPath);
       
   823 #endif
       
   824 
       
   825     QDir::setCurrent(oldpwd);
       
   826 }
       
   827 
       
   828 void tst_QDir::current_data()
       
   829 {
       
   830     QTest::addColumn<QString>("path");
       
   831     QTest::addColumn<QString>("currentDir");
       
   832     QString appPath = SRCDIR;
       
   833     if (appPath.isEmpty())
       
   834         appPath = QCoreApplication::instance()->applicationDirPath();
       
   835     else
       
   836         appPath.chop(1);        // remove the ending slash
       
   837 #if defined Q_WS_WIN
       
   838     if (appPath.endsWith("release", Qt::CaseInsensitive))
       
   839         appPath = appPath.left(appPath.length()-8);
       
   840     else if (appPath.endsWith("debug", Qt::CaseInsensitive))
       
   841         appPath = appPath.left(appPath.length()-6);
       
   842 #endif
       
   843 
       
   844     QTest::newRow("startup") << QString() << appPath;
       
   845     QTest::newRow("relPath") << "testData" << appPath + "/testData";
       
   846 #ifndef Q_WS_WIN
       
   847     QTest::newRow("absPath") << appPath + "/testData" << appPath + "/testData";
       
   848 #else
       
   849     QTest::newRow("absPath") << appPath + "\\testData" << appPath + "/testData";
       
   850 #endif
       
   851     QTest::newRow("nonexistant") << "testd" << QString();
       
   852 
       
   853     QTest::newRow("parent") << ".." << appPath.left(appPath.lastIndexOf('/'));
       
   854 }
       
   855 
       
   856 void tst_QDir::current()
       
   857 {
       
   858     QString oldDir = QDir::currentPath();
       
   859     QString appPath = SRCDIR;
       
   860     if (appPath.isEmpty())
       
   861         appPath = QCoreApplication::instance()->applicationDirPath();
       
   862     QDir::setCurrent(appPath);
       
   863     QFETCH(QString, path);
       
   864     QFETCH(QString, currentDir);
       
   865 
       
   866     if (!path.isEmpty()) {
       
   867         bool b = QDir::setCurrent(path);
       
   868         // If path is non existant, then setCurrent should be false (currentDir is empty in testData)
       
   869         QVERIFY(b == !currentDir.isEmpty());
       
   870     }
       
   871     if (!currentDir.isEmpty()) {
       
   872         QDir newCurrent = QDir::current();
       
   873         QDir::setCurrent(oldDir);
       
   874 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
   875     QCOMPARE(newCurrent.absolutePath().toLower(), currentDir.toLower());
       
   876 #else
       
   877     QCOMPARE(newCurrent.absolutePath(), currentDir);
       
   878 #endif
       
   879     }
       
   880 
       
   881     QDir::setCurrent(oldDir);
       
   882 }
       
   883 
       
   884 void tst_QDir::cd_data()
       
   885 {
       
   886     QTest::addColumn<QString>("startDir");
       
   887     QTest::addColumn<QString>("cdDir");
       
   888     QTest::addColumn<bool>("successExpected");
       
   889     QTest::addColumn<QString>("newDir");
       
   890 
       
   891     QString appPath = QDir::currentPath();
       
   892     int index = appPath.lastIndexOf("/");
       
   893     QTest::newRow("cdUp") << QDir::currentPath() << ".." << true << appPath.left(index==0?1:index);
       
   894     QTest::newRow("noChange") << QDir::currentPath() << "." << true << appPath;
       
   895 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) // on windows QDir::root() is usually c:/ but cd "/" will not force it to be root
       
   896     QTest::newRow("absolute") << QDir::currentPath() << "/" << true << "/";
       
   897 #else
       
   898     QTest::newRow("absolute") << QDir::currentPath() << "/" << true << QDir::root().absolutePath();
       
   899 #endif
       
   900     QTest::newRow("non existant") << "." << "../anonexistingdir" << false << QDir::currentPath();
       
   901     QTest::newRow("self") << "." << (QString("../") + QFileInfo(QDir::currentPath()).fileName()) << true << QDir::currentPath();
       
   902     QTest::newRow("file") << "." << "qdir.pro" << false << "";
       
   903 }
       
   904 
       
   905 void tst_QDir::cd()
       
   906 {
       
   907     QFETCH(QString, startDir);
       
   908     QFETCH(QString, cdDir);
       
   909     QFETCH(bool, successExpected);
       
   910     QFETCH(QString, newDir);
       
   911 
       
   912     QDir d = startDir;
       
   913     QCOMPARE(d.cd(cdDir), successExpected);
       
   914     if (successExpected)
       
   915         QCOMPARE(d.absolutePath(), newDir);
       
   916 }
       
   917 
       
   918 void tst_QDir::setNameFilters_data()
       
   919 {
       
   920     // Effectively copied from entryList2() test
       
   921 
       
   922     QTest::addColumn<QString>("dirName"); // relative from current path or abs
       
   923     QTest::addColumn<QStringList>("nameFilters");
       
   924     QTest::addColumn<QStringList>("expected");
       
   925 
       
   926     QString appPath = SRCDIR;
       
   927     if (appPath.isEmpty())
       
   928         appPath = QCoreApplication::instance()->applicationDirPath();
       
   929     if (!appPath.endsWith("/"))
       
   930         appPath.append("/");
       
   931 
       
   932     QTest::newRow("spaces1") << appPath + "testdir/spaces" << QStringList("*. bar")
       
   933                           << QStringList("foo. bar");
       
   934     QTest::newRow("spaces2") << appPath + "testdir/spaces" << QStringList("*.bar")
       
   935                           << QStringList("foo.bar");
       
   936     QTest::newRow("spaces3") << appPath + "testdir/spaces" << QStringList("foo.*")
       
   937                             << QString("foo. bar,foo.bar").split(",");
       
   938     QTest::newRow("files1")  << appPath + "testdir/dir" << QString("*r.cpp *.pro").split(" ")
       
   939                           << QString("qdir.pro,qrc_qdir.cpp,tst_qdir.cpp").split(",");
       
   940     QTest::newRow("resources1") << QString(":/tst_qdir/resources/entryList") << QStringList("*.data")
       
   941                              << QString("file1.data,file2.data,file3.data").split(',');
       
   942 }
       
   943 
       
   944 void tst_QDir::setNameFilters()
       
   945 {
       
   946     QFETCH(QString, dirName);
       
   947     QFETCH(QStringList, nameFilters);
       
   948     QFETCH(QStringList, expected);
       
   949 
       
   950     QDir dir(dirName);
       
   951     QVERIFY(dir.exists());
       
   952 
       
   953     dir.setNameFilters(nameFilters);
       
   954     QStringList actual = dir.entryList();
       
   955     int max = qMin(actual.count(), expected.count());
       
   956 
       
   957     for (int i=0; i<max; ++i)
       
   958         QCOMPARE(actual[i], expected[i]);
       
   959     QCOMPARE(actual.count(), expected.count());
       
   960 }
       
   961 
       
   962 void
       
   963 tst_QDir::cleanPath_data()
       
   964 {
       
   965     QTest::addColumn<QString>("path");
       
   966     QTest::addColumn<QString>("expected");
       
   967 
       
   968     QTest::newRow("data0") << "/Users/sam/troll/qt4.0//.." << "/Users/sam/troll";
       
   969     QTest::newRow("data1") << "/Users/sam////troll/qt4.0//.." << "/Users/sam/troll";
       
   970     QTest::newRow("data2") << "/" << "/";
       
   971     QTest::newRow("data3") << QDir::cleanPath("../.") << "..";
       
   972     QTest::newRow("data4") << QDir::cleanPath("../..") << "../..";
       
   973 #if !defined(Q_OS_WINCE)
       
   974 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
   975     QTest::newRow("data5") << "d:\\a\\bc\\def\\.." << "d:/a/bc";
       
   976     QTest::newRow("data6") << "d:\\a\\bc\\def\\../../.." << "d:/";
       
   977 #else
       
   978     QTest::newRow("data5") << "d:\\a\\bc\\def\\.." << "d:\\a\\bc\\def\\..";
       
   979     QTest::newRow("data6") << "d:\\a\\bc\\def\\../../.." << "d:\\a\\bc\\def\\../../..";
       
   980 #endif
       
   981 #endif
       
   982     QTest::newRow("data7") << ".//file1.txt" << "file1.txt";
       
   983     QTest::newRow("data8") << "/foo/bar/..//file1.txt" << "/foo/file1.txt";
       
   984     QTest::newRow("data9") << "//" << "/";
       
   985 }
       
   986 
       
   987 
       
   988 void
       
   989 tst_QDir::cleanPath()
       
   990 {
       
   991     QFETCH(QString, path);
       
   992     QFETCH(QString, expected);
       
   993     QString cleaned = QDir::cleanPath(path);
       
   994     QCOMPARE(cleaned, expected);
       
   995 }
       
   996 
       
   997 void tst_QDir::absoluteFilePath_data()
       
   998 {
       
   999     QTest::addColumn<QString>("path");
       
  1000     QTest::addColumn<QString>("fileName");
       
  1001     QTest::addColumn<QString>("expectedFilePath");
       
  1002 
       
  1003     QTest::newRow("0") << "/etc" << "/passwd" << "/passwd";
       
  1004     QTest::newRow("1") << "/etc" << "passwd" << "/etc/passwd";
       
  1005     QTest::newRow("2") << "/" << "passwd" << "/passwd";
       
  1006     QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path";
       
  1007     QTest::newRow("4") << "" << "" << QDir::currentPath();
       
  1008 }
       
  1009 
       
  1010 void tst_QDir::absoluteFilePath()
       
  1011 {
       
  1012     QFETCH(QString, path);
       
  1013     QFETCH(QString, fileName);
       
  1014     QFETCH(QString, expectedFilePath);
       
  1015 
       
  1016     QDir dir(path);
       
  1017     QString absFilePath = dir.absoluteFilePath(fileName);
       
  1018     QCOMPARE(absFilePath, expectedFilePath);
       
  1019 }
       
  1020 
       
  1021 void tst_QDir::absolutePath_data()
       
  1022 {
       
  1023     QTest::addColumn<QString>("path");
       
  1024     QTest::addColumn<QString>("expectedPath");
       
  1025 
       
  1026     QTest::newRow("0") << "/machine/share/dir1" << "/machine/share/dir1";
       
  1027 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
       
  1028     QTest::newRow("1") << "\\machine\\share\\dir1" << "/machine/share/dir1";
       
  1029 # if !defined(Q_OS_SYMBIAN)
       
  1030     QTest::newRow("2") << "//machine/share/dir1" << "//machine/share/dir1";
       
  1031     QTest::newRow("3") << "\\\\machine\\share\\dir1" << "//machine/share/dir1";
       
  1032 # endif
       
  1033     QTest::newRow("4") << "c:/machine/share/dir1" << "c:/machine/share/dir1";
       
  1034     QTest::newRow("5") << "c:\\machine\\share\\dir1" << "c:/machine/share/dir1";
       
  1035 #endif
       
  1036 }
       
  1037 
       
  1038 void tst_QDir::absolutePath()
       
  1039 {
       
  1040     QFETCH(QString, path);
       
  1041     QFETCH(QString, expectedPath);
       
  1042 
       
  1043     QDir dir(path);
       
  1044     QCOMPARE(dir.absolutePath(), expectedPath);
       
  1045 }
       
  1046 
       
  1047 void tst_QDir::relativeFilePath_data()
       
  1048 {
       
  1049     QTest::addColumn<QString>("dir");
       
  1050     QTest::addColumn<QString>("path");
       
  1051     QTest::addColumn<QString>("expected");
       
  1052 
       
  1053     QTest::newRow("0") << "/foo/bar" << "ding.txt" << "ding.txt";
       
  1054     QTest::newRow("1") << "/foo/bar" << "ding/dong.txt"    << "ding/dong.txt";
       
  1055     QTest::newRow("2") << "/foo/bar" << "../ding/dong.txt" << "../ding/dong.txt";
       
  1056 
       
  1057     QTest::newRow("3") << "/foo/bar" << "/foo/bar/ding.txt" << "ding.txt";
       
  1058     QTest::newRow("4") << "/foo/bar/" << "/foo/bar/ding/dong.txt" << "ding/dong.txt";
       
  1059     QTest::newRow("5") << "/foo/bar/" << "/ding/dong.txt" << "../../ding/dong.txt";
       
  1060 
       
  1061     QTest::newRow("6") << "/" << "/ding/dong.txt" << "ding/dong.txt";
       
  1062     QTest::newRow("7") << "/" << "/ding/" << "ding";
       
  1063     QTest::newRow("8") << "/" << "/ding//" << "ding";
       
  1064     QTest::newRow("9") << "/" << "/ding/../dong" << "dong";
       
  1065     QTest::newRow("10") << "/" << "/ding/../../../../dong" << "../../../dong";
       
  1066 
       
  1067     QTest::newRow("11") << "" << "" << "";
       
  1068 
       
  1069 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
       
  1070     QTest::newRow("12") << "C:/foo/bar" << "ding" << "ding";
       
  1071     QTest::newRow("13") << "C:/foo/bar" << "C:/ding/dong" << "../../ding/dong";
       
  1072     QTest::newRow("14") << "C:/foo/bar" << "/ding/dong" << "../../ding/dong";
       
  1073     QTest::newRow("15") << "C:/foo/bar" << "D:/ding/dong" << "D:/ding/dong";
       
  1074     QTest::newRow("16") << "C:" << "C:/ding/dong" << "ding/dong";
       
  1075     QTest::newRow("16") << "C:/" << "C:/ding/dong" << "ding/dong";
       
  1076     QTest::newRow("17") << "C:" << "C:" << "";
       
  1077     QTest::newRow("18") << "C:/" << "C:" << "";
       
  1078     QTest::newRow("19") << "C:" << "C:/" << "";
       
  1079     QTest::newRow("20") << "C:/" << "C:/" << "";
       
  1080     QTest::newRow("17") << "C:" << "C:file.txt" << "file.txt";
       
  1081     QTest::newRow("18") << "C:/" << "C:file.txt" << "file.txt";
       
  1082     QTest::newRow("19") << "C:" << "C:/file.txt" << "file.txt";
       
  1083     QTest::newRow("20") << "C:/" << "C:/file.txt" << "file.txt";
       
  1084     QTest::newRow("21") << "C:" << "D:" << "D:";
       
  1085     QTest::newRow("22") << "C:" << "D:/" << "D:/";
       
  1086     QTest::newRow("23") << "C:/" << "D:" << "D:";
       
  1087     QTest::newRow("24") << "C:/" << "D:/" << "D:/";
       
  1088 # if !defined(Q_OS_SYMBIAN)
       
  1089     QTest::newRow("25") << "C:/foo/bar" << "//anotherHost/foo/bar" << "//anotherHost/foo/bar";
       
  1090     QTest::newRow("26") << "//anotherHost/foo" << "//anotherHost/foo/bar" << "bar";
       
  1091     QTest::newRow("27") << "//anotherHost/foo" << "bar" << "bar";
       
  1092     QTest::newRow("28") << "//anotherHost/foo" << "C:/foo/bar" << "C:/foo/bar";
       
  1093 # endif
       
  1094 #endif
       
  1095 }
       
  1096 
       
  1097 void tst_QDir::relativeFilePath()
       
  1098 {
       
  1099     QFETCH(QString, dir);
       
  1100     QFETCH(QString, path);
       
  1101     QFETCH(QString, expected);
       
  1102 
       
  1103     QCOMPARE(QDir(dir).relativeFilePath(path), expected);
       
  1104 }
       
  1105 
       
  1106 void tst_QDir::filePath_data()
       
  1107 {
       
  1108     QTest::addColumn<QString>("path");
       
  1109     QTest::addColumn<QString>("fileName");
       
  1110     QTest::addColumn<QString>("expectedFilePath");
       
  1111 
       
  1112     QTest::newRow("0") << "/etc" << "/passwd" << "/passwd";
       
  1113     QTest::newRow("1") << "/etc" << "passwd" << "/etc/passwd";
       
  1114     QTest::newRow("2") << "/" << "passwd" << "/passwd";
       
  1115     QTest::newRow("3") << "relative" << "path" << "relative/path";
       
  1116     QTest::newRow("4") << "" << "" << ".";
       
  1117 }
       
  1118 
       
  1119 void tst_QDir::filePath()
       
  1120 {
       
  1121     QFETCH(QString, path);
       
  1122     QFETCH(QString, fileName);
       
  1123     QFETCH(QString, expectedFilePath);
       
  1124 
       
  1125     QDir dir(path);
       
  1126     QString absFilePath = dir.filePath(fileName);
       
  1127     QCOMPARE(absFilePath, expectedFilePath);
       
  1128 }
       
  1129 
       
  1130 void tst_QDir::remove()
       
  1131 {
       
  1132     QFile f("remove-test");
       
  1133     f.open(QIODevice::WriteOnly);
       
  1134     f.close();
       
  1135     QDir dir;
       
  1136     QVERIFY(dir.remove("remove-test"));
       
  1137     QVERIFY(!dir.remove("/remove-test"));
       
  1138 }
       
  1139 
       
  1140 void tst_QDir::rename()
       
  1141 {
       
  1142     QFile f("rename-test");
       
  1143     f.open(QIODevice::WriteOnly);
       
  1144     f.close();
       
  1145     QDir dir;
       
  1146     QVERIFY(dir.rename("rename-test", "rename-test-renamed"));
       
  1147     QVERIFY(dir.rename("rename-test-renamed", "rename-test"));
       
  1148 #if defined(Q_OS_MAC)
       
  1149     QVERIFY(!dir.rename("rename-test", "/etc/rename-test-renamed"));
       
  1150 #elif !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
       
  1151     // on windows/symbian this is possible - maybe make the test a bit better
       
  1152     QVERIFY(!dir.rename("rename-test", "/rename-test-renamed"));
       
  1153 #endif
       
  1154     QVERIFY(dir.remove("rename-test"));
       
  1155 }
       
  1156 
       
  1157 void tst_QDir::exists2_data()
       
  1158 {
       
  1159     QTest::addColumn<QString>("path");
       
  1160     QTest::addColumn<bool>("exists");
       
  1161 
       
  1162     QTest::newRow("0") << "." << true;
       
  1163     QTest::newRow("1") << "/" << true;
       
  1164     QTest::newRow("2") << "" << false;
       
  1165     QTest::newRow("3") << "testData" << true;
       
  1166     QTest::newRow("4") << "/testData" << false;
       
  1167     QTest::newRow("5") << "tst_qdir.cpp" << true;
       
  1168     QTest::newRow("6") << "/resources.cpp" << false;
       
  1169 }
       
  1170 
       
  1171 void tst_QDir::exists2()
       
  1172 {
       
  1173     QFETCH(QString, path);
       
  1174     QFETCH(bool, exists);
       
  1175 
       
  1176     QString oldpwd = QDir::currentPath();
       
  1177     if (strlen(SRCDIR) > 0)
       
  1178         QDir::setCurrent(SRCDIR);
       
  1179 
       
  1180     if (path.isEmpty())
       
  1181         QTest::ignoreMessage(QtWarningMsg, "QDir::exists: Empty or null file name");
       
  1182 
       
  1183     QDir dir;
       
  1184     if (exists)
       
  1185         QVERIFY(dir.exists(path));
       
  1186     else
       
  1187         QVERIFY(!dir.exists(path));
       
  1188 
       
  1189     QDir::setCurrent(oldpwd);
       
  1190 }
       
  1191 
       
  1192 void tst_QDir::dirName_data()
       
  1193 {
       
  1194     QTest::addColumn<QString>("path");
       
  1195     QTest::addColumn<QString>("dirName");
       
  1196 
       
  1197     QTest::newRow("slash0") << "c:/winnt/system32" << "system32";
       
  1198     QTest::newRow("slash1") << "/winnt/system32" << "system32";
       
  1199     QTest::newRow("slash2") << "c:/winnt/system32/kernel32.dll" << "kernel32.dll";
       
  1200 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
  1201     QTest::newRow("bslash0") << "c:\\winnt\\system32" << "system32";
       
  1202     QTest::newRow("bslash1") << "\\winnt\\system32" << "system32";
       
  1203     QTest::newRow("bslash2") << "c:\\winnt\\system32\\kernel32.dll" << "kernel32.dll";
       
  1204 #endif
       
  1205 }
       
  1206 
       
  1207 void tst_QDir::dirName()
       
  1208 {
       
  1209     QFETCH(QString, path);
       
  1210     QFETCH(QString, dirName);
       
  1211 
       
  1212     QDir dir(path);
       
  1213     QCOMPARE(dir.dirName(), dirName);
       
  1214 }
       
  1215 
       
  1216 void tst_QDir::operator_eq()
       
  1217 {
       
  1218     QDir dir1(".");
       
  1219     dir1 = dir1;
       
  1220     dir1.setPath("..");
       
  1221 }
       
  1222 
       
  1223 void tst_QDir::dotAndDotDot()
       
  1224 {
       
  1225 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
       
  1226     QSKIP("WinCE and Symbian do not have . nor ..", SkipAll);
       
  1227 #endif
       
  1228     QDir dir(QString(SRCDIR "testdir/"));
       
  1229     QStringList entryList = dir.entryList(QDir::Dirs);
       
  1230     QCOMPARE(entryList, QStringList() << QString(".") << QString("..") << QString("dir") << QString("spaces"));
       
  1231     entryList = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
       
  1232     QCOMPARE(entryList, QStringList() << QString("dir") << QString("spaces"));
       
  1233 }
       
  1234 
       
  1235 #ifdef QT3_SUPPORT
       
  1236 /*
       
  1237     Tets that the setMatchAllDirs setting survies a call to setFilter.
       
  1238 */
       
  1239 void tst_QDir::matchAllDirs()
       
  1240 {
       
  1241     QDir dir("/");
       
  1242     dir.setMatchAllDirs(true);
       
  1243     dir.setNameFilters(QStringList() << "*.foo");
       
  1244     dir.setFilter(QDir::Hidden);
       
  1245     QVERIFY(dir.matchAllDirs());
       
  1246     QVERIFY(dir.entryList().count() > 0);
       
  1247     dir.setMatchAllDirs(false);
       
  1248     dir.setFilter(QDir::Hidden);
       
  1249     QVERIFY(dir.matchAllDirs() == false);
       
  1250     QCOMPARE(dir.entryList().count(), 0);
       
  1251 
       
  1252 }
       
  1253 #endif
       
  1254 
       
  1255 void tst_QDir::homePath()
       
  1256 {
       
  1257     QDir homeDir = QDir::home();
       
  1258     QString strHome = QDir::homePath();
       
  1259 
       
  1260     // docs say that homePath() is an absolute path
       
  1261     QCOMPARE(strHome, homeDir.absolutePath());
       
  1262     QVERIFY(QDir::isAbsolutePath(strHome));
       
  1263 
       
  1264 #ifdef Q_OS_UNIX
       
  1265     if (strHome.length() > 1)      // root dir = "/"
       
  1266         QVERIFY(!strHome.endsWith('/'));
       
  1267 #elif defined(Q_OS_WIN)
       
  1268     if (strHome.length() > 3)      // root dir = "c:/"; "//" is not really valid...
       
  1269         QVERIFY(!strHome.endsWith('/'));
       
  1270 #endif
       
  1271 
       
  1272     QStringList entries = homeDir.entryList();
       
  1273     for (int i = 0; i < entries.count(); ++i) {
       
  1274         QFileInfo fi(QDir::homePath() + "/" + entries[i]);
       
  1275         QCOMPARE(fi.exists(), true);
       
  1276     }
       
  1277 }
       
  1278 
       
  1279 void tst_QDir::tempPath()
       
  1280 {
       
  1281     QDir dir = QDir::temp();
       
  1282     QString path = QDir::tempPath();
       
  1283 
       
  1284     // docs say that tempPath() is an absolute path
       
  1285     QCOMPARE(path, dir.absolutePath());
       
  1286     QVERIFY(QDir::isAbsolutePath(path));
       
  1287 
       
  1288 #ifdef Q_OS_UNIX
       
  1289     if (path.length() > 1)      // root dir = "/"
       
  1290         QVERIFY(!path.endsWith('/'));
       
  1291 #elif defined(Q_OS_WIN)
       
  1292     if (path.length() > 3)      // root dir = "c:/"; "//" is not really valid...
       
  1293         QVERIFY(!path.endsWith('/'));
       
  1294 #endif
       
  1295 }
       
  1296 
       
  1297 void tst_QDir::rootPath()
       
  1298 {
       
  1299     QDir dir = QDir::root();
       
  1300     QString path = QDir::rootPath();
       
  1301 
       
  1302     // docs say that tempPath() is an absolute path
       
  1303     QCOMPARE(path, dir.absolutePath());
       
  1304     QVERIFY(QDir::isAbsolutePath(path));
       
  1305 
       
  1306 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
       
  1307     QCOMPARE(path, QString("/"));
       
  1308 #endif
       
  1309 }
       
  1310 
       
  1311 void tst_QDir::nativeSeparators()
       
  1312 {
       
  1313 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
  1314     QCOMPARE(QDir::toNativeSeparators(QLatin1String("/")), QString("\\"));
       
  1315     QCOMPARE(QDir::toNativeSeparators(QLatin1String("\\")), QString("\\"));
       
  1316     QCOMPARE(QDir::fromNativeSeparators(QLatin1String("/")), QString("/"));
       
  1317     QCOMPARE(QDir::fromNativeSeparators(QLatin1String("\\")), QString("/"));
       
  1318 #else
       
  1319     QCOMPARE(QDir::toNativeSeparators(QLatin1String("/")), QString("/"));
       
  1320     QCOMPARE(QDir::toNativeSeparators(QLatin1String("\\")), QString("\\"));
       
  1321     QCOMPARE(QDir::fromNativeSeparators(QLatin1String("/")), QString("/"));
       
  1322     QCOMPARE(QDir::fromNativeSeparators(QLatin1String("\\")), QString("\\"));
       
  1323 #endif
       
  1324 }
       
  1325 
       
  1326 void tst_QDir::searchPaths_data()
       
  1327 {
       
  1328     QTest::addColumn<QString>("filename");
       
  1329     QTest::addColumn<QString>("searchPathPrefixes");
       
  1330     QTest::addColumn<QString>("searchPaths");
       
  1331     QTest::addColumn<QString>("expectedAbsolutePath");
       
  1332 
       
  1333     QString srcdir = SRCDIR;
       
  1334     if (srcdir.isEmpty())
       
  1335         srcdir = QDir::currentPath();
       
  1336     else
       
  1337         srcdir.chop(1);         // remove ending slash
       
  1338     QString searchDir = srcdir + "/searchdir";
       
  1339 
       
  1340     // sanity
       
  1341     QTest::newRow("nopath") << "picker.png" << QString() << QString() << QString();
       
  1342     QTest::newRow("emptysearchpath") << "subdir1/picker.png" << QString() << QString() << QString();
       
  1343     QTest::newRow("searchpathwithoutprefix") << SRCDIR "searchdir/subdir1/picker.png" << QString("searchpath") << QString("searchdir") << (searchDir+"/subdir1/picker.png");
       
  1344 
       
  1345     // new
       
  1346     QTest::newRow("novalidsearchpath") << "searchpath:subdir1/picker.png" << QString() << QString() << QString();
       
  1347     QTest::newRow("invalidsearchpath") << "searchpath:subdir1/picker.png" << QString("invalid") << QString("invalid") << QString();
       
  1348     QTest::newRow("onlyvalidsearchpath") << "searchpath:subdir1/picker.png" << QString("searchpath") << QString(SRCDIR "searchdir") << (searchDir+"/subdir1/picker.png");
       
  1349     QTest::newRow("validandinvalidsearchpath") << "searchpath:subdir1/picker.png" << QString("invalid;searchpath") << QString("invalid;" SRCDIR "searchdir") << (searchDir+"/subdir1/picker.png");
       
  1350     QTest::newRow("precedence1") << "searchpath:picker.png" << QString("invalid;searchpath") << QString("invalid;" SRCDIR "searchdir/subdir1," SRCDIR "searchdir/subdir2") << (searchDir+"/subdir1/picker.png");
       
  1351     QTest::newRow("precedence2") << "searchpath:picker.png" << QString("invalid;searchpath") << QString("invalid;" SRCDIR "searchdir/subdir2," SRCDIR "searchdir/subdir1") << (searchDir+"/subdir2/picker.png");
       
  1352     QTest::newRow("precedence3") << "searchpath2:picker.png" << QString("searchpath1;searchpath2") << QString(SRCDIR "searchdir/subdir1;" SRCDIR "searchdir/subdir2") << (searchDir+"/subdir2/picker.png");
       
  1353 
       
  1354     // re
       
  1355 }
       
  1356 
       
  1357 void tst_QDir::searchPaths()
       
  1358 {
       
  1359     QFETCH(QString, filename);
       
  1360     QFETCH(QString, searchPathPrefixes);
       
  1361     QStringList searchPathPrefixList = searchPathPrefixes.split(";", QString::SkipEmptyParts);
       
  1362     QFETCH(QString, searchPaths);
       
  1363     QStringList searchPathsList = searchPaths.split(";", QString::SkipEmptyParts);
       
  1364     QFETCH(QString, expectedAbsolutePath);
       
  1365     bool exists = !expectedAbsolutePath.isEmpty();
       
  1366 
       
  1367     for (int i = 0; i < searchPathPrefixList.count(); ++i) {
       
  1368         QDir::setSearchPaths(searchPathPrefixList.at(i), searchPathsList.at(i).split(","));
       
  1369     }
       
  1370     for (int i = 0; i < searchPathPrefixList.count(); ++i) {
       
  1371         QVERIFY(QDir::searchPaths(searchPathPrefixList.at(i)) == searchPathsList.at(i).split(","));
       
  1372     }
       
  1373 
       
  1374     QCOMPARE(QFile(filename).exists(), exists);
       
  1375     QCOMPARE(QFileInfo(filename).exists(), exists);
       
  1376 
       
  1377     if (exists) {
       
  1378         QCOMPARE(QFileInfo(filename).absoluteFilePath(), expectedAbsolutePath);
       
  1379     }
       
  1380 
       
  1381     for (int i = 0; i < searchPathPrefixList.count(); ++i) {
       
  1382         QDir::setSearchPaths(searchPathPrefixList.at(i), QStringList());
       
  1383     }
       
  1384     for (int i = 0; i < searchPathPrefixList.count(); ++i) {
       
  1385         QVERIFY(QDir::searchPaths(searchPathPrefixList.at(i)).isEmpty());
       
  1386     }
       
  1387 }
       
  1388 
       
  1389 void tst_QDir::entryListWithSearchPaths()
       
  1390 {
       
  1391     QDir realDir(":/tst_qdir/resources/entryList");
       
  1392     QVERIFY(realDir.exists());
       
  1393     QVERIFY(!realDir.entryList().isEmpty());
       
  1394     QVERIFY(realDir.entryList().contains("file3.data"));
       
  1395 
       
  1396     QDir::setSearchPaths("searchpath", QStringList(":/tst_qdir/resources"));
       
  1397     QDir dir("searchpath:entryList/");
       
  1398     QCOMPARE(dir.path(), QString(":/tst_qdir/resources/entryList"));
       
  1399     QVERIFY(dir.exists());
       
  1400     QStringList entryList = dir.entryList();
       
  1401     QVERIFY(entryList.contains("file3.data"));
       
  1402 }
       
  1403 
       
  1404 void tst_QDir::longFileName_data()
       
  1405 {
       
  1406     QTest::addColumn<int>("length");
       
  1407 
       
  1408     QTest::newRow("128") << 128;
       
  1409     QTest::newRow("256") << 256;
       
  1410     QTest::newRow("512") << 512;
       
  1411     QTest::newRow("1024") << 1024;
       
  1412     QTest::newRow("2048") << 2048;
       
  1413     QTest::newRow("4096") << 4096;
       
  1414 }
       
  1415 
       
  1416 void tst_QDir::longFileName()
       
  1417 {
       
  1418     QFETCH(int, length);
       
  1419 
       
  1420     QString fileName(length, QLatin1Char('a'));
       
  1421     fileName += QLatin1String(".txt");
       
  1422 
       
  1423     QFile file(fileName);
       
  1424     if (!file.open(QFile::WriteOnly))
       
  1425         QSKIP("Cannot create long file names", SkipAll);
       
  1426 
       
  1427     QFile file2(fileName);
       
  1428     QVERIFY(file2.open(QFile::ReadOnly));
       
  1429 
       
  1430     QVERIFY(QDir().entryList().contains(fileName));
       
  1431 
       
  1432     file.close();
       
  1433     file2.close();
       
  1434 
       
  1435     QFile::remove(fileName);
       
  1436 }
       
  1437 
       
  1438 QTEST_MAIN(tst_QDir)
       
  1439 #include "tst_qdir.moc"
       
  1440