aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest/quicktest.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-12-06 12:47:30 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-12-10 10:45:19 +0000
commit50f234df500829a0023ed5d396c486f995ad71ef (patch)
treeaf9dc908f4000f9517adc83e99d0d2a3c73dece5 /src/qmltest/quicktest.cpp
parent7efca5aeae1962d61bfae021b92da3133bbda752 (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. Change-Id: I8df0b3702129b1f1d086df73117d3ddb721317cb Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/qmltest/quicktest.cpp')
-rw-r--r--src/qmltest/quicktest.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index f31e9a2b49..8803075284 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -261,6 +261,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
@@ -422,10 +437,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.
@@ -598,11 +611,8 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
// Do this down here so that import paths, plugin paths,
// file selectors, etc. are available in case the user needs access to them.
- if (setup) {
- // Don't check the return value; it's OK if it doesn't exist.
- // If we add more callbacks in the future, it makes sense if the user only implements one of them.
- QMetaObject::invokeMethod(setup, "qmlEngineAvailable", Q_ARG(QQmlEngine*, view.engine()));
- }
+ if (setup)
+ maybeInvokeSetupMethod(setup, "qmlEngineAvailable(QQmlEngine*)", Q_ARG(QQmlEngine*, view.engine()));
view.setObjectName(fi.baseName());
view.setTitle(view.objectName());
@@ -651,10 +661,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);