diff options
Diffstat (limited to 'src/testlib')
| -rw-r--r-- | src/testlib/qtest.h | 26 | ||||
| -rw-r--r-- | src/testlib/qtestcase.cpp | 13 | ||||
| -rw-r--r-- | src/testlib/qtestcase.h | 3 | ||||
| -rw-r--r-- | src/testlib/qtestregistry_p.h | 2 |
4 files changed, 17 insertions, 27 deletions
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index c749cbd492f..431f91d5474 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -181,29 +181,17 @@ inline bool qCompare(quint32 const &t1, quint64 const &t2, const char *actual, } namespace Internal { -template <typename T> -class HasInitMain // SFINAE test for the presence of initMain() -{ -private: - using YesType = char[1]; - using NoType = char[2]; - - template <typename C> static YesType& test( decltype(&C::initMain) ) ; - template <typename C> static NoType& test(...); - -public: - enum { value = sizeof(test<T>(nullptr)) == sizeof(YesType) }; -}; +template <typename T, typename = void> +struct HasInitMain : std::false_type{}; -template<typename T> -typename std::enable_if<HasInitMain<T>::value, void>::type callInitMain() -{ - T::initMain(); -} +template <typename T> +struct HasInitMain<T, std::void_t<decltype(&T::initMain)>> : std::true_type {}; template<typename T> -typename std::enable_if<!HasInitMain<T>::value, void>::type callInitMain() +void callInitMain() { + if constexpr (HasInitMain<T>::value) + T::initMain(); } } // namespace Internal diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 6c7e71294ed..784e69d2486 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -393,6 +393,7 @@ static QString mainSourcePath; static bool inTestFunction = false; #if defined(Q_OS_MACOS) +static std::optional<QTestPrivate::AppNapDisabler> appNapDisabler; static IOPMAssertionID macPowerSavingDisabled = 0; #endif @@ -1881,13 +1882,12 @@ void QTest::qInit(QObject *testObject, int argc, char **argv) QTestPrivate::disableWindowRestore(); // Disable App Nap which may cause tests to stall - QTestPrivate::AppNapDisabler appNapDisabler; + if (!appNapDisabler) + appNapDisabler.emplace(); - if (qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0)) { - IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, - kIOPMAssertionLevelOn, CFSTR("QtTest running tests"), - &macPowerSavingDisabled); - } + IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, + kIOPMAssertionLevelOn, CFSTR("QtTest running tests"), + &macPowerSavingDisabled); #endif QTestPrivate::parseBlackList(); @@ -2041,6 +2041,7 @@ void QTest::qCleanup() #if defined(Q_OS_MACOS) IOPMAssertionRelease(macPowerSavingDisabled); + appNapDisabler = std::nullopt; #endif } diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index ebb32238d67..02ccb9709dc 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -15,6 +15,7 @@ #include <QtCore/qtemporarydir.h> #include <QtCore/qthread.h> +#include <chrono> #ifdef __cpp_concepts #include <concepts> #endif @@ -430,7 +431,7 @@ namespace QTest Q_TESTLIB_EXPORT int qExec(QObject *testObject, const QStringList &arguments); #if QT_CONFIG(batch_test_support) || defined(Q_QDOC) - using TestEntryFunction = int (*)(int, char **); + using TestEntryFunction = std::function<int(int, char **)>; Q_TESTLIB_EXPORT void qRegisterTestCase(const QString &name, TestEntryFunction entryFunction); #endif // QT_CONFIG(batch_test_support) diff --git a/src/testlib/qtestregistry_p.h b/src/testlib/qtestregistry_p.h index 85e236cd046..fcfa6c60701 100644 --- a/src/testlib/qtestregistry_p.h +++ b/src/testlib/qtestregistry_p.h @@ -26,7 +26,7 @@ QT_BEGIN_NAMESPACE namespace QTest { class TestRegistry { public: - using TestEntryFunction = int(*)(int argv, char** argc); + using TestEntryFunction = std::function<int(int, char **)>; static TestRegistry* instance(); |
