Print this page
rev 5994 : imported patch 8001205
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/Locale/LocaleProviders.java
+++ new/test/java/util/Locale/LocaleProviders.java
1 1 /*
2 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 */
23 23 import java.text.*;
24 24 import java.text.spi.*;
25 25 import java.util.*;
26 26 import sun.util.locale.provider.LocaleProviderAdapter;
27 27
28 28 public class LocaleProviders {
29 29
30 30 public static void main(String[] args) {
31 31 String methodName = args[0];
32 32
33 33 switch (methodName) {
34 34 case "getPlatformLocale":
35 35 if (args[1].equals("format")) {
36 36 getPlatformLocale(Locale.Category.FORMAT);
37 37 } else {
38 38 getPlatformLocale(Locale.Category.DISPLAY);
39 39 }
40 40 break;
41 41
42 42 case "adapterTest":
43 43 adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
44 44 break;
45 45
46 46 case "bug7198834Test":
47 47 bug7198834Test();
48 48 break;
49 49
50 50 case "tzNameTest":
51 51 tzNameTest(args[1]);
52 52 break;
53 53
54 + case "bug8001205Test":
55 + bug8001205Test();
56 + break;
57 +
54 58 default:
55 59 throw new RuntimeException("Test method '"+methodName+"' not found.");
56 60 }
57 61 }
58 62
59 63 static void getPlatformLocale(Locale.Category cat) {
60 64 Locale defloc = Locale.getDefault(cat);
61 65 System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
62 66 }
63 67
64 68 static void adapterTest(String expected, String lang, String ctry) {
65 69 Locale testLocale = new Locale(lang, ctry);
66 70 String preference = System.getProperty("java.locale.providers", "");
67 71 LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
68 72 LocaleProviderAdapter.Type type = lda.getAdapterType();
69 73 System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
70 74 if (!type.toString().equals(expected)) {
71 75 throw new RuntimeException("Returned locale data adapter is not correct.");
72 76 }
73 77 }
74 78
75 79 static void bug7198834Test() {
76 80 LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
77 81 LocaleProviderAdapter.Type type = lda.getAdapterType();
78 82 if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
79 83 DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
80 84 String date = df.format(new Date());
81 85 if (date.charAt(date.length()-1) == ' ') {
82 86 throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
83 87 }
84 88 } else {
85 89 System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
86 90 }
87 91 }
88 92
89 93 static void tzNameTest(String id) {
90 94 TimeZone tz = TimeZone.getTimeZone(id);
91 95 String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
92 96 if (tzName.startsWith("GMT")) {
93 97 throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
94 98 }
95 99 }
100 +
101 + static void bug8001205Test() {
102 + Calendar cal = Calendar.getInstance();
103 + cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
104 + String sunday = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT_STANDALONE, Locale.CHINA);
105 + if (sunday == null) {
106 + throw new RuntimeException("Calendar.getDisplayName(DAY_OF_WEEK/SHORT_STANDALONE) returned null.");
107 + }
108 + }
96 109 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX