src/testlib/qtestcase.cpp
changeset 30 5dc02b23752f
parent 19 fcece45ef507
child 33 3e2da88830cd
--- a/src/testlib/qtestcase.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/testlib/qtestcase.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -846,6 +846,9 @@
     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 @@
     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 @@
          " -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 @@
             } 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 @@
         bool invokeOk;
         do {
             QTestResult::setCurrentTestLocation(QTestResult::InitFunc);
-            QMetaObject::invokeMethod(QTest::currentTestObject, "init");
+            invokeMethod(QTest::currentTestObject, "init()");
             if (QTestResult::skipCurrentTest())
                 break;
 
@@ -1223,7 +1246,7 @@
                 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 @@
 
         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 @@
     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 @@
 
         QTestResult::setSkipCurrentTest(false);
         QTestResult::setCurrentTestFunction("cleanupTestCase");
-        QMetaObject::invokeMethod(testObject, "cleanupTestCase");
+        invokeMethod(testObject, "cleanupTestCase()");
     }
     QTestResult::finishedCurrentTestFunction();
     QTestResult::setCurrentTestFunction(0);
@@ -1541,7 +1565,11 @@
 #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 @@
 #endif
     {
 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
-        FatalSignalHandler handler;
+        QScopedPointer<FatalSignalHandler> handler;
+        if (!noCrashHandler)
+            handler.reset(new FatalSignalHandler);
 #endif
         qInvokeTestMethods(testObject);
     }