1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.i18n;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.i18n.Calendar;
29 import com.sun.star.i18n.Currency;
30 import com.sun.star.i18n.ForbiddenCharacters;
31 import com.sun.star.i18n.FormatElement;
32 import com.sun.star.i18n.Implementation;
33 import com.sun.star.i18n.LanguageCountryInfo;
34 import com.sun.star.i18n.LocaleDataItem;
35 import com.sun.star.i18n.XLocaleData;
36 import com.sun.star.lang.Locale;
37 
38 /**
39 * Testing <code>com.sun.star.i18n.XLocaleData</code>
40 * interface methods:
41 * <ul>
42 *  <li><code> getLanguageCountryInfo() </code></li>
43 *  <li><code> getLocaleItem() </code></li>
44 *  <li><code> getAllCalendars() </code></li>
45 *  <li><code> getAllCurrencies() </code></li>
46 *  <li><code> getAllFormats() </code></li>
47 *  <li><code> getCollatorImplementations() </code></li>
48 *  <li><code> getSearchOptions() </code></li>
49 *  <li><code> getCollationOptions() </code></li>
50 *  <li><code> getTransliterations() </code></li>
51 *  <li><code> getForbiddenCharacters() </code></li>
52 *  <li><code> getReservedWord() </code></li>
53 *  <li><code> getAllInstalledLocaleNames() </code></li>
54 * </ul><p>
55 * Test is <b> NOT </b> multithread compilant. <p>
56 * @see com.sun.star.i18n.XLocaleData
57 */
58 public class _XLocaleData extends MultiMethodTest {
59     public XLocaleData oObj = null;
60     public String[] languages = new String[]{"de","en","es","fr","ja","ko","ko"};
61     public String[] countries = new String[]{"DE","US","ES","FR","JP","KR","KR"};
62 
63 
64     /**
65     * Test calls the method, then result is checked. <p>
66     * Has <b> OK </b> status if structure, returned by the method includes
67     * correct values of fields 'Language' and 'Country' for all given locales.
68     */
_getLanguageCountryInfo()69     public void _getLanguageCountryInfo() {
70         boolean res = true;
71         LanguageCountryInfo lci = null;
72 
73         for (int i=0;i<7;i++) {
74             lci = oObj.getLanguageCountryInfo(getLocale(i));
75             /* For debug purposes
76             log.println("Using: language="+languages[i]+" ; country="+countries[i]);
77             log.println("Getting: ");
78             log.println("\t Language="+lci.Language);
79             log.println("\t LanguageDefaultName="+lci.LanguageDefaultName);
80             log.println("\t Country="+lci.Country);
81             log.println("\t CountryDefaultName="+lci.CountryDefaultName);
82             boolean lang = ( lci.Language.equals(languages[i]) );
83             if (!lang) log.println("getting false for language: "+lci.LanguageDefaultName);
84             lang = ( lci.Country.equals(countries[i]) );
85             if (!lang) log.println("getting false for country: "+lci.CountryDefaultName);
86             */
87             res &= ( ( lci.Language.equals(languages[i]) ) && ( lci.Country.equals(countries[i]) ) );
88         }
89         tRes.tested("getLanguageCountryInfo()",res);
90     }
91 
92     /**
93     * Test calls the method, then result is checked. <p>
94     * Has <b> OK </b> status if structure, returned by the method consists of
95     * non empty strings for all given locales.
96     */
_getLocaleItem()97     public void _getLocaleItem() {
98         boolean res = true;
99         LocaleDataItem ldi = null;
100 
101         for (int i=0;i<7;i++) {
102             ldi = oObj.getLocaleItem(getLocale(i));
103 
104             boolean locRes = true ;
105 
106             locRes &= (! ldi.dateSeparator.equals(""));
107             locRes &= (! ldi.decimalSeparator.equals(""));
108             locRes &= (! ldi.doubleQuotationEnd.equals(""));
109             locRes &= (! ldi.doubleQuotationStart.equals(""));
110             locRes &= (! ldi.listSeparator.equals(""));
111             locRes &= (! ldi.LongDateDayOfWeekSeparator.equals(""));
112             locRes &= (! ldi.LongDateDaySeparator.equals(""));
113             locRes &= (! ldi.LongDateMonthSeparator.equals(""));
114             locRes &= (! ldi.LongDateYearSeparator.equals(""));
115             locRes &= (! ldi.measurementSystem.equals(""));
116             locRes &= (! ldi.quotationEnd.equals(""));
117             locRes &= (! ldi.quotationStart.equals(""));
118             locRes &= (! ldi.thousandSeparator.equals(""));
119             locRes &= (! ldi.time100SecSeparator.equals(""));
120             locRes &= (! ldi.timeAM.equals(""));
121             locRes &= (! ldi.timePM.equals(""));
122             locRes &= (! ldi.timeSeparator.equals(""));
123             locRes &= (! ldi.unoID.equals(""));
124 
125             if (!locRes) {
126                 /* for debugging puposes
127                 log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
128                 log.println("Getting: ");
129                 log.println("\t DateSeparator="+ldi.dateSeparator);
130                 log.println("\t decimalSeparator="+ldi.decimalSeparator);
131                 log.println("\t doubleQuotationEnd="+ldi.doubleQuotationEnd);
132                 log.println("\t doubleQuotationStart="+ldi.doubleQuotationStart);
133                 log.println("\t listSeparator="+ldi.listSeparator);
134                 log.println("\t LongDateDayOfWeekSeparator="+ldi.LongDateDayOfWeekSeparator+"end");
135                 log.println("\t LongDateDaySeparator="+ldi.LongDateDaySeparator+"end");
136                 log.println("\t LongDateMonthSeparator="+ldi.LongDateMonthSeparator+"end");
137                 log.println("\t LongDateYearSeparator="+ldi.LongDateYearSeparator+"end");
138                 log.println("\t measurementSystem="+ldi.measurementSystem);
139                 log.println("\t quotationEnd="+ldi.quotationEnd);
140                 log.println("\t quotationStart="+ldi.quotationStart);
141                 log.println("\t thousandSeparator="+ldi.thousandSeparator);
142                 log.println("\t time100SecSeparator="+ldi.time100SecSeparator);
143                 log.println("\t timeAM="+ldi.timeAM);
144                 log.println("\t timePM="+ldi.timePM);
145                 log.println("\t timeSeparator="+ldi.timeSeparator);
146                 log.println("\t unoID="+ldi.unoID);
147                  */
148             }
149         }
150         tRes.tested("getLocaleItem()",res);
151     }
152 
153     /**
154     * Test calls the method for several locales; result is checked
155     * after each call. <p>
156     * Has <b> OK </b> status if all elements of the returned sequence are
157     * correct for all given locales. (boolean method goodCalendar() with a
158     * calendar as an argument returns true)
159     */
_getAllCalendars()160     public void _getAllCalendars() {
161         boolean res = true;
162         boolean printit = false;
163         Calendar[] calendar = new Calendar[1];
164 
165         for (int i=0;i<7;i++) {
166             calendar = oObj.getAllCalendars(getLocale(i));
167             for (int j=0;j<calendar.length;j++) {
168                 if (! goodCalendar(calendar[j]) ) {
169                     printit = true;
170                 }
171                 res &= goodCalendar(calendar[j]);
172             }
173             if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
174             printit = false;
175         }
176         tRes.tested("getAllCalendars()", res);
177     }
178 
179     /**
180     * Test calls the method for several locales; result is checked
181     * after each call. <p>
182     * Has <b> OK </b> status if all elements of the returned sequence are
183     * correct for all given locales. (boolean method goodCurrency() with a
184     * currency as an argument returns true)
185     */
_getAllCurrencies()186     public void _getAllCurrencies() {
187         boolean res = true;
188         boolean printit = false;
189         Currency[] currency = new Currency[1];
190 
191         for (int i=0;i<7;i++) {
192             currency = oObj.getAllCurrencies(getLocale(i));
193             for (int j=0;j<currency.length;j++) {
194                 if (! goodCurrency(currency[j]) ) {
195                     printit=true;
196                 }
197                 res &= goodCurrency(currency[j]);
198             }
199             if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
200             printit =false;
201         }
202         tRes.tested("getAllCurrencies()",res);
203     }
204 
205     /**
206     * Test calls the method for several locales; result is checked
207     * after each call. <p>
208     * Has <b> OK </b> status if all elements of the returned sequence are
209     * correct for all given locales. (boolean method goodFormat() with a
210     * format as an argument returns true)
211     */
_getAllFormats()212     public void _getAllFormats() {
213         boolean res = true;
214         boolean printit = false;
215         FormatElement[] format = new FormatElement[1];
216 
217         for (int i=0;i<7;i++) {
218             format = oObj.getAllFormats(getLocale(i));
219             for (int j=0;j<format.length;j++) {
220                 if (! goodFormat(format[j]) ) {
221                     printit = true;
222                 }
223                 res &= goodFormat(format[j]);
224             }
225             if (printit) log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
226             printit =false;
227         }
228         tRes.tested("getAllFormats()",res);
229     }
230 
231     /**
232     * Test calls the method for several locales; result is checked
233     * after each call. <p>
234     * Has <b> OK </b> status if all structs, returned by the method have non
235     * empty field 'UnoID' for all given locales.
236     */
_getCollatorImplementations()237     public void _getCollatorImplementations() {
238         boolean res = true;
239         boolean printit = false;
240         Implementation[] impl = new Implementation[1];
241 
242         for (int i=0;i<7;i++) {
243             impl = oObj.getCollatorImplementations(getLocale(i));
244             for (int j=0;j<impl.length;j++) {
245                 if ((impl[j].unoID.equals(""))) {
246                     printit = true;
247                 }
248                 res &= (!impl[j].unoID.equals(""));
249             }
250             if (printit) log.println("FAILED for: language=" + languages[i]
251                 + " ; country=" + countries[i]);
252             printit = false;
253         }
254         tRes.tested("getCollatorImplementations()", res);
255     }
256 
257     /**
258     * Test calls the method for several locales; result is checked
259     * after each call. <p>
260     * Has <b> OK </b> status if all strings, returned by the method are not
261     * empty for all given locales.
262     */
_getSearchOptions()263     public void _getSearchOptions() {
264         boolean res = true;
265         boolean printit = false;
266         String[] str = new String[1];
267 
268         for (int i=0;i<7;i++) {
269             str = oObj.getSearchOptions(getLocale(i));
270             for (int j=0;j<str.length;j++) {
271                 if ((str[j].equals(""))) {
272                     printit = true;
273                 }
274                 res &= (!str.equals(""));
275             }
276             if (printit) log.println("FAILED for: language=" + languages[i]
277                 + " ; country=" + countries[i]);
278             printit = false;
279         }
280         tRes.tested("getSearchOptions()",res);
281     }
282 
283     /**
284     * Test calls the method for several locales; result is checked
285     * after each call. <p>
286     * Has <b> OK </b> status if all strings, returned by the method are not
287     * empty for all given locales.
288     */
_getCollationOptions()289     public void _getCollationOptions() {
290         boolean res = true;
291         boolean printit = false;
292         String[] str = new String[1];
293 
294         for (int i=0;i<7;i++) {
295             str = oObj.getCollationOptions(getLocale(i));
296             for (int j=0;j<str.length;j++) {
297                 if ((str[j].equals(""))) {
298                     printit = true;
299                 }
300                 res &= (!str.equals(""));
301             }
302             if (printit) log.println("FAILED for: language=" + languages[i]
303                 + " ; country=" + countries[i]);
304             printit = false;
305         }
306         tRes.tested("getCollationOptions()", res);
307     }
308 
309     /**
310     * Test calls the method for several locales; result is checked
311     * after each call. <p>
312     * Has <b> OK </b> status if all strings, returned by the method are not
313     * empty for all given locales.
314     */
_getTransliterations()315     public void _getTransliterations() {
316         boolean res = true;
317         boolean printit = false;
318         String[] str = new String[1];
319 
320         for (int i=0;i<7;i++) {
321             str = oObj.getTransliterations(getLocale(i));
322             for (int j=0;j<str.length;j++) {
323                 if ((str[j].equals(""))) {
324                     printit = true;
325                 }
326                 res &= (!str.equals(""));
327             }
328             if (printit) log.println("FAILED for: language=" + languages[i]
329                 + " ; country=" + countries[i]);
330             printit = false;
331         }
332         tRes.tested("getTransliterations()", res);
333     }
334 
335     /**
336     * Test calls the method for several locales; result is checked
337     * after each call. <p>
338     * Has <b> OK </b> status if the method returns structure with non-empty
339     * fields for all given locales.
340     */
_getForbiddenCharacters()341     public void _getForbiddenCharacters() {
342         boolean res = true;
343         ForbiddenCharacters fc = null;
344 
345         //the forbidden characters are only available for the asian languages
346         for (int i=4;i<7;i++) {
347             fc = oObj.getForbiddenCharacters(getLocale(i));
348             res &= !( fc.beginLine.equals("") || fc.endLine.equals("") );
349             if ( !res ) {
350                 log.println("FAILED for: language="+languages[i]+" ; country="+countries[i]);
351             }
352         }
353         tRes.tested("getForbiddenCharacters()", res);
354     }
355 
356 
357     /**
358     * Test calls the method for several locales; result is checked
359     * after each call. <p>
360     * Has <b> OK </b> status if all strings, returned by the method are not
361     * empty for all given locales.
362     */
_getReservedWord()363     public void _getReservedWord() {
364         boolean res = true;
365         boolean printit = false;
366         String[] str = new String[1];
367 
368         for (int i=0;i<7;i++) {
369             str = oObj.getReservedWord(getLocale(i));
370             for (int j=0;j<str.length;j++) {
371                 if ((str[j].equals(""))) {
372                     printit = true;
373                 }
374                 res &= (!str.equals(""));
375             }
376             if (printit) log.println("FAILED for: language=" + languages[i]
377                 + " ; country=" + countries[i]);
378             printit = false;
379         }
380         tRes.tested("getReservedWord()", res);
381     }
382 
383 
384     /**
385     * Test calls the method. Then result is checked for all given locales.<p>
386     * Has <b> OK </b> status if locale sequence, returned by the method contains
387     * given locales.
388     */
_getAllInstalledLocaleNames()389     public void _getAllInstalledLocaleNames() {
390         boolean res = true;
391         Locale[] locs = oObj.getAllInstalledLocaleNames();
392 
393         //check if the languages used here are part of this array
394         for (int i=0;i<7;i++) {
395             res &= contains(locs, getLocale(i));
396         }
397         tRes.tested("getAllInstalledLocaleNames()",res);
398     }
399 
400 
401     /**
402     * Method returns locale for a given language and country.
403     * @param k index of needed locale.
404     * @return Locale by the index from arrays defined above
405     */
getLocale(int k)406     public Locale getLocale(int k) {
407         return new Locale(languages[k],countries[k],"");
408     }
409 
410     /**
411     * Method checks given calendar for non empty fields.
412     * @param calendar Calendar to be checked
413     */
goodCalendar(Calendar calendar)414     public boolean goodCalendar(Calendar calendar) {
415         boolean good = true;
416         for (int i=0;i<calendar.Days.length;i++) {
417             //log.println("Day "+i+"(AbbrevName): "+calendar.Days[i].AbbrevName);
418             good &= (! calendar.Days[i].AbbrevName.equals("") );
419             //log.println("Day "+i+"(FullName): "+calendar.Days[i].FullName);
420             good &= (! calendar.Days[i].FullName.equals("") );
421             //log.println("Day "+i+"(ID): "+calendar.Days[i].ID);
422             good &= (! calendar.Days[i].ID.equals("") );
423         }
424         for (int i=0;i<calendar.Months.length;i++) {
425             //log.println("Day "+i+"(AbbrevName): "+calendar.Months[i].AbbrevName);
426             good &= (! calendar.Months[i].AbbrevName.equals("") );
427             //log.println("Day "+i+"(FullName): "+calendar.Months[i].FullName);
428             good &= (! calendar.Months[i].FullName.equals("") );
429             //log.println("Day "+i+"(ID): "+calendar.Months[i].ID);
430             good &= (! calendar.Months[i].ID.equals("") );
431         }
432         for (int i=0;i<calendar.Eras.length;i++) {
433             //log.println("Era "+i+"(AbbrevName): "+calendar.Eras[i].AbbrevName);
434             good &= (! calendar.Eras[i].AbbrevName.equals("") );
435             //log.println("Era "+i+"(FullName): "+calendar.Eras[i].FullName);
436             good &= (! calendar.Eras[i].FullName.equals("") );
437             //log.println("Era "+i+"(ID): "+calendar.Eras[i].ID);
438             good &= (! calendar.Eras[i].ID.equals("") );
439         }
440         //log.println("Start of Week: "+calendar.StartOfWeek);
441         good &= (! calendar.StartOfWeek.equals("") );
442         //log.println("MinimumNumberOfDaysForFirstWeek: "+calendar.MinimumNumberOfDaysForFirstWeek);
443         //log.println("Default: "+calendar.Default);
444         //log.println("Name: "+calendar.Name);
445         good &= (! calendar.Name.equals("") );
446         return good;
447     }
448 
449     /**
450     * Method checks given currency for non empty fields.
451     * @param currency Currency to be checked
452     */
goodCurrency(Currency currency)453     public boolean goodCurrency(Currency currency) {
454         boolean good = true;
455         good &= (!currency.BankSymbol.equals(""));
456         good &= (!currency.Name.equals(""));
457         good &= (!currency.Symbol.equals(""));
458         return good;
459     }
460 
461     /**
462     * Method checks given format for non empty fields.
463     * @param format Format to be checked
464     */
goodFormat(FormatElement format)465     public boolean goodFormat(FormatElement format) {
466         boolean good = true;
467         good &= (!format.formatCode.equals(""));
468         good &= (!format.formatKey.equals(""));
469         good &= (!format.formatType.equals(""));
470         good &= (!format.formatUsage.equals(""));
471         return good;
472     }
473 
474     /**
475     * Method checks that locale sequence contains given locale.
476     * @param locs Locale sequence
477     * @param oneLoc given locale
478     */
contains(Locale[] locs, Locale oneLoc)479     public boolean contains(Locale[] locs, Locale oneLoc) {
480         boolean cont = false;
481         for (int j=0;j<locs.length;j++) {
482             if ( (locs[j].Country.equals(oneLoc.Country)) &&
483                 (locs[j].Language.equals(oneLoc.Language)) ) {
484                     cont=true;
485                     break;
486             }
487         }
488         if (!cont) log.println("Not contained: " + oneLoc.Language);
489         return cont;
490     }
491 
492 } // end XLocaleData
493 
494