Skip to content

Commit 32f67a3

Browse files
author
Justin Lu
committed
8356040: java/util/PluggableLocale/LocaleNameProviderTest.java timed out
Reviewed-by: naoto
1 parent f687644 commit 32f67a3

File tree

1 file changed

+85
-69
lines changed

1 file changed

+85
-69
lines changed

test/jdk/java/util/PluggableLocale/LocaleNameProviderTest.java

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,105 +23,121 @@
2323

2424
/*
2525
* @test
26-
* @bug 4052440 8000273 8062588 8210406 8174269
26+
* @bug 4052440 8000273 8062588 8210406 8174269 8356040
2727
* @summary LocaleNameProvider tests
2828
* @library providersrc/foobarutils
2929
* providersrc/barprovider
3030
* @modules java.base/sun.util.locale.provider
3131
* java.base/sun.util.resources
3232
* @build com.foobar.Utils
3333
* com.bar.*
34-
* @run main/othervm -Djava.locale.providers=CLDR,SPI LocaleNameProviderTest
34+
* @run junit/othervm -Djava.locale.providers=CLDR,SPI LocaleNameProviderTest
3535
*/
3636

37+
import java.util.ArrayList;
3738
import java.util.Arrays;
3839
import java.util.List;
3940
import java.util.Locale;
4041
import java.util.MissingResourceException;
42+
import java.util.ResourceBundle;
4143

4244
import com.bar.LocaleNameProviderImpl;
4345

46+
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.params.ParameterizedTest;
48+
import org.junit.jupiter.params.provider.Arguments;
49+
import org.junit.jupiter.params.provider.MethodSource;
4450
import sun.util.locale.provider.LocaleProviderAdapter;
4551
import sun.util.locale.provider.ResourceBundleBasedAdapter;
4652
import sun.util.resources.OpenListResourceBundle;
4753

4854
public class LocaleNameProviderTest extends ProviderTest {
4955

50-
public static void main(String[] s) {
51-
new LocaleNameProviderTest();
52-
}
56+
private static final LocaleNameProviderImpl LNP = new LocaleNameProviderImpl();
57+
58+
/*
59+
* This is not an exhaustive test. Such a test would require iterating (1000x1000)+
60+
* inputs. Instead, we check against Japanese lang locales which guarantees
61+
* we will run into cases where the CLDR is not the preferred provider as the
62+
* SPI has defined variants of the Japanese locale (E.g. osaka).
63+
* See LocaleNameProviderImpl and LocaleNames ResourceBundle.
64+
*/
65+
@ParameterizedTest
66+
@MethodSource
67+
void checkAvailLocValidityTest(Locale target, Locale test, ResourceBundle rb,
68+
boolean jreSupports, boolean spiSupports) {
69+
// codes
70+
String lang = test.getLanguage();
71+
String ctry = test.getCountry();
72+
String vrnt = test.getVariant();
73+
74+
// the localized name
75+
String langresult = test.getDisplayLanguage(target);
76+
String ctryresult = test.getDisplayCountry(target);
77+
String vrntresult = test.getDisplayVariant(target);
78+
79+
// provider's name (if any)
80+
String providerslang = null;
81+
String providersctry = null;
82+
String providersvrnt = null;
83+
if (spiSupports) {
84+
providerslang = LNP.getDisplayLanguage(lang, target);
85+
providersctry = LNP.getDisplayCountry(ctry, target);
86+
providersvrnt = LNP.getDisplayVariant(vrnt, target);
87+
}
5388

54-
LocaleNameProviderTest() {
55-
checkAvailLocValidityTest();
56-
variantFallbackTest();
57-
}
89+
// JRE's name
90+
String jreslang = null;
91+
String jresctry = null;
92+
String jresvrnt = null;
93+
if (!lang.isEmpty()) {
94+
try {
95+
jreslang = rb.getString(lang);
96+
} catch (MissingResourceException mre) {}
97+
}
98+
if (!ctry.isEmpty()) {
99+
try {
100+
jresctry = rb.getString(ctry);
101+
} catch (MissingResourceException mre) {}
102+
}
103+
if (!vrnt.isEmpty()) {
104+
try {
105+
jresvrnt = rb.getString("%%"+vrnt);
106+
} catch (MissingResourceException mre) {}
107+
}
58108

59-
void checkAvailLocValidityTest() {
60-
LocaleNameProviderImpl lnp = new LocaleNameProviderImpl();
61-
Locale[] availloc = Locale.getAvailableLocales();
62-
Locale[] testloc = availloc.clone();
63-
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR).getLocaleNameProvider().getAvailableLocales());
64-
List<Locale> providerloc = Arrays.asList(lnp.getAvailableLocales());
109+
checkValidity(target, jreslang, providerslang, langresult,
110+
jreSupports && jreslang != null);
111+
checkValidity(target, jresctry, providersctry, ctryresult,
112+
jreSupports && jresctry != null);
113+
checkValidity(target, jresvrnt, providersvrnt, vrntresult,
114+
jreSupports && jresvrnt != null);
115+
}
65116

66-
for (Locale target: availloc) {
117+
public static List<Arguments> checkAvailLocValidityTest() {
118+
var args = new ArrayList<Arguments>();
119+
Locale[] availloc = Locale.availableLocales()
120+
.filter(l -> l.getLanguage().equals("ja"))
121+
.toArray(Locale[]::new);
122+
List<Locale> jreimplloc = Arrays.stream(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR)
123+
.getLocaleNameProvider().getAvailableLocales())
124+
.filter(l -> l.getLanguage().equals("ja"))
125+
.toList();
126+
List<Locale> providerloc = Arrays.asList(LNP.getAvailableLocales());
127+
128+
for (Locale target : availloc) {
67129
// pure JRE implementation
68-
OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR)).getLocaleData().getLocaleNames(target);
130+
OpenListResourceBundle rb = ((ResourceBundleBasedAdapter) LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR)).getLocaleData().getLocaleNames(target);
69131
boolean jreSupportsTarget = jreimplloc.contains(target);
70-
71-
for (Locale test: testloc) {
72-
// codes
73-
String lang = test.getLanguage();
74-
String ctry = test.getCountry();
75-
String vrnt = test.getVariant();
76-
77-
// the localized name
78-
String langresult = test.getDisplayLanguage(target);
79-
String ctryresult = test.getDisplayCountry(target);
80-
String vrntresult = test.getDisplayVariant(target);
81-
82-
// provider's name (if any)
83-
String providerslang = null;
84-
String providersctry = null;
85-
String providersvrnt = null;
86-
if (providerloc.contains(target)) {
87-
providerslang = lnp.getDisplayLanguage(lang, target);
88-
providersctry = lnp.getDisplayCountry(ctry, target);
89-
providersvrnt = lnp.getDisplayVariant(vrnt, target);
90-
}
91-
92-
// JRE's name
93-
String jreslang = null;
94-
String jresctry = null;
95-
String jresvrnt = null;
96-
if (!lang.equals("")) {
97-
try {
98-
jreslang = rb.getString(lang);
99-
} catch (MissingResourceException mre) {}
100-
}
101-
if (!ctry.equals("")) {
102-
try {
103-
jresctry = rb.getString(ctry);
104-
} catch (MissingResourceException mre) {}
105-
}
106-
if (!vrnt.equals("")) {
107-
try {
108-
jresvrnt = rb.getString("%%"+vrnt);
109-
} catch (MissingResourceException mre) {}
110-
}
111-
112-
System.out.print("For key: "+lang+" ");
113-
checkValidity(target, jreslang, providerslang, langresult,
114-
jreSupportsTarget && jreslang != null);
115-
System.out.print("For key: "+ctry+" ");
116-
checkValidity(target, jresctry, providersctry, ctryresult,
117-
jreSupportsTarget && jresctry != null);
118-
System.out.print("For key: "+vrnt+" ");
119-
checkValidity(target, jresvrnt, providersvrnt, vrntresult,
120-
jreSupportsTarget && jresvrnt != null);
132+
boolean providerSupportsTarget = providerloc.contains(target);
133+
for (Locale test : availloc) {
134+
args.add(Arguments.of(target, test, rb, jreSupportsTarget, providerSupportsTarget));
121135
}
122136
}
137+
return args;
123138
}
124139

140+
@Test
125141
void variantFallbackTest() {
126142
Locale YY = Locale.of("yy", "YY", "YYYY");
127143
Locale YY_suffix = Locale.of("yy", "YY", "YYYY_suffix");

0 commit comments

Comments
 (0)