From db5fc3711b00b9f936d5c360cdf4b1304382779b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Sep 2022 10:31:09 -0700 Subject: [PATCH] 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(). Change-Id: If5d5ef6220874ae8858efffd171255b9f20ed501 Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 864fbd65828e0e84e588c896d778ae523a30e97b) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 902e0d734b1..d3f8e7cfb24 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -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("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));