1 /* 2 ******************************************************************************* 3 * Copyright (C) 2006-2011, International Business Machines Corporation and * 4 * others. All Rights Reserved. * 5 ******************************************************************************* 6 */ 7 8 package com.ibm.icu.tests; 9 10 import java.util.Iterator; 11 import java.util.Locale; 12 13 import com.ibm.icu.util.ULocale; 14 import com.ibm.icu.util.ULocale.Category; 15 16 public class ULocaleTest extends ICUTestCase { 17 private String sampleName; 18 private String longULocaleName; 19 private String longULocaleBasename; 20 private String nonNormalizedName; 21 private ULocale longULocale; 22 private Locale sampleLocale; 23 24 /** 25 * @Override 26 */ 27 protected void setUp() throws Exception { 28 super.setUp(); 29 30 sampleName = "ll_CC_VVVV"; 31 longULocaleName = "ll_Ssss_CC_VVVV@collation=phonebook;key=value"; 32 longULocaleBasename = longULocaleName.substring(0, longULocaleName.indexOf('@')); 33 nonNormalizedName = "LL_ssss_cc_VVVV@ Key = value ; Collation = phonebook ; "; 34 longULocale = new ULocale(longULocaleName); 35 sampleLocale = new ULocale(sampleName).toLocale(); 36 } 37 38 /* 39 * Test method for 'com.ibm.icu.x.util.ULocale.hashCode()' 40 */ 41 public void testHashCode() { 42 ULocale obj = ULocale.GERMANY; 43 ULocale eq = new ULocale("de_DE"); 44 ULocale neq = new ULocale("de_DE_FRENCH"); 45 46 ICUTestCase.testEHCS(obj, eq, neq); 47 } 48 49 /* 50 * Test method for 'com.ibm.icu.x.util.ULocale.forLocale(Locale)' 51 */ 52 public void testForLocale() { 53 assertEquals(ULocale.GERMANY, ULocale.forLocale(Locale.GERMANY)); 54 } 55 56 /* 57 * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String)' 58 */ 59 public void testULocaleString() { 60 assertEquals(ULocale.GERMAN, new ULocale("de")); 61 } 62 63 /* 64 * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String)' 65 */ 66 public void testULocaleStringString() { 67 assertEquals(ULocale.GERMANY, new ULocale("de", "DE")); 68 } 69 70 /* 71 * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String, String)' 72 */ 73 public void testULocaleStringStringString() { 74 assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale()); 75 } 76 77 /* 78 * Test method for 'com.ibm.icu.x.util.ULocale.createCanonical(String)' 79 */ 80 public void testCreateCanonical() { 81 ULocale result = ULocale.createCanonical("de__PHONEBOOK"); 82 assertEquals(new ULocale("de@collation=phonebook"), result); 83 } 84 85 /* 86 * Test method for 'com.ibm.icu.x.util.ULocale.toLocale()' 87 */ 88 public void testToLocale() { 89 assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale()); 90 } 91 92 /* 93 * Test method for 'com.ibm.icu.x.util.ULocale.getDefault()' 94 */ 95 public void testGetDefault() { 96 assertEquals(Locale.getDefault(), ULocale.getDefault().toLocale()); 97 } 98 99 /* 100 * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(ULocale)' 101 */ 102 public void testSetDefault() { 103 Locale oldLocale = Locale.getDefault(); 104 ULocale oldULocale = ULocale.getDefault(); 105 try { 106 ULocale.setDefault(longULocale); 107 ICUTestCase.assertNotEqual(Locale.getDefault(), oldLocale); 108 ICUTestCase.assertNotEqual(ULocale.getDefault(), oldULocale); 109 assertEquals(longULocale, ULocale.getDefault()); 110 assertEquals(sampleLocale, Locale.getDefault()); 111 } 112 finally { 113 ULocale.setDefault(oldULocale); 114 Locale.setDefault(oldLocale); // in case of some error 115 } 116 } 117 118 /* 119 * Test method for 'com.ibm.icu.x.util.ULocale.clone()' 120 */ 121 public void testClone() { 122 // see testHashcode 123 } 124 125 /* 126 * Test method for 'com.ibm.icu.x.util.ULocale.equals(Object)' 127 */ 128 public void testEqualsObject() { 129 // see testHashcode 130 } 131 132 /* 133 * Test method for 'com.ibm.icu.x.util.ULocale.getAvailableLocales()' 134 */ 135 public void testGetAvailableLocales() { 136 ULocale[] ulocales = ULocale.getAvailableLocales(); 137 if (ICUTestCase.testingWrapper) { 138 Locale[] locales = Locale.getAvailableLocales(); 139 for (int i = 0; i < ulocales.length; ++i) { 140 assertEquals(ulocales[i].toLocale(), locales[i]); 141 } 142 } 143 // else nothing to test except that the function returned. 144 } 145 146 /* 147 * Test method for 'com.ibm.icu.x.util.ULocale.getISOCountries()' 148 */ 149 public void testGetISOCountries() { 150 String[] ucountries = ULocale.getISOCountries(); 151 assertNotNull(ucountries); 152 if (ICUTestCase.testingWrapper) { 153 // keep our own data for now 154 // our data doesn't match java's so this test would fail 155 // TODO: enable if we decide to use java's data 156 // String[] countries = Locale.getISOCountries(); 157 // TestBoilerplate.assertArraysEqual(ucountries, countries); 158 } 159 // else nothing to test except that the function returned. 160 } 161 162 /* 163 * Test method for 'com.ibm.icu.x.util.ULocale.getISOLanguages()' 164 */ 165 public void testGetISOLanguages() { 166 String[] ulanguages = ULocale.getISOLanguages(); 167 assertNotNull(ulanguages); 168 if (ICUTestCase.testingWrapper) { 169 // keep our own data for now 170 // our data doesn't match java's so this test would fail 171 // TODO: enable if we decide to use java's data 172 // String[] languages = Locale.getISOLanguages(); 173 // TestBoilerplate.assertArraysEqual(ulanguages, languages); 174 } 175 // else nothing to test except that the function returned. 176 } 177 178 /* 179 * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage()' 180 */ 181 public void testGetLanguage() { 182 assertEquals("ll", longULocale.getLanguage()); 183 assertEquals("ll", longULocale.toLocale().getLanguage()); 184 } 185 186 /* 187 * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage(String)' 188 */ 189 public void testGetLanguageString() { 190 assertEquals("ll", ULocale.getLanguage(longULocale.getName())); 191 } 192 193 /* 194 * Test method for 'com.ibm.icu.x.util.ULocale.getScript()' 195 */ 196 public void testGetScript() { 197 assertEquals("Ssss", longULocale.getScript()); 198 } 199 200 /* 201 * Test method for 'com.ibm.icu.x.util.ULocale.getScript(String)' 202 */ 203 public void testGetScriptString() { 204 assertEquals("Ssss", ULocale.getScript(longULocale.getName())); 205 } 206 207 /* 208 * Test method for 'com.ibm.icu.x.util.ULocale.getCountry()' 209 */ 210 public void testGetCountry() { 211 assertEquals("CC", longULocale.getCountry()); 212 assertEquals("CC", longULocale.toLocale().getCountry()); 213 } 214 215 /* 216 * Test method for 'com.ibm.icu.x.util.ULocale.getCountry(String)' 217 */ 218 public void testGetCountryString() { 219 assertEquals("CC", ULocale.getCountry(longULocale.getName())); 220 } 221 222 /* 223 * Test method for 'com.ibm.icu.x.util.ULocale.getVariant()' 224 */ 225 public void testGetVariant() { 226 assertEquals("VVVV", longULocale.getVariant()); 227 assertEquals("VVVV", longULocale.toLocale().getVariant()); 228 } 229 230 /* 231 * Test method for 'com.ibm.icu.x.util.ULocale.getVariant(String)' 232 */ 233 public void testGetVariantString() { 234 assertEquals("VVVV", ULocale.getVariant(longULocale.getName())); 235 } 236 237 /* 238 * Test method for 'com.ibm.icu.x.util.ULocale.getFallback(String)' 239 */ 240 public void testGetFallbackString() { 241 assertEquals(ULocale.GERMAN, ULocale.getFallback(ULocale.GERMANY.getName())); 242 } 243 244 /* 245 * Test method for 'com.ibm.icu.x.util.ULocale.getFallback()' 246 */ 247 public void testGetFallback() { 248 assertEquals(ULocale.GERMAN, ULocale.GERMANY.getFallback()); 249 } 250 251 /* 252 * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName()' 253 */ 254 public void testGetBaseName() { 255 assertEquals(longULocaleBasename, longULocale.getBaseName()); 256 } 257 258 /* 259 * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName(String)' 260 */ 261 public void testGetBaseNameString() { 262 assertEquals(longULocaleBasename, longULocale.getBaseName()); 263 } 264 265 /* 266 * Test method for 'com.ibm.icu.x.util.ULocale.getName()' 267 */ 268 public void testGetName() { 269 assertEquals(longULocaleName, longULocale.getName()); 270 } 271 272 /* 273 * Test method for 'com.ibm.icu.x.util.ULocale.getName(String)' 274 */ 275 public void testGetNameString() { 276 assertEquals(longULocaleName, ULocale.getName(nonNormalizedName)); 277 } 278 279 /* 280 * Test method for 'com.ibm.icu.x.util.ULocale.toString()' 281 */ 282 public void testToString() { 283 assertEquals(longULocaleName, longULocale.toString()); 284 } 285 286 /* 287 * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords()' 288 */ 289 public void testGetKeywords() { 290 Iterator<String> iter = longULocale.getKeywords(); 291 assertEquals(iter.next(), "collation"); 292 assertEquals(iter.next(), "key"); 293 assertFalse(iter.hasNext()); 294 } 295 296 /* 297 * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords(String)' 298 */ 299 public void testGetKeywordsString() { 300 Iterator<String> iter = ULocale.getKeywords(nonNormalizedName); 301 assertEquals(iter.next(), "collation"); 302 assertEquals(iter.next(), "key"); 303 assertFalse(iter.hasNext()); 304 } 305 306 /* 307 * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String)' 308 */ 309 public void testGetKeywordValueString() { 310 assertEquals("value", longULocale.getKeywordValue("key")); 311 assertEquals("phonebook", longULocale.getKeywordValue("collation")); 312 assertNull(longULocale.getKeywordValue("zzyzx")); 313 } 314 315 /* 316 * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String, String)' 317 */ 318 public void testGetKeywordValueStringString() { 319 assertEquals("value", ULocale.getKeywordValue(longULocaleName, "key")); 320 assertEquals("phonebook", ULocale.getKeywordValue(longULocaleName, "collation")); 321 assertNull(ULocale.getKeywordValue(longULocaleName, "zzyzx")); 322 323 } 324 325 /* 326 * Test method for 'com.ibm.icu.x.util.ULocale.canonicalize(String)' 327 */ 328 public void testCanonicalize() { 329 assertEquals("de@collation=phonebook", ULocale.canonicalize("de__PHONEBOOK")); 330 } 331 332 /* 333 * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String)' 334 */ 335 public void testSetKeywordValueStringString() { 336 ULocale munged = longULocale.setKeywordValue("key", "C#"); 337 assertEquals("C#", munged.getKeywordValue("key")); 338 munged = munged.setKeywordValue("zzyzx", "grue"); 339 assertEquals("grue", munged.getKeywordValue("zzyzx")); 340 } 341 342 /* 343 * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String, String)' 344 */ 345 public void testSetKeywordValueStringStringString() { 346 String munged = ULocale.setKeywordValue(longULocaleName, "key", "C#"); 347 assertEquals("C#", ULocale.getKeywordValue(munged, "key")); 348 munged = ULocale.setKeywordValue(munged, "zzyzx", "grue"); 349 assertEquals("grue", ULocale.getKeywordValue(munged, "zzyzx")); 350 } 351 352 /* 353 * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language()' 354 */ 355 public void testGetISO3Language() { 356 String il = ULocale.GERMANY.getISO3Language(); 357 String jl = Locale.GERMANY.getISO3Language(); 358 assertEquals(il, jl); 359 } 360 361 /* 362 * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language(String)' 363 */ 364 public void testGetISO3LanguageString() { 365 String il = ULocale.getISO3Language(ULocale.GERMANY.getName()); 366 String jl = Locale.GERMANY.getISO3Language(); 367 assertEquals(il, jl); 368 } 369 370 /* 371 * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country()' 372 */ 373 public void testGetISO3Country() { 374 String ic = ULocale.GERMANY.getISO3Country(); 375 String jc = Locale.GERMANY.getISO3Country(); 376 assertEquals(ic, jc); 377 } 378 379 /* 380 * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country(String)' 381 */ 382 public void testGetISO3CountryString() { 383 String ic = ULocale.getISO3Country(ULocale.GERMANY.getName()); 384 String jc = Locale.GERMANY.getISO3Country(); 385 assertEquals(ic, jc); 386 } 387 388 /* 389 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage()' 390 */ 391 public void testGetDisplayLanguage() { 392 String idl = ULocale.GERMANY.getDisplayLanguage(); 393 String jdl = Locale.GERMANY.getDisplayLanguage(); 394 assertEquals(idl, jdl); 395 } 396 397 /* 398 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(ULocale)' 399 */ 400 public void testGetDisplayLanguageULocale() { 401 String idl = ULocale.GERMANY.getDisplayLanguage(ULocale.GERMANY); 402 String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); 403 assertEquals(idl, jdl); 404 } 405 406 /* 407 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, String)' 408 */ 409 public void testGetDisplayLanguageStringString() { 410 String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), "de_DE"); 411 String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); 412 assertEquals(idl, jdl); 413 } 414 415 /* 416 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, ULocale)' 417 */ 418 public void testGetDisplayLanguageStringULocale() { 419 String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), ULocale.GERMANY); 420 String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); 421 assertEquals(idl, jdl); 422 } 423 424 /* 425 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript()' 426 */ 427 public void testGetDisplayScript() { 428 String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript(); 429 if (ICUTestCase.testingWrapper) { 430 assertEquals("Hant", is); 431 } else { 432 assertEquals("Traditional Chinese", is); 433 } 434 } 435 436 /* 437 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(ULocale)' 438 */ 439 public void testGetDisplayScriptULocale() { 440 String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript(ULocale.GERMANY); 441 if (ICUTestCase.testingWrapper) { 442 assertEquals("Hant", is); 443 } else { 444 // TODO: look up expected value 445 assertEquals("Hant", is); 446 } 447 } 448 449 /* 450 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, String)' 451 */ 452 public void testGetDisplayScriptStringString() { 453 String is = ULocale.getDisplayScript("zh_Hant", "de_DE"); 454 if (ICUTestCase.testingWrapper) { 455 assertEquals("Hant", is); 456 } else { 457 // TODO: look up expected value 458 assertEquals("Hant", is); 459 } 460 } 461 462 /* 463 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, ULocale)' 464 */ 465 public void testGetDisplayScriptStringULocale() { 466 String is = ULocale.getDisplayScript("zh_Hant", ULocale.GERMANY); 467 if (ICUTestCase.testingWrapper) { 468 assertEquals("Hant", is); 469 } else { 470 // TODO: look up expected value 471 assertEquals("Hant", is); 472 } 473 } 474 475 /* 476 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry()' 477 */ 478 public void testGetDisplayCountry() { 479 String idc = ULocale.GERMANY.getDisplayCountry(); 480 String jdc = Locale.GERMANY.getDisplayCountry(); 481 assertEquals(idc, jdc); 482 } 483 484 /* 485 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(ULocale)' 486 */ 487 public void testGetDisplayCountryULocale() { 488 String idc = ULocale.GERMANY.getDisplayCountry(ULocale.GERMANY); 489 String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); 490 assertEquals(idc, jdc); 491 } 492 493 /* 494 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, String)' 495 */ 496 public void testGetDisplayCountryStringString() { 497 String idc = ULocale.getDisplayCountry("de_DE", "de_DE"); 498 String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); 499 assertEquals(idc, jdc); 500 } 501 502 /* 503 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, ULocale)' 504 */ 505 public void testGetDisplayCountryStringULocale() { 506 String idc = ULocale.getDisplayCountry("de_DE", ULocale.GERMANY); 507 String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); 508 assertEquals(idc, jdc); 509 } 510 511 /* 512 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant()' 513 */ 514 public void testGetDisplayVariant() { 515 String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant(); 516 String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(); 517 assertEquals(jdv, idv); 518 } 519 520 /* 521 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(ULocale)' 522 */ 523 public void testGetDisplayVariantULocale() { 524 String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant(ULocale.GERMANY); 525 String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); 526 assertEquals(jdv, idv); 527 } 528 529 /* 530 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, String)' 531 */ 532 public void testGetDisplayVariantStringString() { 533 String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", "de_DE"); 534 String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); 535 assertEquals(jdv, idv); 536 } 537 538 /* 539 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, ULocale)' 540 */ 541 public void testGetDisplayVariantStringULocale() { 542 String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", ULocale.GERMANY); 543 String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); 544 assertEquals(jdv, idv); 545 } 546 547 /* 548 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String)' 549 */ 550 public void testGetDisplayKeywordString() { 551 String idk = ULocale.getDisplayKeyword("collation"); 552 assertEquals("collation", idk); 553 } 554 555 /* 556 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, String)' 557 */ 558 public void testGetDisplayKeywordStringString() { 559 String idk = ULocale.getDisplayKeyword("collation", "de_DE"); 560 if (ICUTestCase.testingWrapper) { 561 assertEquals("collation", idk); 562 } else { 563 // TODO: find real value 564 assertEquals("collation", idk); 565 } 566 } 567 568 /* 569 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, ULocale)' 570 */ 571 public void testGetDisplayKeywordStringULocale() { 572 String idk = ULocale.getDisplayKeyword("collation", ULocale.GERMANY); 573 if (ICUTestCase.testingWrapper) { 574 assertEquals("collation", idk); 575 } else { 576 // TODO: find real value 577 assertEquals("collation", idk); 578 } 579 } 580 581 /* 582 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String)' 583 */ 584 public void testGetDisplayKeywordValueString() { 585 ULocale ul = new ULocale("de_DE@collation=phonebook"); 586 String idk = ul.getDisplayKeywordValue("collation"); 587 if (ICUTestCase.testingWrapper) { 588 assertEquals("phonebook", idk); 589 } else { 590 // TODO: find real value 591 assertEquals("phonebook", idk); 592 } 593 } 594 595 /* 596 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, ULocale)' 597 */ 598 public void testGetDisplayKeywordValueStringULocale() { 599 ULocale ul = new ULocale("de_DE@collation=phonebook"); 600 String idk = ul.getDisplayKeywordValue("collation", ULocale.GERMANY); 601 if (ICUTestCase.testingWrapper) { 602 assertEquals("phonebook", idk); 603 } else { 604 // TODO: find real value 605 assertEquals("phonebook", idk); 606 } 607 } 608 609 /* 610 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, String)' 611 */ 612 public void testGetDisplayKeywordValueStringStringString() { 613 String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", "de_DE"); 614 if (ICUTestCase.testingWrapper) { 615 assertEquals("phonebook", idk); 616 } else { 617 // TODO: find real value 618 assertEquals("phonebook", idk); 619 } 620 } 621 622 /* 623 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, ULocale)' 624 */ 625 public void testGetDisplayKeywordValueStringStringULocale() { 626 String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", ULocale.GERMANY); 627 if (ICUTestCase.testingWrapper) { 628 assertEquals("phonebook", idk); 629 } else { 630 // TODO: find real value 631 assertEquals("phonebook", idk); 632 } 633 } 634 635 /* 636 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName()' 637 */ 638 public void testGetDisplayName() { 639 String idn = ULocale.GERMANY.getDisplayName(); 640 String jdn = Locale.GERMANY.getDisplayName(); 641 assertEquals(idn, jdn); 642 } 643 644 /* 645 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(ULocale)' 646 */ 647 public void testGetDisplayNameULocale() { 648 String idn = ULocale.GERMANY.getDisplayName(ULocale.GERMANY); 649 String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); 650 assertEquals(idn, jdn); 651 } 652 653 /* 654 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, String)' 655 */ 656 public void testGetDisplayNameStringString() { 657 String idn = ULocale.getDisplayName("de_DE", "de_DE"); 658 String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); 659 assertEquals(idn, jdn); 660 } 661 662 /* 663 * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, ULocale)' 664 */ 665 public void testGetDisplayNameStringULocale() { 666 String idn = ULocale.getDisplayName("de_DE", ULocale.GERMANY); 667 String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); 668 assertEquals(idn, jdn); 669 } 670 671 /* 672 * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, ULocale[], boolean[])' 673 */ 674 public void testAcceptLanguageStringULocaleArrayBooleanArray() { 675 boolean[] fallback = new boolean[1]; 676 ULocale[] locales = { 677 new ULocale("en_CA"), 678 new ULocale("es_US"), 679 }; 680 ULocale result = ULocale.acceptLanguage("en-US, en-GB, en-CA, es-US", locales, fallback); 681 assertEquals(new ULocale("en_CA"), result); 682 assertFalse(fallback[0]); 683 result = ULocale.acceptLanguage("en-US, en-GB, es-US-NEWMEXICO", locales, fallback); 684 assertEquals(new ULocale("es_US"), result); 685 assertTrue(fallback[0]); 686 } 687 688 /* 689 * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], ULocale[], boolean[])' 690 */ 691 public void testAcceptLanguageULocaleArrayULocaleArrayBooleanArray() { 692 boolean[] fallback = new boolean[1]; 693 ULocale[] locales = { 694 new ULocale("en_CA"), 695 new ULocale("es_US"), 696 }; 697 ULocale[] accept_locales = { 698 new ULocale("en_US"), 699 new ULocale("en_GB"), 700 new ULocale("en_CA"), 701 new ULocale("es_US"), 702 }; 703 ULocale[] accept_locales2 = { 704 new ULocale("en_US"), 705 new ULocale("en_GB"), 706 new ULocale("es_US_NEWMEXICO"), 707 }; 708 ULocale result = ULocale.acceptLanguage(accept_locales, locales, fallback); 709 assertEquals(new ULocale("en_CA"), result); 710 assertFalse(fallback[0]); 711 result = ULocale.acceptLanguage(accept_locales2, locales, fallback); 712 assertEquals(new ULocale("es_US"), result); 713 assertTrue(fallback[0]); 714 } 715 716 /* 717 * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, boolean[])' 718 */ 719 public void testAcceptLanguageStringBooleanArray() { 720 boolean[] fallback = new boolean[1]; 721 ULocale result = ULocale.acceptLanguage("en-CA, en-GB, es-US", fallback); 722 assertEquals(new ULocale("en_CA"), result); 723 assertFalse(fallback[0]); 724 result = ULocale.acceptLanguage("es-US-NEWMEXICO", fallback); 725 assertNotNull(result); // actual result depends on jdk 726 assertTrue(fallback[0]); 727 } 728 729 /* 730 * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], boolean[])' 731 */ 732 public void testAcceptLanguageULocaleArrayBooleanArray() { 733 boolean[] fallback = new boolean[1]; 734 ULocale[] accept_locales = { 735 new ULocale("en_CA"), 736 new ULocale("en_GB"), 737 new ULocale("es_US"), 738 }; 739 ULocale[] accept_locales2 = { 740 new ULocale("es_US_NEWMEXICO"), 741 }; 742 ULocale result = ULocale.acceptLanguage(accept_locales, fallback); 743 assertEquals(new ULocale("en_CA"), result); 744 assertFalse(fallback[0]); 745 result = ULocale.acceptLanguage(accept_locales2, fallback); 746 assertNotNull(result); // actual result depends on jdk 747 assertTrue(fallback[0]); 748 } 749 750 /* 751 * Test method for 'com.ibm.icu.x.util.ULocale.toLanguageTag()' 752 */ 753 public void testToLanguageTag() { 754 ULocale[] test_ulocales = { 755 new ULocale("en_US"), 756 new ULocale(""), 757 new ULocale("de_DE@collation=phonebook"), 758 new ULocale("en_Latn_US_POSIX"), 759 new ULocale("th_TH@numbers=thai;calendar=buddhist"), 760 new ULocale("und_CN@timezone=PRC"), 761 new ULocale("iw_IL"), 762 }; 763 764 String[] expected = { 765 "en-US", 766 "und", 767 "de-DE-u-co-phonebk", 768 "en-Latn-US-u-va-posix", 769 "th-TH-u-ca-buddhist-nu-thai", 770 "und-CN-u-tz-cnsha", 771 "he-IL", 772 }; 773 774 for (int i = 0; i < test_ulocales.length; i++) { 775 String result = test_ulocales[i].toLanguageTag(); 776 assertEquals(expected[i], result); 777 } 778 } 779 780 /* 781 * Test method for 'com.ibm.icu.x.util.ULocale.forLanguageTag()' 782 */ 783 public void testForLanguageTag() { 784 String[] test_tags = { 785 "en-us", 786 "Und-Us", 787 "ja-jp-u-ca-japanese", 788 "fr-FR-u-tz-frpar-ca-gregory", 789 }; 790 791 ULocale[] expected = { 792 new ULocale("en_US"), 793 new ULocale("und_US"), 794 new ULocale("ja_JP@calendar=japanese"), 795 new ULocale("fr_FR@calendar=gregorian;timezone=Europe/Paris"), 796 }; 797 798 for (int i = 0; i < test_tags.length; i++) { 799 ULocale result = ULocale.forLanguageTag(test_tags[i]); 800 assertEquals(expected[i], result); 801 } 802 } 803 804 /* 805 * Test method for 'com.ibm.icu.x.util.ULocale.getDefault(Category)' 806 */ 807 public void testGetDefaultCategory() { 808 ULocale dispLoc = ULocale.getDefault(Category.DISPLAY); 809 assertNotNull(dispLoc); 810 ULocale formLoc = ULocale.getDefault(Category.FORMAT); 811 assertNotNull(formLoc); 812 } 813 814 /* 815 * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(Category, ULocale)' 816 */ 817 public void testSetDefaultCategoryULocale() { 818 ULocale orgDefault = ULocale.getDefault(); 819 ULocale orgDisplay = ULocale.getDefault(Category.DISPLAY); 820 ULocale orgFormat = ULocale.getDefault(Category.FORMAT); 821 822 ULocale jaUS = new ULocale("ja_US"); 823 ULocale.setDefault(jaUS); 824 825 // setDefault(ULocale) updates category defaults 826 assertEquals(ULocale.getDefault(), jaUS); 827 assertEquals(ULocale.getDefault(Category.DISPLAY), jaUS); 828 assertEquals(ULocale.getDefault(Category.FORMAT), jaUS); 829 830 ULocale frDE = new ULocale("fr_DE"); 831 ULocale.setDefault(Category.DISPLAY, frDE); 832 833 // setDefault(Category, ULocale) only updates the category default 834 assertEquals(ULocale.getDefault(), jaUS); 835 assertEquals(ULocale.getDefault(Category.DISPLAY), frDE); 836 assertEquals(ULocale.getDefault(Category.FORMAT), jaUS); 837 838 // restore the original 839 ULocale.setDefault(orgDefault); 840 ULocale.setDefault(Category.DISPLAY, orgDisplay); 841 ULocale.setDefault(Category.FORMAT, orgFormat); 842 843 assertEquals(ULocale.getDefault(), orgDefault); 844 assertEquals(ULocale.getDefault(Category.DISPLAY), orgDisplay); 845 assertEquals(ULocale.getDefault(Category.FORMAT), orgFormat); 846 } 847 } 848