summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorJedrzej Nowacki <jedrzej.nowacki@nokia.com>2010-04-29 14:25:20 (GMT)
committerJedrzej Nowacki <jedrzej.nowacki@nokia.com>2010-04-30 07:59:27 (GMT)
commit20143e765b627ba2f8ab77ea9b842dd1549f19f3 (patch)
tree76e3506ee3ef6a6474bbb5f242744c6ed57c66ef /tests/auto/qscriptengine
parent498786a2ab27680b27f8e57b422ff8f32f0c3790 (diff)
downloadQt-20143e765b627ba2f8ab77ea9b842dd1549f19f3.zip
Qt-20143e765b627ba2f8ab77ea9b842dd1549f19f3.tar.gz
Qt-20143e765b627ba2f8ab77ea9b842dd1549f19f3.tar.bz2
Fix conversion between QVariant and QScriptValue.
Function converting from QVariant to QScriptValue is smart and tries to unwrap a value. So QVariant(1234) after conversion will be equal to QScriptValue(1234). It is ok, but QVariant(QVariant(...)) should be unpacked only once. Reviewed-by: Kent Hansen Task-number: QTBUG-10315
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 89ea1db..5501755 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -2059,6 +2059,38 @@ void tst_QScriptEngine::valueConversion()
QVERIFY(!val.isVariant());
QVERIFY(val.isUndefined());
}
+ // Checking nested QVariants
+ {
+ QVariant tmp1;
+ QVariant tmp2(QMetaType::QVariant, &tmp1);
+ QVERIFY(QMetaType::Type(tmp2.type()) == QMetaType::QVariant);
+
+ QScriptValue val1 = qScriptValueFromValue(&eng, tmp1);
+ QScriptValue val2 = qScriptValueFromValue(&eng, tmp2);
+ QVERIFY(val1.isValid());
+ QVERIFY(val2.isValid());
+ QVERIFY(val1.isUndefined());
+ QVERIFY(!val2.isUndefined());
+ QVERIFY(!val1.isVariant());
+ QVERIFY(val2.isVariant());
+ }
+ {
+ QVariant tmp1(123);
+ QVariant tmp2(QMetaType::QVariant, &tmp1);
+ QVariant tmp3(QMetaType::QVariant, &tmp2);
+ QVERIFY(QMetaType::Type(tmp1.type()) == QMetaType::Int);
+ QVERIFY(QMetaType::Type(tmp2.type()) == QMetaType::QVariant);
+ QVERIFY(QMetaType::Type(tmp3.type()) == QMetaType::QVariant);
+
+ QScriptValue val1 = qScriptValueFromValue(&eng, tmp2);
+ QScriptValue val2 = qScriptValueFromValue(&eng, tmp3);
+ QVERIFY(val1.isValid());
+ QVERIFY(val2.isValid());
+ QVERIFY(val1.isVariant());
+ QVERIFY(val2.isVariant());
+ QVERIFY(val1.toVariant().toInt() == 123);
+ QVERIFY(qScriptValueFromValue(&eng, val2.toVariant()).toVariant().toInt() == 123);
+ }
{
QScriptValue val = qScriptValueFromValue(&eng, QVariant(true));
QVERIFY(!val.isVariant());