]>
Commit | Line | Data |
---|---|---|
4388f060 | 1 | /******************************************************************** |
2ca993e8 | 2 | * Copyright (c) 2011-2016, International Business Machines Corporation |
4388f060 A |
3 | * and others. All Rights Reserved. |
4 | ********************************************************************/ | |
5 | /* C API TEST FOR DATE INTERVAL FORMAT */ | |
6 | ||
7 | #include "unicode/utypes.h" | |
8 | ||
9 | #if !UCONFIG_NO_FORMATTING | |
10 | ||
11 | #include "unicode/udateintervalformat.h" | |
12 | #include "unicode/udat.h" | |
13 | #include "unicode/ucal.h" | |
14 | #include "unicode/ustring.h" | |
15 | #include "cintltst.h" | |
16 | #include "cmemory.h" | |
17 | ||
18 | static void TestDateIntervalFormat(void); | |
b331163b | 19 | static void TestFPos_SkelWithSeconds(void); |
4388f060 | 20 | |
4388f060 A |
21 | void addDateIntervalFormatTest(TestNode** root); |
22 | ||
23 | #define TESTCASE(x) addTest(root, &x, "tsformat/cdateintervalformattest/" #x) | |
24 | ||
25 | void addDateIntervalFormatTest(TestNode** root) | |
26 | { | |
27 | TESTCASE(TestDateIntervalFormat); | |
b331163b | 28 | TESTCASE(TestFPos_SkelWithSeconds); |
4388f060 A |
29 | } |
30 | ||
31 | static const char tzUSPacific[] = "US/Pacific"; | |
32 | static const char tzAsiaTokyo[] = "Asia/Tokyo"; | |
33 | #define Date201103021030 1299090600000.0 /* 2011-Mar-02 1030 in US/Pacific, 2011-Mar-03 0330 in Asia/Tokyo */ | |
34 | #define Date201009270800 1285599629000.0 /* 2010-Sep-27 0800 in US/Pacific */ | |
35 | #define _MINUTE (60.0*1000.0) | |
36 | #define _HOUR (60.0*60.0*1000.0) | |
37 | #define _DAY (24.0*60.0*60.0*1000.0) | |
38 | ||
39 | typedef struct { | |
40 | const char * locale; | |
41 | const char * skeleton; | |
42 | const char * tzid; | |
2ca993e8 | 43 | UDateIntervalFormatAttributeValue minimizeType; |
4388f060 A |
44 | const UDate from; |
45 | const UDate to; | |
46 | const char * resultExpected; | |
47 | } DateIntervalFormatTestItem; | |
48 | ||
49 | /* Just a small set of tests for now, the real functionality is tested in the C++ tests */ | |
50 | static const DateIntervalFormatTestItem testItems[] = { | |
2ca993e8 A |
51 | { "en", "MMMdHHmm", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201103021030, Date201103021030 + 7.0*_HOUR, "Mar 2, 10:30 - 17:30" }, |
52 | { "en", "MMMdHHmm", tzAsiaTokyo, UDTITVFMT_MINIMIZE_NONE, Date201103021030, Date201103021030 + 7.0*_HOUR, "Mar 3, 03:30 - 10:30" }, | |
53 | { "en", "yMMMEd", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 12.0*_HOUR, "Mon, Sep 27, 2010" }, | |
54 | { "en", "yMMMEd", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 31.0*_DAY, "Mon, Sep 27 - Thu, Oct 28, 2010" }, | |
55 | { "en", "yMMMEd", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 410.0*_DAY, "Mon, Sep 27, 2010 - Fri, Nov 11, 2011" }, | |
56 | { "de", "Hm", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 12.0*_HOUR, "08:00\\u201320:00 Uhr" }, | |
57 | { "de", "Hm", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 31.0*_DAY, "27.9.2010, 08:00 \\u2013 28.10.2010, 08:00" }, | |
58 | { "ja", "MMMd", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201009270800, Date201009270800 + 1.0*_DAY, "9\\u670827\\u65E5\\uFF5E28\\u65E5" }, | |
59 | { "en", "jm", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201103021030, Date201103021030 + 1.0*_HOUR, "10:30 AM - 11:30 AM" }, | |
60 | { "en", "jm", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201103021030, Date201103021030 + 12.0*_HOUR, "10:30 AM - 10:30 PM" }, | |
61 | { "it", "yMMMMd", tzUSPacific, UDTITVFMT_MINIMIZE_NONE, Date201103021030, Date201103021030 + 15.0*_DAY, "2\\u201317 marzo 2011" }, | |
62 | // Apple-specific | |
63 | { "en", "MMMd", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_MONTHS, Date201009270800, Date201009270800 + 6.0*_DAY, "Sep 27 - 3" }, | |
64 | { "en", "MMMd", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_MONTHS, Date201009270800, Date201009270800 + 32.0*_DAY, "Sep 27 - Oct 29" }, | |
65 | { "fr", "MMMd", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_MONTHS, Date201009270800, Date201009270800 + 6.0*_DAY, "27\\u20133 oct." }, | |
66 | { "fr", "MMMd", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_MONTHS, Date201009270800, Date201009270800 + 32.0*_DAY, "27 sept. \\u2013 29 oct." }, | |
67 | { "en", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800, Date201009270800 + 10.0*_HOUR, "Sep 27, 8:00 AM - 6:00 PM" }, | |
68 | { "en", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800, Date201009270800 + 17.0*_HOUR, "Sep 27, 8:00 AM - Sep 28, 1:00 AM" }, | |
69 | { "en", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 17.0*_HOUR, "Sep 27, 8:00 PM - 1:00 AM" }, | |
70 | { "en", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 26.0*_HOUR, "Sep 27, 8:00 PM - Sep 28, 10:00 AM" }, | |
71 | { "en", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 35.0*_HOUR, "Sep 27, 8:00 PM - Sep 28, 7:00 PM" }, | |
72 | { "fr", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800, Date201009270800 + 10.0*_HOUR, "27 sept. \\u00E0 08:00 \\u2013 18:00" }, | |
73 | { "fr", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800, Date201009270800 + 17.0*_HOUR, "27 sept. \\u00E0 08:00 \\u2013 28 sept. \\u00E0 01:00" }, | |
74 | { "fr", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 17.0*_HOUR, "27 sept. \\u00E0 20:00 \\u2013 01:00" }, | |
75 | { "fr", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 26.0*_HOUR, "27 sept. \\u00E0 20:00 \\u2013 28 sept. \\u00E0 10:00" }, | |
76 | { "fr", "MMMdjmm", tzUSPacific, UDTITVFMT_MINIMIZE_ADJACENT_DAYS, Date201009270800 + 12.0*_HOUR, Date201009270800 + 35.0*_HOUR, "27 sept. \\u00E0 20:00 \\u2013 28 sept. \\u00E0 19:00" }, | |
77 | ||
78 | { NULL, NULL, NULL, UDTITVFMT_MINIMIZE_NONE, 0, 0, NULL } | |
4388f060 A |
79 | }; |
80 | ||
81 | enum { | |
82 | kSkelBufLen = 32, | |
83 | kTZIDBufLen = 96, | |
84 | kFormatBufLen = 128 | |
85 | }; | |
86 | ||
87 | static void TestDateIntervalFormat() | |
88 | { | |
89 | const DateIntervalFormatTestItem * testItemPtr; | |
90 | UErrorCode status = U_ZERO_ERROR; | |
91 | ctest_setTimeZone(NULL, &status); | |
92 | log_verbose("\nTesting udtitvfmt_open() and udtitvfmt_format() with various parameters\n"); | |
93 | for ( testItemPtr = testItems; testItemPtr->locale != NULL; ++testItemPtr ) { | |
94 | UDateIntervalFormat* udtitvfmt; | |
95 | int32_t tzidLen; | |
96 | UChar skelBuf[kSkelBufLen]; | |
97 | UChar tzidBuf[kTZIDBufLen]; | |
98 | const char * tzidForLog = (testItemPtr->tzid)? testItemPtr->tzid: "NULL"; | |
99 | ||
100 | status = U_ZERO_ERROR; | |
101 | u_unescape(testItemPtr->skeleton, skelBuf, kSkelBufLen); | |
102 | if ( testItemPtr->tzid ) { | |
103 | u_unescape(testItemPtr->tzid, tzidBuf, kTZIDBufLen); | |
104 | tzidLen = -1; | |
105 | } else { | |
106 | tzidLen = 0; | |
107 | } | |
108 | udtitvfmt = udtitvfmt_open(testItemPtr->locale, skelBuf, -1, tzidBuf, tzidLen, &status); | |
109 | if ( U_SUCCESS(status) ) { | |
110 | UChar result[kFormatBufLen]; | |
111 | UChar resultExpected[kFormatBufLen]; | |
2ca993e8 A |
112 | udtitvfmt_setAttribute(udtitvfmt, UDTITVFMT_MINIMIZE_TYPE, testItemPtr->minimizeType, &status); |
113 | if ( U_FAILURE(status) ) { | |
114 | log_err("FAIL: udtitvfmt_setAttribute for locale %s, skeleton %s, tzid %s, minimizeType %d: %s\n", | |
115 | testItemPtr->locale, testItemPtr->skeleton, tzidForLog, (int)testItemPtr->minimizeType, myErrorName(status) ); | |
116 | } | |
4388f060 A |
117 | int32_t fmtLen = udtitvfmt_format(udtitvfmt, testItemPtr->from, testItemPtr->to, result, kFormatBufLen, NULL, &status); |
118 | if (fmtLen >= kFormatBufLen) { | |
119 | result[kFormatBufLen-1] = 0; | |
120 | } | |
121 | if ( U_SUCCESS(status) ) { | |
122 | u_unescape(testItemPtr->resultExpected, resultExpected, kFormatBufLen); | |
123 | if ( u_strcmp(result, resultExpected) != 0 ) { | |
124 | char bcharBuf[kFormatBufLen]; | |
2ca993e8 A |
125 | #if 0 |
126 | log_err("ERROR: udtitvfmt_format for locale %s, skeleton %s, tzid %s, minimizeType %d, from %.1f, to %.1f: expect %s, get %s\n", | |
127 | testItemPtr->locale, testItemPtr->skeleton, tzidForLog, (int)testItemPtr->minimizeType, | |
128 | testItemPtr->from, testItemPtr->to, testItemPtr->resultExpected, u_austrcpy(bcharBuf,result) ); | |
129 | #else | |
130 | // Apple-specific version | |
131 | char bexpbuf[kFormatBufLen]; | |
132 | u_strToUTF8(bexpbuf, kFormatBufLen, NULL, resultExpected, -1, &status); | |
133 | u_strToUTF8(bcharBuf, kFormatBufLen, NULL, result, fmtLen, &status); | |
134 | log_err("ERROR: udtitvfmt_format for locale %s, skeleton %s, tzid %s, minimizeType %d, from %.1f, to %.1f: expect %s, get %s\n", | |
135 | testItemPtr->locale, testItemPtr->skeleton, tzidForLog, (int)testItemPtr->minimizeType, | |
136 | testItemPtr->from, testItemPtr->to, bexpbuf, bcharBuf ); | |
137 | #endif | |
4388f060 A |
138 | } |
139 | } else { | |
2ca993e8 A |
140 | log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, tzid %s, minimizeType %d, from %.1f, to %.1f: %s\n", |
141 | testItemPtr->locale, testItemPtr->skeleton, tzidForLog, (int)testItemPtr->minimizeType, | |
142 | testItemPtr->from, testItemPtr->to, myErrorName(status) ); | |
4388f060 A |
143 | } |
144 | udtitvfmt_close(udtitvfmt); | |
145 | } else { | |
146 | log_data_err("FAIL: udtitvfmt_open for locale %s, skeleton %s, tzid %s - %s\n", | |
147 | testItemPtr->locale, testItemPtr->skeleton, tzidForLog, myErrorName(status) ); | |
148 | } | |
149 | } | |
150 | ctest_resetTimeZone(); | |
151 | } | |
152 | ||
b331163b A |
153 | /******************************************************************** |
154 | * TestFPos_SkelWithSeconds and related data | |
155 | ******************************************************************** | |
156 | */ | |
157 | ||
158 | static UChar zoneGMT[] = { 0x47,0x4D,0x54,0 }; // GMT | |
159 | static const UDate startTime = 1416474000000.0; // 2014 Nov 20 09:00 GMT | |
160 | ||
161 | static const double deltas[] = { | |
162 | 0.0, // none | |
163 | 200.0, // 200 millisec | |
164 | 20000.0, // 20 sec | |
165 | 1200000.0, // 20 min | |
166 | 7200000.0, // 2 hrs | |
167 | 43200000.0, // 12 hrs | |
168 | 691200000.0, // 8 days | |
169 | 1382400000.0, // 16 days, | |
170 | 8640000000.0, // 100 days | |
171 | -1.0 | |
172 | }; | |
2ca993e8 | 173 | enum { kNumDeltas = UPRV_LENGTHOF(deltas) - 1 }; |
b331163b A |
174 | |
175 | typedef struct { | |
176 | int32_t posBegin; | |
177 | int32_t posEnd; | |
178 | const char * format; | |
179 | } ExpectPosAndFormat; | |
180 | ||
181 | static const ExpectPosAndFormat exp_en_HHmm[kNumDeltas] = { | |
182 | { 3, 5, "09:00" }, | |
183 | { 3, 5, "09:00" }, | |
184 | { 3, 5, "09:00" }, | |
185 | { 3, 5, "09:00 \\u002D 09:20" }, | |
186 | { 3, 5, "09:00 \\u002D 11:00" }, | |
187 | { 3, 5, "09:00 \\u002D 21:00" }, | |
188 | { 15, 17, "11/20/2014, 09:00 \\u002D 11/28/2014, 09:00" }, | |
189 | { 15, 17, "11/20/2014, 09:00 \\u002D 12/6/2014, 09:00" }, | |
190 | { 15, 17, "11/20/2014, 09:00 \\u002D 2/28/2015, 09:00" } | |
191 | }; | |
192 | ||
193 | static const ExpectPosAndFormat exp_en_HHmmss[kNumDeltas] = { | |
194 | { 3, 5, "09:00:00" }, | |
195 | { 3, 5, "09:00:00" }, | |
196 | { 3, 5, "09:00:00 \\u002D 09:00:20" }, | |
197 | { 3, 5, "09:00:00 \\u002D 09:20:00" }, | |
198 | { 3, 5, "09:00:00 \\u002D 11:00:00" }, | |
199 | { 3, 5, "09:00:00 \\u002D 21:00:00" }, | |
200 | { 15, 17, "11/20/2014, 09:00:00 \\u002D 11/28/2014, 09:00:00" }, | |
201 | { 15, 17, "11/20/2014, 09:00:00 \\u002D 12/6/2014, 09:00:00" }, | |
202 | { 15, 17, "11/20/2014, 09:00:00 \\u002D 2/28/2015, 09:00:00" } | |
203 | }; | |
204 | ||
205 | static const ExpectPosAndFormat exp_en_yyMMdd[kNumDeltas] = { | |
206 | { 0, 0, "11/20/14" }, | |
207 | { 0, 0, "11/20/14" }, | |
208 | { 0, 0, "11/20/14" }, | |
209 | { 0, 0, "11/20/14" }, | |
210 | { 0, 0, "11/20/14" }, | |
211 | { 0, 0, "11/20/14" }, | |
212 | { 0, 0, "11/20/14 \\u002D 11/28/14" }, | |
213 | { 0, 0, "11/20/14 \\u002D 12/6/14" }, | |
214 | { 0, 0, "11/20/14 \\u002D 2/28/15" } | |
215 | }; | |
216 | ||
217 | static const ExpectPosAndFormat exp_en_yyMMddHHmm[kNumDeltas] = { | |
218 | { 13, 15, "11/20/14, 09:00" }, | |
219 | { 13, 15, "11/20/14, 09:00" }, | |
220 | { 13, 15, "11/20/14, 09:00" }, | |
221 | { 13, 15, "11/20/14, 09:00 \\u002D 09:20" }, | |
222 | { 13, 15, "11/20/14, 09:00 \\u002D 11:00" }, | |
223 | { 13, 15, "11/20/14, 09:00 \\u002D 21:00" }, | |
224 | { 13, 15, "11/20/14, 09:00 \\u002D 11/28/14, 09:00" }, | |
225 | { 13, 15, "11/20/14, 09:00 \\u002D 12/06/14, 09:00" }, | |
226 | { 13, 15, "11/20/14, 09:00 \\u002D 02/28/15, 09:00" } | |
227 | }; | |
228 | ||
229 | static const ExpectPosAndFormat exp_en_yyMMddHHmmss[kNumDeltas] = { | |
230 | { 13, 15, "11/20/14, 09:00:00" }, | |
231 | { 13, 15, "11/20/14, 09:00:00" }, | |
232 | { 13, 15, "11/20/14, 09:00:00 \\u002D 09:00:20" }, | |
233 | { 13, 15, "11/20/14, 09:00:00 \\u002D 09:20:00" }, | |
234 | { 13, 15, "11/20/14, 09:00:00 \\u002D 11:00:00" }, | |
235 | { 13, 15, "11/20/14, 09:00:00 \\u002D 21:00:00" }, | |
236 | { 13, 15, "11/20/14, 09:00:00 \\u002D 11/28/14, 09:00:00" }, | |
237 | { 13, 15, "11/20/14, 09:00:00 \\u002D 12/06/14, 09:00:00" }, | |
238 | { 13, 15, "11/20/14, 09:00:00 \\u002D 02/28/15, 09:00:00" } | |
239 | }; | |
240 | ||
241 | static const ExpectPosAndFormat exp_en_yMMMdhmmssz[kNumDeltas] = { | |
242 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT" }, | |
243 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT" }, | |
244 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D 9:00:20 AM GMT" }, | |
245 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D 9:20:00 AM GMT" }, | |
246 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D 11:00:00 AM GMT" }, | |
247 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D 9:00:00 PM GMT" }, | |
248 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D Nov 28, 2014, 9:00:00 AM GMT" }, | |
249 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D Dec 6, 2014, 9:00:00 AM GMT" }, | |
250 | { 16, 18, "Nov 20, 2014, 9:00:00 AM GMT \\u002D Feb 28, 2015, 9:00:00 AM GMT" } | |
251 | }; | |
252 | ||
253 | static const ExpectPosAndFormat exp_ja_yyMMddHHmm[kNumDeltas] = { | |
254 | { 11, 13, "14/11/20 9:00" }, | |
255 | { 11, 13, "14/11/20 9:00" }, | |
256 | { 11, 13, "14/11/20 9:00" }, | |
257 | { 11, 13, "14/11/20 9\\u664200\\u5206\\uFF5E9\\u664220\\u5206" }, | |
258 | { 11, 13, "14/11/20 9\\u664200\\u5206\\uFF5E11\\u664200\\u5206" }, | |
259 | { 11, 13, "14/11/20 9\\u664200\\u5206\\uFF5E21\\u664200\\u5206" }, | |
260 | { 11, 13, "14/11/20 9:00\\uFF5E14/11/28 9:00" }, | |
261 | { 11, 13, "14/11/20 9:00\\uFF5E14/12/06 9:00" }, | |
262 | { 11, 13, "14/11/20 9:00\\uFF5E15/02/28 9:00" } | |
263 | }; | |
264 | ||
265 | static const ExpectPosAndFormat exp_ja_yyMMddHHmmss[kNumDeltas] = { | |
266 | { 11, 13, "14/11/20 9:00:00" }, | |
267 | { 11, 13, "14/11/20 9:00:00" }, | |
268 | { 11, 13, "14/11/20 9:00:00\\uFF5E9:00:20" }, | |
269 | { 11, 13, "14/11/20 9:00:00\\uFF5E9:20:00" }, | |
270 | { 11, 13, "14/11/20 9:00:00\\uFF5E11:00:00" }, | |
271 | { 11, 13, "14/11/20 9:00:00\\uFF5E21:00:00" }, | |
272 | { 11, 13, "14/11/20 9:00:00\\uFF5E14/11/28 9:00:00" }, | |
273 | { 11, 13, "14/11/20 9:00:00\\uFF5E14/12/06 9:00:00" }, | |
274 | { 11, 13, "14/11/20 9:00:00\\uFF5E15/02/28 9:00:00" } | |
275 | }; | |
276 | ||
277 | static const ExpectPosAndFormat exp_ja_yMMMdHHmmss[kNumDeltas] = { | |
278 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00" }, | |
279 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00" }, | |
280 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E9:00:20" }, | |
281 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E9:20:00" }, | |
282 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E11:00:00" }, | |
283 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E21:00:00" }, | |
284 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E2014\\u5E7411\\u670828\\u65E5 9:00:00" }, | |
285 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E2014\\u5E7412\\u67086\\u65E5 9:00:00" }, | |
286 | { 14, 16, "2014\\u5E7411\\u670820\\u65E5 9:00:00\\uFF5E2015\\u5E742\\u670828\\u65E5 9:00:00" } | |
287 | }; | |
288 | ||
289 | typedef struct { | |
290 | const char * locale; | |
291 | const char * skeleton; | |
292 | UDateFormatField fieldToCheck; | |
293 | const ExpectPosAndFormat * expected; | |
294 | } LocaleAndSkeletonItem; | |
295 | ||
296 | static const LocaleAndSkeletonItem locSkelItems[] = { | |
297 | { "en", "HHmm", UDAT_MINUTE_FIELD, exp_en_HHmm }, | |
298 | { "en", "HHmmss", UDAT_MINUTE_FIELD, exp_en_HHmmss }, | |
299 | { "en", "yyMMdd", UDAT_MINUTE_FIELD, exp_en_yyMMdd }, | |
300 | { "en", "yyMMddHHmm", UDAT_MINUTE_FIELD, exp_en_yyMMddHHmm }, | |
301 | { "en", "yyMMddHHmmss", UDAT_MINUTE_FIELD, exp_en_yyMMddHHmmss }, | |
302 | { "en", "yMMMdhmmssz", UDAT_MINUTE_FIELD, exp_en_yMMMdhmmssz }, | |
303 | { "ja", "yyMMddHHmm", UDAT_MINUTE_FIELD, exp_ja_yyMMddHHmm }, | |
304 | { "ja", "yyMMddHHmmss", UDAT_MINUTE_FIELD, exp_ja_yyMMddHHmmss }, | |
305 | { "ja", "yMMMdHHmmss", UDAT_MINUTE_FIELD, exp_ja_yMMMdHHmmss }, | |
306 | { NULL, NULL, (UDateFormatField)0, NULL } | |
307 | }; | |
308 | ||
309 | enum { kSizeUBuf = 96, kSizeBBuf = 192 }; | |
310 | ||
311 | static void TestFPos_SkelWithSeconds() | |
312 | { | |
313 | const LocaleAndSkeletonItem * locSkelItemPtr; | |
314 | for (locSkelItemPtr = locSkelItems; locSkelItemPtr->locale != NULL; locSkelItemPtr++) { | |
315 | UDateIntervalFormat* udifmt; | |
316 | UChar ubuf[kSizeUBuf]; | |
317 | int32_t ulen, uelen; | |
318 | UErrorCode status = U_ZERO_ERROR; | |
319 | ||
320 | u_strFromUTF8(ubuf, kSizeUBuf, &ulen, locSkelItemPtr->skeleton, -1, &status); | |
321 | udifmt = udtitvfmt_open(locSkelItemPtr->locale, ubuf, ulen, zoneGMT, -1, &status); | |
322 | if ( U_FAILURE(status) ) { | |
323 | log_data_err("FAIL: udtitvfmt_open for locale %s, skeleton %s: %s\n", | |
324 | locSkelItemPtr->locale, locSkelItemPtr->skeleton, u_errorName(status)); | |
325 | } else { | |
326 | const double * deltasPtr = deltas; | |
327 | const ExpectPosAndFormat * expectedPtr = locSkelItemPtr->expected; | |
328 | for (; *deltasPtr >= 0.0; deltasPtr++, expectedPtr++) { | |
329 | UFieldPosition fpos = { locSkelItemPtr->fieldToCheck, 0, 0 }; | |
330 | UChar uebuf[kSizeUBuf]; | |
331 | char bbuf[kSizeBBuf]; | |
332 | char bebuf[kSizeBBuf]; | |
333 | status = U_ZERO_ERROR; | |
334 | uelen = u_unescape(expectedPtr->format, uebuf, kSizeUBuf); | |
335 | ulen = udtitvfmt_format(udifmt, startTime, startTime + *deltasPtr, ubuf, kSizeUBuf, &fpos, &status); | |
336 | if ( U_FAILURE(status) ) { | |
337 | log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, delta %.1f: %s\n", | |
338 | locSkelItemPtr->locale, locSkelItemPtr->skeleton, *deltasPtr, u_errorName(status)); | |
339 | } else if ( ulen != uelen || u_strncmp(ubuf,uebuf,uelen) != 0 || | |
340 | fpos.beginIndex != expectedPtr->posBegin || fpos.endIndex != expectedPtr->posEnd ) { | |
341 | u_strToUTF8(bbuf, kSizeBBuf, NULL, ubuf, ulen, &status); | |
342 | u_strToUTF8(bebuf, kSizeBBuf, NULL, uebuf, uelen, &status); // convert back to get unescaped string | |
343 | log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, delta %12.1f, expect %d-%d \"%s\", get %d-%d \"%s\"\n", | |
344 | locSkelItemPtr->locale, locSkelItemPtr->skeleton, *deltasPtr, | |
345 | expectedPtr->posBegin, expectedPtr->posEnd, bebuf, | |
346 | fpos.beginIndex, fpos.endIndex, bbuf); | |
347 | } | |
348 | } | |
349 | udtitvfmt_close(udifmt); | |
350 | } | |
351 | } | |
352 | } | |
353 | ||
4388f060 | 354 | #endif /* #if !UCONFIG_NO_FORMATTING */ |