aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllistmodel
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-04-26 14:42:39 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-28 12:50:17 +0200
commit68a662a2e15b790080ea12c2434f6e1fe60bda1b (patch)
tree2ac79cccf047e4ed5f61f06f9a3823715975daa1 /tests/auto/qml/qqmllistmodel
parentda4f5504822189a7efd279d2380e0737f9de3968 (diff)
Fix translations in states causing failing assertions
This is a smaller fix suitable for the release branch, merely adding support for translations to the bytearray compilation step for states and ensuring a consistent error message when qsTr is used in list models. The proper fix will be done in dev that eliminates the entire intermediate QByteArray storage for custom compilers. Task-number: QTBUG-38492 Change-Id: If5171f16eb742c718e48b8bbcb265b0c241cd5e7 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmllistmodel')
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index 678849c371..9b57eeffa9 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -101,6 +101,8 @@ private slots:
void static_types_data();
void static_i18n();
void static_i18n_data();
+ void dynamic_i18n();
+ void dynamic_i18n_data();
void static_nestedElements();
void static_nestedElements_data();
void dynamic_data();
@@ -341,6 +343,54 @@ void tst_qqmllistmodel::static_i18n()
delete obj;
}
+void tst_qqmllistmodel::dynamic_i18n_data()
+{
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<QVariant>("value");
+ QTest::addColumn<QString>("error");
+
+ QTest::newRow("qsTr")
+ << QString::fromUtf8("ListElement { foo: qsTr(\"test\") }")
+ << QVariant(QString::fromUtf8("test"))
+ << QString("ListElement: cannot use script for property value");
+
+ QTest::newRow("qsTrId")
+ << "ListElement { foo: qsTrId(\"qtn_test\") }"
+ << QVariant(QString("qtn_test"))
+ << QString("ListElement: cannot use script for property value");
+}
+
+void tst_qqmllistmodel::dynamic_i18n()
+{
+ QFETCH(QString, qml);
+ QFETCH(QVariant, value);
+ QFETCH(QString, error);
+
+ qml = "import QtQuick 2.0\nItem { property variant test: model.get(0).foo; ListModel { id: model; " + qml + " } }";
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(qml.toUtf8(),
+ QUrl::fromLocalFile(QString("dummy.qml")));
+
+ if (!error.isEmpty()) {
+ QVERIFY(component.isError());
+ QCOMPARE(component.errors().at(0).description(), error);
+ return;
+ }
+
+ QVERIFY(!component.isError());
+
+ QObject *obj = component.create();
+ QVERIFY(obj != 0);
+
+ QVariant actual = obj->property("test");
+
+ QCOMPARE(actual, value);
+ QCOMPARE(actual.toString(), value.toString());
+
+ delete obj;
+}
void tst_qqmllistmodel::static_nestedElements()
{
QFETCH(int, elementCount);