diff options
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
9 files changed, 159 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/OtherSignalParam.qml b/tests/auto/qml/qqmllanguage/data/OtherSignalParam.qml new file mode 100644 index 0000000000..5707f5e08b --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/OtherSignalParam.qml @@ -0,0 +1,6 @@ +import QtQml 2.0 + +QtObject { + property string testProperty: "Hello, World" + property int answer: 42 +} diff --git a/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml b/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml new file mode 100644 index 0000000000..259f45b7d2 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/SignalEmitter.qml @@ -0,0 +1,25 @@ +import QtQml 2.0 + +QtObject { + // these two need to be set by the test qml + property QtObject testObject + property bool handleSignal + + property SignalParam p: SignalParam { } + property OtherSignalParam op: OtherSignalParam { } + signal testSignal(SignalParam spp); + + function emitTestSignal() { + testObject.expectNull = true; + testSignal(op); + + testObject.expectNull = false; + testSignal(p); + } + + onTestSignal: { + if (handleSignal == true) { + testObject.determineSuccess(spp); + } + } +} diff --git a/tests/auto/qml/qqmllanguage/data/SignalParam.qml b/tests/auto/qml/qqmllanguage/data/SignalParam.qml new file mode 100644 index 0000000000..8139b20268 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/SignalParam.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property int testProperty: 42 +} diff --git a/tests/auto/qml/qqmllanguage/data/signal.1.errors.txt b/tests/auto/qml/qqmllanguage/data/signal.1.errors.txt index 78d996016a..f5c789123d 100644 --- a/tests/auto/qml/qqmllanguage/data/signal.1.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/signal.1.errors.txt @@ -1 +1 @@ -4:12:Expected parameter type +4:12:Invalid signal parameter type: nontype diff --git a/tests/auto/qml/qqmllanguage/data/signal.6.errors.txt b/tests/auto/qml/qqmllanguage/data/signal.6.errors.txt new file mode 100644 index 0000000000..183b05f659 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signal.6.errors.txt @@ -0,0 +1 @@ +4:12:Invalid signal parameter type: Nontype diff --git a/tests/auto/qml/qqmllanguage/data/signal.6.qml b/tests/auto/qml/qqmllanguage/data/signal.6.qml new file mode 100644 index 0000000000..8b6e4011dc --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signal.6.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + signal mySignal(Nontype a) +} diff --git a/tests/auto/qml/qqmllanguage/data/signalParameterTypes.1.qml b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.1.qml new file mode 100644 index 0000000000..e3d4008962 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.1.qml @@ -0,0 +1,44 @@ +import QtQml 2.0 + +QtObject { + id: root + + property bool success: false + property bool gotInvalid: false + property bool expectNull: false + property SignalEmitter e: SignalEmitter { testObject: root; handleSignal: true } + + function determineSuccess(param) { + if (root.expectNull == true) { + if (param != null) { + // the parameter shouldn't have been passed through, but was. + root.success = false; + root.gotInvalid = true; + } else { + root.success = true; + root.gotInvalid = false; + } + return; + } else if (param == null) { + // the parameter should have been passed through, but wasn't. + root.success = false; + return; + } + + if (param.testProperty == 42) { + // got the expected value. if we didn't previously + // get an unexpected value, set success to true. + root.success = (!root.gotInvalid); + } else { + // the value passed through was not what we expected. + root.gotInvalid = true; + root.success = false; + } + } + + Component.onCompleted: { + success = false; + e.emitTestSignal(); + // the handler in the SignalEmitter should call determineSuccess. + } +} diff --git a/tests/auto/qml/qqmllanguage/data/signalParameterTypes.2.qml b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.2.qml new file mode 100644 index 0000000000..5ae1bcecf5 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.2.qml @@ -0,0 +1,48 @@ +import QtQml 2.0 + +QtObject { + id: root + + property bool success: false + property bool gotInvalid: false + property bool expectNull: false + property SignalEmitter e: SignalEmitter { testObject: root; handleSignal: false } // false so it doesn't use bound handler. + + function determineSuccess(param) { + if (root.expectNull == true) { + if (param != null) { + // the parameter shouldn't have been passed through, but was. + root.success = false; + root.gotInvalid = true; + } else { + root.success = true; + root.gotInvalid = false; + } + return; + } else if (param == null) { + // the parameter should have been passed through, but wasn't. + root.success = false; + return; + } + + if (param.testProperty == 42) { + // got the expected value. if we didn't previously + // get an unexpected value, set success to true. + root.success = (!root.gotInvalid); + } else { + // the value passed through was not what we expected. + root.gotInvalid = true; + root.success = false; + } + } + + function handleTestSignal(spp) { + root.determineSuccess(spp); + } + + Component.onCompleted: { + success = false; + e.testSignal.connect(handleTestSignal) + e.emitTestSignal(); + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 04a4bf7f46..ab547dc0ce 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -171,6 +171,7 @@ private slots: void propertyInit(); void remoteLoadCrash(); void signalWithDefaultArg(); + void signalParameterTypes(); // regression tests for crashes void crash1(); @@ -355,6 +356,7 @@ void tst_qqmllanguage::errors_data() QTest::newRow("signal.3") << "signal.3.qml" << "signal.3.errors.txt" << false; QTest::newRow("signal.4") << "signal.4.qml" << "signal.4.errors.txt" << false; QTest::newRow("signal.5") << "signal.5.qml" << "signal.5.errors.txt" << false; + QTest::newRow("signal.6") << "signal.6.qml" << "signal.6.errors.txt" << false; QTest::newRow("method.1") << "method.1.qml" << "method.1.errors.txt" << false; @@ -2923,6 +2925,28 @@ void tst_qqmllanguage::signalWithDefaultArg() delete object; } +void tst_qqmllanguage::signalParameterTypes() +{ + // bound signal handlers + { + QQmlComponent component(&engine, testFileUrl("signalParameterTypes.1.qml")); + QObject *obj = component.create(); + QVERIFY(obj != 0); + QVERIFY(obj->property("success").toBool()); + delete obj; + } + + // dynamic signal connections + { + QQmlComponent component(&engine, testFileUrl("signalParameterTypes.2.qml")); + QObject *obj = component.create(); + QVERIFY(obj != 0); + QEXPECT_FAIL("", "Dynamic connections don't enforce type safety - QTBUG-26662", Abort); + QVERIFY(obj->property("success").toBool()); + delete obj; + } +} + // QTBUG-20639 void tst_qqmllanguage::globalEnums() { |