testlib: Simplify macOS setup/teardown code
Change-Id: If92845ccb044becee136c7791fdb3cfe3641b28d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
5940d20c69
commit
0dc31e667f
@ -302,8 +302,7 @@ static QObject *currentTestObject = nullptr;
|
|||||||
static QString mainSourcePath;
|
static QString mainSourcePath;
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
bool macNeedsActivate = false;
|
static IOPMAssertionID macPowerSavingDisabled = 0;
|
||||||
IOPMAssertionID powerID;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class TestMethods {
|
class TestMethods {
|
||||||
@ -1854,23 +1853,17 @@ void QTest::qInit(QObject *testObject, int argc, char **argv)
|
|||||||
initEnvironment();
|
initEnvironment();
|
||||||
QBenchmarkGlobalData::current = new QBenchmarkGlobalData;
|
QBenchmarkGlobalData::current = new QBenchmarkGlobalData;
|
||||||
|
|
||||||
#if defined(Q_OS_MACX)
|
#if defined(Q_OS_MACOS)
|
||||||
macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0);
|
// Don't restore saved window state for auto tests
|
||||||
|
|
||||||
// Don't restore saved window state for auto tests.
|
|
||||||
QTestPrivate::disableWindowRestore();
|
QTestPrivate::disableWindowRestore();
|
||||||
|
|
||||||
// Disable App Nap which may cause tests to stall.
|
// Disable App Nap which may cause tests to stall
|
||||||
QTestPrivate::AppNapDisabler appNapDisabler;
|
QTestPrivate::AppNapDisabler appNapDisabler;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(Q_OS_MACX)
|
if (qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0)) {
|
||||||
if (macNeedsActivate) {
|
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
|
||||||
CFStringRef reasonForActivity= CFSTR("No Display Sleep");
|
kIOPMAssertionLevelOn, CFSTR("QtTest running tests"),
|
||||||
IOReturn ok = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &powerID);
|
&macPowerSavingDisabled);
|
||||||
|
|
||||||
if (ok != kIOReturnSuccess)
|
|
||||||
macNeedsActivate = false; // no need to release the assertion on exit.
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1966,11 +1959,10 @@ int QTest::qRun()
|
|||||||
|
|
||||||
QTestLog::stopLogging();
|
QTestLog::stopLogging();
|
||||||
|
|
||||||
#if defined(Q_OS_MACX)
|
#if defined(Q_OS_MACOS)
|
||||||
if (macNeedsActivate) {
|
IOPMAssertionRelease(macPowerSavingDisabled);
|
||||||
IOPMAssertionRelease(powerID);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
currentTestObject = nullptr;
|
currentTestObject = nullptr;
|
||||||
|
|
||||||
// Re-throw exception to make debugging easier
|
// Re-throw exception to make debugging easier
|
||||||
@ -2003,8 +1995,7 @@ void QTest::qCleanup()
|
|||||||
QSignalDumper::endDump();
|
QSignalDumper::endDump();
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
if (macNeedsActivate)
|
IOPMAssertionRelease(macPowerSavingDisabled);
|
||||||
IOPMAssertionRelease(powerID);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user