aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp')
-rw-r--r--tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp65
1 files changed, 55 insertions, 10 deletions
diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
index f78bd3ac76..69dbd6179b 100644
--- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
+++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtest.h>
#include <QQmlEngine>
@@ -24,6 +24,8 @@ private slots:
void idTranslation();
void translationChange();
void preferJSContext();
+ void pragmaContext();
+ void pragmaContextStringLiteral();
void listModel();
};
@@ -50,11 +52,11 @@ void tst_qqmltranslation::translation()
QQmlEngine engine;
QQmlComponent component(&engine, testFile);
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
if (verifyCompiledData) {
- QQmlContext *context = qmlContext(object);
+ QQmlContext *context = qmlContext(object.get());
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlRefPointer<QQmlTypeData> typeData = engine->typeLoader.getType(context->baseUrl());
QVERIFY(!typeData->backupSourceCode().isValid());
@@ -66,7 +68,9 @@ void tst_qqmltranslation::translation()
<< QStringLiteral("basic2")
<< QStringLiteral("disambiguation")
<< QStringLiteral("disambiguation2")
- << QStringLiteral("singular") << QStringLiteral("plural");
+ << QStringLiteral("singular")
+ << QStringLiteral("plural")
+ << QStringLiteral("emptyContext");
const QV4::CompiledData::Object *rootObject
= compilationUnit->qmlData->objectAt(/*root object*/0);
@@ -100,9 +104,9 @@ void tst_qqmltranslation::translation()
QCOMPARE(object->property("singular2").toString(), QLatin1String("1 canard"));
QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards"));
QCOMPARE(object->property("plural2").toString(), QLatin1String("2 canards"));
+ QCOMPARE(object->property("emptyContext").toString(), QLatin1String("hello"));
QCoreApplication::removeTranslator(&translator);
- delete object;
}
void tst_qqmltranslation::idTranslation()
@@ -113,11 +117,11 @@ void tst_qqmltranslation::idTranslation()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("idtranslation.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ std::unique_ptr<QObject> object { component.create() };
+ QVERIFY(object);
{
- QQmlContext *context = qmlContext(object);
+ QQmlContext *context = qmlContext(object.get());
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlRefPointer<QQmlTypeData> typeData = engine->typeLoader.getType(context->baseUrl());
QVERIFY(!typeData->backupSourceCode().isValid());
@@ -144,7 +148,6 @@ void tst_qqmltranslation::idTranslation()
QCOMPARE(object->property("idTranslation3").toString(), QLatin1String("bonjour tout le monde"));
QCoreApplication::removeTranslator(&translator);
- delete object;
}
class CppTranslationBase : public QQuickItem
@@ -174,6 +177,12 @@ class DummyTranslator : public QTranslator
return QString::fromUtf8("Deutsch in mylibrary");
if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "nested_js_translation"))
return QString::fromUtf8("Deutsch in Setzung");
+ if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "contextSetWithPragma"))
+ return QString::fromUtf8("Deutsch in Setzung pragma");
+ if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "contextSetWithPragmaStringLiteral"))
+ return QString::fromUtf8("Deutsch in Setzung pragma string literal");
+ if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "setContext"))
+ return QString::fromUtf8("Deutsch in Setzung set");
if (!qstrcmp(sourceText, "soup"))
return QString::fromUtf8("Suppe");
if (!qstrcmp(sourceText, "fish"))
@@ -245,6 +254,42 @@ void tst_qqmltranslation::preferJSContext()
QCoreApplication::removeTranslator(&translator);
}
+void tst_qqmltranslation::pragmaContext()
+{
+ DummyTranslator translator;
+ QCoreApplication::installTranslator(&translator);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("pragmacontext.qml"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->property("german1").toString(),
+ QStringLiteral("Deutsch in Setzung pragma"));
+ QCOMPARE(object->property("german2").toString(),
+ QStringLiteral("Deutsch in Setzung set"));
+
+ QCoreApplication::removeTranslator(&translator);
+}
+
+void tst_qqmltranslation::pragmaContextStringLiteral()
+{
+ DummyTranslator translator;
+ QCoreApplication::installTranslator(&translator);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("pragmacontextstringliteral.qml"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->property("german1").toString(),
+ QStringLiteral("Deutsch in Setzung pragma string literal"));
+ QCOMPARE(object->property("german2").toString(),
+ QStringLiteral("Deutsch in Setzung set"));
+
+ QCoreApplication::removeTranslator(&translator);
+}
+
void tst_qqmltranslation::listModel()
{
QQmlEngine engine;