diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-04-06 13:16:35 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-06-07 17:14:14 +0200 |
commit | cce3445e70ff98e55475c544c43177c2cd4a1034 (patch) | |
tree | e9c6d92b2c930fe93921a2cae6a94c4a4922a460 /tests | |
parent | b2871765ced8059e571d17d4010e8d8ada4e9190 (diff) |
Always include standard name in QLocale::uiLanguages()
Previously, for locales other than the system locale, no entry was
added to the list for the actual locale whose variants - with and
without likely sub-tags - were being appended. In most cases the
standard name will in fact coincide with the variant without likely
sub-tags, so this was unlikely to cause a problem, but it should be
present regardless.
At the same time, turn tst_QLocale::uiLanguages() into a data-driven
test and add another row to its table.
Change-Id: I5cb2d805d78fc3415d82b169caa6154b0f284708
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 7bfa366b66..32b47dbe01 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -128,6 +128,7 @@ private slots: void ampm(); void currency(); void quoteString(); + void uiLanguages_data(); void uiLanguages(); void weekendDays(); void listPatterns(); @@ -2741,47 +2742,49 @@ void tst_QLocale::quoteString() QCOMPARE(de_CH.quoteString(someText), QString::fromUtf8("\xe2\x80\x9e" "text" "\xe2\x80\x9c")); QCOMPARE(de_CH.quoteString(someText, QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\x9a" "text" "\xe2\x80\x98")); - } -void tst_QLocale::uiLanguages() +void tst_QLocale::uiLanguages_data() { - const QLocale c(QLocale::C); - QCOMPARE(c.uiLanguages().size(), 1); - QCOMPARE(c.uiLanguages().at(0), QLatin1String("C")); + QTest::addColumn<QLocale>("locale"); + QTest::addColumn<QStringList>("all"); - const QLocale en_US("en_US"); - QCOMPARE(en_US.uiLanguages().size(), 3); - QCOMPARE(en_US.uiLanguages().at(0), QLatin1String("en")); - QCOMPARE(en_US.uiLanguages().at(1), QLatin1String("en-US")); - QCOMPARE(en_US.uiLanguages().at(2), QLatin1String("en-Latn-US")); - - const QLocale en_Latn_US("en_Latn_US"); - QCOMPARE(en_Latn_US.uiLanguages().size(), 3); - QCOMPARE(en_Latn_US.uiLanguages().at(0), QLatin1String("en")); - QCOMPARE(en_Latn_US.uiLanguages().at(1), QLatin1String("en-US")); - QCOMPARE(en_Latn_US.uiLanguages().at(2), QLatin1String("en-Latn-US")); - - const QLocale en_GB("en_GB"); - QCOMPARE(en_GB.uiLanguages().size(), 2); - QCOMPARE(en_GB.uiLanguages().at(0), QLatin1String("en-GB")); - QCOMPARE(en_GB.uiLanguages().at(1), QLatin1String("en-Latn-GB")); - - const QLocale en_Dsrt_US("en_Dsrt_US"); - QCOMPARE(en_Dsrt_US.uiLanguages().size(), 2); - QCOMPARE(en_Dsrt_US.uiLanguages().at(0), QLatin1String("en-Dsrt")); - QCOMPARE(en_Dsrt_US.uiLanguages().at(1), QLatin1String("en-Dsrt-US")); + QTest::newRow("C") << QLocale::c() << QStringList{QString("C")}; - const QLocale ru_RU("ru_RU"); - QCOMPARE(ru_RU.uiLanguages().size(), 3); - QCOMPARE(ru_RU.uiLanguages().at(0), QLatin1String("ru")); - QCOMPARE(ru_RU.uiLanguages().at(1), QLatin1String("ru-RU")); - QCOMPARE(ru_RU.uiLanguages().at(2), QLatin1String("ru-Cyrl-RU")); - - const QLocale zh_Hant("zh_Hant"); - QCOMPARE(zh_Hant.uiLanguages().size(), 2); - QCOMPARE(zh_Hant.uiLanguages().at(0), QLatin1String("zh-TW")); - QCOMPARE(zh_Hant.uiLanguages().at(1), QLatin1String("zh-Hant-TW")); + QTest::newRow("en_US") + << QLocale("en_US") + << QStringList{QString("en"), QString("en-US"), QString("en-Latn-US")}; + + QTest::newRow("en_Latn_US") + << QLocale("en_Latn_US") // Specifying the default script makes no difference + << QStringList{QString("en"), QString("en-US"), QString("en-Latn-US")}; + + QTest::newRow("en_GB") + << QLocale("en_GB") + << QStringList{QString("en-GB"), QString("en-Latn-GB")}; + + QTest::newRow("en_Dsrt_US") + << QLocale("en_Dsrt_US") + << QStringList{QString("en-Dsrt"), QString("en-Dsrt-US")}; + + QTest::newRow("ru_RU") + << QLocale("ru_RU") + << QStringList{QString("ru"), QString("ru-RU"), QString("ru-Cyrl-RU")}; + + QTest::newRow("zh_Hant") + << QLocale("zh_Hant") + << QStringList{QString("zh-TW"), QString("zh-Hant-TW")}; + + QTest::newRow("zh_Hans_CN") + << QLocale(QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China) + << QStringList{QString("zh"), QString("zh-CN"), QString("zh-Hans-CN")}; +} + +void tst_QLocale::uiLanguages() +{ + QFETCH(const QLocale, locale); + QFETCH(const QStringList, all); + QCOMPARE(locale.uiLanguages(), all); } void tst_QLocale::weekendDays() |