diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-28 17:48:36 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-03-02 14:56:44 (GMT) |
commit | 440394d05989e1d20f82071045106117e907a378 (patch) | |
tree | 5e73663e33a12c70c3352f8e63f1293d2d79086a /tests | |
parent | 010471faf918cfab75032a569aab8e510e47a72a (diff) | |
download | Qt-440394d05989e1d20f82071045106117e907a378.zip Qt-440394d05989e1d20f82071045106117e907a378.tar.gz Qt-440394d05989e1d20f82071045106117e907a378.tar.bz2 |
Added writing script support to QLocale.
Task-number: QTBUG-17105
Reviewed-by: trustme
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 39 | ||||
-rw-r--r-- | tests/manual/qlocale/window.cpp | 28 |
2 files changed, 51 insertions, 16 deletions
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index 7a3e339..cb69d54 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -185,6 +185,7 @@ void tst_QLocale::ctor() QCOMPARE(l.language(), QLocale::C); QCOMPARE(l.country(), QLocale::AnyCountry); } + TEST_CTOR(AnyLanguage, AnyCountry, default_lang, default_country) TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(Aymara, AnyCountry, default_lang, default_country) TEST_CTOR(Aymara, France, default_lang, default_country) @@ -310,6 +311,7 @@ void tst_QLocale::ctor() TEST_CTOR("en@", English, UnitedStates) TEST_CTOR("en.@", English, UnitedStates) TEST_CTOR("en_", English, UnitedStates) + TEST_CTOR("en_U", English, UnitedStates) TEST_CTOR("en_.", English, UnitedStates) TEST_CTOR("en_.@", English, UnitedStates) TEST_CTOR("en.bla", English, UnitedStates) @@ -335,11 +337,35 @@ void tst_QLocale::ctor() TEST_CTOR("es-419", Spanish, LatinAmericaAndTheCaribbean) // test default countries for languages + TEST_CTOR("zh", Chinese, China) + TEST_CTOR("zh-Hans", Chinese, China) TEST_CTOR("mn", Mongolian, Mongolia) TEST_CTOR("ne", Nepali, Nepal) #undef TEST_CTOR +#define TEST_CTOR(req_lc, exp_lang, exp_script, exp_country) \ + { \ + QLocale l(req_lc); \ + QVERIFY2(l.language() == QLocale::exp_lang \ + && l.script() == QLocale::exp_script \ + && l.country() == QLocale::exp_country, \ + QString("requested: \"" + QString(req_lc) + "\", got: " \ + + QLocale::languageToString(l.language()) \ + + "/" + QLocale::scriptToString(l.script()) \ + + "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \ + } + + TEST_CTOR("zh_CN", Chinese, AnyScript, China) + TEST_CTOR("zh_Hans_CN", Chinese, SimplifiedHanScript, China) + TEST_CTOR("zh_Hans", Chinese, SimplifiedHanScript, China) + TEST_CTOR("zh_Hant", Chinese, TraditionalHanScript, HongKong) + TEST_CTOR("zh_Hans_MO", Chinese, SimplifiedHanScript, Macau) + TEST_CTOR("zh_Hant_MO", Chinese, TraditionalHanScript, Macau) + TEST_CTOR("az_Latn_AZ", Azerbaijani, LatinScript, Azerbaijan) + TEST_CTOR("ha_Arab_NG", Hausa, ArabicScript, Nigeria) + TEST_CTOR("ha_Latn_NG", Hausa, LatinScript, Nigeria) +#undef TEST_CTOR } void tst_QLocale::emptyCtor() @@ -412,11 +438,12 @@ void tst_QLocale::emptyCtor() TEST_CTOR("nb_NO", "nb_NO") TEST_CTOR("nn_NO", "nn_NO") + TEST_CTOR("DE", "de_DE"); + TEST_CTOR("EN", "en_US"); + TEST_CTOR("en/", defaultLoc) - TEST_CTOR("DE", defaultLoc); TEST_CTOR("asdfghj", defaultLoc); TEST_CTOR("123456", defaultLoc); - TEST_CTOR("EN", defaultLoc); #undef TEST_CTOR #endif @@ -2086,6 +2113,10 @@ void tst_QLocale::monthName() QCOMPARE(ru.monthName(1, QLocale::LongFormat), QString::fromUtf8("\321\217\320\275\320\262\320\260\321\200\321\217")); QCOMPARE(ru.monthName(1, QLocale::ShortFormat), QString::fromUtf8("\321\217\320\275\320\262\56")); QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257")); + + // check that our CLDR scripts handle surrogate pairs correctly + QLocale dsrt("en-Dsrt-US"); + QCOMPARE(dsrt.monthName(1, QLocale::LongFormat), QString::fromUtf8("\xf0\x90\x90\x96\xf0\x90\x90\xb0\xf0\x90\x91\x8c\xf0\x90\x90\xb7\xf0\x90\x90\xad\xf0\x90\x90\xaf\xf0\x90\x91\x89\xf0\x90\x90\xa8")); } void tst_QLocale::standaloneMonthName() @@ -2191,11 +2222,11 @@ void tst_QLocale::uiLanguages() const QLocale en_US("en_US"); QCOMPARE(en_US.uiLanguages().size(), 1); - QCOMPARE(en_US.uiLanguages().at(0), QLatin1String("en_US")); + QCOMPARE(en_US.uiLanguages().at(0), QLatin1String("en-US")); const QLocale ru_RU("ru_RU"); QCOMPARE(ru_RU.uiLanguages().size(), 1); - QCOMPARE(ru_RU.uiLanguages().at(0), QLatin1String("ru_RU")); + QCOMPARE(ru_RU.uiLanguages().at(0), QLatin1String("ru-RU")); } void tst_QLocale::weekendDays() diff --git a/tests/manual/qlocale/window.cpp b/tests/manual/qlocale/window.cpp index ed66c57..fae88a3 100644 --- a/tests/manual/qlocale/window.cpp +++ b/tests/manual/qlocale/window.cpp @@ -46,19 +46,19 @@ Window::Window() localeCombo->addItem("System", QLocale::system()); - int index = 0; - for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { - QLocale::Language lang = static_cast<QLocale::Language>(_lang); - QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang); - for (int i = 0; i < countries.count(); ++i) { - QLocale::Country country = countries.at(i); - QString label = QLocale::languageToString(lang); + QStringList locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + foreach (const QString &name, locales) { + QLocale locale(name); + QString label = QLocale::languageToString(locale.language()); + label += QLatin1Char('/'); + if (locale.script() != QLocale::AnyScript) { + label += QLocale::scriptToString(locale.script()); label += QLatin1Char('/'); - label += QLocale::countryToString(country); - localeCombo->addItem(label, QLocale(lang, country)); - ++index; } + label += QLocale::countryToString(locale.country()); + localeCombo->addItem(label, locale); } + connect(localeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(localeChanged(int))); @@ -102,15 +102,19 @@ void Window::systemLocaleChanged() { QLocale l = QLocale::system(); QString lang = QLocale::languageToString(l.language()); + QString script = QLocale::scriptToString(l.script()); QString country = QLocale::countryToString(l.country()); - localeCombo->setItemText(0, QString("System: %1/%2").arg(lang, country)); + if (l.script() != QLocale::AnyScript) + localeCombo->setItemText(0, QString("System: %1-%2-%3").arg(lang, script, country)); + else + localeCombo->setItemText(0, QString("System: %1-%2").arg(lang, country)); emit localeChanged(0); } void Window::localeChanged(int idx) { QLocale locale = localeCombo->itemData(idx).toLocale(); - localeName->setText(QString("Locale: %1").arg(locale.name())); + localeName->setText(QString("Locale: %1 (%2)").arg(locale.bcp47Name(), locale.name())); emit localeChanged(locale); } |