aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-07-11 13:01:33 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-03 03:38:49 +0200
commitaa25ad8d5f476d6db59012a122833ebe677eaf69 (patch)
tree37eb955dabc252304aefe821d03be5e3857f22c9 /tests/auto/qml/qqmllanguage
parentd64224041efe9febc683cf5ee7155a9cc88058d9 (diff)
Make QQmlScriptString opaque.
Allow for future optimization by encapsulating the raw script data. Change-Id: I1863103e8e6d74ede60593cabb240e16f2ae657e Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r--tests/auto/qml/qqmllanguage/data/scriptString5.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/scriptString6.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp51
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);
}
}