aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-12-06 12:47:30 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-03-21 09:07:33 +0000
commit2fcbb80e3306d809b708cf46c0f6d0852fe87e17 (patch)
tree89162fa7e7c41d80e8df39ac68fde84a4f747be6
parent52ac0ea8cbdc9a2b8e895ceee09994fba229ee12 (diff)
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 <gatis.paeglis@qt.io> (cherry picked from commit 50f234df500829a0023ed5d396c486f995ad71ef) Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/qmltest/quicktest.cpp29
1 files 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);