]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/TestUtil.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / tests / localespi / src / com / ibm / icu / dev / test / localespi / TestUtil.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008-2009, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test.localespi;
8
9 import java.util.Locale;
10
11 public class TestUtil {
12
13     private static final String ICU_VARIANT = "ICU";
14     private static final String ICU_VARIANT_SUFFIX = "_ICU";
15
16     public static Locale toICUExtendedLocale(Locale locale) {
17         if (isICUExtendedLocale(locale)) {
18             return locale;
19         }
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);
23     }
24
25     public static boolean isICUExtendedLocale(Locale locale) {
26         String variant = locale.getVariant();
27         if (variant.equals(ICU_VARIANT) || variant.endsWith(ICU_VARIANT_SUFFIX)) {
28             return true;
29         }
30         return false;
31     }
32
33     public static boolean equals(Object o1, Object o2) {
34         if (o1 == null && o2 == null) {
35             return true;
36         }
37         if (o1 == null || o2 == null) {
38             return false;
39         }
40         return o1.equals(o2);
41     }
42
43     private static final boolean SUNJRE;
44     private static final boolean IBMJRE;
45
46     static {
47         String javaVendor = System.getProperty("java.vendor");
48         if (javaVendor != null) {
49             if (javaVendor.indexOf("Sun") >= 0) {
50                 SUNJRE = true;
51                 IBMJRE = false;
52             } else if (javaVendor.indexOf("IBM") >= 0) {
53                 SUNJRE = false;
54                 IBMJRE = true;
55             } else {
56                 SUNJRE = false;
57                 IBMJRE = false;
58             }
59         } else {
60             SUNJRE = false;
61             IBMJRE = false;
62         }
63     }
64
65     public static boolean isSUNJRE() {
66         return SUNJRE;
67     }
68     public static boolean isIBMJRE() {
69         return IBMJRE;
70     }
71
72     /*
73      * Ticket#6368
74      * 
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.
77      * 
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.
81      *   
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.
85      * 
86      * For now, we exclude these problematic locales from locale spi test cases on IBM Java 6.
87      */
88     public static boolean isProblematicIBMLocale(Locale loc) {
89         if (!isIBMJRE()) {
90             return false;
91         }
92         if (loc.getLanguage().equals("sh")) {
93             return true;
94         }
95         String variant = loc.getVariant();
96         if (variant.startsWith("EURO") || variant.startsWith("PREEURO")
97                 || variant.startsWith("Cyrl") || variant.startsWith("Latn")) {
98             return true;
99         }
100         return false;
101     }
102 }