101
102 static void tzNameTest(String id) {
103 TimeZone tz = TimeZone.getTimeZone(id);
104 String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
105 if (tzName.startsWith("GMT")) {
106 throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
107 }
108 }
109
110 static void bug8001440Test() {
111 Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
112 NumberFormat nf = NumberFormat.getInstance(locale);
113 String nu = nf.format(1234560);
114 }
115
116 // This test assumes Windows localized language/country display names.
117 static void bug8010666Test() {
118 if (System.getProperty("os.name").startsWith("Windows")) {
119 NumberFormat nf = NumberFormat.getInstance(Locale.US);
120 try {
121 double ver = nf.parse(System.getProperty("os.version")).doubleValue();
122 System.out.printf("Windows version: %.1f\n", ver);
123 if (ver >= 6.0) {
124 LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(LocaleNameProvider.class, Locale.ENGLISH);
125 LocaleProviderAdapter.Type type = lda.getAdapterType();
126 if (type == LocaleProviderAdapter.Type.HOST) {
127 Locale mkmk = Locale.forLanguageTag("mk-MK");
128 String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
129 if (!"Macedonian (FYROM)".equals(result)) {
130 throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"mk\". Returned name was \"" + result + "\"");
131 }
132 result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
133 if (!"English".equals(result)) {
134 throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"en\". Returned name was \"" + result + "\"");
135 }
136 result = Locale.US.getDisplayCountry(Locale.ENGLISH);
137 if (ver >= 6.1 && !"United States".equals(result)) {
138 throw new RuntimeException("Windows locale name provider did not return expected localized country name for \"US\". Returned name was \"" + result + "\"");
139 }
140 } else {
141 throw new RuntimeException("Windows Host LocaleProviderAdapter was not selected for English locale.");
142 }
143 }
144 } catch (ParseException pe) {
145 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
146 }
147 }
148 }
149
150 static void bug8013086Test(String lang, String ctry) {
151 try {
152 // Throws a NullPointerException if the test fails.
153 System.out.println(new SimpleDateFormat("z", new Locale(lang, ctry)).parse("UTC"));
154 } catch (ParseException pe) {
155 // ParseException is fine in this test, as it's not "UTC"
156 }
157 }
158 }
|
101
102 static void tzNameTest(String id) {
103 TimeZone tz = TimeZone.getTimeZone(id);
104 String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
105 if (tzName.startsWith("GMT")) {
106 throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
107 }
108 }
109
110 static void bug8001440Test() {
111 Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
112 NumberFormat nf = NumberFormat.getInstance(locale);
113 String nu = nf.format(1234560);
114 }
115
116 // This test assumes Windows localized language/country display names.
117 static void bug8010666Test() {
118 if (System.getProperty("os.name").startsWith("Windows")) {
119 NumberFormat nf = NumberFormat.getInstance(Locale.US);
120 try {
121 double ver = nf.parse(System.getProperty("os.version"))
122 .doubleValue();
123 System.out.printf("Windows version: %.1f\n", ver);
124 if (ver >= 6.0) {
125 LocaleProviderAdapter lda =
126 LocaleProviderAdapter.getAdapter(
127 LocaleNameProvider.class, Locale.ENGLISH);
128 LocaleProviderAdapter.Type type = lda.getAdapterType();
129 if (type == LocaleProviderAdapter.Type.HOST) {
130 LocaleNameProvider lnp = lda.getLocaleNameProvider();
131 Locale mkmk = Locale.forLanguageTag("mk-MK");
132 String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
133 String expected =
134 lnp.getDisplayLanguage(mkmk.getLanguage(),
135 Locale.ENGLISH);
136 System.out.printf(" Display language name for" +
137 " (mk_MK): expected: \"%s\", returned: \"%s\"\n",
138 expected, result);
139 if (result != null &&
140 expected != null &&
141 !result.equals(expected)) {
142 throw new RuntimeException("Windows locale name" +
143 " provider did not return expected localized" +
144 " language name for \"mk\". Returned name was" +
145 " \"" + result + "\", expected: \"" + expected +
146 "\"");
147 }
148 result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
149 expected =
150 lnp.getDisplayLanguage(Locale.US.getLanguage(),
151 Locale.ENGLISH);
152 System.out.printf(" Display language name for" +
153 " (en_US): expected: \"%s\", returned: \"%s\"\n",
154 expected, result);
155 if (result != null &&
156 expected != null &&
157 !result.equals(expected)) {
158 throw new RuntimeException("Windows locale name" +
159 " provider did not return expected localized" +
160 " language name for \"en\". Returned name was" +
161 " \"" + result + "\", expected: \"" + expected + "\"");
162 }
163 if (ver >= 6.1) {
164 result = Locale.US.getDisplayCountry(Locale.ENGLISH);
165 expected = lnp.getDisplayCountry(
166 Locale.US.getCountry(), Locale.ENGLISH);
167 System.out.printf(" Display country name for" +
168 " (en_US): expected: \"%s\", returned: \"%s\"\n",
169 expected, result);
170 if (result != null &&
171 expected != null &&
172 !result.equals(expected)) {
173 throw new RuntimeException("Windows locale" +
174 " name provider did not return expected" +
175 " localized country name for \"US\"." +
176 " Returned name was \"" + result + "\"," +
177 " expected: \"" + expected + "\"");
178 }
179 }
180 } else {
181 throw new RuntimeException("Windows Host" +
182 " LocaleProviderAdapter was not selected for" +
183 " English locale.");
184 }
185 }
186 } catch (ParseException pe) {
187 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
188 }
189 }
190 }
191
192 static void bug8013086Test(String lang, String ctry) {
193 try {
194 // Throws a NullPointerException if the test fails.
195 System.out.println(new SimpleDateFormat("z", new Locale(lang, ctry)).parse("UTC"));
196 } catch (ParseException pe) {
197 // ParseException is fine in this test, as it's not "UTC"
198 }
199 }
200 }
|