Test QFileInfo::isWritable when it should return false
Extend existing tests to verify that QFileInfo::isWritable returns false when file is read-only or non-existent. Task-number: QTBUG-124011 Pick-to: 6.5 Change-Id: If41241b500aa76036b39a53590b5e0b6ab2f20ea Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 42004d245e2bf4846520e5e186a5c86aa87a6019) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 471debef077f294fe7b40af7d0a2d4bb81779511)
This commit is contained in:
parent
51d0d5f529
commit
b876453932
@ -1898,9 +1898,24 @@ void tst_QFileInfo::isWritable()
|
||||
tempfile.write("This file is generated by the QFileInfo autotest.");
|
||||
tempfile.close();
|
||||
|
||||
// isWritable returns true when file is writable
|
||||
QVERIFY(QFileInfo("tempfile.txt").isWritable());
|
||||
|
||||
QFile::setPermissions("tempfile.txt",
|
||||
QFileDevice::ReadOwner | QFileDevice::ReadUser | QFileDevice::ReadGroup);
|
||||
|
||||
// isWritable returns false when read-only, unless root
|
||||
bool isRoot = false;
|
||||
#if defined (Q_OS_UNIX)
|
||||
isRoot = (geteuid() == 0);
|
||||
#endif
|
||||
QCOMPARE(QFileInfo("tempfile.txt").isWritable(), isRoot);
|
||||
|
||||
tempfile.remove();
|
||||
|
||||
// isWritable returns false when file does not exist
|
||||
QVERIFY(!QFileInfo("tempfile.txt").isWritable());
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
QFileInfo fi("c:\\pagefile.sys");
|
||||
QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData());
|
||||
|
Loading…
x
Reference in New Issue
Block a user