tst_QFile::setPermissions/Unix: test both chmod() and fchmod()
On Unix, we have the fchmod(2) system call that changes the permissions of an open file descriptor. This commit adds a test for that, by not closing the QFile before setPermissions(). Change-Id: If5d5ef6220874ae8858efffd171255b9f20ed501 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 864fbd65828e0e84e588c896d778ae523a30e97b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
bc2546ba5f
commit
db5fc3711b
@ -168,6 +168,7 @@ private slots:
|
||||
void permissionsNtfs_data();
|
||||
void permissionsNtfs();
|
||||
#endif
|
||||
void setPermissions_data();
|
||||
void setPermissions();
|
||||
void copy();
|
||||
void copyAfterFail();
|
||||
@ -1417,11 +1418,20 @@ 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()
|
||||
{
|
||||
#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();
|
||||
@ -1430,7 +1440,8 @@ void tst_QFile::setPermissions()
|
||||
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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user