]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/tsdtfmsy.cpp
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / test / intltest / tsdtfmsy.cpp
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2006, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 #include "unicode/utypes.h"
8
9 #if !UCONFIG_NO_FORMATTING
10
11 #include "tsdtfmsy.h"
12
13 #include "unicode/dtfmtsym.h"
14
15
16 void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
17 {
18 if (exec) logln("TestSuite DateFormatSymbols");
19 switch (index) {
20 TESTCASE(0,TestSymbols);
21 TESTCASE(1,TestGetMonths);
22 TESTCASE(2,TestGetMonths2);
23 TESTCASE(3,TestGetWeekdays2);
24 TESTCASE(4,TestGetEraNames);
25 default: name = ""; break;
26 }
27 }
28
29 /**
30 * Test getMonths.
31 */
32 void IntlTestDateFormatSymbols::TestGetMonths()
33 {
34 UErrorCode status = U_ZERO_ERROR;
35 int32_t cnt;
36 const UnicodeString* month;
37 DateFormatSymbols *symbol;
38
39 symbol=new DateFormatSymbols(Locale::getDefault(), status);
40
41 month=symbol->getMonths(cnt);
42
43 logln((UnicodeString)"size = " + cnt);
44
45 for (int32_t i=0; i<cnt; ++i)
46 {
47 logln(month[i]);
48 }
49
50 delete symbol;
51 }
52
53 void IntlTestDateFormatSymbols::TestGetMonths2()
54 {
55 UErrorCode status = U_ZERO_ERROR;
56 DateFormatSymbols *symbol;
57
58 symbol=new DateFormatSymbols(Locale::getDefault(), status);
59
60 DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
61 DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
62
63 for (int32_t i = 0; i < 2; i++) {
64 for (int32_t j = 0; j < 3; j++) {
65 int32_t cnt;
66 const UnicodeString * month = symbol->getMonths(cnt,context[i],width[j]);
67
68 logln((UnicodeString)"size = " + cnt);
69
70 for (int32_t k = 0; k < cnt; k++) {
71 logln(month[k]);
72 }
73 }
74 }
75 delete symbol;
76 }
77
78 void IntlTestDateFormatSymbols::TestGetWeekdays2()
79 {
80 UErrorCode status = U_ZERO_ERROR;
81 DateFormatSymbols *symbol;
82
83 symbol=new DateFormatSymbols(Locale::getDefault(), status);
84
85 DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
86 DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
87
88 for (int32_t i = 0; i < 2; i++) {
89 for (int32_t j = 0; j < 3; j++) {
90 int32_t cnt;
91 const UnicodeString * wd = symbol->getWeekdays(cnt,context[i],width[j]);
92
93 logln((UnicodeString)"size = " + cnt);
94
95 for (int32_t k = 0; k < cnt; k++) {
96 logln(wd[k]);
97 }
98 }
99 }
100 delete symbol;
101 }
102
103
104 void IntlTestDateFormatSymbols::TestGetEraNames()
105 {
106 UErrorCode status = U_ZERO_ERROR;
107 int32_t cnt;
108 const UnicodeString* name;
109 DateFormatSymbols *symbol;
110
111 symbol=new DateFormatSymbols(Locale::getDefault(), status);
112
113 name=symbol->getEraNames(cnt);
114
115 logln((UnicodeString)"size = " + cnt);
116
117 for (int32_t i=0; i<cnt; ++i)
118 {
119 logln(name[i]);
120 }
121
122 delete symbol;
123 }
124
125 /**
126 * Test the API of DateFormatSymbols; primarily a simple get/set set.
127 */
128 void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
129 {
130 UErrorCode status = U_ZERO_ERROR;
131
132 DateFormatSymbols fr(Locale::getFrench(), status);
133 if(U_FAILURE(status)) {
134 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
135 }
136
137 status = U_ZERO_ERROR;
138 DateFormatSymbols fr2(Locale::getFrench(), status);
139 if(U_FAILURE(status)) {
140 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
141 }
142
143 status = U_ZERO_ERROR;
144 DateFormatSymbols en(Locale::getEnglish(), status);
145 if(U_FAILURE(status)) {
146 errln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status));
147 }
148
149 if(en == fr || ! (en != fr) ) {
150 errln("ERROR: English DateFormatSymbols equal to French");
151 }
152
153 // just do some VERY basic tests to make sure that get/set work
154
155 int32_t count = 0;
156 const UnicodeString *eras = en.getEras(count);
157 if(count == 0) {
158 errln("ERROR: 0 english eras.. exitting..\n");
159 return;
160 }
161
162 fr.setEras(eras, count);
163 if( *en.getEras(count) != *fr.getEras(count)) {
164 errln("ERROR: setEras() failed");
165 }
166
167 const UnicodeString *months = en.getMonths(count);
168 fr.setMonths(months, count);
169 if( *en.getMonths(count) != *fr.getMonths(count)) {
170 errln("ERROR: setMonths() failed");
171 }
172
173 const UnicodeString *shortMonths = en.getShortMonths(count);
174 fr.setShortMonths(shortMonths, count);
175 if( *en.getShortMonths(count) != *fr.getShortMonths(count)) {
176 errln("ERROR: setShortMonths() failed");
177 }
178
179 const UnicodeString *wideMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
180 fr2.setMonths(wideMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
181 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
182 *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
183 errln("ERROR: setMonths(FORMAT,WIDE) failed");
184 }
185
186 const UnicodeString *abbrMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
187 fr2.setMonths(abbrMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
188 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
189 *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
190 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
191 }
192
193 const UnicodeString *narrowMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
194 fr.setMonths(narrowMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
195 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
196 *fr.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
197 errln("ERROR: setMonths(FORMAT,NARROW) failed");
198 }
199
200 const UnicodeString *standaloneWideMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
201 fr.setMonths(standaloneWideMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
202 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
203 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
204 errln("ERROR: setMonths(STANDALONE,WIDE) failed");
205 }
206
207 const UnicodeString *standaloneShortMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
208 fr.setMonths(standaloneShortMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
209 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
210 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
211 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
212 }
213
214 const UnicodeString *standaloneNarrowMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
215 fr.setMonths(standaloneNarrowMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
216 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
217 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
218 errln("ERROR: setMonths(STANDALONE,NARROW) failed");
219 }
220
221 const UnicodeString *weekdays = en.getWeekdays(count);
222 fr.setWeekdays(weekdays, count);
223 if( *en.getWeekdays(count) != *fr.getWeekdays(count)) {
224 errln("ERROR: setWeekdays() failed");
225 }
226
227 const UnicodeString *shortWeekdays = en.getShortWeekdays(count);
228 fr.setShortWeekdays(shortWeekdays, count);
229 if( *en.getShortWeekdays(count) != *fr.getShortWeekdays(count)) {
230 errln("ERROR: setShortWeekdays() failed");
231 }
232
233 const UnicodeString *wideWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
234 fr2.setWeekdays(wideWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
235 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
236 *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
237 errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
238 }
239
240 const UnicodeString *abbrWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
241 fr2.setWeekdays(abbrWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
242 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
243 *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
244 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
245 }
246
247 const UnicodeString *narrowWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
248 fr.setWeekdays(narrowWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
249 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
250 *fr.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
251 errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
252 }
253
254 const UnicodeString *standaloneWideWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
255 fr.setWeekdays(standaloneWideWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
256 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
257 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
258 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
259 }
260
261 const UnicodeString *standaloneShortWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
262 fr.setWeekdays(standaloneShortWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
263 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
264 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
265 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
266 }
267
268 const UnicodeString *standaloneNarrowWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
269 fr.setWeekdays(standaloneNarrowWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
270 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
271 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
272 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
273 }
274
275 const UnicodeString *wideQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
276 fr2.setQuarters(wideQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
277 if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE) !=
278 *fr2.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE )) {
279 errln("ERROR: setQuarters(FORMAT, WIDE) failed");
280 }
281
282 const UnicodeString *abbrQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
283 fr2.setQuarters(abbrQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
284 if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED) !=
285 *fr2.getQuarters(count,DateFormatSymbols::FORMAT ,DateFormatSymbols::ABBREVIATED )) {
286 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
287 }
288
289 const UnicodeString *standaloneWideQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
290 fr.setQuarters(standaloneWideQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
291 if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE) !=
292 *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE )) {
293 errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
294 }
295
296 const UnicodeString *standaloneShortQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
297 fr.setQuarters(standaloneShortQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
298 if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED) !=
299 *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED )) {
300 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
301 }
302
303 const UnicodeString *ampms = en.getAmPmStrings(count);
304 fr.setAmPmStrings(ampms, count);
305 if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
306 errln("ERROR: setAmPmStrings() failed");
307 }
308
309 int32_t rowCount = 0, columnCount = 0;
310 const UnicodeString **strings = en.getZoneStrings(rowCount, columnCount);
311 fr.setZoneStrings(strings, rowCount, columnCount);
312 const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount);
313 for(int32_t i = 0; i < rowCount; i++) {
314 for(int32_t j = 0; j < columnCount; j++) {
315 if( strings[i][j] != strings1[i][j] ) {
316 errln("ERROR: setZoneStrings() failed");
317 }
318
319 }
320 }
321
322 UnicodeString localPattern, pat1, pat2;
323 localPattern = en.getLocalPatternChars(localPattern);
324 fr.setLocalPatternChars(localPattern);
325 if( en.getLocalPatternChars(pat1) != fr.getLocalPatternChars(pat2)) {
326 errln("ERROR: setLocalPatternChars() failed");
327 }
328
329
330 status = U_ZERO_ERROR;
331 DateFormatSymbols foo(status);
332 DateFormatSymbols bar(foo);
333
334 en = fr;
335
336 if(en != fr) {
337 errln("ERROR: Assignment operator failed");
338 }
339 if(foo != bar) {
340 errln("ERROR: Copy Constructor failed");
341 }
342 }
343
344 #endif /* #if !UCONFIG_NO_FORMATTING */