summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qmetaobject.cpp5
-rw-r--r--src/testlib/qtestcase.cpp28
-rw-r--r--tests/auto/qmetaobject/tst_qmetaobject.cpp13
3 files changed, 38 insertions, 8 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index be1b2ae..ecffe99 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -1137,8 +1137,11 @@ bool QMetaObject::invokeMethod(QObject *obj,
idx = obj->metaObject()->indexOfMethod(norm.constData());
}
- if (idx < 0 || idx >= obj->metaObject()->methodCount())
+ if (idx < 0 || idx >= obj->metaObject()->methodCount()) {
+ qWarning("QMetaObject::invokeMethod: No such method %s::%s",
+ obj->metaObject()->className(), sig.constData());
return false;
+ }
QMetaMethod method = obj->metaObject()->method(idx);
return method.invoke(obj, type, ret,
val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 5c9dd55..4590f17 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -877,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) {
@@ -1213,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;
@@ -1233,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
@@ -1300,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()) {
@@ -1466,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();
@@ -1498,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);
diff --git a/tests/auto/qmetaobject/tst_qmetaobject.cpp b/tests/auto/qmetaobject/tst_qmetaobject.cpp
index 15b6204..bd54975 100644
--- a/tests/auto/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/qmetaobject/tst_qmetaobject.cpp
@@ -513,6 +513,19 @@ void tst_QMetaObject::invokeMetaMember()
QVERIFY(QMetaObject::invokeMethod(&obj, "sig1", Q_RETURN_ARG(QString, exp), Q_ARG(QString, "hehe")));
QCOMPARE(exp, QString("yessir"));
QCOMPARE(obj.slotResult, QString("sl1:hehe"));
+
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::doesNotExist()");
+ QVERIFY(!QMetaObject::invokeMethod(&obj, "doesNotExist"));
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString)(QString)");
+ QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1(QString)", Q_ARG(QString, "arg")));
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)");
+ QVERIFY(!QMetaObject::invokeMethod(&obj, "sl3", Q_ARG(QString, "arg")));
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)");
+ QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1", Q_ARG(QString, "arg"), Q_ARG(QString, "arg"), Q_ARG(QString, "arg")));
+
+ //should not have changed since last test.
+ QCOMPARE(exp, QString("yessir"));
+ QCOMPARE(obj.slotResult, QString("sl1:hehe"));
}
void tst_QMetaObject::invokeQueuedMetaMember()