diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2012-10-26 17:18:22 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-29 13:46:50 +0100 |
commit | 8fedf683691d4ce6e1c1aea5dda3a4f16f29b635 (patch) | |
tree | b6615a44f91afd8d7e40d36a0df399682628414a /tests | |
parent | b626b98b9552b459919f90496e60931e9f2071f1 (diff) |
Fix qfile:invalidFile() test.
The test expects 'fail:invalid' to be an invalid file,
which it no longer is on Windows 7. It also assumes that
f: is an invalid drive. Fix by picking a drive that does not exist.
Task-number: QTBUG-27306
Change-Id: I9d9b36c50fc31d2561d3c4eec66f65d96084f0d7
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 1f2d4fe4f5..fe378b2095 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -1027,14 +1027,44 @@ void tst_QFile::ungetChar() QCOMPARE(buf[2], '4'); } +#ifdef Q_OS_WIN +QString driveLetters() +{ + wchar_t volumeName[MAX_PATH]; + wchar_t path[MAX_PATH]; + const HANDLE h = FindFirstVolumeW(volumeName, MAX_PATH); + if (h == INVALID_HANDLE_VALUE) + return QString(); + QString result; + do { + if (GetVolumePathNamesForVolumeNameW(volumeName, path, MAX_PATH, NULL)) { + if (path[1] == L':') + result.append(QChar(path[0])); + } + } while (FindNextVolumeW(h, volumeName, MAX_PATH)); + FindVolumeClose(h); + return result; +} + +static inline QChar invalidDriveLetter() +{ + const QString drives = driveLetters().toLower(); + for (char c = 'a'; c <= 'z'; ++c) + if (!drives.contains(QLatin1Char(c))) + return QLatin1Char(c); + Q_ASSERT(false); // All drive letters used?! + return QChar(); +} + +#endif // Q_OS_WIN + void tst_QFile::invalidFile_data() { QTest::addColumn<QString>("fileName"); #if !defined(Q_OS_WIN) QTest::newRow( "x11" ) << QString( "qwe//" ); #else - QTest::newRow( "colon1" ) << QString( "fail:invalid" ); - QTest::newRow( "colon2" ) << QString( "f:ail:invalid" ); + QTest::newRow( "colon2" ) << invalidDriveLetter() + QString::fromLatin1(":ail:invalid"); QTest::newRow( "colon3" ) << QString( ":failinvalid" ); QTest::newRow( "forwardslash" ) << QString( "fail/invalid" ); QTest::newRow( "asterisk" ) << QString( "fail*invalid" ); @@ -1050,8 +1080,7 @@ void tst_QFile::invalidFile() { QFETCH( QString, fileName ); QFile f( fileName ); - QEXPECT_FAIL("colon1", "QTBUG-27306", Continue); - QVERIFY( !f.open( QIODevice::ReadWrite ) ); + QVERIFY2( !f.open( QIODevice::ReadWrite ), qPrintable(fileName) ); } void tst_QFile::createFile() |