summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2021-01-22 10:36:20 +0100
committerKai Köhne <kai.koehne@qt.io>2021-01-25 19:56:59 +0100
commite7c028bb9c262048538f3fc2fb50018707bd0955 (patch)
treea53e72286f2b6ad25daf88e8ab070e94bf02b71e /tests/auto/corelib
parentaa3b42d6342c6756c3ce941db0bbf1122ae48224 (diff)
QLocale: Allow direct conversion from language, country, and script codes
This complements patch a148c7b5d71d244, where languageToCode(), countryToCode() scriptToCode() methods were introduced, with matching codeToLanguage(), codeToCountry(), and codeToScript() methods. This allows us to remove the use of private Qt Core API in Qt Linguist. [ChangeLog][QtCore][QLocale] Added static codeToLanguage(), codeToCountry(), codeToScript() methods that convert ISO code strings to the respective enum values. Change-Id: If5c0843a718c006ade086a6f74ceb86ac6e0fce4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index 04c54b903b..4ed4bd0c11 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -151,6 +151,7 @@ private slots:
void numberFormatChakma();
void lcsToCode();
+ void codeToLcs();
// *** ORDER-DEPENDENCY *** (This Is Bad.)
// Test order is determined by order of declaration here: *all* tests that
@@ -3240,5 +3241,31 @@ void tst_QLocale::lcsToCode()
QCOMPARE(QLocale::scriptToCode(QLocale::SimplifiedHanScript), QString("Hans"));
}
+void tst_QLocale::codeToLcs()
+{
+ QCOMPARE(QLocale::codeToLanguage(QString()), QLocale::AnyLanguage);
+ QCOMPARE(QLocale::codeToLanguage(QString(" ")), QLocale::AnyLanguage);
+ QCOMPARE(QLocale::codeToLanguage(QString("und")), QLocale::AnyLanguage);
+ QCOMPARE(QLocale::codeToLanguage(QString("e")), QLocale::AnyLanguage);
+ QCOMPARE(QLocale::codeToLanguage(QString("en")), QLocale::English);
+ QCOMPARE(QLocale::codeToLanguage(QString("EN")), QLocale::English);
+ QCOMPARE(QLocale::codeToLanguage(QString("eng")), QLocale::AnyLanguage);
+ QCOMPARE(QLocale::codeToLanguage(QString("ha")), QLocale::Hausa);
+ QCOMPARE(QLocale::codeToLanguage(QString("haw")), QLocale::Hawaiian);
+
+ QCOMPARE(QLocale::codeToCountry(QString()), QLocale::AnyCountry);
+ QCOMPARE(QLocale::codeToCountry(QString("ZZ")), QLocale::AnyCountry);
+ QCOMPARE(QLocale::codeToCountry(QString("US")), QLocale::UnitedStates);
+ QCOMPARE(QLocale::codeToCountry(QString("us")), QLocale::UnitedStates);
+ QCOMPARE(QLocale::codeToCountry(QString("USA")), QLocale::AnyCountry);
+ QCOMPARE(QLocale::codeToCountry(QString("EU")), QLocale::EuropeanUnion);
+ QCOMPARE(QLocale::codeToCountry(QString("001")), QLocale::World);
+ QCOMPARE(QLocale::codeToCountry(QString("150")), QLocale::Europe);
+
+ QCOMPARE(QLocale::codeToScript(QString()), QLocale::AnyScript);
+ QCOMPARE(QLocale::codeToScript(QString("Zzzz")), QLocale::AnyScript);
+ QCOMPARE(QLocale::codeToScript(QString("Hans")), QLocale::SimplifiedHanScript);
+}
+
QTEST_MAIN(tst_QLocale)
#include "tst_qlocale.moc"