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;
159 for (int i
=0;i
<7;i
++) {
160 Calendar
[] calendar
= oObj
.getAllCalendars(getLocale(i
));
161 for (int j
=0;j
<calendar
.length
;j
++) {
162 if (! goodCalendar(calendar
[j
]) ) {
165 res
&= goodCalendar(calendar
[j
]);
167 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
170 tRes
.tested("getAllCalendars()", res
);
174 * Test calls the method for several locales; result is checked
175 * after each call. <p>
176 * Has <b> OK </b> status if all elements of the returned sequence are
177 * correct for all given locales. (boolean method goodCurrency() with a
178 * currency as an argument returns true)
180 public void _getAllCurrencies() {
182 boolean printit
= false;
184 for (int i
=0;i
<7;i
++) {
185 Currency
[] currency
= oObj
.getAllCurrencies(getLocale(i
));
186 for (int j
=0;j
<currency
.length
;j
++) {
187 if (! goodCurrency(currency
[j
]) ) {
190 res
&= goodCurrency(currency
[j
]);
192 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
195 tRes
.tested("getAllCurrencies()",res
);
199 * Test calls the method for several locales; result is checked
200 * after each call. <p>
201 * Has <b> OK </b> status if all elements of the returned sequence are
202 * correct for all given locales. (boolean method goodFormat() with a
203 * format as an argument returns true)
205 public void _getAllFormats() {
207 boolean printit
= false;
209 for (int i
=0;i
<7;i
++) {
210 FormatElement
[] format
= oObj
.getAllFormats(getLocale(i
));
211 for (int j
=0;j
<format
.length
;j
++) {
212 if (! goodFormat(format
[j
]) ) {
215 res
&= goodFormat(format
[j
]);
217 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
220 tRes
.tested("getAllFormats()",res
);
224 * Test calls the method for several locales; result is checked
225 * after each call. <p>
226 * Has <b> OK </b> status if all structs, returned by the method have non
227 * empty field 'UnoID' for all given locales.
229 public void _getCollatorImplementations() {
231 boolean printit
= false;
233 for (int i
=0;i
<7;i
++) {
234 Implementation
[] impl
= oObj
.getCollatorImplementations(getLocale(i
));
235 for (int j
=0;j
<impl
.length
;j
++) {
236 if (impl
[j
].unoID
.equals("")) {
239 res
&= (!impl
[j
].unoID
.equals(""));
241 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
242 + " ; country=" + countries
[i
]);
245 tRes
.tested("getCollatorImplementations()", res
);
249 * Test calls the method for several locales; result is checked
250 * after each call. <p>
251 * Has <b> OK </b> status if all strings, returned by the method are not
252 * empty for all given locales.
254 public void _getSearchOptions() {
256 boolean printit
= false;
258 for (int i
=0;i
<7;i
++) {
259 String
[] str
= oObj
.getSearchOptions(getLocale(i
));
260 for (int j
=0;j
<str
.length
;j
++) {
261 if (str
[j
].equals("")) {
264 res
&= (!str
[j
].equals(""));
266 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
267 + " ; country=" + countries
[i
]);
270 tRes
.tested("getSearchOptions()",res
);
274 * Test calls the method for several locales; result is checked
275 * after each call. <p>
276 * Has <b> OK </b> status if all strings, returned by the method are not
277 * empty for all given locales.
279 public void _getCollationOptions() {
281 boolean printit
= false;
283 for (int i
=0;i
<7;i
++) {
284 String
[] str
= oObj
.getCollationOptions(getLocale(i
));
285 for (int j
=0;j
<str
.length
;j
++) {
286 if (str
[j
].equals("")) {
289 res
&= (!str
[j
].equals(""));
291 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
292 + " ; country=" + countries
[i
]);
295 tRes
.tested("getCollationOptions()", res
);
299 * Test calls the method for several locales; result is checked
300 * after each call. <p>
301 * Has <b> OK </b> status if all strings, returned by the method are not
302 * empty for all given locales.
304 public void _getTransliterations() {
306 boolean printit
= false;
308 for (int i
=0;i
<7;i
++) {
309 String
[] str
= oObj
.getTransliterations(getLocale(i
));
310 for (int j
=0;j
<str
.length
;j
++) {
311 if (str
[j
].equals("")) {
314 res
&= (!str
[j
].equals(""));
316 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
317 + " ; country=" + countries
[i
]);
320 tRes
.tested("getTransliterations()", res
);
324 * Test calls the method for several locales; result is checked
325 * after each call. <p>
326 * Has <b> OK </b> status if the method returns structure with non-empty
327 * fields for all given locales.
329 public void _getForbiddenCharacters() {
331 ForbiddenCharacters fc
= null;
333 //the forbidden characters are only available for the asian languages
334 for (int i
=4;i
<7;i
++) {
335 fc
= oObj
.getForbiddenCharacters(getLocale(i
));
336 res
&= !( fc
.beginLine
.equals("") || fc
.endLine
.equals("") );
338 log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
341 tRes
.tested("getForbiddenCharacters()", res
);
346 * Test calls the method for several locales; result is checked
347 * after each call. <p>
348 * Has <b> OK </b> status if all strings, returned by the method are not
349 * empty for all given locales.
351 public void _getReservedWord() {
353 boolean printit
= false;
355 for (int i
=0;i
<7;i
++) {
356 String
[] str
= oObj
.getReservedWord(getLocale(i
));
357 for (int j
=0;j
<str
.length
;j
++) {
358 if (str
[j
].equals("")) {
361 res
&= (!str
[j
].equals(""));
363 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
364 + " ; country=" + countries
[i
]);
367 tRes
.tested("getReservedWord()", res
);
372 * Test calls the method. Then result is checked for all given locales.<p>
373 * Has <b> OK </b> status if locale sequence, returned by the method contains
376 public void _getAllInstalledLocaleNames() {
378 Locale
[] locs
= oObj
.getAllInstalledLocaleNames();
380 //check if the languages used here are part of this array
381 for (int i
=0;i
<7;i
++) {
382 res
&= contains(locs
, getLocale(i
));
384 tRes
.tested("getAllInstalledLocaleNames()",res
);
389 * Method returns locale for a given language and country.
390 * @param k index of needed locale.
391 * @return Locale by the index from arrays defined above
393 public Locale
getLocale(int k
) {
394 return new Locale(languages
[k
],countries
[k
],"");
398 * Method checks given calendar for non empty fields.
399 * @param calendar Calendar to be checked
401 public boolean goodCalendar(Calendar calendar
) {
403 for (int i
=0;i
<calendar
.Days
.length
;i
++) {
404 good
&= (! calendar
.Days
[i
].AbbrevName
.equals("") );
405 good
&= (! calendar
.Days
[i
].FullName
.equals("") );
406 good
&= (! calendar
.Days
[i
].ID
.equals("") );
408 for (int i
=0;i
<calendar
.Months
.length
;i
++) {
409 good
&= (! calendar
.Months
[i
].AbbrevName
.equals("") );
410 good
&= (! calendar
.Months
[i
].FullName
.equals("") );
411 good
&= (! calendar
.Months
[i
].ID
.equals("") );
413 for (int i
=0;i
<calendar
.Eras
.length
;i
++) {
414 good
&= (! calendar
.Eras
[i
].AbbrevName
.equals("") );
415 good
&= (! calendar
.Eras
[i
].FullName
.equals("") );
416 good
&= (! calendar
.Eras
[i
].ID
.equals("") );
418 good
&= (! calendar
.StartOfWeek
.equals("") );
419 good
&= (! calendar
.Name
.equals("") );
424 * Method checks given currency for non empty fields.
425 * @param currency Currency to be checked
427 public boolean goodCurrency(Currency currency
) {
429 good
&= (!currency
.BankSymbol
.equals(""));
430 good
&= (!currency
.Name
.equals(""));
431 good
&= (!currency
.Symbol
.equals(""));
436 * Method checks given format for non empty fields.
437 * @param format Format to be checked
439 public boolean goodFormat(FormatElement format
) {
441 good
&= (!format
.formatCode
.equals(""));
442 good
&= (!format
.formatKey
.equals(""));
443 good
&= (!format
.formatType
.equals(""));
444 good
&= (!format
.formatUsage
.equals(""));
449 * Method checks that locale sequence contains given locale.
450 * @param locs Locale sequence
451 * @param oneLoc given locale
453 public boolean contains(Locale
[] locs
, Locale oneLoc
) {
454 boolean cont
= false;
455 for (int j
=0;j
<locs
.length
;j
++) {
456 if ( (locs
[j
].Country
.equals(oneLoc
.Country
)) &&
457 (locs
[j
].Language
.equals(oneLoc
.Language
)) ) {
462 if (!cont
) log
.println("Not contained: " + oneLoc
.Language
);