aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-08-08 14:53:45 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-09 05:57:33 +0200
commitf09517bd9c907698a05ee92ccf158a06db3340b8 (patch)
treec8bae3c214f06c1293d3f0706960f7139dc999db /tests/auto
parent9c2ab7af355d0132af771f8784e42c13d1f49183 (diff)
Ensure that copy sequences can be passed as arguments
Previously, automatic conversion from JS array to sequence copy resource was not performed in the case where the array was passed as a parameter to a QObject function invocation. This commit adds code to check if the parameter type is a sequence type - and if so, and if the value is a variantlist, we convert it to a sequence of the appropriate type. Change-Id: I3cc3e2f95604bc71d1d8d237e1acffa1e03b78ba Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml23
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp30
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h1
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp4
4 files changed, 34 insertions, 24 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml
index f6614dad0c..088e240ad4 100644
--- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml
+++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml
@@ -157,4 +157,27 @@ Item {
if (jsIntList == jsIntList2) success = false;
if (jsIntList != jsIntList) success = false;
}
+
+ // this test ensures that copy resource sequences can be passed as parameters
+ function testCopyParameters() {
+ success = false;
+
+ var jsIntList = msco.generateIntSequence();
+ success = msco.parameterEqualsGeneratedIntSequence(jsIntList);
+ if (success == false) return;
+
+ // here we construct something which should be converted to a copy sequence automatically.
+ success = msco.parameterEqualsGeneratedIntSequence([1,2,3]);
+ }
+
+ // this test ensures that reference resource sequences are converted
+ // to copy resource sequences when passed as parameters.
+ function testReferenceParameters() {
+ success = false;
+
+ msco.intListProperty = msco.generateIntSequence();
+ var jsIntList = msco.intListProperty
+ success = msco.parameterEqualsGeneratedIntSequence(jsIntList);
+ if (success == false) return;
+ }
}
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index 9669e371de..a0bdbb6156 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -225,35 +225,17 @@ public:
{
return stringList;
}
- Q_INVOKABLE QList<int> integers(QVariant v) const
+ Q_INVOKABLE QList<int> integers(QList<int> v) const
{
- QList<int> intList;
- QList<QVariant> vList = v.toList();
- for (int i=0 ; i < vList.size() ; ++i) {
- int iv = vList[i].toInt();
- intList.append(iv);
- }
- return intList;
+ return v;
}
- Q_INVOKABLE QList<qreal> reals(QVariant v) const
+ Q_INVOKABLE QList<qreal> reals(QList<qreal> v) const
{
- QList<qreal> realList;
- QList<QVariant> vList = v.toList();
- for (int i=0 ; i < vList.size() ; ++i) {
- qreal fv = vList[i].toReal();
- realList.append(fv);
- }
- return realList;
+ return v;
}
- Q_INVOKABLE QList<bool> bools(QVariant v) const
+ Q_INVOKABLE QList<bool> bools(QList<bool> v) const
{
- QList<bool> boolList;
- QList<QVariant> vList = v.toList();
- for (int i=0 ; i < vList.size() ; ++i) {
- bool bv = vList[i].toBool();
- boolList.append(bv);
- }
- return boolList;
+ return v;
}
};
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index c05405ab53..da6baa4e6c 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -1393,6 +1393,7 @@ public:
Q_INVOKABLE QList<QString> generateStringSequence() const { QList<QString> retn; retn << "one" << "two" << "three"; return retn; }
Q_INVOKABLE QList<QUrl> generateUrlSequence() const { QList<QUrl> retn; retn << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); return retn; }
Q_INVOKABLE QStringList generateQStringSequence() const { QStringList retn; retn << "one" << "two" << "three"; return retn; }
+ Q_INVOKABLE bool parameterEqualsGeneratedIntSequence(const QList<int>& param) const { return (param == generateIntSequence()); }
// "reference resource" underlying qobject deletion test:
Q_INVOKABLE MySequenceConversionObject *generateTestObject() const { return new MySequenceConversionObject; }
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 6fa6c3b49e..55b76f1d20 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -5569,6 +5569,10 @@ void tst_qqmlecmascript::sequenceConversionCopy()
QCOMPARE(object->property("success").toBool(), true);
QMetaObject::invokeMethod(object, "testEqualitySemantics");
QCOMPARE(object->property("success").toBool(), true);
+ QMetaObject::invokeMethod(object, "testCopyParameters");
+ QCOMPARE(object->property("success").toBool(), true);
+ QMetaObject::invokeMethod(object, "testReferenceParameters");
+ QCOMPARE(object->property("success").toBool(), true);
delete object;
}