summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2020-12-11 16:40:37 +0100
committerKai Köhne <kai.koehne@qt.io>2021-01-18 15:52:31 +0100
commitf1465c621c11712991fabe5b8b81ccbb6eea4bb9 (patch)
tree638ea8c9f7e1cf9989736db30ad411a67939c815 /tests/auto/corelib
parent2d8757f879d8f410319aae41ff902ba5a679d9dd (diff)
QLocale: Allow direct conversion to language, country, and script codes
Currently the codes are only exposed in aggregated form, i.e. through name(), bcp47Name(). There are use cases though where you are only interested in either language, country, or script codes. One example is in Qt Linguist. This patch therefore exposes the static languageToCode(), countryToCode(), scriptToCode() methods that were so far only available in the private API also in the public API. [ChangeLog][QtCore][QLocale] Added static languageToCode(), countryToCode() scriptToCode() methods that convert enum values to the respective ISO code strings. Fixes: QTBUG-39542 Fixes: QTBUG-64942 Change-Id: Ib1d5c3293e2f53245ba4c1fc8159275bcb290080 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index 327cb7d714..04c54b903b 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -150,6 +150,8 @@ private slots:
void numberGroupingIndia();
void numberFormatChakma();
+ void lcsToCode();
+
// *** ORDER-DEPENDENCY *** (This Is Bad.)
// Test order is determined by order of declaration here: *all* tests that
// QLocale::setDefault() *must* appear *after* all other tests !
@@ -3224,5 +3226,19 @@ void tst_QLocale::numberFormatChakma()
QCOMPARE(chakma.toULongLong(strResult64), uint64);
}
+void tst_QLocale::lcsToCode()
+{
+ QCOMPARE(QLocale::languageToCode(QLocale::AnyLanguage), QString());
+ QCOMPARE(QLocale::languageToCode(QLocale::C), QString("C"));
+ QCOMPARE(QLocale::languageToCode(QLocale::English), QString("en"));
+
+ QCOMPARE(QLocale::countryToCode(QLocale::AnyCountry), QString());
+ QCOMPARE(QLocale::countryToCode(QLocale::UnitedStates), QString("US"));
+ QCOMPARE(QLocale::countryToCode(QLocale::EuropeanUnion), QString("EU"));
+
+ QCOMPARE(QLocale::scriptToCode(QLocale::AnyScript), QString());
+ QCOMPARE(QLocale::scriptToCode(QLocale::SimplifiedHanScript), QString("Hans"));
+}
+
QTEST_MAIN(tst_QLocale)
#include "tst_qlocale.moc"