diff options
Diffstat (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp')
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 828a90e86e..9fe8dee040 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -74,9 +74,7 @@ QT_END_NAMESPACE # undef fileno #endif -#if defined(Q_OS_WIN) -#include "../../../network-settings.h" -#endif +#include "../../../../shared/filesystem.h" #ifndef STDIN_FILENO #define STDIN_FILENO 0 @@ -170,6 +168,7 @@ private slots: void permissionsNtfs_data(); void permissionsNtfs(); #endif + void setPermissions_data(); void setPermissions(); void copy(); void copyAfterFail(); @@ -542,7 +541,7 @@ void tst_QFile::exists() QVERIFY(!file.exists()); #if defined(Q_OS_WIN) - const QString uncPath = "//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt"; + const QString uncPath = "//" + QTest::uncServerName() + "/testshare/readme.txt"; QFile unc(uncPath); QVERIFY2(unc.exists(), msgFileDoesNotExist(uncPath).constData()); #endif @@ -608,7 +607,7 @@ void tst_QFile::open_data() QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) << false << QFile::OpenError; } - QTest::newRow("uncFile") << "//" + QtNetworkSettings::winServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly) + QTest::newRow("uncFile") << "//" + QTest::uncServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly) << true << QFile::NoError; #endif } @@ -682,7 +681,7 @@ void tst_QFile::size_data() QTest::newRow( "exist01" ) << m_testFile << (qint64)245; #if defined(Q_OS_WIN) // Only test UNC on Windows./ - QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testshare/test.pri") << (qint64)34; + QTest::newRow("unc") << "//" + QString(QTest::uncServerName() + "/testshare/test.pri") << (qint64)34; #endif } @@ -1419,21 +1418,38 @@ void tst_QFile::permissionsNtfs() } #endif +void tst_QFile::setPermissions_data() +{ + QTest::addColumn<bool>("opened"); + QTest::newRow("closed") << false; // chmod() + QTest::newRow("opened") << true; // fchmod() +} + void tst_QFile::setPermissions() { - if ( QFile::exists( "createme.txt" ) ) - QFile::remove( "createme.txt" ); +#ifdef Q_OS_QNX + QSKIP("This test doesn't pass on QNX and no one has cared to investigate."); +#endif + QFETCH(bool, opened); + + auto remove = []() { QFile::remove("createme.txt"); }; + auto guard = qScopeGuard(remove); + remove(); QVERIFY( !QFile::exists( "createme.txt" ) ); QFile f("createme.txt"); QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(f).constData()); f.putChar('a'); - f.close(); + if (!opened) + f.close(); QFile::Permissions perms(QFile::WriteUser | QFile::ReadUser); + QVERIFY(f.setPermissions(QFile::ReadUser)); + QVERIFY((f.permissions() & perms) == QFile::ReadUser); QVERIFY(f.setPermissions(perms)); QVERIFY((f.permissions() & perms) == perms); + // we should end the test with the file in writeable state } void tst_QFile::copy() @@ -1769,7 +1785,7 @@ void tst_QFile::largeUncFileSupport() qint64 size = Q_INT64_C(8589934592); qint64 dataOffset = Q_INT64_C(8589914592); QByteArray knownData("LargeFile content at offset 8589914592"); - QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin"); + QString largeFile("//" + QTest::uncServerName() + "/testsharelargefile/file.bin"); const QByteArray largeFileEncoded = QFile::encodeName(largeFile); { @@ -2450,7 +2466,7 @@ void tst_QFile::writeLargeDataBlock_data() #if defined(Q_OS_WIN) && !defined(QT_NO_NETWORK) // Some semi-randomness to avoid collisions. QTest::newRow("unc file") - << QString("//" + QtNetworkSettings::winServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt") + << QString("//" + QTest::uncServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt") .arg(QHostInfo::localHostName()) .arg(QTime::currentTime().msec()) << (int)OpenQFile; #endif @@ -2618,7 +2634,7 @@ static void unixPipe_helper(int pipes[2]) QFile f; if (useStdio) { FILE *fh = fdopen(pipes[0], "rb"); - QVERIFY(f.open(fh, QIODevice::ReadOnly | QIODevice::Unbuffered)); + QVERIFY(f.open(fh, QIODevice::ReadOnly | QIODevice::Unbuffered, QFileDevice::AutoCloseHandle)); } else { QVERIFY(f.open(pipes[0], QIODevice::ReadOnly | QIODevice::Unbuffered)); } @@ -2875,7 +2891,7 @@ void tst_QFile::miscWithUncPathAsCurrentDir() { #if defined(Q_OS_WIN) QString current = QDir::currentPath(); - const QString path = QLatin1String("//") + QtNetworkSettings::winServerName() + const QString path = QLatin1String("//") + QTest::uncServerName() + QLatin1String("/testshare"); QVERIFY2(QDir::setCurrent(path), qPrintable(QDir::toNativeSeparators(path))); QFile file("test.pri"); |