From deea48ef6a545ba0c198efcc8db3c5ba7b0b432b Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 1 Feb 2012 13:57:24 +0000 Subject: [PATCH] Fix QFile autotest not to require elevated privilege to pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The open test case tests opening a device path on windows. As this requires privilege elevation, the test fails when running nmake check from a console. As the CI machines appear to run tests with admin privileges, first check opening the device using the windows API. If that succeeds, then opening using QFile should succeed. If that fails, the opening using QFile should fail. (Since Windows vista, members of the "administrators" group do not run at elevated privilege all the time. The user needs to opt in via a UAC prompt or "run as administrator". This is similar to using the sudo command on unix) Ran the test as administrator and normally. Now passes in both cases. Change-Id: Ibd7682eceb61e35d4912fa0392df536f4331f6ed Reviewed-by: João Abecasis --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 00e45354ba3..67a4f71f540 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -53,7 +53,9 @@ #include #endif #include -#ifndef Q_OS_WIN +#ifdef Q_OS_WIN +# include +#else # include # include #endif @@ -476,8 +478,16 @@ void tst_QFile::open_data() QTest::newRow("noreadfile") << QString("noreadfile") << int(QIODevice::ReadOnly) << false << QFile::OpenError; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) - << true << QFile::NoError; + //opening devices requires administrative privileges (and elevation). + HANDLE hTest = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hTest != INVALID_HANDLE_VALUE) { + CloseHandle(hTest); + QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) + << true << QFile::NoError; + } else { + QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) + << false << QFile::OpenError; + } QTest::newRow("uncFile") << "//" + QtNetworkSettings::winServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly) << true << QFile::NoError; #endif