2 *******************************************************************************
\r
3 * Copyright (C) 2008-2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.localespi;
\r
9 import java.util.Locale;
\r
11 public class TestUtil {
\r
13 private static final String ICU_VARIANT = "ICU";
\r
14 private static final String ICU_VARIANT_SUFFIX = "_ICU";
\r
16 public static Locale toICUExtendedLocale(Locale locale) {
\r
17 if (isICUExtendedLocale(locale)) {
\r
20 String variant = locale.getVariant();
\r
21 variant = variant.length() == 0 ? ICU_VARIANT : variant + ICU_VARIANT_SUFFIX;
\r
22 return new Locale(locale.getLanguage(), locale.getCountry(), variant);
\r
25 public static boolean isICUExtendedLocale(Locale locale) {
\r
26 String variant = locale.getVariant();
\r
27 if (variant.equals(ICU_VARIANT) || variant.endsWith(ICU_VARIANT_SUFFIX)) {
\r
33 public static boolean equals(Object o1, Object o2) {
\r
34 if (o1 == null && o2 == null) {
\r
37 if (o1 == null || o2 == null) {
\r
40 return o1.equals(o2);
\r
43 private static final boolean SUNJRE;
\r
44 private static final boolean IBMJRE;
\r
47 String javaVendor = System.getProperty("java.vendor");
\r
48 if (javaVendor != null) {
\r
49 if (javaVendor.indexOf("Sun") >= 0) {
\r
52 } else if (javaVendor.indexOf("IBM") >= 0) {
\r
65 public static boolean isSUNJRE() {
\r
68 public static boolean isIBMJRE() {
\r
75 * The ICU4J locale spi test cases reports many errors on IBM Java 6. There are two kinds
\r
76 * of problems observed and both of them look like implementation problems in IBM Java 6.
\r
78 * - When a locale has variant field (for example, sr_RS_Cyrl, de_DE_PREEURO), adding ICU
\r
79 * suffix in the variant field (for example, sr_RS_Cyrl_ICU, de_DE_PREEURO_ICU) has no effects.
\r
80 * For these locales, IBM JRE 6 ignores installed Locale providers.
\r
82 * - For "sh" sublocales with "ICU" variant (for example, sh__ICU, sh_CS_ICU), IBM JRE 6 also
\r
83 * ignores installed ICU locale providers. Probably, "sh" is internally mapped to "sr_RS_Cyrl"
\r
84 * internally before locale look up.
\r
86 * For now, we exclude these problematic locales from locale spi test cases on IBM Java 6.
\r
88 public static boolean isProblematicIBMLocale(Locale loc) {
\r
92 if (loc.getLanguage().equals("sh")) {
\r
95 String variant = loc.getVariant();
\r
96 if (variant.startsWith("EURO") || variant.startsWith("PREEURO")
\r
97 || variant.startsWith("Cyrl") || variant.startsWith("Latn")) {
\r