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