2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.i18n
.Calendar
;
24 import com
.sun
.star
.i18n
.Currency
;
25 import com
.sun
.star
.i18n
.ForbiddenCharacters
;
26 import com
.sun
.star
.i18n
.FormatElement
;
27 import com
.sun
.star
.i18n
.Implementation
;
28 import com
.sun
.star
.i18n
.LanguageCountryInfo
;
29 import com
.sun
.star
.i18n
.LocaleDataItem
;
30 import com
.sun
.star
.i18n
.XLocaleData
;
31 import com
.sun
.star
.lang
.Locale
;
34 * Testing <code>com.sun.star.i18n.XLocaleData</code>
37 * <li><code> getLanguageCountryInfo() </code></li>
38 * <li><code> getLocaleItem() </code></li>
39 * <li><code> getAllCalendars() </code></li>
40 * <li><code> getAllCurrencies() </code></li>
41 * <li><code> getAllFormats() </code></li>
42 * <li><code> getCollatorImplementations() </code></li>
43 * <li><code> getSearchOptions() </code></li>
44 * <li><code> getCollationOptions() </code></li>
45 * <li><code> getTransliterations() </code></li>
46 * <li><code> getForbiddenCharacters() </code></li>
47 * <li><code> getReservedWord() </code></li>
48 * <li><code> getAllInstalledLocaleNames() </code></li>
50 * Test is <b> NOT </b> multithread compliant. <p>
51 * @see com.sun.star.i18n.XLocaleData
53 public class _XLocaleData
extends MultiMethodTest
{
54 public XLocaleData oObj
= null;
55 public String
[] languages
= new String
[]{"de","en","es","fr","ja","ko","ko"};
56 public String
[] countries
= new String
[]{"DE","US","ES","FR","JP","KR","KR"};
60 * Test calls the method, then result is checked. <p>
61 * Has <b> OK </b> status if structure, returned by the method includes
62 * correct values of fields 'Language' and 'Country' for all given locales.
64 public void _getLanguageCountryInfo() {
66 LanguageCountryInfo lci
= null;
68 for (int i
=0;i
<7;i
++) {
69 lci
= oObj
.getLanguageCountryInfo(getLocale(i
));
71 log.println("Using: language="+languages[i]+" ; country="+countries[i]);
72 log.println("Getting: ");
73 log.println("\t Language="+lci.Language);
74 log.println("\t LanguageDefaultName="+lci.LanguageDefaultName);
75 log.println("\t Country="+lci.Country);
76 log.println("\t CountryDefaultName="+lci.CountryDefaultName);
77 boolean lang = ( lci.Language.equals(languages[i]) );
78 if (!lang) log.println("getting false for language: "+lci.LanguageDefaultName);
79 lang = ( lci.Country.equals(countries[i]) );
80 if (!lang) log.println("getting false for country: "+lci.CountryDefaultName);
82 res
&= ( ( lci
.Language
.equals(languages
[i
]) ) && ( lci
.Country
.equals(countries
[i
]) ) );
84 tRes
.tested("getLanguageCountryInfo()",res
);
88 * Test calls the method, then result is checked. <p>
89 * Has <b> OK </b> status if structure, returned by the method consists of
90 * non empty strings for all given locales.
92 public void _getLocaleItem() {
94 LocaleDataItem ldi
= null;
96 for (int i
=0;i
<7;i
++) {
97 ldi
= oObj
.getLocaleItem(getLocale(i
));
99 boolean locRes
= true ;
101 locRes
&= (! ldi
.dateSeparator
.equals(""));
102 locRes
&= (! ldi
.decimalSeparator
.equals(""));
103 locRes
&= (! ldi
.doubleQuotationEnd
.equals(""));
104 locRes
&= (! ldi
.doubleQuotationStart
.equals(""));
105 locRes
&= (! ldi
.listSeparator
.equals(""));
106 locRes
&= (! ldi
.LongDateDayOfWeekSeparator
.equals(""));
107 locRes
&= (! ldi
.LongDateDaySeparator
.equals(""));
108 locRes
&= (! ldi
.LongDateMonthSeparator
.equals(""));
109 locRes
&= (! ldi
.LongDateYearSeparator
.equals(""));
110 locRes
&= (! ldi
.measurementSystem
.equals(""));
111 locRes
&= (! ldi
.quotationEnd
.equals(""));
112 locRes
&= (! ldi
.quotationStart
.equals(""));
113 locRes
&= (! ldi
.thousandSeparator
.equals(""));
114 locRes
&= (! ldi
.time100SecSeparator
.equals(""));
115 locRes
&= (! ldi
.timeAM
.equals(""));
116 locRes
&= (! ldi
.timePM
.equals(""));
117 locRes
&= (! ldi
.timeSeparator
.equals(""));
118 locRes
&= (! ldi
.unoID
.equals(""));
121 /* for debugging purposes
122 log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
123 log.println("Getting: ");
124 log.println("\t DateSeparator="+ldi.dateSeparator);
125 log.println("\t decimalSeparator="+ldi.decimalSeparator);
126 log.println("\t doubleQuotationEnd="+ldi.doubleQuotationEnd);
127 log.println("\t doubleQuotationStart="+ldi.doubleQuotationStart);
128 log.println("\t listSeparator="+ldi.listSeparator);
129 log.println("\t LongDateDayOfWeekSeparator="+ldi.LongDateDayOfWeekSeparator+"end");
130 log.println("\t LongDateDaySeparator="+ldi.LongDateDaySeparator+"end");
131 log.println("\t LongDateMonthSeparator="+ldi.LongDateMonthSeparator+"end");
132 log.println("\t LongDateYearSeparator="+ldi.LongDateYearSeparator+"end");
133 log.println("\t measurementSystem="+ldi.measurementSystem);
134 log.println("\t quotationEnd="+ldi.quotationEnd);
135 log.println("\t quotationStart="+ldi.quotationStart);
136 log.println("\t thousandSeparator="+ldi.thousandSeparator);
137 log.println("\t time100SecSeparator="+ldi.time100SecSeparator);
138 log.println("\t timeAM="+ldi.timeAM);
139 log.println("\t timePM="+ldi.timePM);
140 log.println("\t timeSeparator="+ldi.timeSeparator);
141 log.println("\t unoID="+ldi.unoID);
145 tRes
.tested("getLocaleItem()",res
);
149 * Test calls the method for several locales; result is checked
150 * after each call. <p>
151 * Has <b> OK </b> status if all elements of the returned sequence are
152 * correct for all given locales. (boolean method goodCalendar() with a
153 * calendar as an argument returns true)
155 public void _getAllCalendars() {
157 boolean printit
= false;
158 Calendar
[] calendar
= new Calendar
[1];
160 for (int i
=0;i
<7;i
++) {
161 calendar
= oObj
.getAllCalendars(getLocale(i
));
162 for (int j
=0;j
<calendar
.length
;j
++) {
163 if (! goodCalendar(calendar
[j
]) ) {
166 res
&= goodCalendar(calendar
[j
]);
168 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
171 tRes
.tested("getAllCalendars()", res
);
175 * Test calls the method for several locales; result is checked
176 * after each call. <p>
177 * Has <b> OK </b> status if all elements of the returned sequence are
178 * correct for all given locales. (boolean method goodCurrency() with a
179 * currency as an argument returns true)
181 public void _getAllCurrencies() {
183 boolean printit
= false;
184 Currency
[] currency
= new Currency
[1];
186 for (int i
=0;i
<7;i
++) {
187 currency
= oObj
.getAllCurrencies(getLocale(i
));
188 for (int j
=0;j
<currency
.length
;j
++) {
189 if (! goodCurrency(currency
[j
]) ) {
192 res
&= goodCurrency(currency
[j
]);
194 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
197 tRes
.tested("getAllCurrencies()",res
);
201 * Test calls the method for several locales; result is checked
202 * after each call. <p>
203 * Has <b> OK </b> status if all elements of the returned sequence are
204 * correct for all given locales. (boolean method goodFormat() with a
205 * format as an argument returns true)
207 public void _getAllFormats() {
209 boolean printit
= false;
210 FormatElement
[] format
= new FormatElement
[1];
212 for (int i
=0;i
<7;i
++) {
213 format
= oObj
.getAllFormats(getLocale(i
));
214 for (int j
=0;j
<format
.length
;j
++) {
215 if (! goodFormat(format
[j
]) ) {
218 res
&= goodFormat(format
[j
]);
220 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
223 tRes
.tested("getAllFormats()",res
);
227 * Test calls the method for several locales; result is checked
228 * after each call. <p>
229 * Has <b> OK </b> status if all structs, returned by the method have non
230 * empty field 'UnoID' for all given locales.
232 public void _getCollatorImplementations() {
234 boolean printit
= false;
235 Implementation
[] impl
= new Implementation
[1];
237 for (int i
=0;i
<7;i
++) {
238 impl
= oObj
.getCollatorImplementations(getLocale(i
));
239 for (int j
=0;j
<impl
.length
;j
++) {
240 if ((impl
[j
].unoID
.equals(""))) {
243 res
&= (!impl
[j
].unoID
.equals(""));
245 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
246 + " ; country=" + countries
[i
]);
249 tRes
.tested("getCollatorImplementations()", res
);
253 * Test calls the method for several locales; result is checked
254 * after each call. <p>
255 * Has <b> OK </b> status if all strings, returned by the method are not
256 * empty for all given locales.
258 public void _getSearchOptions() {
260 boolean printit
= false;
261 String
[] str
= new String
[1];
263 for (int i
=0;i
<7;i
++) {
264 str
= oObj
.getSearchOptions(getLocale(i
));
265 for (int j
=0;j
<str
.length
;j
++) {
266 if ((str
[j
].equals(""))) {
269 res
&= (!str
.equals(""));
271 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
272 + " ; country=" + countries
[i
]);
275 tRes
.tested("getSearchOptions()",res
);
279 * Test calls the method for several locales; result is checked
280 * after each call. <p>
281 * Has <b> OK </b> status if all strings, returned by the method are not
282 * empty for all given locales.
284 public void _getCollationOptions() {
286 boolean printit
= false;
287 String
[] str
= new String
[1];
289 for (int i
=0;i
<7;i
++) {
290 str
= oObj
.getCollationOptions(getLocale(i
));
291 for (int j
=0;j
<str
.length
;j
++) {
292 if ((str
[j
].equals(""))) {
295 res
&= (!str
.equals(""));
297 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
298 + " ; country=" + countries
[i
]);
301 tRes
.tested("getCollationOptions()", res
);
305 * Test calls the method for several locales; result is checked
306 * after each call. <p>
307 * Has <b> OK </b> status if all strings, returned by the method are not
308 * empty for all given locales.
310 public void _getTransliterations() {
312 boolean printit
= false;
313 String
[] str
= new String
[1];
315 for (int i
=0;i
<7;i
++) {
316 str
= oObj
.getTransliterations(getLocale(i
));
317 for (int j
=0;j
<str
.length
;j
++) {
318 if ((str
[j
].equals(""))) {
321 res
&= (!str
.equals(""));
323 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
324 + " ; country=" + countries
[i
]);
327 tRes
.tested("getTransliterations()", res
);
331 * Test calls the method for several locales; result is checked
332 * after each call. <p>
333 * Has <b> OK </b> status if the method returns structure with non-empty
334 * fields for all given locales.
336 public void _getForbiddenCharacters() {
338 ForbiddenCharacters fc
= null;
340 //the forbidden characters are only available for the asian languages
341 for (int i
=4;i
<7;i
++) {
342 fc
= oObj
.getForbiddenCharacters(getLocale(i
));
343 res
&= !( fc
.beginLine
.equals("") || fc
.endLine
.equals("") );
345 log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
348 tRes
.tested("getForbiddenCharacters()", res
);
353 * Test calls the method for several locales; result is checked
354 * after each call. <p>
355 * Has <b> OK </b> status if all strings, returned by the method are not
356 * empty for all given locales.
358 public void _getReservedWord() {
360 boolean printit
= false;
361 String
[] str
= new String
[1];
363 for (int i
=0;i
<7;i
++) {
364 str
= oObj
.getReservedWord(getLocale(i
));
365 for (int j
=0;j
<str
.length
;j
++) {
366 if ((str
[j
].equals(""))) {
369 res
&= (!str
.equals(""));
371 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
372 + " ; country=" + countries
[i
]);
375 tRes
.tested("getReservedWord()", res
);
380 * Test calls the method. Then result is checked for all given locales.<p>
381 * Has <b> OK </b> status if locale sequence, returned by the method contains
384 public void _getAllInstalledLocaleNames() {
386 Locale
[] locs
= oObj
.getAllInstalledLocaleNames();
388 //check if the languages used here are part of this array
389 for (int i
=0;i
<7;i
++) {
390 res
&= contains(locs
, getLocale(i
));
392 tRes
.tested("getAllInstalledLocaleNames()",res
);
397 * Method returns locale for a given language and country.
398 * @param k index of needed locale.
399 * @return Locale by the index from arrays defined above
401 public Locale
getLocale(int k
) {
402 return new Locale(languages
[k
],countries
[k
],"");
406 * Method checks given calendar for non empty fields.
407 * @param calendar Calendar to be checked
409 public boolean goodCalendar(Calendar calendar
) {
411 for (int i
=0;i
<calendar
.Days
.length
;i
++) {
412 good
&= (! calendar
.Days
[i
].AbbrevName
.equals("") );
413 good
&= (! calendar
.Days
[i
].FullName
.equals("") );
414 good
&= (! calendar
.Days
[i
].ID
.equals("") );
416 for (int i
=0;i
<calendar
.Months
.length
;i
++) {
417 good
&= (! calendar
.Months
[i
].AbbrevName
.equals("") );
418 good
&= (! calendar
.Months
[i
].FullName
.equals("") );
419 good
&= (! calendar
.Months
[i
].ID
.equals("") );
421 for (int i
=0;i
<calendar
.Eras
.length
;i
++) {
422 good
&= (! calendar
.Eras
[i
].AbbrevName
.equals("") );
423 good
&= (! calendar
.Eras
[i
].FullName
.equals("") );
424 good
&= (! calendar
.Eras
[i
].ID
.equals("") );
426 good
&= (! calendar
.StartOfWeek
.equals("") );
427 good
&= (! calendar
.Name
.equals("") );
432 * Method checks given currency for non empty fields.
433 * @param currency Currency to be checked
435 public boolean goodCurrency(Currency currency
) {
437 good
&= (!currency
.BankSymbol
.equals(""));
438 good
&= (!currency
.Name
.equals(""));
439 good
&= (!currency
.Symbol
.equals(""));
444 * Method checks given format for non empty fields.
445 * @param format Format to be checked
447 public boolean goodFormat(FormatElement format
) {
449 good
&= (!format
.formatCode
.equals(""));
450 good
&= (!format
.formatKey
.equals(""));
451 good
&= (!format
.formatType
.equals(""));
452 good
&= (!format
.formatUsage
.equals(""));
457 * Method checks that locale sequence contains given locale.
458 * @param locs Locale sequence
459 * @param oneLoc given locale
461 public boolean contains(Locale
[] locs
, Locale oneLoc
) {
462 boolean cont
= false;
463 for (int j
=0;j
<locs
.length
;j
++) {
464 if ( (locs
[j
].Country
.equals(oneLoc
.Country
)) &&
465 (locs
[j
].Language
.equals(oneLoc
.Language
)) ) {
470 if (!cont
) log
.println("Not contained: " + oneLoc
.Language
);