diff options
Diffstat (limited to 'tests/auto/qml/qqmlengine/tst_qqmlengine.cpp')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index ff8d6e2b2c..1e9b6434c4 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -1195,34 +1195,47 @@ void tst_qqmlengine::createComponentOnSingletonDestruction() void tst_qqmlengine::uiLanguage() { - QQmlEngine engine; + { + QQmlEngine engine; - QObject::connect(&engine, &QJSEngine::uiLanguageChanged, [&engine]() { - engine.retranslate(); - }); + QObject::connect(&engine, &QJSEngine::uiLanguageChanged, [&engine]() { + engine.retranslate(); + }); - QSignalSpy uiLanguageChangeSpy(&engine, SIGNAL(uiLanguageChanged())); + QSignalSpy uiLanguageChangeSpy(&engine, SIGNAL(uiLanguageChanged())); - QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); + QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - QScopedPointer<QObject> object(component.create()); - QVERIFY(!object.isNull()); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); - QVERIFY(engine.uiLanguage().isEmpty()); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 1); + QVERIFY(engine.uiLanguage().isEmpty()); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 1); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - engine.setUiLanguage("TestLanguage"); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 2); - QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + engine.setUiLanguage("TestLanguage"); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 2); + QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + engine.evaluate("Qt.uiLanguage = \"anotherLanguage\""); + QCOMPARE(engine.uiLanguage(), QString("anotherLanguage")); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 3); + QCOMPARE(object->property("chosenLanguage").toString(), "anotherLanguage"); + } + + { + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - engine.evaluate("Qt.uiLanguage = \"anotherLanguage\""); - QCOMPARE(engine.uiLanguage(), QString("anotherLanguage")); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 3); - QCOMPARE(object->property("chosenLanguage").toString(), "anotherLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + engine.setUiLanguage("TestLanguage"); + QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + } } QTEST_MAIN(tst_qqmlengine) |