aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-02-14 15:48:56 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2019-02-17 08:10:17 +0000
commit94d30df911dccd830a18d7c2e75397505ef9a600 (patch)
treee9890f9cb006fdc38bbed9fe94d553868d905166 /tests
parentd96a700cc3611480ff76023287cb06f455a37b02 (diff)
Check parameter types when invoking C++ functions from QML
We now check if the given parameters can be converted to the expected arguments of the function being invoked and throw a type error if not. Previously we would still invoke the method with random parameters. [ChangeLog][QtQml][Important Behavior Changes] The parameters passed to C++ functions from QML are now checked for compatibility with the expected arguments. If they cannot be converted, a type error is thrown in JavaScript and the function is not invoked. Fixes: QTBUG-73405 Change-Id: If16089510d314bb7cdb7d4db86478114c61281a8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp42
-rw-r--r--tests/auto/qml/qqmllanguage/data/SignalEmitter.qml14
2 files changed, 30 insertions, 26 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 788ecce1c5..6a97fc5d8b 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -2762,32 +2762,28 @@ void tst_qqmlecmascript::callQtInvokables()
QCOMPARE(o->actuals().at(0), QVariant(QString()));
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QPointF(0)", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QPointF(0)", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 12);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), QVariant(QPointF()));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QPointF(null)", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QPointF(null)", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 12);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), QVariant(QPointF()));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QPointF(undefined)", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QPointF(undefined)", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 12);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), QVariant(QPointF()));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QPointF(object)", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QPointF(object)", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 12);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), QVariant(QPointF()));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPointF())", QV4::Primitive::undefinedValue()));
@@ -2804,18 +2800,16 @@ void tst_qqmlecmascript::callQtInvokables()
QCOMPARE(o->actuals().at(0), QVariant(QPointF(9, 12)));
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QObject(0)", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QObject(0)", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 13);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), qVariantFromValue((QObject *)nullptr));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
- QVERIFY(EVALUATE_VALUE("object.method_QObject(\"Hello world\")", QV4::Primitive::undefinedValue()));
+ QVERIFY(!EVALUATE_VALUE("object.method_QObject(\"Hello world\")", QV4::Primitive::undefinedValue()));
QCOMPARE(o->error(), false);
- QCOMPARE(o->invoked(), 13);
- QCOMPARE(o->actuals().count(), 1);
- QCOMPARE(o->actuals().at(0), qVariantFromValue((QObject *)nullptr));
+ QCOMPARE(o->invoked(), -1);
+ QCOMPARE(o->actuals().count(), 0);
o->reset();
QVERIFY(EVALUATE_VALUE("object.method_QObject(null)", QV4::Primitive::undefinedValue()));
diff --git a/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml b/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml
index 259f45b7d2..31fe5e4a5e 100644
--- a/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml
+++ b/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml
@@ -10,8 +10,18 @@ QtObject {
signal testSignal(SignalParam spp);
function emitTestSignal() {
- testObject.expectNull = true;
- testSignal(op);
+ var caught = false;
+ try {
+ testObject.expectNull = true;
+ testSignal(op);
+ } catch(e) {
+ // good: We want a type error here
+ caught = true;
+ if (handleSignal)
+ testObject.determineSuccess(null);
+ }
+ if (!caught && handleSignal)
+ testObject.determineSuccess("fail");
testObject.expectNull = false;
testSignal(p);