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