diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-14 14:46:00 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-17 08:01:59 +0000 |
commit | 80b5f8c2f448be574e731e5d371c38b84578f5c3 (patch) | |
tree | ad30c4deb23a330acc54cb25bb9bf7ab739225ae /tests | |
parent | ee89a8c052db0fa3dffe3e01c4c0309cf9ec80d0 (diff) |
Add a test that verifies the this object in signal handlers
Ask expected, this passes currently. The this object is set to the scope
object in QQmlJavaScriptExpression::evaluate, which
QQmlBoundSignalExpression::evaluate calls.
Task-number: QTBUG-66942
Change-Id: I16a709768f9c798910377a52b5e882bb6d554a5f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/signalHandlers.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 25 |
2 files changed, 25 insertions, 13 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml index cd68fb9b82..14326bb9e6 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml @@ -102,4 +102,17 @@ QtObject { }) return testSuccess } + + property QtObject subObject: QtObject { + id: subObject + property int value + property bool ok: false + onValueChanged: this.ok = true + } + + function testThisInSignalHandler() { + subObject.ok = false + subObject.value = subObject.value + 1 + return subObject.ok + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 5ff959515e..31cf40be16 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -6278,41 +6278,40 @@ void tst_qqmlecmascript::includeRemoteSuccess() void tst_qqmlecmascript::signalHandlers() { QQmlComponent component(&engine, testFileUrl("signalHandlers.qml")); - QObject *o = component.create(); + QScopedPointer<QObject> o(component.create()); QVERIFY(o != nullptr); - QCOMPARE(o->property("count").toInt(), 0); - QMetaObject::invokeMethod(o, "testSignalCall"); + QMetaObject::invokeMethod(o.data(), "testSignalCall"); QCOMPARE(o->property("count").toInt(), 1); - QMetaObject::invokeMethod(o, "testSignalHandlerCall"); + QMetaObject::invokeMethod(o.data(), "testSignalHandlerCall"); QCOMPARE(o->property("count").toInt(), 1); QCOMPARE(o->property("errorString").toString(), QLatin1String("TypeError: Property 'onTestSignal' of object [object Object] is not a function")); QCOMPARE(o->property("funcCount").toInt(), 0); - QMetaObject::invokeMethod(o, "testSignalConnection"); + QMetaObject::invokeMethod(o.data(), "testSignalConnection"); QCOMPARE(o->property("funcCount").toInt(), 1); - QMetaObject::invokeMethod(o, "testSignalHandlerConnection"); + QMetaObject::invokeMethod(o.data(), "testSignalHandlerConnection"); QCOMPARE(o->property("funcCount").toInt(), 2); - QMetaObject::invokeMethod(o, "testSignalDefined"); + QMetaObject::invokeMethod(o.data(), "testSignalDefined"); QCOMPARE(o->property("definedResult").toBool(), true); - QMetaObject::invokeMethod(o, "testSignalHandlerDefined"); + QMetaObject::invokeMethod(o.data(), "testSignalHandlerDefined"); QCOMPARE(o->property("definedHandlerResult").toBool(), true); QVariant result; - QMetaObject::invokeMethod(o, "testConnectionOnAlias", Q_RETURN_ARG(QVariant, result)); + QMetaObject::invokeMethod(o.data(), "testConnectionOnAlias", Q_RETURN_ARG(QVariant, result)); QCOMPARE(result.toBool(), true); - QMetaObject::invokeMethod(o, "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result)); + QMetaObject::invokeMethod(o.data(), "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result)); QCOMPARE(result.toBool(), true); - QMetaObject::invokeMethod(o, "testSignalWithClosureArgument", Q_RETURN_ARG(QVariant, result)); + QMetaObject::invokeMethod(o.data(), "testSignalWithClosureArgument", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + QMetaObject::invokeMethod(o.data(), "testThisInSignalHandler", Q_RETURN_ARG(QVariant, result)); QCOMPARE(result.toBool(), true); - - delete o; } void tst_qqmlecmascript::qtbug_37351() |