diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-09-02 14:52:25 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-09-06 20:40:12 +0200 |
commit | 78dee15da43597126d0a8579cf5db3ec4f019ca8 (patch) | |
tree | 3d70687ba15fc5a1520070f666b7b772fbd74786 /tests/auto | |
parent | 71cc5e3ed54c17dfe91880b4dffefc2081fd13d6 (diff) |
Fix QLocale::system() standalone day and month handling
Some backends were missing support for standalone days and months,
also the standaloneDayName() implementation was always using the
same codepath as dayName().
This patch fixes the issues.
Support for narrow format will be added in the following patch.
Task-number: QTBUG-84877
Pick-to: 6.2
Change-Id: I38ee06342cafab544e3c69097bd0e6ae68e85645
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 57e5c5313d..de72c0a4c4 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -148,6 +148,11 @@ private slots: void systemLocale_data(); void systemLocale(); +#ifndef QT_NO_SYSTEMLOCALE + void systemLocaleDayAndMonthNames_data(); + void systemLocaleDayAndMonthNames(); +#endif + void numberGroupingIndia(); void numberFormatChakma(); @@ -3224,6 +3229,128 @@ void tst_QLocale::systemLocale() QCOMPARE(QLocale::system(), originalSystemLocale); } +#ifndef QT_NO_SYSTEMLOCALE + +void tst_QLocale::systemLocaleDayAndMonthNames_data() +{ + QTest::addColumn<QByteArray>("locale"); + QTest::addColumn<QDate>("date"); + QTest::addColumn<QLocale::FormatType>("format"); + QTest::addColumn<QString>("month"); + QTest::addColumn<QString>("standaloneMonth"); + QTest::addColumn<QString>("day"); + QTest::addColumn<QString>("standaloneDay"); + + // en_US and de_DE locale outputs for ICU and macOS are similar. + // ru_RU are different. + // Windows has its own representation for all of the locales + +#if QT_CONFIG(icu) + // августа, август, понедельник, понедельник + QTest::newRow("ru_RU 30.08.2021 long") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::LongFormat + << QString("\u0430\u0432\u0433\u0443\u0441\u0442\u0430") + << QString("\u0430\u0432\u0433\u0443\u0441\u0442") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a"); + // авг., авг., пн, пн + QTest::newRow("ru_RU 30.08.2021 short") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::ShortFormat + << QString("\u0430\u0432\u0433.") << QString("\u0430\u0432\u0433.") + << QString("\u043f\u043d") << QString("\u043f\u043d"); +#elif defined(Q_OS_DARWIN) + // августа, август, понедельник, понедельник + QTest::newRow("ru_RU 30.08.2021 long") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::LongFormat + << QString("\u0430\u0432\u0433\u0443\u0441\u0442\u0430") + << QString("\u0430\u0432\u0433\u0443\u0441\u0442") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a"); + // авг., авг., Пн, Пн + QTest::newRow("ru_RU 30.08.2021 short") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::ShortFormat + << QString("\u0430\u0432\u0433.") << QString("\u0430\u0432\u0433.") + << QString("\u041f\u043d") << QString("\u041f\u043d"); +#endif + +#if QT_CONFIG(icu) || defined(Q_OS_DARWIN) + QTest::newRow("en_US 30.08.2021 long") + << QByteArray("en_US") << QDate(2021, 8, 30) << QLocale::LongFormat + << "August" << "August" << "Monday" << "Monday"; + QTest::newRow("en_US 30.08.2021 short") + << QByteArray("en_US") << QDate(2021, 8, 30) << QLocale::ShortFormat + << "Aug" << "Aug" << "Mon" << "Mon"; + + QTest::newRow("de_DE 30.08.2021 long") + << QByteArray("de_DE") << QDate(2021, 8, 30) << QLocale::LongFormat + << "August" << "August" << "Montag" << "Montag"; + QTest::newRow("de_DE 30.08.2021 short") + << QByteArray("de_DE") << QDate(2021, 8, 30) << QLocale::ShortFormat + << "Aug." << "Aug" << "Mo." << "Mo"; +#elif defined(Q_OS_WIN) + // августа, Август, понедельник, понедельник + QTest::newRow("ru_RU 30.08.2021 long") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::LongFormat + << QString("\u0430\u0432\u0433\u0443\u0441\u0442\u0430") + << QString("\u0410\u0432\u0433\u0443\u0441\u0442") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a") + << QString("\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a"); + // авг, авг, Пн, пн + QTest::newRow("ru_RU 30.08.2021 short") + << QByteArray("ru_RU") << QDate(2021, 8, 30) << QLocale::ShortFormat + << QString("\u0430\u0432\u0433") << QString("\u0430\u0432\u0433") + << QString("\u041f\u043d") << QString("\u043f\u043d"); + + QTest::newRow("en_US 30.08.2021 long") + << QByteArray("en_US") << QDate(2021, 8, 30) << QLocale::LongFormat + << "August" << "August" << "Monday" << "Monday"; + QTest::newRow("en_US 30.08.2021 short") + << QByteArray("en_US") << QDate(2021, 8, 30) << QLocale::ShortFormat + << "Aug" << "Aug" << "Mon" << "Mon"; + + QTest::newRow("de_DE 30.08.2021 long") + << QByteArray("de_DE") << QDate(2021, 8, 30) << QLocale::LongFormat + << "August" << "August" << "Montag" << "Montag"; + QTest::newRow("de_DE 30.08.2021 short") + << QByteArray("de_DE") << QDate(2021, 8, 30) << QLocale::ShortFormat + << "Aug" << "Aug" << "Mo" << "Mo"; +#else + QSKIP("This test can't run on this OS"); +#endif +} + +void tst_QLocale::systemLocaleDayAndMonthNames() +{ + QFETCH(QByteArray, locale); + QFETCH(QDate, date); + QFETCH(QLocale::FormatType, format); + QFETCH(QString, month); + QFETCH(QString, standaloneMonth); + QFETCH(QString, day); + QFETCH(QString, standaloneDay); + locale += ".UTF-8"; // So we don't have to repeat it on every data row ! + + const TransientLocale tested(LC_ALL, locale.constData()); + + QLocale sys = QLocale::system(); +#if !QT_CONFIG(icu) + // setlocale() does not really change locale on Windows and macOS, we + // need to actually set the locale manually to run the test + if (!locale.startsWith(sys.name().toLatin1())) + QSKIP(("Set locale to " + locale + " manually to run this test.").constData()); +#endif + + const int m = date.month(); + QCOMPARE(sys.monthName(m, format), month); + QCOMPARE(sys.standaloneMonthName(m, format), standaloneMonth); + + const int d = date.dayOfWeek(); + QCOMPARE(sys.dayName(d, format), day); + QCOMPARE(sys.standaloneDayName(d, format), standaloneDay); +} + +#endif // QT_NO_SYSTEMLOCALE + void tst_QLocale::numberGroupingIndia() { const QLocale indian(QLocale::Hindi, QLocale::India); |