aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-07-13 15:53:04 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-08 06:04:03 +0200
commit92562eacbc3c614a83a734f1108ed7df02415eae (patch)
tree05fc063849e032cb03e4f919811d8ea4da147773 /tests
parentb2120f68683b7948891d72fe077f44ab7e6baf18 (diff)
Allow signal parameters which are custom QML object-types
This commit allows lazy resolution of signal parameter types, which allows QML object types to be used as signal parameters. If a signal is emitted with an incorrect parameter type, it will be passed through as a null parameter. Task-number: QTBUG-14550 Change-Id: I7e899ad57452826cc405bed10c541f8d35789d04 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/data/OtherSignalParam.qml6
-rw-r--r--tests/auto/qml/qqmllanguage/data/SignalEmitter.qml25
-rw-r--r--tests/auto/qml/qqmllanguage/data/SignalParam.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/signal.1.errors.txt2
-rw-r--r--tests/auto/qml/qqmllanguage/data/signal.6.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/signal.6.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/signalParameterTypes.1.qml44
-rw-r--r--tests/auto/qml/qqmllanguage/data/signalParameterTypes.2.qml48
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp24
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()
{