bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / i18n / _XLocaleData.java
blobb9f1ba126c516a60448f78579cfb6ad35cf6f235
1 /*
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 .
19 package ifc.i18n;
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;
33 /**
34 * Testing <code>com.sun.star.i18n.XLocaleData</code>
35 * interface methods:
36 * <ul>
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>
49 * </ul><p>
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"};
59 /**
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() {
65 boolean res = true;
66 LanguageCountryInfo lci = null;
68 for (int i=0;i<7;i++) {
69 lci = oObj.getLanguageCountryInfo(getLocale(i));
70 /* For debug purposes
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);
87 /**
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() {
93 boolean res = true;
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(""));
120 if (!locRes) {
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() {
156 boolean res = true;
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]) ) {
164 printit = true;
166 res &= goodCalendar(calendar[j]);
168 if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
169 printit = false;
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() {
182 boolean res = true;
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]) ) {
190 printit=true;
192 res &= goodCurrency(currency[j]);
194 if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
195 printit =false;
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() {
208 boolean res = true;
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]) ) {
216 printit = true;
218 res &= goodFormat(format[j]);
220 if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
221 printit =false;
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() {
233 boolean res = true;
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(""))) {
241 printit = true;
243 res &= (!impl[j].unoID.equals(""));
245 if (printit) log.println("FAILED for: language=" + languages[i]
246 + " ; country=" + countries[i]);
247 printit = false;
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() {
259 boolean res = true;
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(""))) {
267 printit = true;
269 res &= (!str.equals(""));
271 if (printit) log.println("FAILED for: language=" + languages[i]
272 + " ; country=" + countries[i]);
273 printit = false;
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() {
285 boolean res = true;
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(""))) {
293 printit = true;
295 res &= (!str.equals(""));
297 if (printit) log.println("FAILED for: language=" + languages[i]
298 + " ; country=" + countries[i]);
299 printit = false;
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() {
311 boolean res = true;
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(""))) {
319 printit = true;
321 res &= (!str.equals(""));
323 if (printit) log.println("FAILED for: language=" + languages[i]
324 + " ; country=" + countries[i]);
325 printit = false;
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() {
337 boolean res = true;
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("") );
344 if ( !res ) {
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() {
359 boolean res = true;
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(""))) {
367 printit = true;
369 res &= (!str.equals(""));
371 if (printit) log.println("FAILED for: language=" + languages[i]
372 + " ; country=" + countries[i]);
373 printit = false;
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
382 * given locales.
384 public void _getAllInstalledLocaleNames() {
385 boolean res = true;
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) {
410 boolean good = true;
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("") );
428 return good;
432 * Method checks given currency for non empty fields.
433 * @param currency Currency to be checked
435 public boolean goodCurrency(Currency currency) {
436 boolean good = true;
437 good &= (!currency.BankSymbol.equals(""));
438 good &= (!currency.Name.equals(""));
439 good &= (!currency.Symbol.equals(""));
440 return good;
444 * Method checks given format for non empty fields.
445 * @param format Format to be checked
447 public boolean goodFormat(FormatElement format) {
448 boolean good = true;
449 good &= (!format.formatCode.equals(""));
450 good &= (!format.formatKey.equals(""));
451 good &= (!format.formatType.equals(""));
452 good &= (!format.formatUsage.equals(""));
453 return good;
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)) ) {
466 cont=true;
467 break;
470 if (!cont) log.println("Not contained: " + oneLoc.Language);
471 return cont;
474 } // end XLocaleData