summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-01-31 18:59:19 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-02-01 00:49:19 +0100
commit0dc31e667fc66ed98e855a0553958555e2fab2d5 (patch)
treea814d03602fb794da0f9ab587ef2c3f12ae853de /src/testlib/qtestcase.cpp
parent5940d20c69e21476c10ff38ed0689ea2f0b68c94 (diff)
testlib: Simplify macOS setup/teardown code
Change-Id: If92845ccb044becee136c7791fdb3cfe3641b28d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 2f62d51c58..76a1b36a61 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -302,8 +302,7 @@ static QObject *currentTestObject = nullptr;
static QString mainSourcePath;
#if defined(Q_OS_MACOS)
-bool macNeedsActivate = false;
-IOPMAssertionID powerID;
+static IOPMAssertionID macPowerSavingDisabled = 0;
#endif
class TestMethods {
@@ -1854,23 +1853,17 @@ void QTest::qInit(QObject *testObject, int argc, char **argv)
initEnvironment();
QBenchmarkGlobalData::current = new QBenchmarkGlobalData;
-#if defined(Q_OS_MACX)
- macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0);
-
- // Don't restore saved window state for auto tests.
+#if defined(Q_OS_MACOS)
+ // Don't restore saved window state for auto tests
QTestPrivate::disableWindowRestore();
- // Disable App Nap which may cause tests to stall.
+ // Disable App Nap which may cause tests to stall
QTestPrivate::AppNapDisabler appNapDisabler;
-#endif
-
-#if defined(Q_OS_MACX)
- if (macNeedsActivate) {
- CFStringRef reasonForActivity= CFSTR("No Display Sleep");
- IOReturn ok = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &powerID);
- if (ok != kIOReturnSuccess)
- macNeedsActivate = false; // no need to release the assertion on exit.
+ if (qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0)) {
+ IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
+ kIOPMAssertionLevelOn, CFSTR("QtTest running tests"),
+ &macPowerSavingDisabled);
}
#endif
@@ -1966,11 +1959,10 @@ int QTest::qRun()
QTestLog::stopLogging();
-#if defined(Q_OS_MACX)
- if (macNeedsActivate) {
- IOPMAssertionRelease(powerID);
- }
+#if defined(Q_OS_MACOS)
+ IOPMAssertionRelease(macPowerSavingDisabled);
#endif
+
currentTestObject = nullptr;
// Re-throw exception to make debugging easier
@@ -2003,8 +1995,7 @@ void QTest::qCleanup()
QSignalDumper::endDump();
#if defined(Q_OS_MACOS)
- if (macNeedsActivate)
- IOPMAssertionRelease(powerID);
+ IOPMAssertionRelease(macPowerSavingDisabled);
#endif
}