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_data();
|
||||||
void permissionsNtfs();
|
void permissionsNtfs();
|
||||||
#endif
|
#endif
|
||||||
|
void setPermissions_data();
|
||||||
void setPermissions();
|
void setPermissions();
|
||||||
void copy();
|
void copy();
|
||||||
void copyAfterFail();
|
void copyAfterFail();
|
||||||
@ -1417,11 +1418,20 @@ void tst_QFile::permissionsNtfs()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void tst_QFile::setPermissions_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<bool>("opened");
|
||||||
|
QTest::newRow("closed") << false; // chmod()
|
||||||
|
QTest::newRow("opened") << true; // fchmod()
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QFile::setPermissions()
|
void tst_QFile::setPermissions()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_QNX
|
#ifdef Q_OS_QNX
|
||||||
QSKIP("This test doesn't pass on QNX and no one has cared to investigate.");
|
QSKIP("This test doesn't pass on QNX and no one has cared to investigate.");
|
||||||
#endif
|
#endif
|
||||||
|
QFETCH(bool, opened);
|
||||||
|
|
||||||
auto remove = []() { QFile::remove("createme.txt"); };
|
auto remove = []() { QFile::remove("createme.txt"); };
|
||||||
auto guard = qScopeGuard(remove);
|
auto guard = qScopeGuard(remove);
|
||||||
remove();
|
remove();
|
||||||
@ -1430,6 +1440,7 @@ void tst_QFile::setPermissions()
|
|||||||
QFile f("createme.txt");
|
QFile f("createme.txt");
|
||||||
QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(f).constData());
|
QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(f).constData());
|
||||||
f.putChar('a');
|
f.putChar('a');
|
||||||
|
if (!opened)
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
QFile::Permissions perms(QFile::WriteUser | QFile::ReadUser);
|
QFile::Permissions perms(QFile::WriteUser | QFile::ReadUser);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user