]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/tsdtfmsy.cpp
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / test / intltest / tsdtfmsy.cpp
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2003, 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 case 0: name = "DateFormatSymbols test";
21 if (exec) {
22 logln("DateFormatSymbols test---"); logln("");
23 testSymbols(/*par*/);
24 }
25 break;
26
27 case 1: name = "TestGetMonths";
28 if (exec) {
29 logln("TestGetMonths test---"); logln("");
30 TestGetMonths();
31 }
32 break;
33
34 default: name = ""; break;
35 }
36 }
37
38 /**
39 * Test getMonths.
40 */
41 void IntlTestDateFormatSymbols::TestGetMonths()
42 {
43 UErrorCode status = U_ZERO_ERROR;
44 int32_t cnt;
45 const UnicodeString* month;
46 DateFormatSymbols *symbol;
47
48 symbol=new DateFormatSymbols(Locale::getDefault(), status);
49
50 month=symbol->getMonths(cnt);
51
52 logln((UnicodeString)"size = " + cnt);
53
54 for (int32_t i=0; i<cnt; ++i)
55 {
56 logln(month[i]);
57 }
58
59 delete symbol;
60 }
61
62 /**
63 * Test the API of DateFormatSymbols; primarily a simple get/set set.
64 */
65 void IntlTestDateFormatSymbols::testSymbols(/* char *par */)
66 {
67 UErrorCode status = U_ZERO_ERROR;
68
69 DateFormatSymbols fr(Locale::getFrench(), status);
70 if(U_FAILURE(status)) {
71 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
72 }
73
74 status = U_ZERO_ERROR;
75 DateFormatSymbols en(Locale::getEnglish(), status);
76 if(U_FAILURE(status)) {
77 errln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status));
78 }
79
80 if(en == fr || ! (en != fr) ) {
81 errln("ERROR: English DateFormatSymbols equal to French");
82 }
83
84 // just do some VERY basic tests to make sure that get/set work
85
86 int32_t count = 0;
87 const UnicodeString *eras = en.getEras(count);
88 if(count == 0) {
89 errln("ERROR: 0 english eras.. exitting..\n");
90 return;
91 }
92
93 fr.setEras(eras, count);
94 if( *en.getEras(count) != *fr.getEras(count)) {
95 errln("ERROR: setEras() failed");
96 }
97
98 const UnicodeString *months = en.getMonths(count);
99 fr.setMonths(months, count);
100 if( *en.getMonths(count) != *fr.getMonths(count)) {
101 errln("ERROR: setMonths() failed");
102 }
103
104 const UnicodeString *shortMonths = en.getShortMonths(count);
105 fr.setShortMonths(shortMonths, count);
106 if( *en.getShortMonths(count) != *fr.getShortMonths(count)) {
107 errln("ERROR: setShortMonths() failed");
108 }
109
110 const UnicodeString *weekdays = en.getWeekdays(count);
111 fr.setWeekdays(weekdays, count);
112 if( *en.getWeekdays(count) != *fr.getWeekdays(count)) {
113 errln("ERROR: setWeekdays() failed");
114 }
115
116 const UnicodeString *shortWeekdays = en.getShortWeekdays(count);
117 fr.setShortWeekdays(shortWeekdays, count);
118 if( *en.getShortWeekdays(count) != *fr.getShortWeekdays(count)) {
119 errln("ERROR: setShortWeekdays() failed");
120 }
121
122 const UnicodeString *ampms = en.getAmPmStrings(count);
123 fr.setAmPmStrings(ampms, count);
124 if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
125 errln("ERROR: setAmPmStrings() failed");
126 }
127
128 int32_t rowCount = 0, columnCount = 0;
129 const UnicodeString **strings = en.getZoneStrings(rowCount, columnCount);
130 fr.setZoneStrings(strings, rowCount, columnCount);
131 const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount);
132 for(int32_t i = 0; i < rowCount; i++) {
133 for(int32_t j = 0; j < columnCount; j++) {
134 if( strings[i][j] != strings1[i][j] ) {
135 errln("ERROR: setZoneStrings() failed");
136 }
137
138 }
139 }
140
141 UnicodeString localPattern, pat1, pat2;
142 localPattern = en.getLocalPatternChars(localPattern);
143 fr.setLocalPatternChars(localPattern);
144 if( en.getLocalPatternChars(pat1) != fr.getLocalPatternChars(pat2)) {
145 errln("ERROR: setLocalPatternChars() failed");
146 }
147
148
149 status = U_ZERO_ERROR;
150 DateFormatSymbols foo(status);
151 DateFormatSymbols bar(foo);
152
153 en = fr;
154
155 if(en != fr || foo != bar) {
156 errln("ERROR: Copy Constructor or Assignment failed");
157 }
158 }
159
160 #endif /* #if !UCONFIG_NO_FORMATTING */