31 * @summary Unit test for CLDR FormatData resources
32 */
33
34 import java.util.*;
35 import static java.util.Calendar.*;
36 import sun.util.locale.provider.*;
37
38 public class CldrFormatNamesTest {
39 private static final Locale ARABIC = new Locale("ar");
40 private static final Locale ZH_HANT = Locale.forLanguageTag("zh-Hant");
41
42 /*
43 * The first element is a Locale followed by key-value pairs
44 * in a FormatData resource bundle. The value type is either
45 * String or String[].
46 */
47 static final Object[][] CLDR_DATA = {
48 {
49 Locale.JAPAN,
50 "field.zone", "\u30bf\u30a4\u30e0\u30be\u30fc\u30f3",
51 "cldr.japanese.DatePatterns", new String[] {
52 "Gy\u5e74M\u6708d\u65e5EEEE",
53 "Gy\u5e74M\u6708d\u65e5",
54 "Gy\u5e74M\u6708d\u65e5",
55 "Gyy/MM/dd",
56 },
57 "cldr.roc.DatePatterns", new String[] {
58 "Gy\u5e74M\u6708d\u65e5EEEE",
59 "Gy\u5e74M\u6708d\u65e5",
60 "Gy/MM/dd",
61 "Gy/MM/dd",
62 },
63 "calendarname.buddhist", "\u30bf\u30a4\u4ecf\u6559\u66a6",
64 },
65 {
66 Locale.PRC,
67 "field.zone", "\u533a\u57df",
68 "cldr.islamic.DatePatterns", new String[] {
69 "Gy\u5e74M\u6708d\u65e5EEEE",
70 "Gy\u5e74M\u6708d\u65e5",
71 "Gy\u5e74M\u6708d\u65e5",
72 "Gyy-MM-dd",
73 },
74 "calendarname.islamic", "\u4f0a\u65af\u5170\u65e5\u5386",
75 },
76 {
77 Locale.GERMANY,
78 "field.dayperiod", "Tagesh\u00e4lfte",
79 "cldr.islamic.DatePatterns", new String[] {
80 "EEEE d. MMMM y G",
81 "d. MMMM y G",
82 "d. MMM y G",
83 "d.M.y G",
84 },
85 "calendarname.islamic", "Islamischer Kalender",
86 },
87 };
88
89 // Islamic calendar symbol names in ar
90 private static final String[] ISLAMIC_MONTH_NAMES = {
91 "\u0645\u062d\u0631\u0645",
92 "\u0635\u0641\u0631",
93 "\u0631\u0628\u064a\u0639 \u0627\u0644\u0623\u0648\u0644",
94 "\u0631\u0628\u064a\u0639 \u0627\u0644\u0622\u062e\u0631",
95 "\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0623\u0648\u0644\u0649",
96 "\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0622\u062e\u0631\u0629",
97 "\u0631\u062c\u0628",
98 "\u0634\u0639\u0628\u0627\u0646",
99 "\u0631\u0645\u0636\u0627\u0646",
102 "\u0630\u0648 \u0627\u0644\u062d\u062c\u0629",
103 };
104 private static final String[] ISLAMIC_ERA_NAMES = {
105 "",
106 "\u0647\u0640",
107 };
108
109 // Minguo calendar symbol names in zh_Hant
110 private static final String[] ROC_ERA_NAMES = {
111 "\u6c11\u570b\u524d",
112 "\u6c11\u570b",
113 };
114
115 private static int errors = 0;
116
117 // This test is CLDR data dependent.
118 public static void main(String[] args) {
119 for (Object[] data : CLDR_DATA) {
120 Locale locale = (Locale) data[0];
121 ResourceBundle rb = LocaleProviderAdapter.getResourceBundleBased()
122 .getLocaleResources(locale).getFormatData();
123 for (int i = 1; i < data.length; ) {
124 String key = (String) data[i++];
125 Object expected = data[i++];
126 if (rb.containsKey(key)) {
127 Object value = rb.getObject(key);
128 if (expected instanceof String) {
129 if (!expected.equals(value)) {
130 errors++;
131 System.err.printf("error: key='%s', got '%s' expected '%s'%n",
132 key, value, expected);
133 }
134 } else if (expected instanceof String[]) {
135 try {
136 if (!Arrays.equals((Object[]) value, (Object[]) expected)) {
137 errors++;
138 System.err.printf("error: key='%s', got '%s' expected '%s'%n",
139 key, Arrays.asList((Object[])value),
140 Arrays.asList((Object[])expected));
141 }
142 } catch (Exception e) {
150 }
151 }
152 }
153
154 // test Islamic calendar names in Arabic
155 testSymbolNames(ARABIC, "islamic", ISLAMIC_MONTH_NAMES, MONTH, LONG, "month");
156 testSymbolNames(ARABIC, "islamic", ISLAMIC_ERA_NAMES, ERA, SHORT, "era");
157
158 // test ROC (Minguo) calendar names in zh-Hant
159 testSymbolNames(ZH_HANT, "roc", ROC_ERA_NAMES, ERA, SHORT, "era");
160
161 if (errors > 0) {
162 throw new RuntimeException("test failed");
163 }
164 }
165
166 private static void testSymbolNames(Locale locale, String calType, String[] expected,
167 int field, int style, String fieldName) {
168 for (int i = 0; i < expected.length; i++) {
169 String expt = expected[i];
170 String name = CalendarDataUtility.retrieveFieldValueName(calType, field, i, style, locale);
171 if (!expt.equals(name)) {
172 errors++;
173 System.err.printf("error: wrong %s %s name in %s: value=%d, got='%s', expected='%s'%n",
174 calType, fieldName, locale, i, name, expt);
175 }
176 }
177 }
178 }
|
31 * @summary Unit test for CLDR FormatData resources
32 */
33
34 import java.util.*;
35 import static java.util.Calendar.*;
36 import sun.util.locale.provider.*;
37
38 public class CldrFormatNamesTest {
39 private static final Locale ARABIC = new Locale("ar");
40 private static final Locale ZH_HANT = Locale.forLanguageTag("zh-Hant");
41
42 /*
43 * The first element is a Locale followed by key-value pairs
44 * in a FormatData resource bundle. The value type is either
45 * String or String[].
46 */
47 static final Object[][] CLDR_DATA = {
48 {
49 Locale.JAPAN,
50 "field.zone", "\u30bf\u30a4\u30e0\u30be\u30fc\u30f3",
51 "java.time.japanese.DatePatterns", new String[] {
52 "Gy\u5e74M\u6708d\u65e5EEEE",
53 "Gy\u5e74M\u6708d\u65e5",
54 "Gy\u5e74M\u6708d\u65e5",
55 "Gyy/MM/dd",
56 },
57 "java.time.roc.DatePatterns", new String[] {
58 "Gy\u5e74M\u6708d\u65e5EEEE",
59 "Gy\u5e74M\u6708d\u65e5",
60 "Gy/MM/dd",
61 "Gy/MM/dd",
62 },
63 "calendarname.buddhist", "\u30bf\u30a4\u4ecf\u6559\u66a6",
64 },
65 {
66 Locale.PRC,
67 "field.zone", "\u533a\u57df",
68 "java.time.islamic.DatePatterns", new String[] {
69 "Gy\u5e74M\u6708d\u65e5EEEE",
70 "Gy\u5e74M\u6708d\u65e5",
71 "Gy\u5e74M\u6708d\u65e5",
72 "Gyy-MM-dd",
73 },
74 "calendarname.islamic", "\u4f0a\u65af\u5170\u65e5\u5386",
75 },
76 {
77 Locale.GERMANY,
78 "field.dayperiod", "Tagesh\u00e4lfte",
79 "java.time.islamic.DatePatterns", new String[] {
80 "EEEE d. MMMM y G",
81 "d. MMMM y G",
82 "d. MMM y G",
83 "d.M.y G",
84 },
85 "calendarname.islamic", "Islamischer Kalender",
86 },
87 };
88
89 // Islamic calendar symbol names in ar
90 private static final String[] ISLAMIC_MONTH_NAMES = {
91 "\u0645\u062d\u0631\u0645",
92 "\u0635\u0641\u0631",
93 "\u0631\u0628\u064a\u0639 \u0627\u0644\u0623\u0648\u0644",
94 "\u0631\u0628\u064a\u0639 \u0627\u0644\u0622\u062e\u0631",
95 "\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0623\u0648\u0644\u0649",
96 "\u062c\u0645\u0627\u062f\u0649 \u0627\u0644\u0622\u062e\u0631\u0629",
97 "\u0631\u062c\u0628",
98 "\u0634\u0639\u0628\u0627\u0646",
99 "\u0631\u0645\u0636\u0627\u0646",
102 "\u0630\u0648 \u0627\u0644\u062d\u062c\u0629",
103 };
104 private static final String[] ISLAMIC_ERA_NAMES = {
105 "",
106 "\u0647\u0640",
107 };
108
109 // Minguo calendar symbol names in zh_Hant
110 private static final String[] ROC_ERA_NAMES = {
111 "\u6c11\u570b\u524d",
112 "\u6c11\u570b",
113 };
114
115 private static int errors = 0;
116
117 // This test is CLDR data dependent.
118 public static void main(String[] args) {
119 for (Object[] data : CLDR_DATA) {
120 Locale locale = (Locale) data[0];
121 ResourceBundle rb = LocaleProviderAdapter.getResourceBundleBased()
122 .getLocaleResources(locale).getJavaTimeFormatData();
123 for (int i = 1; i < data.length; ) {
124 String key = (String) data[i++];
125 Object expected = data[i++];
126 if (rb.containsKey(key)) {
127 Object value = rb.getObject(key);
128 if (expected instanceof String) {
129 if (!expected.equals(value)) {
130 errors++;
131 System.err.printf("error: key='%s', got '%s' expected '%s'%n",
132 key, value, expected);
133 }
134 } else if (expected instanceof String[]) {
135 try {
136 if (!Arrays.equals((Object[]) value, (Object[]) expected)) {
137 errors++;
138 System.err.printf("error: key='%s', got '%s' expected '%s'%n",
139 key, Arrays.asList((Object[])value),
140 Arrays.asList((Object[])expected));
141 }
142 } catch (Exception e) {
150 }
151 }
152 }
153
154 // test Islamic calendar names in Arabic
155 testSymbolNames(ARABIC, "islamic", ISLAMIC_MONTH_NAMES, MONTH, LONG, "month");
156 testSymbolNames(ARABIC, "islamic", ISLAMIC_ERA_NAMES, ERA, SHORT, "era");
157
158 // test ROC (Minguo) calendar names in zh-Hant
159 testSymbolNames(ZH_HANT, "roc", ROC_ERA_NAMES, ERA, SHORT, "era");
160
161 if (errors > 0) {
162 throw new RuntimeException("test failed");
163 }
164 }
165
166 private static void testSymbolNames(Locale locale, String calType, String[] expected,
167 int field, int style, String fieldName) {
168 for (int i = 0; i < expected.length; i++) {
169 String expt = expected[i];
170 String name = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, i, style, locale);
171 if (!expt.equals(name)) {
172 errors++;
173 System.err.printf("error: wrong %s %s name in %s: value=%d, got='%s', expected='%s'%n",
174 calType, fieldName, locale, i, name, expt);
175 }
176 }
177 }
178 }
|