aboutsummaryrefslogtreecommitdiffstats
path: root/tests
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
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')
-rw-r--r--tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp4
-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
-rw-r--r--tests/auto/quick/qquickstates/tst_qquickstates.cpp15
5 files changed, 62 insertions, 18 deletions
diff --git a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
index 5cc6289212..8e53efe5eb 100644
--- a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
+++ b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
@@ -88,14 +88,14 @@ void tst_qqmlexpression::scriptString()
QVERIFY(testObj != 0);
QQmlScriptString script = testObj->scriptString();
- QCOMPARE(script.script(), QLatin1String("value1 + value2"));
+ QVERIFY(!script.isEmpty());
QQmlExpression expression(script);
QVariant value = expression.evaluate();
QCOMPARE(value.toInt(), 15);
QQmlScriptString scriptError = testObj->scriptStringError();
- QCOMPARE(scriptError.script(), QLatin1String("value3 * 5"));
+ QVERIFY(!scriptError.isEmpty());
//verify that the expression has the correct error location information
QQmlExpression expressionError(scriptError);
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);
}
}
diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
index 0a42ae5678..b8a3a49583 100644
--- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp
+++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
@@ -702,8 +702,9 @@ void tst_qquickstates::anchorChanges()
QQuickAnchorChanges *aChanges = qobject_cast<QQuickAnchorChanges*>(state->operationAt(0));
QVERIFY(aChanges != 0);
- QCOMPARE(aChanges->anchors()->left().script(), QLatin1String("undefined"));
- QCOMPARE(aChanges->anchors()->right().script(), QLatin1String("container.right"));
+ QCOMPARE(aChanges->anchors()->left().isUndefinedLiteral(), true);
+ QVERIFY(!aChanges->anchors()->left().isEmpty());
+ QVERIFY(!aChanges->anchors()->right().isEmpty());
rectPrivate->setState("right");
QCOMPARE(innerRect->x(), qreal(150));
@@ -765,8 +766,8 @@ void tst_qquickstates::anchorChanges3()
QQuickAnchorChanges *aChanges = qobject_cast<QQuickAnchorChanges*>(state->operationAt(0));
QVERIFY(aChanges != 0);
- QCOMPARE(aChanges->anchors()->top().script(), QLatin1String("container.top"));
- QCOMPARE(aChanges->anchors()->bottom().script(), QLatin1String("bottomGuideline.bottom"));
+ QVERIFY(!aChanges->anchors()->top().isEmpty());
+ QVERIFY(!aChanges->anchors()->bottom().isEmpty());
rectPrivate->setState("reanchored");
QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect));
@@ -818,8 +819,8 @@ void tst_qquickstates::anchorChanges4()
QQuickAnchorChanges *aChanges = qobject_cast<QQuickAnchorChanges*>(state->operationAt(0));
QVERIFY(aChanges != 0);
- QCOMPARE(aChanges->anchors()->horizontalCenter().script(), QLatin1String("bottomGuideline.horizontalCenter"));
- QCOMPARE(aChanges->anchors()->verticalCenter().script(), QLatin1String("leftGuideline.verticalCenter"));
+ QVERIFY(!aChanges->anchors()->horizontalCenter().isEmpty());
+ QVERIFY(!aChanges->anchors()->verticalCenter().isEmpty());
QQuickItemPrivate::get(rect)->setState("reanchored");
QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect));
@@ -856,7 +857,7 @@ void tst_qquickstates::anchorChanges5()
QQuickAnchorChanges *aChanges = qobject_cast<QQuickAnchorChanges*>(state->operationAt(0));
QVERIFY(aChanges != 0);
- QCOMPARE(aChanges->anchors()->baseline().script(), QLatin1String("leftGuideline.baseline"));
+ QVERIFY(!aChanges->anchors()->baseline().isEmpty());
QQuickItemPrivate::get(rect)->setState("reanchored");
QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect));