Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <sal/config.h>
11 :
12 : #include <cppunit/TestFixture.h>
13 : #include <cppunit/TestAssert.h>
14 : #include <cppunit/extensions/HelperMacros.h>
15 : #include <cppunit/plugin/TestPlugIn.h>
16 :
17 : #include <i18nlangtag/mslangid.hxx>
18 : #include <i18nlangtag/languagetag.hxx>
19 :
20 : #include <rtl/ustring.hxx>
21 : #include <rtl/ustrbuf.hxx>
22 : #include <osl/file.hxx>
23 :
24 : #include <com/sun/star/lang/Locale.hpp>
25 :
26 : using namespace com::sun::star;
27 :
28 : // To test the replacement code add '&& 0' and also in
29 : // source/languagetag/languagetag.cxx
30 : #if defined(ENABLE_LIBLANGTAG)
31 : #define USE_LIBLANGTAG 1
32 : #else
33 : #define USE_LIBLANGTAG 0
34 : #endif
35 :
36 : namespace {
37 :
38 : class TestLanguageTag : public CppUnit::TestFixture
39 : {
40 : public:
41 2 : TestLanguageTag() {}
42 4 : virtual ~TestLanguageTag() {}
43 :
44 : void testAllTags();
45 : void testAllIsoLangEntries();
46 :
47 2 : CPPUNIT_TEST_SUITE(TestLanguageTag);
48 1 : CPPUNIT_TEST(testAllTags);
49 1 : CPPUNIT_TEST(testAllIsoLangEntries);
50 5 : CPPUNIT_TEST_SUITE_END();
51 : };
52 :
53 1 : void TestLanguageTag::testAllTags()
54 : {
55 : {
56 1 : OUString s_de_Latn_DE( "de-Latn-DE" );
57 2 : LanguageTag de_DE( s_de_Latn_DE, true );
58 2 : OUString aBcp47 = de_DE.getBcp47();
59 2 : lang::Locale aLocale = de_DE.getLocale();
60 1 : LanguageType nLanguageType = de_DE.getLanguageType();
61 : #if USE_LIBLANGTAG
62 1 : CPPUNIT_ASSERT_MESSAGE("Default script should be stripped after canonicalize.", aBcp47 == "de-DE" );
63 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
64 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
65 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
66 1 : CPPUNIT_ASSERT( nLanguageType == LANGUAGE_GERMAN );
67 1 : CPPUNIT_ASSERT( de_DE.getLanguage() == "de" );
68 1 : CPPUNIT_ASSERT( de_DE.getCountry() == "DE" );
69 1 : CPPUNIT_ASSERT( de_DE.getScript().isEmpty() );
70 1 : CPPUNIT_ASSERT( de_DE.getLanguageAndScript() == "de" );
71 : #else
72 : // The simple replacement code doesn't do any fancy stuff.
73 : CPPUNIT_ASSERT_MESSAGE("Default script was stripped after canonicalize!?!", aBcp47 == s_de_Latn_DE );
74 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
75 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
76 : CPPUNIT_ASSERT( aLocale.Variant == "de-Latn-DE" );
77 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( nLanguageType) ); // XXX not canonicalized!
78 : CPPUNIT_ASSERT( de_DE.getLanguage() == "de" );
79 : CPPUNIT_ASSERT( de_DE.getCountry() == "DE" );
80 : CPPUNIT_ASSERT( de_DE.getScript() == "Latn" );
81 : CPPUNIT_ASSERT( de_DE.getLanguageAndScript() == "de-Latn" );
82 : #endif
83 2 : CPPUNIT_ASSERT( de_DE.makeFallback().getBcp47() == "de-DE");
84 : }
85 :
86 : {
87 1 : OUString s_klingon( "i-klingon" );
88 2 : LanguageTag klingon( s_klingon, true );
89 2 : lang::Locale aLocale = klingon.getLocale();
90 : #if USE_LIBLANGTAG
91 1 : CPPUNIT_ASSERT( klingon.getBcp47() == "tlh" );
92 1 : CPPUNIT_ASSERT( aLocale.Language == "tlh" );
93 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
94 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
95 1 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( klingon.getLanguageType()) );
96 1 : CPPUNIT_ASSERT( klingon.isValidBcp47() );
97 1 : CPPUNIT_ASSERT( klingon.isIsoLocale() );
98 1 : CPPUNIT_ASSERT( klingon.isIsoODF() );
99 1 : LanguageType nLang = klingon.getLanguageType();
100 2 : LanguageTag klingon_id( nLang);
101 2 : CPPUNIT_ASSERT( klingon_id.getBcp47() == "tlh" );
102 : #else
103 : CPPUNIT_ASSERT( klingon.getBcp47() == s_klingon );
104 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
105 : CPPUNIT_ASSERT( aLocale.Country == "" );
106 : CPPUNIT_ASSERT( aLocale.Variant == s_klingon );
107 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( klingon.getLanguageType()) );
108 : CPPUNIT_ASSERT( klingon.isValidBcp47() == true );
109 : CPPUNIT_ASSERT( klingon.isIsoLocale() == false );
110 : CPPUNIT_ASSERT( klingon.isIsoODF() == false );
111 : LanguageType nLang = klingon.getLanguageType();
112 : LanguageTag klingon_id( nLang);
113 : CPPUNIT_ASSERT( klingon_id.getBcp47() == s_klingon );
114 : #endif
115 : }
116 :
117 : {
118 1 : OUString s_sr_RS( "sr-RS" );
119 2 : LanguageTag sr_RS( s_sr_RS, true );
120 2 : lang::Locale aLocale = sr_RS.getLocale();
121 1 : CPPUNIT_ASSERT( sr_RS.getBcp47() == s_sr_RS );
122 1 : CPPUNIT_ASSERT( aLocale.Language == "sr" );
123 1 : CPPUNIT_ASSERT( aLocale.Country == "RS" );
124 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
125 1 : CPPUNIT_ASSERT( sr_RS.getLanguageType() == LANGUAGE_USER_SERBIAN_CYRILLIC_SERBIA );
126 1 : CPPUNIT_ASSERT( sr_RS.isValidBcp47() );
127 1 : CPPUNIT_ASSERT( sr_RS.isIsoLocale() );
128 2 : CPPUNIT_ASSERT( sr_RS.isIsoODF() );
129 : }
130 :
131 : {
132 1 : OUString s_sr_Latn_RS( "sr-Latn-RS" );
133 2 : LanguageTag sr_RS( s_sr_Latn_RS, true );
134 2 : lang::Locale aLocale = sr_RS.getLocale();
135 1 : CPPUNIT_ASSERT( sr_RS.getBcp47() == s_sr_Latn_RS );
136 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
137 1 : CPPUNIT_ASSERT( aLocale.Country == "RS" );
138 1 : CPPUNIT_ASSERT( aLocale.Variant == s_sr_Latn_RS );
139 1 : CPPUNIT_ASSERT( sr_RS.getLanguageType() == LANGUAGE_USER_SERBIAN_LATIN_SERBIA );
140 1 : CPPUNIT_ASSERT( sr_RS.isValidBcp47() );
141 1 : CPPUNIT_ASSERT( !sr_RS.isIsoLocale() );
142 1 : CPPUNIT_ASSERT( sr_RS.isIsoODF() );
143 1 : CPPUNIT_ASSERT( sr_RS.getLanguage() == "sr" );
144 1 : CPPUNIT_ASSERT( sr_RS.getCountry() == "RS" );
145 1 : CPPUNIT_ASSERT( sr_RS.getScript() == "Latn" );
146 2 : CPPUNIT_ASSERT( sr_RS.getLanguageAndScript() == "sr-Latn" );
147 : }
148 :
149 : {
150 1 : OUString s_sr_Latn_CS( "sr-Latn-CS" );
151 2 : LanguageTag sr_Latn_CS( s_sr_Latn_CS, true );
152 2 : lang::Locale aLocale = sr_Latn_CS.getLocale();
153 1 : CPPUNIT_ASSERT( sr_Latn_CS.getBcp47() == s_sr_Latn_CS );
154 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
155 1 : CPPUNIT_ASSERT( aLocale.Country == "CS" );
156 1 : CPPUNIT_ASSERT( aLocale.Variant == s_sr_Latn_CS );
157 1 : CPPUNIT_ASSERT( sr_Latn_CS.getLanguageType() == LANGUAGE_SERBIAN_LATIN_SAM );
158 1 : CPPUNIT_ASSERT( sr_Latn_CS.isValidBcp47() );
159 1 : CPPUNIT_ASSERT( !sr_Latn_CS.isIsoLocale() );
160 1 : CPPUNIT_ASSERT( sr_Latn_CS.isIsoODF() );
161 1 : CPPUNIT_ASSERT( sr_Latn_CS.getLanguage() == "sr" );
162 1 : CPPUNIT_ASSERT( sr_Latn_CS.getCountry() == "CS" );
163 1 : CPPUNIT_ASSERT( sr_Latn_CS.getScript() == "Latn" );
164 1 : CPPUNIT_ASSERT( sr_Latn_CS.getLanguageAndScript() == "sr-Latn" );
165 2 : ::std::vector< OUString > sr_Latn_CS_Fallbacks( sr_Latn_CS.getFallbackStrings( true));
166 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks.size() == 9);
167 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[0] == "sr-Latn-CS");
168 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[1] == "sr-Latn-YU");
169 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[2] == "sh-CS");
170 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[3] == "sh-YU");
171 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[4] == "sr-Latn");
172 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[5] == "sh");
173 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[6] == "sr-CS");
174 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[7] == "sr-YU");
175 1 : CPPUNIT_ASSERT( sr_Latn_CS_Fallbacks[8] == "sr");
176 2 : CPPUNIT_ASSERT( sr_Latn_CS.makeFallback().getBcp47() == "sr-Latn-CS");
177 : }
178 :
179 : // 'sh-RS' has an internal override to 'sr-Latn-RS'
180 : {
181 1 : OUString s_sh_RS( "sh-RS" );
182 2 : LanguageTag sh_RS( s_sh_RS, true );
183 2 : lang::Locale aLocale = sh_RS.getLocale();
184 1 : CPPUNIT_ASSERT( sh_RS.getBcp47() == "sr-Latn-RS" );
185 1 : CPPUNIT_ASSERT( aLocale.Language == I18NLANGTAG_QLT );
186 1 : CPPUNIT_ASSERT( aLocale.Country == "RS" );
187 1 : CPPUNIT_ASSERT( aLocale.Variant == "sr-Latn-RS" );
188 1 : CPPUNIT_ASSERT( sh_RS.getLanguageType() == LANGUAGE_USER_SERBIAN_LATIN_SERBIA );
189 1 : CPPUNIT_ASSERT( sh_RS.isValidBcp47() );
190 1 : CPPUNIT_ASSERT( !sh_RS.isIsoLocale() );
191 1 : CPPUNIT_ASSERT( sh_RS.isIsoODF() );
192 1 : CPPUNIT_ASSERT( sh_RS.getLanguage() == "sr" );
193 1 : CPPUNIT_ASSERT( sh_RS.getCountry() == "RS" );
194 1 : CPPUNIT_ASSERT( sh_RS.getScript() == "Latn" );
195 1 : CPPUNIT_ASSERT( sh_RS.getLanguageAndScript() == "sr-Latn" );
196 2 : ::std::vector< OUString > sh_RS_Fallbacks( sh_RS.getFallbackStrings( true));
197 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks.size() == 6);
198 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[0] == "sr-Latn-RS");
199 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[1] == "sh-RS");
200 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[2] == "sr-Latn");
201 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[3] == "sh");
202 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[4] == "sr-RS");
203 1 : CPPUNIT_ASSERT( sh_RS_Fallbacks[5] == "sr");
204 1 : CPPUNIT_ASSERT( sh_RS.makeFallback().getBcp47() == "sr-Latn-RS");
205 1 : CPPUNIT_ASSERT( sh_RS.getBcp47() == "sr-Latn-RS");
206 2 : CPPUNIT_ASSERT( sh_RS.getLanguageType() == LANGUAGE_USER_SERBIAN_LATIN_SERBIA );
207 : }
208 :
209 : // 'bs-Latn-BA' with 'Latn' suppress-script, we map that ourselves for a
210 : // known LangID with an override and canonicalization should work the same
211 : // without liblangtag.
212 : {
213 1 : OUString s_bs_Latn_BA( "bs-Latn-BA" );
214 2 : LanguageTag bs_Latn_BA( s_bs_Latn_BA, true );
215 2 : lang::Locale aLocale = bs_Latn_BA.getLocale();
216 1 : CPPUNIT_ASSERT( bs_Latn_BA.getBcp47() == "bs-BA" );
217 1 : CPPUNIT_ASSERT( aLocale.Language == "bs" );
218 1 : CPPUNIT_ASSERT( aLocale.Country == "BA" );
219 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
220 1 : CPPUNIT_ASSERT( bs_Latn_BA.getLanguageType() == LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA );
221 1 : CPPUNIT_ASSERT( bs_Latn_BA.isValidBcp47() );
222 1 : CPPUNIT_ASSERT( bs_Latn_BA.isIsoLocale() );
223 1 : CPPUNIT_ASSERT( bs_Latn_BA.isIsoODF() );
224 1 : CPPUNIT_ASSERT( bs_Latn_BA.getLanguage() == "bs" );
225 1 : CPPUNIT_ASSERT( bs_Latn_BA.getCountry() == "BA" );
226 1 : CPPUNIT_ASSERT( bs_Latn_BA.getScript().isEmpty() );
227 1 : CPPUNIT_ASSERT( bs_Latn_BA.getLanguageAndScript() == "bs" );
228 2 : ::std::vector< OUString > bs_Latn_BA_Fallbacks( bs_Latn_BA.getFallbackStrings( true));
229 1 : CPPUNIT_ASSERT( bs_Latn_BA_Fallbacks.size() == 2);
230 1 : CPPUNIT_ASSERT( bs_Latn_BA_Fallbacks[0] == "bs-BA");
231 1 : CPPUNIT_ASSERT( bs_Latn_BA_Fallbacks[1] == "bs");
232 1 : CPPUNIT_ASSERT( bs_Latn_BA.makeFallback().getBcp47() == "bs-BA");
233 1 : CPPUNIT_ASSERT( bs_Latn_BA.getBcp47() == "bs-BA");
234 2 : CPPUNIT_ASSERT( bs_Latn_BA.getLanguageType() == LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA );
235 : }
236 :
237 : {
238 1 : OUString s_ca_ES_valencia( "ca-ES-valencia" );
239 2 : LanguageTag ca_ES_valencia( s_ca_ES_valencia, true );
240 2 : lang::Locale aLocale = ca_ES_valencia.getLocale();
241 1 : CPPUNIT_ASSERT( ca_ES_valencia.getBcp47() == s_ca_ES_valencia );
242 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
243 1 : CPPUNIT_ASSERT( aLocale.Country == "ES" );
244 1 : CPPUNIT_ASSERT( aLocale.Variant == s_ca_ES_valencia );
245 1 : CPPUNIT_ASSERT( ca_ES_valencia.getLanguageType() == LANGUAGE_CATALAN_VALENCIAN );
246 1 : CPPUNIT_ASSERT( ca_ES_valencia.isValidBcp47() );
247 1 : CPPUNIT_ASSERT( !ca_ES_valencia.isIsoLocale() );
248 1 : CPPUNIT_ASSERT( !ca_ES_valencia.isIsoODF() );
249 1 : CPPUNIT_ASSERT( ca_ES_valencia.getLanguage() == "ca" );
250 1 : CPPUNIT_ASSERT( ca_ES_valencia.getCountry() == "ES" );
251 1 : CPPUNIT_ASSERT( ca_ES_valencia.getScript().isEmpty() );
252 1 : CPPUNIT_ASSERT( ca_ES_valencia.getLanguageAndScript() == "ca" );
253 2 : ::std::vector< OUString > ca_ES_valencia_Fallbacks( ca_ES_valencia.getFallbackStrings( true));
254 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks.size() == 5);
255 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[0] == "ca-ES-valencia");
256 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[1] == "ca-XV");
257 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[2] == "ca-valencia");
258 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[3] == "ca-ES");
259 1 : CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[4] == "ca");
260 2 : CPPUNIT_ASSERT( ca_ES_valencia.makeFallback().getBcp47() == "ca-ES-valencia");
261 : }
262 :
263 : {
264 1 : OUString s_ca_valencia( "ca-valencia" );
265 2 : LanguageTag ca_valencia( s_ca_valencia, true );
266 2 : lang::Locale aLocale = ca_valencia.getLocale();
267 1 : CPPUNIT_ASSERT( ca_valencia.getBcp47() == s_ca_valencia );
268 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
269 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
270 1 : CPPUNIT_ASSERT( aLocale.Variant == s_ca_valencia );
271 1 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( ca_valencia.getLanguageType()) );
272 1 : CPPUNIT_ASSERT( ca_valencia.isValidBcp47() );
273 1 : CPPUNIT_ASSERT( !ca_valencia.isIsoLocale() );
274 1 : CPPUNIT_ASSERT( !ca_valencia.isIsoODF() );
275 1 : CPPUNIT_ASSERT( ca_valencia.getLanguage() == "ca" );
276 1 : CPPUNIT_ASSERT( ca_valencia.getCountry().isEmpty() );
277 1 : CPPUNIT_ASSERT( ca_valencia.getScript().isEmpty() );
278 1 : CPPUNIT_ASSERT( ca_valencia.getLanguageAndScript() == "ca" );
279 2 : ::std::vector< OUString > ca_valencia_Fallbacks( ca_valencia.getFallbackStrings( true));
280 1 : CPPUNIT_ASSERT( ca_valencia_Fallbacks.size() == 2);
281 1 : CPPUNIT_ASSERT( ca_valencia_Fallbacks[0] == "ca-valencia");
282 1 : CPPUNIT_ASSERT( ca_valencia_Fallbacks[1] == "ca");
283 2 : CPPUNIT_ASSERT( ca_valencia.makeFallback().getBcp47() == "ca-ES-valencia");
284 : }
285 :
286 : // 'ca-XV' has an internal override to 'ca-ES-valencia'
287 : {
288 1 : OUString s_ca_XV( "ca-XV" );
289 2 : OUString s_ca_ES_valencia( "ca-ES-valencia" );
290 2 : LanguageTag ca_XV( s_ca_XV, true );
291 2 : lang::Locale aLocale = ca_XV.getLocale();
292 1 : CPPUNIT_ASSERT( ca_XV.getBcp47() == s_ca_ES_valencia );
293 1 : CPPUNIT_ASSERT( aLocale.Language == I18NLANGTAG_QLT );
294 1 : CPPUNIT_ASSERT( aLocale.Country == "ES" );
295 1 : CPPUNIT_ASSERT( aLocale.Variant == s_ca_ES_valencia );
296 1 : CPPUNIT_ASSERT( ca_XV.getLanguageType() == LANGUAGE_CATALAN_VALENCIAN );
297 1 : CPPUNIT_ASSERT( ca_XV.isValidBcp47() );
298 1 : CPPUNIT_ASSERT( !ca_XV.isIsoLocale() );
299 1 : CPPUNIT_ASSERT( !ca_XV.isIsoODF() );
300 1 : CPPUNIT_ASSERT( ca_XV.getLanguage() == "ca" );
301 1 : CPPUNIT_ASSERT( ca_XV.getCountry() == "ES" );
302 1 : CPPUNIT_ASSERT( ca_XV.getScript().isEmpty() );
303 1 : CPPUNIT_ASSERT( ca_XV.getLanguageAndScript() == "ca" );
304 2 : ::std::vector< OUString > ca_XV_Fallbacks( ca_XV.getFallbackStrings( true));
305 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks.size() == 5);
306 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks[0] == "ca-ES-valencia");
307 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks[1] == "ca-XV");
308 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks[2] == "ca-valencia");
309 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks[3] == "ca-ES");
310 1 : CPPUNIT_ASSERT( ca_XV_Fallbacks[4] == "ca");
311 2 : CPPUNIT_ASSERT( ca_XV.makeFallback().getBcp47() == "ca-ES-valencia");
312 : }
313 :
314 : {
315 1 : OUString s_de_DE( "de-DE" );
316 2 : LanguageTag de_DE( s_de_DE, true );
317 2 : lang::Locale aLocale = de_DE.getLocale();
318 1 : CPPUNIT_ASSERT( de_DE.getBcp47() == s_de_DE );
319 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
320 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
321 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
322 1 : CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN );
323 1 : CPPUNIT_ASSERT( de_DE.isValidBcp47() );
324 1 : CPPUNIT_ASSERT( de_DE.isIsoLocale() );
325 1 : CPPUNIT_ASSERT( de_DE.isIsoODF() );
326 1 : CPPUNIT_ASSERT( de_DE.getLanguage() == "de" );
327 1 : CPPUNIT_ASSERT( de_DE.getCountry() == "DE" );
328 1 : CPPUNIT_ASSERT( de_DE.getScript().isEmpty() );
329 1 : CPPUNIT_ASSERT( de_DE.getLanguageAndScript() == "de" );
330 2 : ::std::vector< OUString > de_DE_Fallbacks( de_DE.getFallbackStrings( true));
331 1 : CPPUNIT_ASSERT( de_DE_Fallbacks.size() == 2);
332 1 : CPPUNIT_ASSERT( de_DE_Fallbacks[0] == "de-DE");
333 1 : CPPUNIT_ASSERT( de_DE_Fallbacks[1] == "de");
334 2 : CPPUNIT_ASSERT( de_DE.makeFallback().getBcp47() == "de-DE");
335 : }
336 :
337 : {
338 1 : OUString s_de_DE( "de-DE" );
339 2 : LanguageTag de_DE( lang::Locale( "de", "DE", "" ) );
340 2 : lang::Locale aLocale = de_DE.getLocale();
341 1 : CPPUNIT_ASSERT( de_DE.getBcp47() == s_de_DE );
342 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
343 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
344 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
345 2 : CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN );
346 : }
347 :
348 : {
349 1 : OUString s_de_DE( "de-DE" );
350 2 : LanguageTag de_DE( LANGUAGE_GERMAN );
351 2 : lang::Locale aLocale = de_DE.getLocale();
352 1 : CPPUNIT_ASSERT( de_DE.getBcp47() == s_de_DE );
353 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
354 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
355 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
356 2 : CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN );
357 : }
358 :
359 : // Unmapped but known language-only.
360 : {
361 1 : OUString s_de( "de" );
362 2 : LanguageTag de( s_de, true );
363 2 : lang::Locale aLocale = de.getLocale();
364 1 : CPPUNIT_ASSERT( de.getBcp47() == s_de );
365 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
366 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
367 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
368 1 : LanguageType de_LangID = de.getLanguageType();
369 1 : CPPUNIT_ASSERT( de_LangID != LANGUAGE_GERMAN );
370 1 : CPPUNIT_ASSERT( de_LangID == MsLangId::getPrimaryLanguage( LANGUAGE_GERMAN) );
371 1 : CPPUNIT_ASSERT( de.makeFallback().getBcp47() == "de-DE");
372 : // Check registered mapping.
373 2 : LanguageTag de_l( de_LangID);
374 2 : CPPUNIT_ASSERT( de_l.getBcp47() == s_de );
375 : }
376 :
377 : // "bo" and "dz" share the same primary language ID, only one gets it
378 : // assigned, "dz" language-only has a special mapping.
379 : {
380 1 : LanguageTag bo( "bo", true );
381 1 : CPPUNIT_ASSERT( bo.getLanguageType() == MsLangId::getPrimaryLanguage( LANGUAGE_TIBETAN) );
382 2 : LanguageTag dz( "dz", true );
383 2 : CPPUNIT_ASSERT( dz.getLanguageType() == LANGUAGE_USER_DZONGKHA_MAP_LONLY );
384 : }
385 :
386 : // "no", "nb" and "nn" share the same primary language ID, which even is
387 : // assigned to "no-NO" for legacy so none gets it assigned, all on-the-fly
388 : // except if there is a defined MS-LCID for LanguageScriptOnly (LSO).
389 : {
390 1 : LanguageTag no( "no", true );
391 1 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( no.getLanguageType()) );
392 2 : LanguageTag nb( "nb", true );
393 1 : CPPUNIT_ASSERT( nb.getLanguageType() == LANGUAGE_NORWEGIAN_BOKMAL_LSO );
394 2 : LanguageTag nn( "nn", true );
395 1 : CPPUNIT_ASSERT( nn.getLanguageType() == LANGUAGE_NORWEGIAN_NYNORSK_LSO );
396 2 : LanguageTag no_NO( "no-NO", true );
397 2 : CPPUNIT_ASSERT( no_NO.getLanguageType() == LANGUAGE_NORWEGIAN );
398 : }
399 :
400 : // 'de-1901' derived from 'de-DE-1901' grandfathered to check that it is
401 : // accepted as (DIGIT 3ALNUM) variant
402 : {
403 1 : OUString s_de_1901( "de-1901" );
404 2 : LanguageTag de_1901( s_de_1901 );
405 2 : lang::Locale aLocale = de_1901.getLocale();
406 1 : CPPUNIT_ASSERT( de_1901.getBcp47() == s_de_1901 );
407 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
408 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
409 1 : CPPUNIT_ASSERT( aLocale.Variant == s_de_1901 );
410 1 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( de_1901.getLanguageType()) );
411 1 : CPPUNIT_ASSERT( de_1901.isValidBcp47() );
412 1 : CPPUNIT_ASSERT( !de_1901.isIsoLocale() );
413 1 : CPPUNIT_ASSERT( !de_1901.isIsoODF() );
414 1 : CPPUNIT_ASSERT( de_1901.getLanguageAndScript() == "de" );
415 1 : CPPUNIT_ASSERT( de_1901.getVariants() == "1901" );
416 2 : ::std::vector< OUString > de_1901_Fallbacks( de_1901.getFallbackStrings( true));
417 1 : CPPUNIT_ASSERT( de_1901_Fallbacks.size() == 2);
418 1 : CPPUNIT_ASSERT( de_1901_Fallbacks[0] == "de-1901");
419 2 : CPPUNIT_ASSERT( de_1901_Fallbacks[1] == "de");
420 : }
421 :
422 : // 'en-GB-oed' is known grandfathered for English, Oxford English
423 : // Dictionary spelling
424 : {
425 1 : OUString s_en_GB_oed( "en-GB-oed" );
426 2 : LanguageTag en_GB_oed( s_en_GB_oed );
427 2 : lang::Locale aLocale = en_GB_oed.getLocale();
428 1 : CPPUNIT_ASSERT( en_GB_oed.getBcp47() == s_en_GB_oed );
429 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
430 1 : CPPUNIT_ASSERT( aLocale.Country == "GB" ); // only 'GB' because we handle it, liblangtag would not fill this
431 1 : CPPUNIT_ASSERT( aLocale.Variant == s_en_GB_oed );
432 1 : CPPUNIT_ASSERT( en_GB_oed.getLanguageType() == LANGUAGE_USER_ENGLISH_UK_OED );
433 1 : CPPUNIT_ASSERT( en_GB_oed.isValidBcp47() );
434 1 : CPPUNIT_ASSERT( !en_GB_oed.isIsoLocale() );
435 1 : CPPUNIT_ASSERT( !en_GB_oed.isIsoODF() );
436 1 : CPPUNIT_ASSERT( en_GB_oed.getLanguageAndScript() == "en" );
437 1 : CPPUNIT_ASSERT( en_GB_oed.getVariants() == "oed" );
438 2 : ::std::vector< OUString > en_GB_oed_Fallbacks( en_GB_oed.getFallbackStrings( true));
439 1 : CPPUNIT_ASSERT( en_GB_oed_Fallbacks.size() == 3);
440 1 : CPPUNIT_ASSERT( en_GB_oed_Fallbacks[0] == "en-GB-oed");
441 1 : CPPUNIT_ASSERT( en_GB_oed_Fallbacks[1] == "en-GB");
442 2 : CPPUNIT_ASSERT( en_GB_oed_Fallbacks[2] == "en");
443 : // 'en-oed' is not a valid fallback!
444 : }
445 :
446 : #if USE_LIBLANGTAG
447 : // 'zh-yue-HK' uses redundant 'zh-yue' and should be preferred 'yue-HK'
448 : #if 0
449 : /* XXX Disabled because liblangtag in lt_tag_canonicalize() after replacing
450 : * 'zh-yue' with the preferred 'yue' does:
451 : * "If the language tag starts with a primary language subtag that is also
452 : * an extlang subtag, then the language tag is prepended with the extlang's
453 : * 'Prefix'."
454 : * Primary language 'yue' is also extlang 'yue' for which the prefix
455 : * happens to be 'zh' ... so the result is 'zh-yue-HK' again. */
456 : {
457 : OUString s_zh_yue_HK( "zh-yue-HK" );
458 : LanguageTag zh_yue_HK( s_zh_yue_HK );
459 : lang::Locale aLocale = zh_yue_HK.getLocale();
460 : CPPUNIT_ASSERT( zh_yue_HK.getBcp47() == "yue-HK" );
461 : CPPUNIT_ASSERT( aLocale.Language == "yue" );
462 : CPPUNIT_ASSERT( aLocale.Country == "HK" );
463 : CPPUNIT_ASSERT( aLocale.Variant == "" );
464 : CPPUNIT_ASSERT( zh_yue_HK.getLanguageType() == LANGUAGE_YUE_CHINESE_HONGKONG );
465 : CPPUNIT_ASSERT( zh_yue_HK.isValidBcp47() == true );
466 : CPPUNIT_ASSERT( zh_yue_HK.isIsoLocale() == true );
467 : CPPUNIT_ASSERT( zh_yue_HK.isIsoODF() == true );
468 : CPPUNIT_ASSERT( zh_yue_HK.getLanguageAndScript() == "yue" );
469 : CPPUNIT_ASSERT( zh_yue_HK.getVariants() == "" );
470 : ::std::vector< OUString > zh_yue_HK_Fallbacks( zh_yue_HK.getFallbackStrings( true));
471 : CPPUNIT_ASSERT( zh_yue_HK_Fallbacks.size() == 2);
472 : CPPUNIT_ASSERT( zh_yue_HK_Fallbacks[0] == "yue-HK");
473 : CPPUNIT_ASSERT( zh_yue_HK_Fallbacks[1] == "yue");
474 : }
475 : #endif
476 : #endif
477 :
478 : // 'qtz' is a local use known pseudolocale for key ID resource
479 : {
480 1 : OUString s_qtz( "qtz" );
481 2 : LanguageTag qtz( s_qtz );
482 2 : lang::Locale aLocale = qtz.getLocale();
483 1 : CPPUNIT_ASSERT( qtz.getBcp47() == s_qtz );
484 1 : CPPUNIT_ASSERT( aLocale.Language == "qtz" );
485 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
486 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
487 2 : CPPUNIT_ASSERT( qtz.getLanguageType() == LANGUAGE_USER_KEYID );
488 : }
489 :
490 : // 'qty' is a local use unknown locale
491 : {
492 1 : OUString s_qty( "qty" );
493 2 : LanguageTag qty( s_qty );
494 2 : lang::Locale aLocale = qty.getLocale();
495 1 : CPPUNIT_ASSERT( qty.getBcp47() == s_qty );
496 1 : CPPUNIT_ASSERT( aLocale.Language == "qty" );
497 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
498 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
499 2 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( qty.getLanguageType()) );
500 : }
501 :
502 : // 'x-comment' is a privateuse known "locale"
503 : {
504 1 : OUString s_xcomment( "x-comment" );
505 2 : LanguageTag xcomment( s_xcomment );
506 2 : lang::Locale aLocale = xcomment.getLocale();
507 1 : CPPUNIT_ASSERT( xcomment.getBcp47() == s_xcomment );
508 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
509 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
510 1 : CPPUNIT_ASSERT( aLocale.Variant == "x-comment" );
511 2 : CPPUNIT_ASSERT( xcomment.getLanguageType() == LANGUAGE_USER_PRIV_COMMENT );
512 : }
513 :
514 : // 'x-foobar' is a privateuse unknown "locale"
515 : {
516 1 : OUString s_xfoobar( "x-foobar" );
517 2 : LanguageTag xfoobar( s_xfoobar );
518 2 : lang::Locale aLocale = xfoobar.getLocale();
519 1 : CPPUNIT_ASSERT( xfoobar.getBcp47() == s_xfoobar );
520 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
521 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
522 1 : CPPUNIT_ASSERT( aLocale.Variant == "x-foobar" );
523 2 : CPPUNIT_ASSERT( LanguageTag::isOnTheFlyID( xfoobar.getLanguageType()) );
524 : }
525 :
526 : // '*' the dreaded jolly joker is a "privateuse" known "locale"
527 : {
528 1 : OUString s_joker( "*" );
529 2 : LanguageTag joker( s_joker );
530 2 : lang::Locale aLocale = joker.getLocale();
531 1 : CPPUNIT_ASSERT( joker.getBcp47() == s_joker );
532 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
533 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
534 1 : CPPUNIT_ASSERT( aLocale.Variant == "*" );
535 1 : CPPUNIT_ASSERT( joker.getLanguageType() == LANGUAGE_USER_PRIV_JOKER );
536 :
537 1 : joker.reset( LANGUAGE_USER_PRIV_JOKER );
538 1 : aLocale = joker.getLocale();
539 1 : CPPUNIT_ASSERT( joker.getBcp47() == s_joker );
540 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
541 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
542 1 : CPPUNIT_ASSERT( aLocale.Variant == "*" );
543 2 : CPPUNIT_ASSERT( joker.getLanguageType() == LANGUAGE_USER_PRIV_JOKER );
544 : }
545 :
546 : // test reset() methods
547 : {
548 1 : LanguageTag aTag( LANGUAGE_DONTKNOW );
549 2 : lang::Locale aLocale;
550 :
551 1 : aTag.reset( LANGUAGE_GERMAN );
552 1 : aLocale = aTag.getLocale();
553 1 : CPPUNIT_ASSERT( aTag.getBcp47() == "de-DE" );
554 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
555 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
556 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
557 1 : CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_GERMAN );
558 :
559 1 : aTag.reset( "en-US" );
560 1 : aLocale = aTag.getLocale();
561 1 : CPPUNIT_ASSERT( aTag.getBcp47() == "en-US" );
562 1 : CPPUNIT_ASSERT( aLocale.Language == "en" );
563 1 : CPPUNIT_ASSERT( aLocale.Country == "US" );
564 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
565 1 : CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_ENGLISH_US );
566 :
567 1 : aTag.reset( lang::Locale( "de", "DE", "" ) );
568 1 : aLocale = aTag.getLocale();
569 1 : CPPUNIT_ASSERT( aTag.getBcp47() == "de-DE" );
570 1 : CPPUNIT_ASSERT( aLocale.Language == "de" );
571 1 : CPPUNIT_ASSERT( aLocale.Country == "DE" );
572 1 : CPPUNIT_ASSERT( aLocale.Variant.isEmpty() );
573 2 : CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_GERMAN );
574 : }
575 :
576 : {
577 1 : OUString s_uab( "unreg-and-bad" );
578 2 : LanguageTag uab( s_uab, true );
579 2 : lang::Locale aLocale = uab.getLocale();
580 1 : CPPUNIT_ASSERT( uab.getBcp47() == s_uab );
581 1 : CPPUNIT_ASSERT( aLocale.Language == "qlt" );
582 1 : CPPUNIT_ASSERT( aLocale.Country.isEmpty() );
583 1 : CPPUNIT_ASSERT( aLocale.Variant == s_uab );
584 1 : CPPUNIT_ASSERT( uab.getLanguageType() == LANGUAGE_DONTKNOW );
585 1 : CPPUNIT_ASSERT( !uab.isValidBcp47() );
586 1 : CPPUNIT_ASSERT( !uab.isIsoLocale() );
587 2 : CPPUNIT_ASSERT( !uab.isIsoODF() );
588 : }
589 :
590 : // test static isValidBcp47() method
591 : {
592 1 : OUString aCanonicalized;
593 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "en-US", &aCanonicalized) && aCanonicalized == "en-US" );
594 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "x-foobar", &aCanonicalized) && aCanonicalized == "x-foobar" );
595 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "qaa", &aCanonicalized) && aCanonicalized == "qaa" );
596 1 : CPPUNIT_ASSERT( !LanguageTag::isValidBcp47( "unreg-and-bad", &aCanonicalized) );
597 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "en-US", &aCanonicalized, true) && aCanonicalized == "en-US" );
598 1 : CPPUNIT_ASSERT( !LanguageTag::isValidBcp47( "x-foobar", &aCanonicalized, true) && aCanonicalized == "x-foobar" );
599 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "qaa", &aCanonicalized, true) && aCanonicalized == "qaa" );
600 : #if USE_LIBLANGTAG
601 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "de-Latn-DE", &aCanonicalized) && aCanonicalized == "de-DE" );
602 : /* TODO: at least some (those we know) grandfathered tags should be
603 : * recognized by the replacement code. */
604 1 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "en-GB-oed", &aCanonicalized) && aCanonicalized == "en-GB-oed" );
605 : #else
606 : CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "de-Latn-DE", &aCanonicalized) && aCanonicalized == "de-Latn-DE" );
607 : #endif
608 : }
609 1 : }
610 :
611 555 : static bool checkMapping( const OUString& rStr1, const OUString& rStr2 )
612 : {
613 555 : if (rStr1 == "la-Latn" ) return rStr2 == "la";
614 554 : if (rStr1 == "tzm-Latn-DZ" ) return rStr2 == "kab-DZ";
615 553 : if (rStr1 == "bs-Latn-BA" ) return rStr2 == "bs-BA";
616 552 : if (rStr1 == "bs-Latn" ) return rStr2 == "bs";
617 551 : if (rStr1 == "cz" ) return rStr2 == "cs-CZ";
618 550 : if (rStr1 == "iw-IL" ) return rStr2 == "he-IL";
619 549 : if (rStr1 == "in-ID" ) return rStr2 == "id-ID";
620 548 : if (rStr1 == "sr-YU" ) return rStr2 == "sr-CS";
621 547 : if (rStr1 == "sh-RS" ) return rStr2 == "sr-Latn-RS";
622 545 : if (rStr1 == "sh-YU" ) return rStr2 == "sr-Latn-CS";
623 544 : if (rStr1 == "sh-CS" ) return rStr2 == "sr-Latn-CS";
624 543 : if (rStr1 == "sh-ME" ) return rStr2 == "sr-Latn-ME";
625 541 : if (rStr1 == "sh-BA" ) return rStr2 == "sr-Latn-BA";
626 540 : if (rStr1 == "sh" ) return rStr2 == "sr-Latn";
627 539 : if (rStr1 == "lah-PK" ) return rStr2 == "pnb-Arab-PK";
628 538 : if (rStr1 == "pa-PK" ) return rStr2 == "pnb-Arab-PK";
629 537 : if (rStr1 == "ca-XV" ) return rStr2 == "ca-ES-valencia";
630 536 : if (rStr1 == "qcv-ES" ) return rStr2 == "ca-ES-valencia";
631 535 : if (rStr1 == "ns-ZA" ) return rStr2 == "nso-ZA";
632 534 : if (rStr1 == "ven-ZA" ) return rStr2 == "ve-ZA";
633 533 : if (rStr1 == "qu-EC" ) return rStr2 == "quz-EC";
634 532 : if (rStr1 == "qu-PE" ) return rStr2 == "quz-PE";
635 531 : if (rStr1 == "ff-NG" ) return rStr2 == "fuv-NG";
636 530 : if (rStr1 == "ji-IL" ) return rStr2 == "yi-IL";
637 529 : if (rStr1 == "iu-CA" ) return rStr2 == "iu-Latn-CA";
638 528 : if (rStr1 == "iu" ) return rStr2 == "iu-Latn";
639 527 : if (rStr1 == "gbz-AF" ) return rStr2 == "prs-AF";
640 526 : if (rStr1 == "ber-DZ" ) return rStr2 == "kab-DZ";
641 525 : if (rStr1 == "tmz-MA" ) return rStr2 == "tzm-Tfng-MA";
642 523 : if (rStr1 == "ber-MA" ) return rStr2 == "tzm-Tfng-MA";
643 522 : if (rStr1 == "mg-MG" ) return rStr2 == "plt-MG";
644 521 : if (rStr1 == "pli" ) return rStr2 == "pi-Latn";
645 520 : if (rStr1 == "ks" ) return rStr2 == "ks-Arab";
646 519 : if (rStr1 == "chr-US" ) return rStr2 == "chr-Cher-US";
647 518 : if (rStr1 == "sd-PK" ) return rStr2 == "sd-Arab-PK";
648 517 : if (rStr1 == "sr-Cyrl-RS" ) return rStr2 == "sr-RS";
649 516 : if (rStr1 == "sr-Cyrl-ME" ) return rStr2 == "sr-ME";
650 515 : if (rStr1 == "sr-Cyrl-BA" ) return rStr2 == "sr-BA";
651 514 : if (rStr1 == "sr-Cyrl-CS" ) return rStr2 == "sr-CS";
652 513 : if (rStr1 == "sr-Cyrl" ) return rStr2 == "sr";
653 512 : if (rStr1 == "yi-Hebr-US" ) return rStr2 == "yi-US";
654 511 : if (rStr1 == "yi-Hebr-IL" ) return rStr2 == "yi-IL";
655 510 : if (rStr1 == "ha-NG" ) return rStr2 == "ha-Latn-NG";
656 509 : if (rStr1 == "ha-GH" ) return rStr2 == "ha-Latn-GH";
657 508 : if (rStr1 == "ku-Arab-IQ" ) return rStr2 == "ckb-IQ";
658 507 : if (rStr1 == "ku-Arab" ) return rStr2 == "ckb";
659 506 : if (rStr1 == "kmr-TR" ) return rStr2 == "kmr-Latn-TR";
660 505 : if (rStr1 == "ku-TR" ) return rStr2 == "kmr-Latn-TR";
661 504 : if (rStr1 == "kmr-SY" ) return rStr2 == "kmr-Latn-SY";
662 503 : if (rStr1 == "ku-SY" ) return rStr2 == "kmr-Latn-SY";
663 502 : if (rStr1 == "ku-IQ" ) return rStr2 == "ckb-IQ";
664 500 : if (rStr1 == "ku-IR" ) return rStr2 == "ckb-IR";
665 499 : return rStr1 == rStr2;
666 : }
667 :
668 1 : void TestLanguageTag::testAllIsoLangEntries()
669 : {
670 1 : const ::std::vector< MsLangId::LanguagetagMapping > aList( MsLangId::getDefinedLanguagetags());
671 556 : for (::std::vector< MsLangId::LanguagetagMapping >::const_iterator it( aList.begin()); it != aList.end(); ++it)
672 : {
673 555 : bool b=false;
674 555 : if ((*it).maBcp47 == "la-VA")
675 2 : b=true;
676 : (void)b;
677 :
678 555 : LanguageTag aTagString( (*it).maBcp47, true);
679 1110 : LanguageTag aTagID( (*it).mnLang);
680 555 : if (!checkMapping( (*it).maBcp47, aTagString.getBcp47()))
681 : {
682 0 : OString aMessage( OUStringToOString( (*it).maBcp47, RTL_TEXTENCODING_ASCII_US));
683 0 : aMessage += " -> " + OUStringToOString( aTagString.getBcp47(), RTL_TEXTENCODING_ASCII_US);
684 0 : CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), (*it).maBcp47 == aTagString.getBcp47());
685 : }
686 555 : if ((*it).maBcp47 != aTagID.getBcp47())
687 : {
688 : // There are multiple mappings, ID must be equal after conversions.
689 72 : LanguageTag aTagBack( aTagID.getBcp47(), true);
690 72 : if (aTagString.getLanguageType() != aTagBack.getLanguageType())
691 : {
692 0 : OString aMessage( OUStringToOString( (*it).maBcp47, RTL_TEXTENCODING_ASCII_US));
693 0 : aMessage += " " + OUStringToOString( aTagString.getBcp47(), RTL_TEXTENCODING_ASCII_US) + ": " +
694 0 : OUStringToOString( aTagString.getBcp47(), RTL_TEXTENCODING_ASCII_US) + " " +
695 0 : OString::number( aTagString.getLanguageType(), 16) +
696 0 : " -> " + OUStringToOString( aTagBack.getBcp47(), RTL_TEXTENCODING_ASCII_US) + " " +
697 0 : OString::number( aTagBack.getLanguageType(), 16);
698 0 : CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), aTagString.getLanguageType() == aTagBack.getLanguageType());
699 72 : }
700 : }
701 : #if 0
702 : // This does not hold, there are cases like 'ar'
703 : // LANGUAGE_ARABIC_PRIMARY_ONLY that when mapped back results in
704 : // 'ar-SA' as default locale.
705 : if ((*it).mnLang != aTagString.getLanguageType())
706 : {
707 : // There are multiple mappings, string must be equal after conversions.
708 : LanguageTag aTagBack( aTagString.getLanguageType());
709 : if (aTagID.getBcp47() != aTagBack.getBcp47())
710 : {
711 : OString aMessage( OUStringToOString( (*it).maBcp47, RTL_TEXTENCODING_ASCII_US));
712 : aMessage += " " + OUStringToOString( aTagID.getBcp47(), RTL_TEXTENCODING_ASCII_US) +
713 : " -> " + OUStringToOString( aTagBack.getBcp47(), RTL_TEXTENCODING_ASCII_US);
714 : CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), aTagID.getBcp47() == aTagBack.getBcp47());
715 : }
716 : }
717 : #endif
718 556 : }
719 :
720 : // Uncommenting this makes the test break and output SAL_WARN/INFO
721 : //CPPUNIT_ASSERT( true == false );
722 1 : }
723 :
724 1 : CPPUNIT_TEST_SUITE_REGISTRATION( TestLanguageTag );
725 :
726 : }
727 :
728 4 : CPPUNIT_PLUGIN_IMPLEMENT();
729 :
730 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|