From 864fbd65828e0e84e588c896d778ae523a30e97b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Sep 2022 10:31:09 -0700 Subject: tst_QFile::setPermissions/Unix: test both chmod() and fchmod() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(). Pick-to: 6.4 Change-Id: If5d5ef6220874ae8858efffd171255b9f20ed501 Reviewed-by: MÃ¥rten Nordheim --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index df3f13dc39..ee96797445 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -172,6 +172,7 @@ private slots: void permissionsNtfs_data(); void permissionsNtfs(); #endif + void setPermissions_data(); void setPermissions(); void copy(); void copyAfterFail(); @@ -1421,11 +1422,20 @@ void tst_QFile::permissionsNtfs() } #endif +void tst_QFile::setPermissions_data() +{ + QTest::addColumn("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(); @@ -1434,7 +1444,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)); -- cgit v1.2.3