diff options
Diffstat (limited to 'tests/auto/qml/qqmllocale/tst_qqmllocale.cpp')
-rw-r--r-- | tests/auto/qml/qqmllocale/tst_qqmllocale.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index a90749208c..e3094db708 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -102,6 +102,7 @@ private slots: void numberFromLocaleString_data(); void numberFromLocaleString(); void numberConstToLocaleString(); + void numberOptions(); void stringLocaleCompare_data(); void stringLocaleCompare(); @@ -448,7 +449,7 @@ void tst_qqmllocale::firstDayOfWeek() Q_ARG(QVariant, QVariant(locale))); QVariant val = obj->property("firstDayOfWeek"); - QCOMPARE(val.type(), QVariant::Int); + QCOMPARE(val.userType(), QMetaType::Int); int day = int(QLocale(locale).firstDayOfWeek()); if (day == 7) // JS Date days in range 0(Sunday) to 6(Saturday) @@ -1157,6 +1158,35 @@ void tst_qqmllocale::numberConstToLocaleString() QCOMPARE(obj->property("const2").toString(), l.toString(1234., 'f', 2)); } +void tst_qqmllocale::numberOptions() +{ + QQmlEngine engine; + QQmlComponent comp(&engine); + comp.setData(R"( + import QtQml 2.15 + QtObject { + id: root + property string formatted + property bool caughtException: false + Component.onCompleted: () => { + const myLocale = Qt.locale("de_DE") + myLocale.numberOptions = Locale.OmitGroupSeparator | Locale.RejectTrailingZeroesAfterDot + root.formatted = Number(10000).toLocaleString(myLocale, 'f', 4) + try { + Number.fromLocaleString(myLocale, "1,10"); + } catch (e) {console.warn(e); root.caughtException = true} + } + } + )", QUrl("testdata")); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Error: Locale: Number.fromLocaleString(): Invalid format"); + QScopedPointer<QObject> root {comp.create()}; + qDebug() << comp.errorString(); + QVERIFY(root); + QCOMPARE(root->property("formatted").toString(), QLatin1String("10000,0000")); + QCOMPARE(root->property("caughtException").toBool(), true); + +} + void tst_qqmllocale::stringLocaleCompare_data() { QTest::addColumn<QString>("string1"); |