diff options
Diffstat (limited to 'tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp')
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index 5774b68c32..3bf83d81e1 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 Research In Motion. -// 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 <QQmlApplicationEngine> #include <QScopedPointer> @@ -28,6 +28,8 @@ private slots: void removeObjectsWhenDestroyed(); void loadTranslation_data(); void loadTranslation(); + void loadFromModuleTranslation_data(); + void loadFromModuleTranslation(); void translationChange(); void setInitialProperties(); void failureToLoadTriggersWarningSignal(); @@ -144,7 +146,7 @@ void tst_qqmlapplicationengine::application() #if QT_CONFIG(process) QDir::setCurrent(buildDir); - QProcess *testProcess = new QProcess(this); + std::unique_ptr<QProcess> testProcess = std::make_unique<QProcess>(this); #ifdef Q_OS_QNX QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("QT_FORCE_STDERR_LOGGING", "1"); // QTBUG-76546 @@ -164,7 +166,7 @@ void tst_qqmlapplicationengine::application() QVERIFY2(QString(testStdErr).endsWith(QString(expectedStdErr)), QByteArray("\nExpected ending:\n") + expectedStdErr + QByteArray("\nActual output:\n") + testStdErr); - delete testProcess; + testProcess.reset(); QDir::setCurrent(srcDir); #else // process QSKIP("No process support"); @@ -191,7 +193,7 @@ void tst_qqmlapplicationengine::applicationProperties() QCoreApplication::setOrganizationName(firstOrganization); QCoreApplication::setOrganizationDomain(firstDomain); - QQmlApplicationEngine *test = new QQmlApplicationEngine(testFileUrl("applicationTest.qml")); + std::unique_ptr<QQmlApplicationEngine> test = std::make_unique<QQmlApplicationEngine>(testFileUrl("applicationTest.qml")); QObject* root = test->rootObjects().at(0); QVERIFY(root); QCOMPARE(root->property("originalName").toString(), firstName); @@ -223,8 +225,6 @@ void tst_qqmlapplicationengine::applicationProperties() QCOMPARE(versionChanged.size(), 1); QCOMPARE(organizationChanged.size(), 1); QCOMPARE(domainChanged.size(), 1); - - delete test; } void tst_qqmlapplicationengine::removeObjectsWhenDestroyed() @@ -268,6 +268,53 @@ void tst_qqmlapplicationengine::loadTranslation() QCOMPARE(rootObject->property("translation").toString(), translation); } +void tst_qqmlapplicationengine::loadFromModuleTranslation_data() +{ + QTest::addColumn<QString>("executable"); + QTest::addColumn<QLocale::Language>("LANG"); + QTest::addColumn<QString>("output"); + + QString qmlTypeExecutable = "loadFromModuleTranslationsQmlType/i18nLoadFromModuleQmlType"; + QString cppTypeExecutable = "loadFromModuleTranslationsCppType/i18nLoadFromModuleCppType"; + + QTest::newRow("Qml: en -> en") << qmlTypeExecutable << QLocale::English << "Hello"; + QTest::newRow("Qml: en -> fr") << qmlTypeExecutable << QLocale::French << "Salut"; + QTest::newRow("Cpp: en -> en") << cppTypeExecutable << QLocale::English << "Hello"; + QTest::newRow("Cpp: en -> es") << cppTypeExecutable << QLocale::Spanish << "Hola"; +} + +void tst_qqmlapplicationengine::loadFromModuleTranslation() +{ +#if defined(Q_OS_ANDROID) + QSKIP("Test doesn't currently run on Android"); + return; +#endif + +#if QT_CONFIG(process) + QFETCH(QString, executable); + QFETCH(QLocale::Language, LANG); + QFETCH(QString, output); + + QDir::setCurrent(buildDir); + QProcess app; + auto env = QProcessEnvironment::systemEnvironment(); + env.insert("qtlang", QString::number(int(LANG))); + env.insert("LOADFROMMODULE_TEST_EXPECTED_OUTPUT", output); + app.setProcessEnvironment(env); + app.start(executable); + QVERIFY(app.waitForStarted()); + QVERIFY(app.waitForFinished()); + + auto status = app.exitStatus(); + auto code = app.exitCode(); + QVERIFY2(code == 0, + QStringLiteral("status: %1, exitCode: %2").arg(status).arg(code).toStdString().c_str()); + app.kill(); +#else + QSKIP("No process support"); +#endif +} + void tst_qqmlapplicationengine::translationChange() { if (QLocale().language() == QLocale::SwissGerman) { |