diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-31 01:00:06 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-31 01:00:06 +0100 |
commit | c6c3613af3229b818b37482bfe285bbdb2e09e85 (patch) | |
tree | 9ba2466de0f426b5e7c666c053e9a0aa6a32d3b8 /tests/auto/qml/qqmlqt | |
parent | e898490b4e6d6f85ea826a4e864b602e361fb7e5 (diff) | |
parent | f7647d5adaaed4c651cb2e65c7ce66d7ef6639f1 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I55a13797b753d2598f6f7cf817bba0d7768e37a3
Diffstat (limited to 'tests/auto/qml/qqmlqt')
-rw-r--r-- | tests/auto/qml/qqmlqt/data/formattingLocale.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 52 |
2 files changed, 52 insertions, 12 deletions
diff --git a/tests/auto/qml/qqmlqt/data/formattingLocale.qml b/tests/auto/qml/qqmlqt/data/formattingLocale.qml new file mode 100644 index 0000000000..9da349b101 --- /dev/null +++ b/tests/auto/qml/qqmlqt/data/formattingLocale.qml @@ -0,0 +1,12 @@ +import QtQml 2.15 + +QtObject { + required property var myDateTime + required property var myDate + property var myTime + + property string dateTimeString: Qt.formatDateTime(myDateTime, Qt.locale("de_DE"), Locale.NarrowFormat) + property string dateString: Qt.formatDate(myDate, Qt.locale("de_DE")) + + function invalidUsage() { Qt.formatTime(myTime, null, "hello") } +} diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 8fa18c9860..4a2e6841e7 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -91,6 +91,7 @@ private slots: void dateTimeFormatting_data(); void dateTimeFormattingVariants(); void dateTimeFormattingVariants_data(); + void dateTimeFormattingWithLocale(); void isQtObject(); void btoa(); void atob(); @@ -738,12 +739,12 @@ void tst_qqmlqt::dateTimeFormatting() QQmlComponent component(&eng, testFileUrl("formatting.qml")); QStringList warnings; - warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format" - << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments" - << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format" - << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments" - << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format" - << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments"; + warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":36: Error: Qt.formatDate(): Missing argument" + << component.url().toString() + ":40: Error: Qt.formatTime(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":39: Error: Qt.formatTime(): Missing argument" + << component.url().toString() + ":43: Error: Qt.formatDateTime(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":42: Error: Qt.formatDateTime(): Missing argument"; foreach (const QString &warning, warnings) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); @@ -773,6 +774,8 @@ void tst_qqmlqt::dateTimeFormatting() void tst_qqmlqt::dateTimeFormatting_data() { + QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED + // Test intentionally uses deprecated enumerators from Qt::DateFormat QTest::addColumn<QString>("method"); QTest::addColumn<QStringList>("inputProperties"); QTest::addColumn<QStringList>("expectedResults"); @@ -802,6 +805,7 @@ void tst_qqmlqt::dateTimeFormatting_data() << (QStringList() << dateTime.toString(Qt::DefaultLocaleShortDate) << dateTime.toString(Qt::DefaultLocaleLongDate) << dateTime.toString("M/d/yy H:m:s a")); + QT_WARNING_POP } void tst_qqmlqt::dateTimeFormattingVariants() @@ -814,12 +818,12 @@ void tst_qqmlqt::dateTimeFormattingVariants() QQmlComponent component(&eng, testFileUrl("formatting.qml")); QStringList warnings; - warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format" - << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments" - << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format" - << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments" - << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format" - << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments"; + warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":36: Error: Qt.formatDate(): Missing argument" + << component.url().toString() + ":40: Error: Qt.formatTime(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":39: Error: Qt.formatTime(): Missing argument" + << component.url().toString() + ":43: Error: Qt.formatDateTime(): Bad second argument (must be either string, number or locale)" + << component.url().toString() + ":42: Error: Qt.formatDateTime(): Missing argument"; foreach (const QString &warning, warnings) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); @@ -840,6 +844,8 @@ void tst_qqmlqt::dateTimeFormattingVariants() void tst_qqmlqt::dateTimeFormattingVariants_data() { + QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED + // Test intentionally uses deprecated enumerators from Qt::DateFormat QTest::addColumn<QString>("method"); QTest::addColumn<QVariant>("variant"); QTest::addColumn<QStringList>("expectedResults"); @@ -880,6 +886,28 @@ void tst_qqmlqt::dateTimeFormattingVariants_data() QTest::newRow("formatDate, int") << "formatDate" << QVariant::fromValue(integer) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); QTest::newRow("formatDateTime, int") << "formatDateTime" << QVariant::fromValue(integer) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); QTest::newRow("formatTime, int") << "formatTime" << QVariant::fromValue(integer) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + QT_WARNING_POP +} + +void tst_qqmlqt::dateTimeFormattingWithLocale() +{ + QQmlEngine engine; + auto url = testFileUrl("formattingLocale.qml"); + QQmlComponent comp(&engine, url); + QDateTime dateTime = QDateTime::fromString("M1d1y9800:01:02", + "'M'M'd'd'y'yyhh:mm:ss"); + QDate date(1995, 5, 17); + QScopedPointer<QObject> o(comp.createWithInitialProperties({ {"myDateTime", dateTime}, {"myDate", date} })); + QVERIFY(!o.isNull()); + + auto dateTimeString = o->property("dateTimeString").toString(); + QCOMPARE(dateTimeString, QLocale("de_DE").toString(dateTime, QLocale::NarrowFormat)); + auto dateString = o->property("dateString").toString(); + QCOMPARE(dateString, QLocale("de_DE").toString(date, QLocale::ShortFormat)); + + QString warningMsg = url.toString() + QLatin1String(":11: Error: Qt.formatTime(): Third argument must be a Locale format option"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, warningMsg.toUtf8().constData()); + QMetaObject::invokeMethod(o.get(), "invalidUsage"); } void tst_qqmlqt::isQtObject() |