aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-09-08 14:06:22 +0200
committerLars Knoll <lars.knoll@digia.com>2014-09-11 09:56:48 +0200
commit91d6a63ab317817990c3b2306860adbd8916cca4 (patch)
tree44962e20ce14c594d1f77c7ac4d54d53bd1b158e /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parent8fab54a5495226b8c06d7708357a23e83444abc0 (diff)
Fix roundtrip conversion between JS var and QVariant
Always convert null to a QVariant(VoidStar) as documented in QJSValue. Make sure the reverse conversion will lead back to a null JS value. Adjusted two test cases that expected an invalid QVariant when setting the property to null, and added test cases for the correct conversion. Task-number: QTBUG-40880 Change-Id: I6eb01f0067f2c89779c53fd2cd0a1193047ed2cc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 06d061a9fa..01125f86f6 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -213,6 +213,7 @@ private slots:
void deletedEngine();
void libraryScriptAssert();
void variantsAssignedUndefined();
+ void variants();
void qtbug_9792();
void qtcreatorbug_1289();
void noSpuriousWarningsAtShutdown();
@@ -5737,6 +5738,29 @@ void tst_qqmlecmascript::variantsAssignedUndefined()
delete object;
}
+void tst_qqmlecmascript::variants()
+{
+ QQmlComponent component(&engine, testFileUrl("variants.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QVERIFY(object->property("undefinedVariant").type() == QVariant::Invalid);
+ QVERIFY(object->property("nullVariant").type() == (int)QMetaType::VoidStar);
+ QVERIFY(object->property("intVariant").type() == QVariant::Int);
+ QVERIFY(object->property("doubleVariant").type() == QVariant::Double);
+
+ QVariant result;
+ QMetaObject::invokeMethod(object, "checkNull", Q_RETURN_ARG(QVariant, result));
+ QCOMPARE(result.toBool(), true);
+
+ QMetaObject::invokeMethod(object, "checkUndefined", Q_RETURN_ARG(QVariant, result));
+ QCOMPARE(result.toBool(), true);
+
+ QMetaObject::invokeMethod(object, "checkNumber", Q_RETURN_ARG(QVariant, result));
+ QCOMPARE(result.toBool(), true);
+}
+
void tst_qqmlecmascript::qtbug_9792()
{
QQmlComponent component(&engine, testFileUrl("qtbug_9792.qml"));