1 /* |
1 /* |
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
31 import java.io.InputStreamReader; |
31 import java.io.InputStreamReader; |
32 import java.io.ObjectInputStream; |
32 import java.io.ObjectInputStream; |
33 import java.io.ObjectOutputStream; |
33 import java.io.ObjectOutputStream; |
34 import java.net.URISyntaxException; |
34 import java.net.URISyntaxException; |
35 import java.net.URL; |
35 import java.net.URL; |
|
36 import java.text.DecimalFormatSymbols; |
36 import java.util.ArrayList; |
37 import java.util.ArrayList; |
37 import java.util.Arrays; |
38 import java.util.Arrays; |
|
39 import java.util.Calendar; |
38 import java.util.IllformedLocaleException; |
40 import java.util.IllformedLocaleException; |
39 import java.util.List; |
41 import java.util.List; |
40 import java.util.Locale; |
42 import java.util.Locale; |
41 import java.util.Locale.Builder; |
43 import java.util.Locale.Builder; |
42 import java.util.Set; |
44 import java.util.Set; |
43 |
45 |
44 /** |
46 /** |
45 * @test |
47 * @test |
46 * @bug 6875847 6992272 7002320 7015500 7023613 |
48 * @bug 6875847 6992272 7002320 7015500 7023613 7032820 7033504 |
47 * @summary test API changes to Locale |
49 * @summary test API changes to Locale |
|
50 * @compile LocaleEnhanceTest.java |
|
51 * @run main/othervm -esa LocaleEnhanceTest |
48 */ |
52 */ |
49 public class LocaleEnhanceTest extends LocaleTestFmwk { |
53 public class LocaleEnhanceTest extends LocaleTestFmwk { |
50 |
54 |
51 public static void main(String[] args) throws Exception { |
55 public static void main(String[] args) throws Exception { |
52 List<String> argList = new ArrayList<String>(); |
56 List<String> argList = new ArrayList<String>(); |
591 // duplicated extension are just ignored |
595 // duplicated extension are just ignored |
592 Locale locale = Locale.forLanguageTag("und-d-aa-00-bb-01-D-AA-10-cc-11-c-1234"); |
596 Locale locale = Locale.forLanguageTag("und-d-aa-00-bb-01-D-AA-10-cc-11-c-1234"); |
593 assertEquals("extension", "aa-00-bb-01", locale.getExtension('d')); |
597 assertEquals("extension", "aa-00-bb-01", locale.getExtension('d')); |
594 assertEquals("extension c", "1234", locale.getExtension('c')); |
598 assertEquals("extension c", "1234", locale.getExtension('c')); |
595 |
599 |
|
600 locale = Locale.forLanguageTag("und-U-ca-gregory-u-ca-japanese"); |
|
601 assertEquals("Unicode extension", "ca-gregory", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION)); |
|
602 |
596 // redundant Unicode locale keys in an extension are ignored |
603 // redundant Unicode locale keys in an extension are ignored |
597 locale = Locale.forLanguageTag("und-u-aa-000-bb-001-bB-002-cc-003-c-1234"); |
604 locale = Locale.forLanguageTag("und-u-aa-000-bb-001-bB-002-cc-003-c-1234"); |
598 assertEquals("Unicode keywords", "aa-000-bb-001-cc-003", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION)); |
605 assertEquals("Unicode keywords", "aa-000-bb-001-cc-003", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION)); |
599 assertEquals("Duplicated Unicode locake key followed by an extension", "1234", locale.getExtension('c')); |
606 assertEquals("Duplicated Unicode locake key followed by an extension", "1234", locale.getExtension('c')); |
600 } |
607 } |
1273 String out = loc.toString(); |
1280 String out = loc.toString(); |
1274 assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out); |
1281 assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out); |
1275 } |
1282 } |
1276 } |
1283 } |
1277 |
1284 |
|
1285 /* |
|
1286 * 7033504: (lc) incompatible behavior change for ja_JP_JP and th_TH_TH locales |
|
1287 */ |
|
1288 public void testBug7033504() { |
|
1289 checkCalendar(new Locale("ja", "JP", "jp"), "java.util.GregorianCalendar"); |
|
1290 checkCalendar(new Locale("ja", "jp", "jp"), "java.util.GregorianCalendar"); |
|
1291 checkCalendar(new Locale("ja", "JP", "JP"), "java.util.JapaneseImperialCalendar"); |
|
1292 checkCalendar(new Locale("ja", "jp", "JP"), "java.util.JapaneseImperialCalendar"); |
|
1293 checkCalendar(Locale.forLanguageTag("en-u-ca-japanese"), |
|
1294 "java.util.JapaneseImperialCalendar"); |
|
1295 |
|
1296 checkDigit(new Locale("th", "TH", "th"), '0'); |
|
1297 checkDigit(new Locale("th", "th", "th"), '0'); |
|
1298 checkDigit(new Locale("th", "TH", "TH"), '\u0e50'); |
|
1299 checkDigit(new Locale("th", "TH", "TH"), '\u0e50'); |
|
1300 checkDigit(Locale.forLanguageTag("en-u-nu-thai"), '\u0e50'); |
|
1301 } |
|
1302 |
|
1303 private void checkCalendar(Locale loc, String expected) { |
|
1304 Calendar cal = Calendar.getInstance(loc); |
|
1305 assertEquals("Wrong calendar", expected, cal.getClass().getName()); |
|
1306 } |
|
1307 |
|
1308 private void checkDigit(Locale loc, Character expected) { |
|
1309 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc); |
|
1310 Character zero = dfs.getZeroDigit(); |
|
1311 assertEquals("Wrong digit zero char", expected, zero); |
|
1312 } |
|
1313 |
1278 /// |
1314 /// |
1279 /// utility asserts |
1315 /// utility asserts |
1280 /// |
1316 /// |
1281 |
1317 |
1282 private void assertTrue(String msg, boolean v) { |
1318 private void assertTrue(String msg, boolean v) { |