summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp48
1 files changed, 39 insertions, 9 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 6591481..63e22cc 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -846,6 +846,9 @@ namespace QTest
static int mouseDelay = -1;
static int eventDelay = -1;
static int keyVerbose = -1;
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+ static bool noCrashHandler = false;
+#endif
void filter_unprintable(char *str)
{
@@ -874,6 +877,19 @@ int qt_snprintf(char *str, int size, const char *format, ...)
return res;
}
+/*! \internal
+ Invoke a method of the object without generating warning if the method does not exist
+ */
+static void invokeMethod(QObject *obj, const char *methodName)
+{
+ const QMetaObject *metaObject = obj->metaObject();
+ int funcIndex = metaObject->indexOfMethod(methodName);
+ if (funcIndex >= 0) {
+ QMetaMethod method = metaObject->method(funcIndex);
+ method.invoke(obj, Qt::DirectConnection);
+ }
+}
+
bool Q_TESTLIB_EXPORT defaultKeyVerbose()
{
if (keyVerbose == -1) {
@@ -976,6 +992,9 @@ static void qParseArgs(int argc, char *argv[])
" -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
" -maxwarnings n : Sets the maximum amount of messages to output.\n"
" 0 means unlimited, default: 2000\n"
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+ " -nocrashhandler : Disables the crash handler\n"
+#endif
"\n"
" Benchmark related options:\n"
#ifdef QTESTLIB_USE_VALGRIND
@@ -1056,6 +1075,10 @@ static void qParseArgs(int argc, char *argv[])
} else {
QTestLog::setMaxWarnings(qToInt(argv[++i]));
}
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+ } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
+ QTest::noCrashHandler = true;
+#endif
} else if (strcmp(argv[i], "-keyevent-verbose") == 0) {
QTest::keyVerbose = 1;
#ifdef QTESTLIB_USE_VALGRIND
@@ -1203,7 +1226,7 @@ static void qInvokeTestMethodDataEntry(char *slot)
bool invokeOk;
do {
QTestResult::setCurrentTestLocation(QTestResult::InitFunc);
- QMetaObject::invokeMethod(QTest::currentTestObject, "init");
+ invokeMethod(QTest::currentTestObject, "init()");
if (QTestResult::skipCurrentTest())
break;
@@ -1223,7 +1246,7 @@ static void qInvokeTestMethodDataEntry(char *slot)
QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__);
QTestResult::setCurrentTestLocation(QTestResult::CleanupFunc);
- QMetaObject::invokeMethod(QTest::currentTestObject, "cleanup");
+ invokeMethod(QTest::currentTestObject, "cleanup()");
QTestResult::setCurrentTestLocation(QTestResult::NoWhere);
// If this test method has a benchmark, repeat until all measurements are
@@ -1290,8 +1313,9 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
if (curGlobalDataIndex == 0) {
QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
- QTest::qt_snprintf(member, 512, "%s_data", slot);
- QMetaObject::invokeMethod(QTest::currentTestObject, member, Qt::DirectConnection);
+ QTest::qt_snprintf(member, 512, "%s_data()", slot);
+ invokeMethod(QTest::currentTestObject, member);
+
// if we encounter a SkipAll in the _data slot, we skip the whole
// testfunction, no matter how much global data exists
if (QTestResult::skipCurrentTest()) {
@@ -1456,11 +1480,11 @@ static void qInvokeTestMethods(QObject *testObject)
QTestResult::setCurrentTestFunction("initTestCase");
QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
QTestTable::globalTestTable();
- QMetaObject::invokeMethod(testObject, "initTestCase_data", Qt::DirectConnection);
+ invokeMethod(testObject, "initTestCase_data()");
if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
QTestResult::setCurrentTestLocation(QTestResult::InitFunc);
- QMetaObject::invokeMethod(testObject, "initTestCase");
+ invokeMethod(testObject, "initTestCase()");
// finishedCurrentTestFunction() resets QTestResult::testFailed(), so use a local copy.
const bool previousFailed = QTestResult::testFailed();
@@ -1488,7 +1512,7 @@ static void qInvokeTestMethods(QObject *testObject)
QTestResult::setSkipCurrentTest(false);
QTestResult::setCurrentTestFunction("cleanupTestCase");
- QMetaObject::invokeMethod(testObject, "cleanupTestCase");
+ invokeMethod(testObject, "cleanupTestCase()");
}
QTestResult::finishedCurrentTestFunction();
QTestResult::setCurrentTestFunction(0);
@@ -1541,7 +1565,11 @@ FatalSignalHandler::FatalSignalHandler()
#ifndef Q_WS_QWS
// Don't overwrite any non-default handlers
// however, we need to replace the default QWS handlers
- if (oldact.sa_flags & SA_SIGINFO || oldact.sa_handler != SIG_DFL) {
+ if (
+#ifdef SA_SIGINFO
+ oldact.sa_flags & SA_SIGINFO ||
+#endif
+ oldact.sa_handler != SIG_DFL) {
sigaction(fatalSignals[i], &oldact, 0);
} else
#endif
@@ -1681,7 +1709,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
#endif
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
- FatalSignalHandler handler;
+ QScopedPointer<FatalSignalHandler> handler;
+ if (!noCrashHandler)
+ handler.reset(new FatalSignalHandler);
#endif
qInvokeTestMethods(testObject);
}