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