diff options
author | Eike Rathke <erack@redhat.com> | 2013-04-03 18:35:05 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-04-03 21:19:24 +0200 |
commit | 8d470713b6187e6284077a7b951335ecacd8befa (patch) | |
tree | 927472b36377b31c2df05ef3a22361007c9daa11 /i18npool/qa | |
parent | f51aff9e69b2eb5ad60167a055a969842eb3bcb8 (diff) |
test IsoLangEntry table LanguageTag conversions
Change-Id: Ie56e68459f655a66bf33368cee5e9a99b9dd0141
Diffstat (limited to 'i18npool/qa')
-rw-r--r-- | i18npool/qa/cppunit/test_languagetag.cxx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/i18npool/qa/cppunit/test_languagetag.cxx b/i18npool/qa/cppunit/test_languagetag.cxx index f2f6e3073153..227be2068677 100644 --- a/i18npool/qa/cppunit/test_languagetag.cxx +++ b/i18npool/qa/cppunit/test_languagetag.cxx @@ -14,6 +14,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/plugin/TestPlugIn.h> +#include <i18npool/mslangid.hxx> #include <i18npool/languagetag.hxx> #include <rtl/ustring.hxx> @@ -41,9 +42,11 @@ public: virtual ~TestLanguageTag() {} void testAllTags(); + void testAllIsoLangEntries(); CPPUNIT_TEST_SUITE(TestLanguageTag); CPPUNIT_TEST(testAllTags); + CPPUNIT_TEST(testAllIsoLangEntries); CPPUNIT_TEST_SUITE_END(); }; @@ -274,6 +277,53 @@ void TestLanguageTag::testAllTags() } } +void TestLanguageTag::testAllIsoLangEntries() +{ + const MsLangId::IsoLangEntry* pLangEntry; + sal_Int32 nIndex = 0; + while (((pLangEntry = MsLangId::getIsoLangEntry( nIndex++ )) != NULL) && (pLangEntry->mnLang != LANGUAGE_DONTKNOW)) + { + LanguageTag aTagString( pLangEntry->getTagString(), true); + LanguageTag aTagID( pLangEntry->mnLang); + if (pLangEntry->getTagString() != aTagString.getBcp47()) + { + OString aMessage( OUStringToOString( pLangEntry->getTagString(), RTL_TEXTENCODING_ASCII_US)); + aMessage += " -> " + OUStringToOString( aTagString.getBcp47(), RTL_TEXTENCODING_ASCII_US); + CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), pLangEntry->getTagString() == aTagString.getBcp47()); + } + if (pLangEntry->getTagString() != aTagID.getBcp47()) + { + // There are multiple mappings, ID must be equal after conversions. + LanguageTag aTagBack( aTagID.getBcp47(), true); + if (aTagString.getLanguageType() != aTagBack.getLanguageType()) + { + OString aMessage( OUStringToOString( pLangEntry->getTagString(), RTL_TEXTENCODING_ASCII_US)); + aMessage += " " + OString::number( aTagString.getLanguageType(), 16) + + " -> " + OString::number( aTagBack.getLanguageType(), 16); + CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), aTagString.getLanguageType() == aTagBack.getLanguageType()); + } + } +#if 0 + // This does not hold, there are cases like 'ar' + // LANGUAGE_ARABIC_PRIMARY_ONLY that when mapped back results in + // 'ar-SA' as default locale. + if (pLangEntry->mnLang != aTagString.getLanguageType()) + { + // There are multiple mappings, string must be equal after conversions. + LanguageTag aTagBack( aTagString.getLanguageType()); + if (aTagID.getBcp47() != aTagBack.getBcp47()) + { + OString aMessage( OUStringToOString( pLangEntry->getTagString(), RTL_TEXTENCODING_ASCII_US)); + aMessage += " " + OUStringToOString( aTagID.getBcp47(), RTL_TEXTENCODING_ASCII_US) + + " -> " + OUStringToOString( aTagBack.getBcp47(), RTL_TEXTENCODING_ASCII_US); + CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), aTagID.getBcp47() == aTagBack.getBcp47()); + } + } +#endif + } + +} + CPPUNIT_TEST_SUITE_REGISTRATION( TestLanguageTag ); } |