diff options
author | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-11-06 10:07:43 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2018-11-06 10:40:15 +0000 |
commit | 00b1ff4607a560a2df674d56a70ecf3bd3e4f3df (patch) | |
tree | 1e7dd0c185b5adea5d4387785b020da6996f3ee0 /tests | |
parent | 0477a057fd02050fd330760bf046f5e0e91a9331 (diff) |
Fix translation bindings when qtquickcompiler is used
It turns out that the context information is lost when using the
compiler. The unit->unitData()->sourceFileIndex is wrong (always 0),
which should probably be fixed. This change only works around that by
using unit->fileName(); instead.
Make sure that the test actually verifies translations happen and have a
context.
Done-with: Jan Arve Sæther
Fixes: QTBUG-71553
Change-Id: Ib5926bd4b9a6267644f5c9328a84c23d61ca5466
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 6c399f6874..97ac466e94 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -36,6 +36,7 @@ #include <QSysInfo> #include <QLoggingCategory> #include <private/qqmlcomponent_p.h> +#include <qtranslator.h> class tst_qmlcachegen: public QObject { @@ -169,11 +170,26 @@ void tst_qmlcachegen::loadGeneratedFile() QVERIFY(unitData->flags & QV4::CompiledData::Unit::StaticData); } +class QTestTranslator : public QTranslator +{ +public: + QString translate(const char *context, const char *sourceText, const char */*disambiguation*/, int /*n*/) const override + { + m_lastContext = QString::fromUtf8(context); + return QString::fromUtf8(sourceText).toUpper(); + } + bool isEmpty() const override { return true; } + mutable QString m_lastContext; +}; + void tst_qmlcachegen::translationExpressionSupport() { QTemporaryDir tempDir; QVERIFY(tempDir.isValid()); + QTestTranslator translator; + qApp->installTranslator(&translator); + const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) { QFile f(tempDir.path() + '/' + fileName); const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate); @@ -207,7 +223,8 @@ void tst_qmlcachegen::translationExpressionSupport() CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(testFilePath)); QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); - QCOMPARE(obj->property("text").toString(), QString("All Ok")); + QCOMPARE(obj->property("text").toString(), QString("ALL Ok")); + QCOMPARE(translator.m_lastContext, QStringLiteral("test")); } void tst_qmlcachegen::signalHandlerParameters() |