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