4
0
mirror of https://github.com/QuasarApp/installer-framework.git synced 2025-05-07 18:49:34 +00:00

Add better test branch for testSetDefaultFilePermissions() on Windows

As the function to be tested is now enabled also on Windows platforms,
this should at least check that the unsetting of legacy read-only flag
works as intended.

Task-number: QTIFW-1464
Change-Id: Ibe126d279a31aaa3d204cf6a8fe04a05ea195bb8
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
This commit is contained in:
Arttu Tarkiainen 2019-11-04 15:35:17 +02:00
parent 03166d8e49
commit f667bf73d0

@ -44,11 +44,39 @@ private slots:
void testSetDefaultFilePermissions()
{
#if defined(Q_OS_WIN)
QVERIFY(setDefaultFilePermissions(QInstaller::generateTemporaryFileName(),
DefaultFilePermissions::NonExecutable));
QString fileName = QInstaller::generateTemporaryFileName();
QFile testFile(fileName);
QVERIFY(setDefaultFilePermissions(QInstaller::generateTemporaryFileName(),
DefaultFilePermissions::Executable));
QVERIFY(testFile.open(QIODevice::ReadWrite));
QVERIFY(testFile.exists());
testFile.close();
// Set permissions containing none of the Write* flags, this will cause
// the read-only flag to be set for the file
QVERIFY(testFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::ReadUser
| QFileDevice::ReadGroup | QFileDevice::ReadOther));
// Verify that the file cannot be opened for both reading and writing, i.e.
// it should be read-only.
QVERIFY(!testFile.open(QIODevice::ReadWrite));
// Now try to remove the read-only flag
QVERIFY(setDefaultFilePermissions(&testFile, DefaultFilePermissions::NonExecutable));
// Verify that the file can now be opened for both reading and writing
QVERIFY(testFile.open(QIODevice::ReadWrite));
testFile.close();
QVERIFY(testFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::ReadUser
| QFileDevice::ReadGroup | QFileDevice::ReadOther));
// Check that the behavior is same with 'Executable' argument
QVERIFY(setDefaultFilePermissions(&testFile, DefaultFilePermissions::Executable));
QVERIFY(testFile.open(QIODevice::ReadWrite));
testFile.close();
QVERIFY(testFile.remove());
#elif defined(Q_OS_UNIX)
// Need to include the "user" flags here as they will be returned
// by QFile::permissions(). Same as owner permissions of the file.