diff options
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 77a59d0cf0..0cf2f3256b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -65,6 +65,7 @@ #include <QtTest/private/cycle_p.h> #include <numeric> +#include <algorithm> #include <stdarg.h> #include <stdio.h> @@ -1130,9 +1131,7 @@ namespace QTest static int keyDelay = -1; static int mouseDelay = -1; static int eventDelay = -1; -#if defined(Q_OS_UNIX) static bool noCrashHandler = false; -#endif /*! \internal Invoke a method of the object without generating warning if the method does not exist @@ -1335,9 +1334,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" " -maxwarnings n : Sets the maximum amount of messages to output.\n" " 0 means unlimited, default: 2000\n" -#if defined(Q_OS_UNIX) " -nocrashhandler : Disables the crash handler\n" -#endif "\n" " Benchmarking options:\n" #ifdef QTESTLIB_USE_VALGRIND @@ -1468,10 +1465,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } else { QTestLog::setMaxWarnings(qToInt(argv[++i])); } -#if defined(Q_OS_UNIX) } else if (strcmp(argv[i], "-nocrashhandler") == 0) { QTest::noCrashHandler = true; -#endif #ifdef QTESTLIB_USE_VALGRIND } else if (strcmp(argv[i], "-callgrind") == 0) { if (QBenchmarkValgrindUtils::haveValgrind()) @@ -1636,13 +1631,14 @@ QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container) if (count == 1) return container.at(0); - QList<QBenchmarkResult> containerCopy = container; - qSort(containerCopy); - const int middle = count / 2; + QList<QBenchmarkResult> containerCopy = container; + const QList<QBenchmarkResult>::iterator begin = containerCopy.begin(), mid = begin + middle, end = containerCopy.end(); + std::nth_element(begin, mid, end); + // ### handle even-sized containers here by doing an aritmetic mean of the two middle items. - return containerCopy.at(middle); + return *mid; } struct QTestDataSetter @@ -2083,6 +2079,18 @@ FatalSignalHandler::~FatalSignalHandler() } // namespace +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +static LONG WINAPI windowsFaultHandler(struct _EXCEPTION_POINTERS *exInfo) +{ + char appName[MAX_PATH]; + if (!GetModuleFileNameA(NULL, appName, MAX_PATH)) + appName[0] = 0; + fprintf(stderr, "A crash occurred in %s (exception code 0x%lx).", + appName, exInfo->ExceptionRecord->ExceptionCode); + return EXCEPTION_EXECUTE_HANDLER; +} +#endif // Q_OS_WIN) && !Q_OS_WINCE + /*! Executes tests declared in \a testObject. In addition, the private slots \c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()} @@ -2138,13 +2146,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) try { #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -# if !defined(Q_CC_MINGW) - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); -# endif - SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); -#endif - #if defined(Q_OS_MACX) if (macNeedsActivate) { CFStringRef reasonForActivity= CFSTR("No Display Sleep"); @@ -2170,6 +2171,16 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) qtest_qParseArgs(argc, argv, false); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + if (!noCrashHandler) { +# ifndef Q_CC_MINGW + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); +# endif + SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); + SetUnhandledExceptionFilter(windowsFaultHandler); + } // !noCrashHandler +#endif // Q_OS_WIN) && !Q_OS_WINCE + #ifdef QTESTLIB_USE_VALGRIND if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) { const QStringList origAppArgs(QCoreApplication::arguments()); |