summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-05 14:48:52 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-05 14:56:53 (GMT)
commit9691523b796c6acc6a837a5f5a34fef16aa74c48 (patch)
tree355174d4b7fa66aeac721caa01d98ca3616768cf /tests
parentff9497f82d605688453e2f027bab7c719048f0d2 (diff)
downloadQt-9691523b796c6acc6a837a5f5a34fef16aa74c48.zip
Qt-9691523b796c6acc6a837a5f5a34fef16aa74c48.tar.gz
Qt-9691523b796c6acc6a837a5f5a34fef16aa74c48.tar.bz2
have QScriptValue::toVariant() convert Array objects to QVariantLists
Converting the array to its string representation is not very useful. Now round-trip conversion will work as well. Reviewed-by: Ariya Hidayat
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index bf91001..ad1080a 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -1301,6 +1301,27 @@ void tst_QScriptValue::toVariant()
QCOMPARE(str.toVariant(), QVariant(QString("ciao")));
QCOMPARE(qscriptvalue_cast<QVariant>(str), QVariant(QString("ciao")));
}
+
+ // array
+ {
+ QVariantList listIn;
+ listIn << 123 << "hello";
+ QScriptValue array = qScriptValueFromValue(&eng, listIn);
+ QVERIFY(array.isArray());
+ QCOMPARE(array.property("length").toInt32(), 2);
+ QVariant ret = array.toVariant();
+ QCOMPARE(ret.type(), QVariant::List);
+ QVariantList listOut = ret.toList();
+ QCOMPARE(listOut.size(), listIn.size());
+ for (int i = 0; i < listIn.size(); ++i)
+ QVERIFY(listOut.at(i) == listIn.at(i));
+ // round-trip conversion
+ QScriptValue array2 = qScriptValueFromValue(&eng, ret);
+ QVERIFY(array2.isArray());
+ QCOMPARE(array2.property("length").toInt32(), array.property("length").toInt32());
+ for (int i = 0; i < array.property("length").toInt32(); ++i)
+ QVERIFY(array2.property(i).strictlyEquals(array.property(i)));
+ }
}
// unfortunately, this is necessary in order to do qscriptvalue_cast<QPushButton*>(...)