1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XLocaleData.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.i18n
.Calendar
;
36 import com
.sun
.star
.i18n
.Currency
;
37 import com
.sun
.star
.i18n
.ForbiddenCharacters
;
38 import com
.sun
.star
.i18n
.FormatElement
;
39 import com
.sun
.star
.i18n
.Implementation
;
40 import com
.sun
.star
.i18n
.LanguageCountryInfo
;
41 import com
.sun
.star
.i18n
.LocaleDataItem
;
42 import com
.sun
.star
.i18n
.XLocaleData
;
43 import com
.sun
.star
.lang
.Locale
;
46 * Testing <code>com.sun.star.i18n.XLocaleData</code>
49 * <li><code> getLanguageCountryInfo() </code></li>
50 * <li><code> getLocaleItem() </code></li>
51 * <li><code> getAllCalendars() </code></li>
52 * <li><code> getAllCurrencies() </code></li>
53 * <li><code> getAllFormats() </code></li>
54 * <li><code> getCollatorImplementations() </code></li>
55 * <li><code> getSearchOptions() </code></li>
56 * <li><code> getCollationOptions() </code></li>
57 * <li><code> getTransliterations() </code></li>
58 * <li><code> getForbiddenCharacters() </code></li>
59 * <li><code> getReservedWord() </code></li>
60 * <li><code> getAllInstalledLocaleNames() </code></li>
62 * Test is <b> NOT </b> multithread compilant. <p>
63 * @see com.sun.star.i18n.XLocaleData
65 public class _XLocaleData
extends MultiMethodTest
{
66 public XLocaleData oObj
= null;
67 public String
[] languages
= new String
[]{"de","en","es","fr","ja","ko","ko"};
68 public String
[] countries
= new String
[]{"DE","US","ES","FR","JP","KR","KR"};
72 * Test calls the method, then result is checked. <p>
73 * Has <b> OK </b> status if structure, returned by the method includes
74 * correct values of fields 'Language' and 'Country' for all given locales.
76 public void _getLanguageCountryInfo() {
78 LanguageCountryInfo lci
= null;
80 for (int i
=0;i
<7;i
++) {
81 lci
= oObj
.getLanguageCountryInfo(getLocale(i
));
83 log.println("Using: language="+languages[i]+" ; country="+countries[i]);
84 log.println("Getting: ");
85 log.println("\t Language="+lci.Language);
86 log.println("\t LanguageDefaultName="+lci.LanguageDefaultName);
87 log.println("\t Country="+lci.Country);
88 log.println("\t CountryDefaultName="+lci.CountryDefaultName);
89 boolean lang = ( lci.Language.equals(languages[i]) );
90 if (!lang) log.println("getting false for language: "+lci.LanguageDefaultName);
91 lang = ( lci.Country.equals(countries[i]) );
92 if (!lang) log.println("getting false for country: "+lci.CountryDefaultName);
94 res
&= ( ( lci
.Language
.equals(languages
[i
]) ) && ( lci
.Country
.equals(countries
[i
]) ) );
96 tRes
.tested("getLanguageCountryInfo()",res
);
100 * Test calls the method, then result is checked. <p>
101 * Has <b> OK </b> status if structure, returned by the method consists of
102 * non empty strings for all given locales.
104 public void _getLocaleItem() {
106 LocaleDataItem ldi
= null;
108 for (int i
=0;i
<7;i
++) {
109 ldi
= oObj
.getLocaleItem(getLocale(i
));
111 boolean locRes
= true ;
113 locRes
&= (! ldi
.dateSeparator
.equals(""));
114 locRes
&= (! ldi
.decimalSeparator
.equals(""));
115 locRes
&= (! ldi
.doubleQuotationEnd
.equals(""));
116 locRes
&= (! ldi
.doubleQuotationStart
.equals(""));
117 locRes
&= (! ldi
.listSeparator
.equals(""));
118 locRes
&= (! ldi
.LongDateDayOfWeekSeparator
.equals(""));
119 locRes
&= (! ldi
.LongDateDaySeparator
.equals(""));
120 locRes
&= (! ldi
.LongDateMonthSeparator
.equals(""));
121 locRes
&= (! ldi
.LongDateYearSeparator
.equals(""));
122 locRes
&= (! ldi
.measurementSystem
.equals(""));
123 locRes
&= (! ldi
.quotationEnd
.equals(""));
124 locRes
&= (! ldi
.quotationStart
.equals(""));
125 locRes
&= (! ldi
.thousandSeparator
.equals(""));
126 locRes
&= (! ldi
.time100SecSeparator
.equals(""));
127 locRes
&= (! ldi
.timeAM
.equals(""));
128 locRes
&= (! ldi
.timePM
.equals(""));
129 locRes
&= (! ldi
.timeSeparator
.equals(""));
130 locRes
&= (! ldi
.unoID
.equals(""));
133 /* for debugging puposes
134 log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
135 log.println("Getting: ");
136 log.println("\t DateSeparator="+ldi.dateSeparator);
137 log.println("\t decimalSeparator="+ldi.decimalSeparator);
138 log.println("\t doubleQuotationEnd="+ldi.doubleQuotationEnd);
139 log.println("\t doubleQuotationStart="+ldi.doubleQuotationStart);
140 log.println("\t listSeparator="+ldi.listSeparator);
141 log.println("\t LongDateDayOfWeekSeparator="+ldi.LongDateDayOfWeekSeparator+"end");
142 log.println("\t LongDateDaySeparator="+ldi.LongDateDaySeparator+"end");
143 log.println("\t LongDateMonthSeparator="+ldi.LongDateMonthSeparator+"end");
144 log.println("\t LongDateYearSeparator="+ldi.LongDateYearSeparator+"end");
145 log.println("\t measurementSystem="+ldi.measurementSystem);
146 log.println("\t quotationEnd="+ldi.quotationEnd);
147 log.println("\t quotationStart="+ldi.quotationStart);
148 log.println("\t thousandSeparator="+ldi.thousandSeparator);
149 log.println("\t time100SecSeparator="+ldi.time100SecSeparator);
150 log.println("\t timeAM="+ldi.timeAM);
151 log.println("\t timePM="+ldi.timePM);
152 log.println("\t timeSeparator="+ldi.timeSeparator);
153 log.println("\t unoID="+ldi.unoID);
157 tRes
.tested("getLocaleItem()",res
);
161 * Test calls the method for several locales; result is checked
162 * after each call. <p>
163 * Has <b> OK </b> status if all elements of the returned sequence are
164 * correct for all given locales. (boolean method goodCalendar() with a
165 * calendar as an argument returns true)
167 public void _getAllCalendars() {
169 boolean printit
= false;
170 Calendar
[] calendar
= new Calendar
[1];
172 for (int i
=0;i
<7;i
++) {
173 calendar
= oObj
.getAllCalendars(getLocale(i
));
174 for (int j
=0;j
<calendar
.length
;j
++) {
175 if (! goodCalendar(calendar
[j
]) ) {
178 res
&= goodCalendar(calendar
[j
]);
180 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
183 tRes
.tested("getAllCalendars()", res
);
187 * Test calls the method for several locales; result is checked
188 * after each call. <p>
189 * Has <b> OK </b> status if all elements of the returned sequence are
190 * correct for all given locales. (boolean method goodCurrency() with a
191 * currency as an argument returns true)
193 public void _getAllCurrencies() {
195 boolean printit
= false;
196 Currency
[] currency
= new Currency
[1];
198 for (int i
=0;i
<7;i
++) {
199 currency
= oObj
.getAllCurrencies(getLocale(i
));
200 for (int j
=0;j
<currency
.length
;j
++) {
201 if (! goodCurrency(currency
[j
]) ) {
204 res
&= goodCurrency(currency
[j
]);
206 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
209 tRes
.tested("getAllCurrencies()",res
);
213 * Test calls the method for several locales; result is checked
214 * after each call. <p>
215 * Has <b> OK </b> status if all elements of the returned sequence are
216 * correct for all given locales. (boolean method goodFormat() with a
217 * format as an argument returns true)
219 public void _getAllFormats() {
221 boolean printit
= false;
222 FormatElement
[] format
= new FormatElement
[1];
224 for (int i
=0;i
<7;i
++) {
225 format
= oObj
.getAllFormats(getLocale(i
));
226 for (int j
=0;j
<format
.length
;j
++) {
227 if (! goodFormat(format
[j
]) ) {
230 res
&= goodFormat(format
[j
]);
232 if (printit
) log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
235 tRes
.tested("getAllFormats()",res
);
239 * Test calls the method for several locales; result is checked
240 * after each call. <p>
241 * Has <b> OK </b> status if all structs, returned by the method have non
242 * empty field 'UnoID' for all given locales.
244 public void _getCollatorImplementations() {
246 boolean printit
= false;
247 Implementation
[] impl
= new Implementation
[1];
249 for (int i
=0;i
<7;i
++) {
250 impl
= oObj
.getCollatorImplementations(getLocale(i
));
251 for (int j
=0;j
<impl
.length
;j
++) {
252 if ((impl
[j
].unoID
.equals(""))) {
255 res
&= (!impl
[j
].unoID
.equals(""));
257 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
258 + " ; country=" + countries
[i
]);
261 tRes
.tested("getCollatorImplementations()", res
);
265 * Test calls the method for several locales; result is checked
266 * after each call. <p>
267 * Has <b> OK </b> status if all strings, returned by the method are not
268 * empty for all given locales.
270 public void _getSearchOptions() {
272 boolean printit
= false;
273 String
[] str
= new String
[1];
275 for (int i
=0;i
<7;i
++) {
276 str
= oObj
.getSearchOptions(getLocale(i
));
277 for (int j
=0;j
<str
.length
;j
++) {
278 if ((str
[j
].equals(""))) {
281 res
&= (!str
.equals(""));
283 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
284 + " ; country=" + countries
[i
]);
287 tRes
.tested("getSearchOptions()",res
);
291 * Test calls the method for several locales; result is checked
292 * after each call. <p>
293 * Has <b> OK </b> status if all strings, returned by the method are not
294 * empty for all given locales.
296 public void _getCollationOptions() {
298 boolean printit
= false;
299 String
[] str
= new String
[1];
301 for (int i
=0;i
<7;i
++) {
302 str
= oObj
.getCollationOptions(getLocale(i
));
303 for (int j
=0;j
<str
.length
;j
++) {
304 if ((str
[j
].equals(""))) {
307 res
&= (!str
.equals(""));
309 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
310 + " ; country=" + countries
[i
]);
313 tRes
.tested("getCollationOptions()", res
);
317 * Test calls the method for several locales; result is checked
318 * after each call. <p>
319 * Has <b> OK </b> status if all strings, returned by the method are not
320 * empty for all given locales.
322 public void _getTransliterations() {
324 boolean printit
= false;
325 String
[] str
= new String
[1];
327 for (int i
=0;i
<7;i
++) {
328 str
= oObj
.getTransliterations(getLocale(i
));
329 for (int j
=0;j
<str
.length
;j
++) {
330 if ((str
[j
].equals(""))) {
333 res
&= (!str
.equals(""));
335 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
336 + " ; country=" + countries
[i
]);
339 tRes
.tested("getTransliterations()", res
);
343 * Test calls the method for several locales; result is checked
344 * after each call. <p>
345 * Has <b> OK </b> status if the method returns structure with non-empty
346 * fields for all given locales.
348 public void _getForbiddenCharacters() {
350 ForbiddenCharacters fc
= null;
352 //the forbidden characters are only available for the asian languages
353 for (int i
=4;i
<7;i
++) {
354 fc
= oObj
.getForbiddenCharacters(getLocale(i
));
355 res
&= !( fc
.beginLine
.equals("") || fc
.endLine
.equals("") );
357 log
.println("FAILED for: language="+languages
[i
]+" ; country="+countries
[i
]);
360 tRes
.tested("getForbiddenCharacters()", res
);
365 * Test calls the method for several locales; result is checked
366 * after each call. <p>
367 * Has <b> OK </b> status if all strings, returned by the method are not
368 * empty for all given locales.
370 public void _getReservedWord() {
372 boolean printit
= false;
373 String
[] str
= new String
[1];
375 for (int i
=0;i
<7;i
++) {
376 str
= oObj
.getReservedWord(getLocale(i
));
377 for (int j
=0;j
<str
.length
;j
++) {
378 if ((str
[j
].equals(""))) {
381 res
&= (!str
.equals(""));
383 if (printit
) log
.println("FAILED for: language=" + languages
[i
]
384 + " ; country=" + countries
[i
]);
387 tRes
.tested("getReservedWord()", res
);
392 * Test calls the method. Then result is checked for all given locales.<p>
393 * Has <b> OK </b> status if locale sequence, returned by the method contains
396 public void _getAllInstalledLocaleNames() {
398 Locale
[] locs
= oObj
.getAllInstalledLocaleNames();
400 //check if the languages used here are part of this array
401 for (int i
=0;i
<7;i
++) {
402 res
&= contains(locs
, getLocale(i
));
404 tRes
.tested("getAllInstalledLocaleNames()",res
);
409 * Method returns locale for a given language and country.
410 * @param localeIndex index of needed locale.
411 * @return Locale by the index from arrays defined above
413 public Locale
getLocale(int k
) {
414 return new Locale(languages
[k
],countries
[k
],"");
418 * Method checks given calendar for non empty fields.
419 * @param calendar Calendar to be checked
421 public boolean goodCalendar(Calendar calendar
) {
423 for (int i
=0;i
<calendar
.Days
.length
;i
++) {
424 //log.println("Day "+i+"(AbbrevName): "+calendar.Days[i].AbbrevName);
425 good
&= (! calendar
.Days
[i
].AbbrevName
.equals("") );
426 //log.println("Day "+i+"(FullName): "+calendar.Days[i].FullName);
427 good
&= (! calendar
.Days
[i
].FullName
.equals("") );
428 //log.println("Day "+i+"(ID): "+calendar.Days[i].ID);
429 good
&= (! calendar
.Days
[i
].ID
.equals("") );
431 for (int i
=0;i
<calendar
.Months
.length
;i
++) {
432 //log.println("Day "+i+"(AbbrevName): "+calendar.Months[i].AbbrevName);
433 good
&= (! calendar
.Months
[i
].AbbrevName
.equals("") );
434 //log.println("Day "+i+"(FullName): "+calendar.Months[i].FullName);
435 good
&= (! calendar
.Months
[i
].FullName
.equals("") );
436 //log.println("Day "+i+"(ID): "+calendar.Months[i].ID);
437 good
&= (! calendar
.Months
[i
].ID
.equals("") );
439 for (int i
=0;i
<calendar
.Eras
.length
;i
++) {
440 //log.println("Era "+i+"(AbbrevName): "+calendar.Eras[i].AbbrevName);
441 good
&= (! calendar
.Eras
[i
].AbbrevName
.equals("") );
442 //log.println("Era "+i+"(FullName): "+calendar.Eras[i].FullName);
443 good
&= (! calendar
.Eras
[i
].FullName
.equals("") );
444 //log.println("Era "+i+"(ID): "+calendar.Eras[i].ID);
445 good
&= (! calendar
.Eras
[i
].ID
.equals("") );
447 //log.println("Start of Week: "+calendar.StartOfWeek);
448 good
&= (! calendar
.StartOfWeek
.equals("") );
449 //log.println("MinimumNumberOfDaysForFirstWeek: "+calendar.MinimumNumberOfDaysForFirstWeek);
450 //log.println("Default: "+calendar.Default);
451 //log.println("Name: "+calendar.Name);
452 good
&= (! calendar
.Name
.equals("") );
457 * Method checks given currency for non empty fields.
458 * @param currency Currency to be checked
460 public boolean goodCurrency(Currency currency
) {
462 good
&= (!currency
.BankSymbol
.equals(""));
463 good
&= (!currency
.Name
.equals(""));
464 good
&= (!currency
.Symbol
.equals(""));
469 * Method checks given format for non empty fields.
470 * @param format Format to be checked
472 public boolean goodFormat(FormatElement format
) {
474 good
&= (!format
.formatCode
.equals(""));
475 good
&= (!format
.formatKey
.equals(""));
476 good
&= (!format
.formatType
.equals(""));
477 good
&= (!format
.formatUsage
.equals(""));
482 * Method checks that locale sequence contains given locale.
483 * @param locs Locale sequence
484 * @param oneLoc given locale
486 public boolean contains(Locale
[] locs
, Locale oneLoc
) {
487 boolean cont
= false;
488 for (int j
=0;j
<locs
.length
;j
++) {
489 if ( (locs
[j
].Country
.equals(oneLoc
.Country
)) &&
490 (locs
[j
].Language
.equals(oneLoc
.Language
)) ) {
495 if (!cont
) log
.println("Not contained: " + oneLoc
.Language
);