From 2fcbb80e3306d809b708cf46c0f6d0852fe87e17 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 6 Dec 2018 12:47:30 +0100 Subject: Don't warn if invokable test setup function doesn't exist This was never the intention (as the code comments imply), but it was never tested. This is a cherry-pick of 50f234df500829a0023ed5d396c486f995ad71ef because it went to dev (5.13) when it should have originally went to 5.12. Change-Id: I8df0b3702129b1f1d086df73117d3ddb721317cb Reviewed-by: Gatis Paeglis (cherry picked from commit 50f234df500829a0023ed5d396c486f995ad71ef) Reviewed-by: Richard Moe Gustavsen --- src/qmltest/quicktest.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 5288bb34f1..22d329bb80 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -199,6 +199,21 @@ bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000) return spy.size(); } +void maybeInvokeSetupMethod(QObject *setupObject, const char *member, QGenericArgument val0 = QGenericArgument(nullptr)) +{ + // It's OK if it doesn't exist: since we have more than one callback that + // can be called, it makes sense if the user only implements one of them. + // We do this the long way rather than just calling the static + // QMetaObject::invokeMethod(), because that will issue a warning if the + // function doesn't exist, which we don't want. + const QMetaObject *setupMetaObject = setupObject->metaObject(); + const int methodIndex = setupMetaObject->indexOfMethod(member); + if (methodIndex != -1) { + const QMetaMethod method = setupMetaObject->method(methodIndex); + method.invoke(setupObject, val0); + } +} + using namespace QV4::CompiledData; class TestCaseCollector @@ -360,10 +375,8 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch } } - if (setup) { - // Don't check the return value; it's OK if it doesn't exist. - QMetaObject::invokeMethod(setup, "applicationAvailable"); - } + if (setup) + maybeInvokeSetupMethod(setup, "applicationAvailable()"); // Look for QML-specific command-line options. // -import dir Specify an import directory. @@ -508,7 +521,7 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch // QML files though, because it attempts to import modules, which might not be available // if qmlRegisterType()/QQmlEngine::addImportPath() are called in qmlEngineAvailable(). if (setup) - QMetaObject::invokeMethod(setup, "qmlEngineAvailable", Q_ARG(QQmlEngine*, &engine)); + maybeInvokeSetupMethod(setup, "qmlEngineAvailable(QQmlEngine*)", Q_ARG(QQmlEngine*, &engine)); TestCaseCollector testCaseCollector(fi, &engine); if (!testCaseCollector.errors().isEmpty()) { @@ -591,10 +604,8 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch } } - if (setup) { - // Don't check the return value; it's OK if it doesn't exist. - QMetaObject::invokeMethod(setup, "cleanupTestCase"); - } + if (setup) + maybeInvokeSetupMethod(setup, "cleanupTestCase()"); // Flush the current logging stream. QuickTestResult::setProgramName(nullptr); -- cgit v1.2.3