aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-04-05 12:11:25 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-04-06 11:19:16 +0000
commit9b961334cfd81ec5fcc4dc7d2c50154cddd5f230 (patch)
tree427538213284200910d9ee53220c5cac246dd891 /tests
parent028a85f4f462093ca93ae95865eb6cbcbaec199a (diff)
Fix support for jsTr() and QT_TR_NOOP in list elements when caching
Similar to the Qt Quick Compiler we need to do the expression simplification pass at cache generation time to extract translation calls in list elements. Change-Id: I267fc9647ab82bc83d6b087c06c0036df38238ff Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index 27bb2348b8..b7e616a050 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -42,6 +42,7 @@ private slots:
void initTestCase();
void loadGeneratedFile();
+ void translationExpressionSupport();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -116,6 +117,47 @@ void tst_qmlcachegen::loadGeneratedFile()
QCOMPARE(obj->property("value").toInt(), 42);
}
+void tst_qmlcachegen::translationExpressionSupport()
+{
+ QTemporaryDir tempDir;
+ QVERIFY(tempDir.isValid());
+
+ const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) {
+ QFile f(tempDir.path() + '/' + fileName);
+ const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate);
+ Q_ASSERT(ok);
+ f.write(contents);
+ return f.fileName();
+ };
+
+ const QString testFilePath = writeTempFile("test.qml", "import QtQml.Models 2.2\n"
+ "import QtQml 2.2\n"
+ "QtObject {\n"
+ " property ListModel model: ListModel {\n"
+ " ListElement {\n"
+ " text: qsTr(\"All\")\n"
+ " }\n"
+ " ListElement {\n"
+ " text: QT_TR_NOOP(\"Ok\")\n"
+ " }\n"
+ " }\n"
+ " property string text: model.get(0).text + \" \" + model.get(1).text\n"
+ "}");
+
+
+ QVERIFY(generateCache(testFilePath));
+
+ const QString cacheFilePath = testFilePath + QLatin1Char('c');
+ QVERIFY(QFile::exists(cacheFilePath));
+ QVERIFY(QFile::remove(testFilePath));
+
+ QQmlEngine engine;
+ CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(testFilePath));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("text").toString(), QString("All Ok"));
+}
+
QTEST_GUILESS_MAIN(tst_qmlcachegen)
#include "tst_qmlcachegen.moc"