diff options
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/scriptString5.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/scriptString6.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 51 |
3 files changed, 52 insertions, 9 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/scriptString5.qml b/tests/auto/qml/qqmllanguage/data/scriptString5.qml new file mode 100644 index 0000000000..12485bb19e --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/scriptString5.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: null +} diff --git a/tests/auto/qml/qqmllanguage/data/scriptString6.qml b/tests/auto/qml/qqmllanguage/data/scriptString6.qml new file mode 100644 index 0000000000..c30f2245c8 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/scriptString6.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: undefined +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 316d7e28a7..04a4bf7f46 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -52,6 +52,7 @@ #include <private/qqmlproperty_p.h> #include <private/qqmlmetatype_p.h> #include <private/qqmlglobal_p.h> +#include <private/qqmlscriptstring_p.h> #include "testtypes.h" #include "testhttpserver.h" @@ -1693,14 +1694,23 @@ void tst_qqmllanguage::scriptString() MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); QVERIFY(object != 0); - QCOMPARE(object->scriptProperty().script(), QString("foo + bar")); - QCOMPARE(object->scriptProperty().scopeObject(), qobject_cast<QObject*>(object)); - QCOMPARE(object->scriptProperty().context(), qmlContext(object)); + QVERIFY(!object->scriptProperty().isEmpty()); + QCOMPARE(object->scriptProperty().stringLiteral(), QString()); + bool ok; + QCOMPARE(object->scriptProperty().numberLiteral(&ok), qreal(0.)); + QCOMPARE(ok, false); + + const QQmlScriptStringPrivate *scriptPrivate = QQmlScriptStringPrivate::get(object->scriptProperty()); + QVERIFY(scriptPrivate != 0); + QCOMPARE(scriptPrivate->script, QString("foo + bar")); + QCOMPARE(scriptPrivate->scope, qobject_cast<QObject*>(object)); + QCOMPARE(scriptPrivate->context, qmlContext(object)); QVERIFY(object->grouped() != 0); - QCOMPARE(object->grouped()->script().script(), QString("console.log(1921)")); - QCOMPARE(object->grouped()->script().scopeObject(), qobject_cast<QObject*>(object)); - QCOMPARE(object->grouped()->script().context(), qmlContext(object)); + const QQmlScriptStringPrivate *groupedPrivate = QQmlScriptStringPrivate::get(object->grouped()->script()); + QCOMPARE(groupedPrivate->script, QString("console.log(1921)")); + QCOMPARE(groupedPrivate->scope, qobject_cast<QObject*>(object)); + QCOMPARE(groupedPrivate->context, qmlContext(object)); } { @@ -1709,7 +1719,7 @@ void tst_qqmllanguage::scriptString() MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); QVERIFY(object != 0); - QCOMPARE(object->scriptProperty().script(), QString("\"hello\\n\\\"world\\\"\"")); + QCOMPARE(object->scriptProperty().stringLiteral(), QString("hello\\n\\\"world\\\"")); } { @@ -1718,7 +1728,10 @@ void tst_qqmllanguage::scriptString() MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); QVERIFY(object != 0); - QCOMPARE(object->scriptProperty().script(), QString("12.345")); + bool ok; + QCOMPARE(object->scriptProperty().numberLiteral(&ok), qreal(12.345)); + QCOMPARE(ok, true); + } { @@ -1727,7 +1740,27 @@ void tst_qqmllanguage::scriptString() MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); QVERIFY(object != 0); - QCOMPARE(object->scriptProperty().script(), QString("true")); + bool ok; + QCOMPARE(object->scriptProperty().booleanLiteral(&ok), true); + QCOMPARE(ok, true); + } + + { + QQmlComponent component(&engine, testFileUrl("scriptString5.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().isNullLiteral(), true); + } + + { + QQmlComponent component(&engine, testFileUrl("scriptString6.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().isUndefinedLiteral(), true); } } |