diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2020-03-10 14:23:53 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2020-03-10 14:24:28 +0100 |
commit | 3f3e82fb05eb9eb9e03ccf8ed7de987b91e698ee (patch) | |
tree | 484247f63e601abd8b012b86e6cde6ff56710cbb /tests/auto/translation | |
parent | c3ff6b78ba8e0978bc408f6e3e490bcd32f6cfb0 (diff) | |
parent | 6cdd4b53031de17b36b30b00de0a6945470a35ad (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/imports/controls/qtquickcontrols2plugin.cpp
Change-Id: Ifc09ea9f71fdba119fe8eed99f0bdcb402444f27
Diffstat (limited to 'tests/auto/translation')
-rw-r--r-- | tests/auto/translation/data/comboBox.qml | 65 | ||||
-rw-r--r-- | tests/auto/translation/data/dialogButtonBoxWithCustomButtons.qml | 75 | ||||
-rw-r--r-- | tests/auto/translation/qml_jp.qm | bin | 0 -> 135 bytes | |||
-rw-r--r-- | tests/auto/translation/qml_jp.ts | 28 | ||||
-rw-r--r-- | tests/auto/translation/qtbase_fr.qm | bin | 0 -> 259 bytes | |||
-rw-r--r-- | tests/auto/translation/qtbase_fr.ts | 1 | ||||
-rw-r--r-- | tests/auto/translation/translation.pro | 5 | ||||
-rw-r--r-- | tests/auto/translation/tst_translation.cpp | 65 |
8 files changed, 234 insertions, 5 deletions
diff --git a/tests/auto/translation/data/comboBox.qml b/tests/auto/translation/data/comboBox.qml new file mode 100644 index 00000000..8bb8ed6f --- /dev/null +++ b/tests/auto/translation/data/comboBox.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.13 +import QtQuick.Controls 2.13 + +ComboBox { + objectName: "comboBox" + textRole: "label" + model: ListModel { + ListElement { + label: qsTr("Hello") + } + ListElement { + label: qsTr("ListView") + } + } +} diff --git a/tests/auto/translation/data/dialogButtonBoxWithCustomButtons.qml b/tests/auto/translation/data/dialogButtonBoxWithCustomButtons.qml new file mode 100644 index 00000000..6f046cf1 --- /dev/null +++ b/tests/auto/translation/data/dialogButtonBoxWithCustomButtons.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.14 +import QtQuick.Controls 2.14 + +Item { + property Dialog dialog: Dialog { + width: 300 + height: 300 + visible: true + + footer: DialogButtonBox { + Button { + objectName: "okButton" + text: qsTr("OK") + + DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole + } + Button { + objectName: "cancelButton" + text: qsTr("Cancel") + + DialogButtonBox.buttonRole: DialogButtonBox.RejectRole + } + } + } +} diff --git a/tests/auto/translation/qml_jp.qm b/tests/auto/translation/qml_jp.qm Binary files differnew file mode 100644 index 00000000..a3712e99 --- /dev/null +++ b/tests/auto/translation/qml_jp.qm diff --git a/tests/auto/translation/qml_jp.ts b/tests/auto/translation/qml_jp.ts new file mode 100644 index 00000000..303c142f --- /dev/null +++ b/tests/auto/translation/qml_jp.ts @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="ja_JP"> +<context> + <name>main</name> + <message> + <location filename="../main.qml" line="8"/> + <source>Hello World</source> + <translation>こんにちは世界</translation> + </message> + <message> + <location filename="../main.qml" line="12"/> + <source>Hello Text</source> + <translation>ハローテキスト</translation> + </message> + <message> + <location filename="../main.qml" line="35"/> + <source>Hello</source> + <translation>こんにちは</translation> + </message> + <message> + <location filename="../main.qml" line="38"/> + <source>ListView</source> + <translation>リストビュー</translation> + </message> +</context> +</TS> + diff --git a/tests/auto/translation/qtbase_fr.qm b/tests/auto/translation/qtbase_fr.qm Binary files differnew file mode 100644 index 00000000..176675a8 --- /dev/null +++ b/tests/auto/translation/qtbase_fr.qm diff --git a/tests/auto/translation/qtbase_fr.ts b/tests/auto/translation/qtbase_fr.ts index a2a05a07..7aff8bd7 100644 --- a/tests/auto/translation/qtbase_fr.ts +++ b/tests/auto/translation/qtbase_fr.ts @@ -20,3 +20,4 @@ </message> </context> </TS> + diff --git a/tests/auto/translation/translation.pro b/tests/auto/translation/translation.pro index d2d9d6ee..a33cf56a 100644 --- a/tests/auto/translation/translation.pro +++ b/tests/auto/translation/translation.pro @@ -13,7 +13,4 @@ TESTDATA = data/* OTHER_FILES += \ data/*.qml -# We only want to run lrelease, which is why we use EXTRA_TRANSLATIONS. -EXTRA_TRANSLATIONS = qtbase_fr.ts -# Embed the translations in a qrc file. -CONFIG += lrelease embed_translations +RESOURCES += qml_jp.qm qtbase_fr.qm diff --git a/tests/auto/translation/tst_translation.cpp b/tests/auto/translation/tst_translation.cpp index 9cbca915..ffb39f96 100644 --- a/tests/auto/translation/tst_translation.cpp +++ b/tests/auto/translation/tst_translation.cpp @@ -42,8 +42,10 @@ #include <QtGui/qpa/qplatformtheme.h> #include <QtQuick/qquickview.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> +#include <QtQuickTemplates2/private/qquickcombobox_p.h> #include <QtQuickTemplates2/private/qquickdialog_p.h> #include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h> +#include <QtQuickTemplates2/private/qquicktextfield_p.h> using namespace QQuickVisualTestUtil; @@ -53,6 +55,8 @@ class tst_translation : public QQmlDataTest private slots: void dialogButtonBox(); + void dialogButtonBoxWithCustomButtons(); + void comboBox(); }; void tst_translation::dialogButtonBox() @@ -82,7 +86,7 @@ void tst_translation::dialogButtonBox() QCOMPARE(discardButton->text(), defaultDiscardText); QTranslator translator; - QVERIFY(translator.load(":/i18n/qtbase_fr.qm")); + QVERIFY(translator.load("qtbase_fr.qm", ":/")); QVERIFY(qApp->installTranslator(&translator)); view.engine()->retranslate(); @@ -95,6 +99,65 @@ void tst_translation::dialogButtonBox() QCOMPARE(discardButton->text(), translatedDiscardText); } +// Test that custom buttons with explicitly specified text +// do not have that text overwritten on language changes. +void tst_translation::dialogButtonBoxWithCustomButtons() +{ + // This is just a way of simulating the translator going out of scope + // after the QML has been loaded. + QScopedPointer<QTranslator> translator(new QTranslator); + // Doesn't matter which language it is, as we won't be using it anyway. + QVERIFY(translator->load("qtbase_fr.qm", ":/")); + QVERIFY(qApp->installTranslator(translator.data())); + + QQuickView view(testFileUrl("dialogButtonBoxWithCustomButtons.qml")); + if (view.status() != QQuickView::Ready) + QFAIL("Failed to load QML file"); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickDialog *dialog = view.rootObject()->property("dialog").value<QQuickDialog*>(); + QVERIFY(dialog); + + QQuickDialogButtonBox *dialogButtonBox = qobject_cast<QQuickDialogButtonBox*>(dialog->footer()); + QVERIFY(dialogButtonBox); + + auto okButton = dialogButtonBox->findChild<QQuickAbstractButton*>("okButton"); + QVERIFY(okButton); + QCOMPARE(okButton->text(), QLatin1String("OK")); + + QQuickAbstractButton *cancelButton = dialogButtonBox->findChild<QQuickAbstractButton*>("cancelButton"); + QVERIFY(cancelButton); + QCOMPARE(cancelButton->text(), QLatin1String("Cancel")); + + // Delete the translator and hence cause a LanguageChange event, + // but _without_ calling QQmlEngine::retranslate(), which would + // restore the original bindings and hence not reproduce the issue. + translator.reset(); + QCOMPARE(okButton->text(), QLatin1String("OK")); + QCOMPARE(cancelButton->text(), QLatin1String("Cancel")); +} + +void tst_translation::comboBox() +{ + QQuickView view(testFileUrl("comboBox.qml")); + + QQuickComboBox *comboBox = qobject_cast<QQuickComboBox*>(view.rootObject()); + QVERIFY(comboBox); + QCOMPARE(comboBox->displayText(), QLatin1String("Hello")); + + QQuickTextField *contentItem = qobject_cast<QQuickTextField*>(comboBox->contentItem()); + QVERIFY(contentItem); + QCOMPARE(contentItem->text(), QLatin1String("Hello")); + + QTranslator translator; + QVERIFY(translator.load("qml_jp.qm", ":/")); + QVERIFY(qApp->installTranslator(&translator)); + view.engine()->retranslate(); + QTRY_COMPARE(comboBox->displayText(), QString::fromUtf8("こんにちは")); + QCOMPARE(contentItem->text(), QString::fromUtf8("こんにちは")); +} + QTEST_MAIN(tst_translation) #include "tst_translation.moc" |