aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-06-18 15:06:16 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-22 00:13:28 +0200
commitfa457e593deca9fcffe2d6ec6ca0aa40d9fa7b76 (patch)
treea8e53434055544fcf3ebeb9ba5982b3d7f72cf38 /tests
parent57e3325affbe8bbb8edcc2c6d072db28aee46438 (diff)
Support enum return types in Q_INVOKABLE functions.
Handle enums correctly when used as the return type of a Q_INVOKABLE function. Task-number: QTBUG-23543 Change-Id: I14a506ffee08f5ba6aa0fdf27d6104a3ae5c48b3 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/invokableEnumRet.qml11
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h4
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp21
3 files changed, 34 insertions, 2 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/invokableEnumRet.qml b/tests/auto/qml/qqmlecmascript/data/invokableEnumRet.qml
new file mode 100644
index 0000000000..21dfd6ae35
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/invokableEnumRet.qml
@@ -0,0 +1,11 @@
+import Qt.test 1.0
+import QtQuick 2.0
+
+MyQmlObject {
+ id: root
+ property bool test: false
+ Component.onCompleted: {
+ test = (root.getEnumValue() == 3)
+ }
+}
+
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 2631002719..8f3804a05b 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -187,6 +187,8 @@ public:
int intProperty() const { return m_intProperty; }
void setIntProperty(int i) { m_intProperty = i; emit intChanged(); }
+ Q_INVOKABLE MyEnum2 getEnumValue() const { return EnumValue4; }
+
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c, MyEnum2 d, Qt::MouseButtons e);
@@ -695,6 +697,8 @@ public:
Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
+ Q_INVOKABLE void method_unknown(MyInvokableObject *o) { invoke(28); }
+
private:
friend class MyInvokableBaseObject;
void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 9f4a8576d7..d344758147 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -245,6 +245,7 @@ private slots:
void callQtInvokables();
void invokableObjectArg();
void invokableObjectRet();
+ void invokableEnumRet();
void qtbug_20344();
void qtbug_22679();
void qtbug_22843_data();
@@ -2288,9 +2289,9 @@ void tst_qqmlecmascript::callQtInvokables()
}
o.reset();
- QVERIFY(EVALUATE_VALUE("object.method_NoArgs_unknown()", v8::Undefined()));
+ QVERIFY(EVALUATE_ERROR("object.method_NoArgs_unknown()"));
QCOMPARE(o.error(), false);
- QCOMPARE(o.invoked(), 5);
+ QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
o.reset();
@@ -2741,6 +2742,12 @@ void tst_qqmlecmascript::callQtInvokables()
QCOMPARE(o.invoked(), 27);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QJsonValue::Undefined));
+
+ o.reset();
+ QVERIFY(EVALUATE_ERROR("object.method_unknown(null)"));
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), -1);
+ QCOMPARE(o.actuals().count(), 0);
}
// QTBUG-13047 (check that you can pass registered object types as args)
@@ -2768,6 +2775,16 @@ void tst_qqmlecmascript::invokableObjectRet()
delete o;
}
+void tst_qqmlecmascript::invokableEnumRet()
+{
+ QQmlComponent component(&engine, testFileUrl("invokableEnumRet.qml"));
+
+ QObject *o = component.create();
+ QVERIFY(o);
+ QCOMPARE(o->property("test").toBool(), true);
+ delete o;
+}
+
// QTBUG-5675
void tst_qqmlecmascript::listToVariant()
{