Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Nov 21, 2023
1 parent 3897148 commit 7d1f79f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
8 changes: 4 additions & 4 deletions test/jdk/java/util/Locale/ThaiGov.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

/*
* @test
* @bug 4474409
* @bug 4474409 8174269
* @summary Tests some localized methods with Thai locale
* @author John O'Conner
* @modules jdk.localedata
* @run junit/othervm -Djava.locale.providers=COMPAT ThaiGov
* @run junit ThaiGov
*/

import java.text.DateFormat;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void numberTest() {
// Test currency formatting for Thai
@Test
public void currencyTest() {
final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";
final String strExpected = "\u0e3f\u00a0\u0e51\u0e52,\u0e53\u0e54\u0e55,\u0e56\u0e57\u0e58.\u0e52\u0e53";
NumberFormat nf = NumberFormat.getCurrencyInstance(TH);
String str = nf.format(VALUE);
assertEquals(strExpected, str);
Expand All @@ -77,7 +77,7 @@ public void dateTest() {
cal.setTime(date);


final String strExpected = "\u0E27\u0E31\u0E19\u0E1E\u0E38\u0E18\u0E17\u0E35\u0E48\u0020\u0E51\u0020\u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21\u0020\u0E1E\u002E\u0E28\u002E\u0020\u0E52\u0E55\u0E54\u0E55\u002C\u0020\u0E58\u0020\u0E19\u0E32\u0E2C\u0E34\u0E01\u0E32\u0020\u0E53\u0E50\u0020\u0E19\u0E32\u0E17\u0E35\u0020\u0E50\u0E50\u0020\u0E27\u0E34\u0E19\u0E32\u0E17\u0E35";
final String strExpected = "\u0e27\u0e31\u0e19\u0e1e\u0e38\u0e18\u0e17\u0e35\u0e48 \u0e51 \u0e1e\u0e24\u0e29\u0e20\u0e32\u0e04\u0e21 \u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a \u0e52\u0e55\u0e54\u0e55 \u0e58 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 \u0e53\u0e50 \u0e19\u0e32\u0e17\u0e35 \u0e50\u0e50 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35 \u0e40\u0e27\u0e25\u0e32\u0e2d\u0e2d\u0e21\u0e41\u0e2a\u0e07\u0e41\u0e1b\u0e0b\u0e34\u0e1f\u0e34\u0e01\u0e43\u0e19\u0e2d\u0e40\u0e21\u0e23\u0e34\u0e01\u0e32\u0e40\u0e2b\u0e19\u0e37\u0e2d";
Date value = cal.getTime();

// th_TH_TH test
Expand Down
21 changes: 11 additions & 10 deletions test/jdk/java/util/PluggableLocale/BreakIteratorProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,18 +23,19 @@

/*
* @test
* @bug 4052440 8062588 8165804 8210406 8291660
* @bug 4052440 8062588 8165804 8210406 8291660 8174269
* @summary BreakIteratorProvider tests
* @library providersrc/foobarutils
* providersrc/fooprovider
* @modules java.base/sun.util.locale.provider
* java.base/sun.util.resources
* @build com.foobar.Utils
* com.foo.*
* @run main/othervm -Djava.locale.providers=JRE,SPI BreakIteratorProviderTest
* @run main/othervm -Djava.locale.providers=CLDR,SPI BreakIteratorProviderTest
*/

import java.text.BreakIterator;
import java.text.Collator;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -52,8 +53,8 @@ public class BreakIteratorProviderTest extends ProviderTest {
BreakIteratorProviderImpl bip = new BreakIteratorProviderImpl();
List<Locale> availloc = Arrays.asList(BreakIterator.getAvailableLocales());
List<Locale> providerloc = Arrays.asList(bip.getAvailableLocales());
List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getBreakIteratorProvider().getAvailableLocales());
List<Locale> fallbackloc = Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getAvailableLocales());
List<Locale> fallbackimplloc = Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getCollatorProvider().getAvailableLocales());

public static void main(String[] s) {
new BreakIteratorProviderTest();
Expand All @@ -66,7 +67,7 @@ public static void main(String[] s) {

void availableLocalesTest() {
Set<Locale> localesFromAPI = new HashSet<>(availloc);
Set<Locale> localesExpected = new HashSet<>(jreloc);
Set<Locale> localesExpected = new HashSet<>(fallbackloc);
localesExpected.addAll(providerloc);
if (localesFromAPI.equals(localesExpected)) {
System.out.println("availableLocalesTest passed.");
Expand All @@ -79,9 +80,9 @@ void objectValidityTest() {

for (Locale target: availloc) {
// pure JRE implementation
ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getBreakIteratorInfo(target);
ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK)).getLocaleData().getBreakIteratorInfo(target);
String[] classNames = rb.getStringArray("BreakIteratorClasses");
boolean jreSupportsLocale = jreimplloc.contains(target);
boolean fbSupportsLocale = fallbackimplloc.contains(target);

// result object
String[] result = new String[4];
Expand All @@ -101,15 +102,15 @@ void objectValidityTest() {

// JRE
String[] jresResult = new String[4];
if (jreSupportsLocale) {
if (fbSupportsLocale) {
jresResult[0] = "sun.util.locale.provider.BreakIteratorProviderImpl$GraphemeBreakIterator";
for (int i = 1; i < 4; i++) {
jresResult[i] = "sun.text." + classNames[i - 1];
}
}

for (int i = 0; i < 4; i++) {
checkValidity(target, jresResult[i], providersResult[i], result[i], jreSupportsLocale);
checkValidity(target, jresResult[i], providersResult[i], result[i], fbSupportsLocale);
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions test/jdk/java/util/PluggableLocale/CollatorProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,15 +23,15 @@

/*
* @test
* @bug 4052440 8062588 8210406
* @bug 4052440 8062588 8210406 8174269
* @summary CollatorProvider tests
* @library providersrc/foobarutils
* providersrc/fooprovider
* @modules java.base/sun.util.locale.provider
* java.base/sun.util.resources
* @build com.foobar.Utils
* com.foo.*
* @run main/othervm -Djava.locale.providers=JRE,SPI CollatorProviderTest
* @run main/othervm -Djava.locale.providers=CLDR,SPI CollatorProviderTest
*/

import java.text.Collator;
Expand All @@ -56,8 +56,8 @@ public class CollatorProviderTest extends ProviderTest {
CollatorProviderImpl cp = new CollatorProviderImpl();
List<Locale> availloc = Arrays.asList(Collator.getAvailableLocales());
List<Locale> providerloc = Arrays.asList(cp.getAvailableLocales());
List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCollatorProvider().getAvailableLocales());
List<Locale> fallbackloc = Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getAvailableLocales());
List<Locale> fallbackimplloc = Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getCollatorProvider().getAvailableLocales());

public static void main(String[] s) {
new CollatorProviderTest();
Expand All @@ -70,12 +70,13 @@ public static void main(String[] s) {

void availableLocalesTest() {
Set<Locale> localesFromAPI = new HashSet<>(availloc);
Set<Locale> localesExpected = new HashSet<>(jreloc);
Set<Locale> localesExpected = new HashSet<>(fallbackloc);
localesExpected.addAll(providerloc);
if (localesFromAPI.equals(localesExpected)) {
System.out.println("availableLocalesTest passed.");
} else {
throw new RuntimeException("availableLocalesTest failed");
localesFromAPI.removeAll(localesExpected);
throw new RuntimeException("availableLocalesTest failed"+ localesFromAPI);
}
}

Expand All @@ -85,12 +86,12 @@ void objectValidityTest() {

for (Locale target: availloc) {
// pure JRE implementation
Set<Locale> jreimplloc = new HashSet<>();
for (String tag : ((AvailableLanguageTags)LocaleProviderAdapter.forJRE().getCollatorProvider()).getAvailableLanguageTags()) {
jreimplloc.add(Locale.forLanguageTag(tag));
Set<Locale> fbil = new HashSet<>();
for (String tag : ((AvailableLanguageTags)LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getCollatorProvider()).getAvailableLanguageTags()) {
fbil.add(Locale.forLanguageTag(tag));
}
ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getCollationData(target);
boolean jreSupportsLocale = jreimplloc.contains(target);
ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK)).getLocaleData().getCollationData(target);
boolean fbSupportsLocale = fbil.contains(target);

// result object
Collator result = Collator.getInstance(target);
Expand All @@ -101,19 +102,19 @@ void objectValidityTest() {
providersResult = cp.getInstance(target);
}

// JRE rule
Collator jresResult = null;
if (jreSupportsLocale) {
// Fallback rule
Collator fbResult = null;
if (fbSupportsLocale) {
try {
String rules = rb.getString("Rule");
jresResult = new RuleBasedCollator(defrules+rules);
jresResult.setDecomposition(Collator.NO_DECOMPOSITION);
fbResult = new RuleBasedCollator(defrules+rules);
fbResult.setDecomposition(Collator.NO_DECOMPOSITION);
} catch (MissingResourceException mre) {
} catch (ParseException pe) {
}
}

checkValidity(target, jresResult, providersResult, result, jreSupportsLocale);
checkValidity(target, fbResult, providersResult, result, fbSupportsLocale);
}
}
}
11 changes: 6 additions & 5 deletions test/jdk/java/util/PluggableLocale/GenericTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 4052440 8062588 8210406
* @bug 4052440 8062588 8210406 8174269
* @summary Generic tests for the pluggable locales feature
* @library providersrc/foobarutils
* providersrc/barprovider
Expand All @@ -32,7 +32,7 @@
* @build com.foobar.Utils
* com.bar.*
* com.foo.*
* @run main/othervm -Djava.locale.providers=JRE,SPI GenericTest
* @run main/othervm -Djava.locale.providers=CLDR,SPI GenericTest
*/

import java.util.Arrays;
Expand Down Expand Up @@ -86,12 +86,13 @@ public static void main(String[] s) {
* Make sure that all the locales are available from the existing providers
*/
void availableLocalesTest() {
// Check that Locale.getAvailableLocales() returns the union of the JRE supported
// Check that Locale.getAvailableLocales() returns the union of the CLDR/FALLBACK supported
// locales and providers' locales
HashSet<Locale> result =
new HashSet<>(Arrays.asList(Locale.getAvailableLocales()));
HashSet<Locale> expected =
new HashSet<>(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));
new HashSet<>(Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR).getAvailableLocales()));
expected.addAll(Arrays.asList(LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.FALLBACK).getAvailableLocales()));
expected.addAll(Arrays.asList(breakIP.getAvailableLocales()));
expected.addAll(Arrays.asList(collatorP.getAvailableLocales()));
expected.addAll(Arrays.asList(dateFP.getAvailableLocales()));
Expand Down

0 comments on commit 7d1f79f

Please sign in to comment.