aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-10-19 14:37:24 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-10-21 03:26:01 +0000
commit9e107fff416a20d298ed1d8d19def7fe998d5328 (patch)
tree40671158808e98d234c4996d659377d9f0ac849e
parentd04c122a526b68dfc59c025e8e6873dc766a14cf (diff)
tst_qqmllocale: evaluate QML in root object context instead of engine's
That way, enums from the Locale type are available and we don't need any workarounds. Change-Id: I1d96c0fd951678de4b4852f3a41ac3b45eb45b29 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 65be4cb32e77798a8e5c2602ccb196db18a57a0c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qqmllocale/data/functions.qml3
-rw-r--r--tests/auto/qml/qqmllocale/tst_qqmllocale.cpp12
2 files changed, 7 insertions, 8 deletions
diff --git a/tests/auto/qml/qqmllocale/data/functions.qml b/tests/auto/qml/qqmllocale/data/functions.qml
index 9fee78a836..42e26a508c 100644
--- a/tests/auto/qml/qqmllocale/data/functions.qml
+++ b/tests/auto/qml/qqmllocale/data/functions.qml
@@ -3,9 +3,6 @@ import QtQuick
QtObject {
property var locale: Qt.locale()
- // TODO: Workaround for not being able to use "Locale" in QQmlExpression (QTBUG-91747).
- property var localeType: Locale
-
function setLocale(l) {
locale = Qt.locale(l)
}
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
index 90420b7630..d058b6ec89 100644
--- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
+++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
@@ -663,15 +663,15 @@ void tst_qqmllocale::addFormattedDataSizeDataForLocale(const QString &localeStr)
expectedResult = locale.formattedDataSize(1000000, 3);
QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage;
- functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeIecFormat)");
+ functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeIecFormat)");
expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeIecFormat);
QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage;
- functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeTraditionalFormat)");
+ functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeTraditionalFormat)");
expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeTraditionalFormat);
QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage;
- functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeSIFormat)");
+ functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeSIFormat)");
expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeSIFormat);
QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage;
}
@@ -695,7 +695,7 @@ void tst_qqmllocale::formattedDataSize_data()
QString errorMessage = ".*Locale: formattedDataSize\\(\\): Expected 1-3 arguments, but received 0";
QTest::newRow("too few args") << "en_AU" << functionCallScript << QString() << errorMessage;
- functionCallScript = "locale.formattedDataSize(10, 1, localeType.DataSizeIecFormat, \"foo\")";
+ functionCallScript = "locale.formattedDataSize(10, 1, Locale.DataSizeIecFormat, \"foo\")";
errorMessage = ".*Locale: formattedDataSize\\(\\): Expected 1-3 arguments, but received 4";
QTest::newRow("too many args") << "en_AU" << functionCallScript << QString() << errorMessage;
@@ -727,7 +727,9 @@ void tst_qqmllocale::formattedDataSize()
QVERIFY(QMetaObject::invokeMethod(object.data(), "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(localeStr))));
- QQmlExpression qmlExpression(engine.rootContext(), object.data(), functionCallScript);
+ // Make sure that we use the object's context rather than the root context,
+ // so that e.g. enums from the Locale type are available (QTBUG-91747).
+ QQmlExpression qmlExpression(qmlContext(object.data()), object.data(), functionCallScript);
const QVariant evaluationResult = qmlExpression.evaluate();
if (expectedErrorMessagePattern.isEmpty()) {
QVERIFY2(!qmlExpression.hasError(), qPrintable(qmlExpression.error().toString()));