• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 *   Copyright (C) 2007-2016, International Business Machines
7 *   Corporation and others.  All Rights Reserved.
8 *
9 *******************************************************************************
10 *   file name:  udatpg_test.c
11 *   encoding:   UTF-8
12 *   tab size:   8 (not used)
13 *   indentation:4
14 *
15 *   created on: 2007aug01
16 *   created by: Markus W. Scherer
17 *
18 *   Test of the C wrapper for the DateTimePatternGenerator.
19 *   Calls each C API function and exercises code paths in the wrapper,
20 *   but the full functionality is tested in the C++ intltest.
21 *
22 *   One item to note: C API functions which return a const UChar *
23 *   should return a NUL-terminated string.
24 *   (The C++ implementation needs to use getTerminatedBuffer()
25 *   on UnicodeString objects which end up being returned this way.)
26 */
27 
28 #include "unicode/utypes.h"
29 
30 #if !UCONFIG_NO_FORMATTING
31 #include "unicode/udat.h"
32 #include "unicode/udatpg.h"
33 #include "unicode/ustring.h"
34 #include "cintltst.h"
35 #include "cmemory.h"
36 
37 void addDateTimePatternGeneratorTest(TestNode** root);
38 
39 #define TESTCASE(x) addTest(root, &x, "tsformat/udatpg_test/" #x)
40 
41 static void TestOpenClose(void);
42 static void TestUsage(void);
43 static void TestBuilder(void);
44 static void TestOptions(void);
45 static void TestGetFieldDisplayNames(void);
46 
addDateTimePatternGeneratorTest(TestNode ** root)47 void addDateTimePatternGeneratorTest(TestNode** root) {
48     TESTCASE(TestOpenClose);
49     TESTCASE(TestUsage);
50     TESTCASE(TestBuilder);
51     TESTCASE(TestOptions);
52     TESTCASE(TestGetFieldDisplayNames);
53 }
54 
55 /*
56  * Pipe symbol '|'. We pass only the first UChar without NUL-termination.
57  * The second UChar is just to verify that the API does not pick that up.
58  */
59 static const UChar pipeString[]={ 0x7c, 0x0a };
60 
61 static const UChar testSkeleton1[]={ 0x48, 0x48, 0x6d, 0x6d, 0 }; /* HHmm */
62 static const UChar expectingBestPattern[]={ 0x48, 0x2e, 0x6d, 0x6d, 0 }; /* H.mm */
63 static const UChar testPattern[]={ 0x48, 0x48, 0x3a, 0x6d, 0x6d, 0 }; /* HH:mm */
64 static const UChar expectingSkeleton[]= { 0x48, 0x48, 0x6d, 0x6d, 0 }; /* HHmm */
65 static const UChar expectingBaseSkeleton[]= { 0x48, 0x6d, 0 }; /* HHmm */
66 static const UChar redundantPattern[]={ 0x79, 0x79, 0x4d, 0x4d, 0x4d, 0 }; /* yyMMM */
67 static const UChar testFormat[]= {0x7B, 0x31, 0x7D, 0x20, 0x7B, 0x30, 0x7D, 0};  /* {1} {0} */
68 static const UChar appendItemName[]= {0x68, 0x72, 0};  /* hr */
69 static const UChar testPattern2[]={ 0x48, 0x48, 0x3a, 0x6d, 0x6d, 0x20, 0x76, 0 }; /* HH:mm v */
70 static const UChar replacedStr[]={ 0x76, 0x76, 0x76, 0x76, 0 }; /* vvvv */
71 /* results for getBaseSkeletons() - {Hmv}, {yMMM} */
72 static const UChar resultBaseSkeletons[2][10] = {{0x48,0x6d, 0x76, 0}, {0x79, 0x4d, 0x4d, 0x4d, 0 } };
73 static const UChar sampleFormatted[] = {0x31, 0x30, 0x20, 0x6A, 0x75, 0x69, 0x6C, 0x2E, 0}; /* 10 juil. */
74 static const UChar skeleton[]= {0x4d, 0x4d, 0x4d, 0x64, 0};  /* MMMd */
75 static const UChar timeZoneGMT[] = { 0x0047, 0x004d, 0x0054, 0x0000 };  /* "GMT" */
76 
TestOpenClose()77 static void TestOpenClose() {
78     UErrorCode errorCode=U_ZERO_ERROR;
79     UDateTimePatternGenerator *dtpg, *dtpg2;
80     const UChar *s;
81     int32_t length;
82 
83     /* Open a DateTimePatternGenerator for the default locale. */
84     dtpg=udatpg_open(NULL, &errorCode);
85     if(U_FAILURE(errorCode)) {
86         log_err_status(errorCode, "udatpg_open(NULL) failed - %s\n", u_errorName(errorCode));
87         return;
88     }
89     udatpg_close(dtpg);
90 
91     /* Now one for German. */
92     dtpg=udatpg_open("de", &errorCode);
93     if(U_FAILURE(errorCode)) {
94         log_err("udatpg_open(de) failed - %s\n", u_errorName(errorCode));
95         return;
96     }
97 
98     /* Make some modification which we verify gets passed on to the clone. */
99     udatpg_setDecimal(dtpg, pipeString, 1);
100 
101     /* Clone the generator. */
102     dtpg2=udatpg_clone(dtpg, &errorCode);
103     if(U_FAILURE(errorCode) || dtpg2==NULL) {
104         log_err("udatpg_clone() failed - %s\n", u_errorName(errorCode));
105         return;
106     }
107 
108     /* Verify that the clone has the custom decimal symbol. */
109     s=udatpg_getDecimal(dtpg2, &length);
110     if(s==pipeString || length!=1 || 0!=u_memcmp(s, pipeString, length) || s[length]!=0) {
111         log_err("udatpg_getDecimal(cloned object) did not return the expected string\n");
112         return;
113     }
114 
115     udatpg_close(dtpg);
116     udatpg_close(dtpg2);
117 }
118 
119 typedef struct {
120     UDateTimePatternField field;
121     UChar name[12];
122 } AppendItemNameData;
123 
124 static const AppendItemNameData appendItemNameData[] = { /* for Finnish */
125     { UDATPG_YEAR_FIELD,    {0x0076,0x0075,0x006F,0x0073,0x0069,0} }, /* "vuosi" */
126     { UDATPG_MONTH_FIELD,   {0x006B,0x0075,0x0075,0x006B,0x0061,0x0075,0x0073,0x0069,0} }, /* "kuukausi" */
127     { UDATPG_WEEKDAY_FIELD, {0x0076,0x0069,0x0069,0x006B,0x006F,0x006E,0x0070,0x00E4,0x0069,0x0076,0x00E4,0} },
128     { UDATPG_DAY_FIELD,     {0x0070,0x00E4,0x0069,0x0076,0x00E4,0} },
129     { UDATPG_HOUR_FIELD,    {0x0074,0x0075,0x006E,0x0074,0x0069,0} }, /* "tunti" */
130     { UDATPG_FIELD_COUNT,   {0}        }  /* terminator */
131 };
132 
TestUsage()133 static void TestUsage() {
134     UErrorCode errorCode=U_ZERO_ERROR;
135     UDateTimePatternGenerator *dtpg;
136     const AppendItemNameData * appItemNameDataPtr;
137     UChar bestPattern[20];
138     UChar result[20];
139     int32_t length;
140     UChar *s;
141     const UChar *r;
142 
143     dtpg=udatpg_open("fi", &errorCode);
144     if(U_FAILURE(errorCode)) {
145         log_err_status(errorCode, "udatpg_open(fi) failed - %s\n", u_errorName(errorCode));
146         return;
147     }
148     length = udatpg_getBestPattern(dtpg, testSkeleton1, 4,
149                                    bestPattern, 20, &errorCode);
150     if(U_FAILURE(errorCode)) {
151         log_err("udatpg_getBestPattern failed - %s\n", u_errorName(errorCode));
152         return;
153     }
154     if((u_memcmp(bestPattern, expectingBestPattern, length)!=0) || bestPattern[length]!=0) {
155         log_err("udatpg_getBestPattern did not return the expected string\n");
156         return;
157     }
158 
159 
160     /* Test skeleton == NULL */
161     s=NULL;
162     length = udatpg_getBestPattern(dtpg, s, 0, bestPattern, 20, &errorCode);
163     if(!U_FAILURE(errorCode)&&(length!=0) ) {
164         log_err("udatpg_getBestPattern failed in illegal argument - skeleton is NULL.\n");
165         return;
166     }
167 
168     /* Test udatpg_getSkeleton */
169     length = udatpg_getSkeleton(dtpg, testPattern, 5, result, 20,  &errorCode);
170     if(U_FAILURE(errorCode)) {
171         log_err("udatpg_getSkeleton failed - %s\n", u_errorName(errorCode));
172         return;
173     }
174     if((u_memcmp(result, expectingSkeleton, length)!=0) || result[length]!=0) {
175         log_err("udatpg_getSkeleton did not return the expected string\n");
176         return;
177     }
178 
179     /* Test pattern == NULL */
180     s=NULL;
181     length = udatpg_getSkeleton(dtpg, s, 0, result, 20, &errorCode);
182     if(!U_FAILURE(errorCode)&&(length!=0) ) {
183         log_err("udatpg_getSkeleton failed in illegal argument - pattern is NULL.\n");
184         return;
185     }
186 
187     /* Test udatpg_getBaseSkeleton */
188     length = udatpg_getBaseSkeleton(dtpg, testPattern, 5, result, 20,  &errorCode);
189     if(U_FAILURE(errorCode)) {
190         log_err("udatpg_getBaseSkeleton failed - %s\n", u_errorName(errorCode));
191         return;
192     }
193     if((u_memcmp(result, expectingBaseSkeleton, length)!=0) || result[length]!=0) {
194         log_err("udatpg_getBaseSkeleton did not return the expected string\n");
195         return;
196     }
197 
198     /* Test pattern == NULL */
199     s=NULL;
200     length = udatpg_getBaseSkeleton(dtpg, s, 0, result, 20, &errorCode);
201     if(!U_FAILURE(errorCode)&&(length!=0) ) {
202         log_err("udatpg_getBaseSkeleton failed in illegal argument - pattern is NULL.\n");
203         return;
204     }
205 
206     /* set append format to {1}{0} */
207     udatpg_setAppendItemFormat( dtpg, UDATPG_MONTH_FIELD, testFormat, 7 );
208     r = udatpg_getAppendItemFormat(dtpg, UDATPG_MONTH_FIELD, &length);
209 
210 
211     if(length!=7 || 0!=u_memcmp(r, testFormat, length) || r[length]!=0) {
212         log_err("udatpg_setAppendItemFormat did not return the expected string\n");
213         return;
214     }
215 
216     for (appItemNameDataPtr = appendItemNameData; appItemNameDataPtr->field <  UDATPG_FIELD_COUNT; appItemNameDataPtr++) {
217         int32_t nameLength;
218         const UChar * namePtr = udatpg_getAppendItemName(dtpg, appItemNameDataPtr->field, &nameLength);
219         if ( namePtr == NULL || u_strncmp(appItemNameDataPtr->name, namePtr, nameLength) != 0 ) {
220             log_err("udatpg_getAppendItemName returns invalid name for field %d\n", (int)appItemNameDataPtr->field);
221         }
222     }
223 
224     /* set append name to hr */
225     udatpg_setAppendItemName(dtpg, UDATPG_HOUR_FIELD, appendItemName, 2);
226     r = udatpg_getAppendItemName(dtpg, UDATPG_HOUR_FIELD, &length);
227 
228     if(length!=2 || 0!=u_memcmp(r, appendItemName, length) || r[length]!=0) {
229         log_err("udatpg_setAppendItemName did not return the expected string\n");
230         return;
231     }
232 
233     /* set date time format to {1}{0} */
234     udatpg_setDateTimeFormat( dtpg, testFormat, 7 );
235     r = udatpg_getDateTimeFormat(dtpg, &length);
236 
237     if(length!=7 || 0!=u_memcmp(r, testFormat, length) || r[length]!=0) {
238         log_err("udatpg_setDateTimeFormat did not return the expected string\n");
239         return;
240     }
241     udatpg_close(dtpg);
242 }
243 
TestBuilder()244 static void TestBuilder() {
245     UErrorCode errorCode=U_ZERO_ERROR;
246     UDateTimePatternGenerator *dtpg;
247     UDateTimePatternConflict conflict;
248     UEnumeration *en;
249     UChar result[20];
250     int32_t length, pLength;
251     const UChar *s, *p;
252     const UChar* ptrResult[2];
253     int32_t count=0;
254     UDateTimePatternGenerator *generator;
255     int32_t formattedCapacity, resultLen,patternCapacity ;
256     UChar   pattern[40], formatted[40];
257     UDateFormat *formatter;
258     UDate sampleDate = 837039928046.0;
259     static const char locale[]= "fr";
260     UErrorCode status=U_ZERO_ERROR;
261 
262     /* test create an empty DateTimePatternGenerator */
263     dtpg=udatpg_openEmpty(&errorCode);
264     if(U_FAILURE(errorCode)) {
265         log_err("udatpg_openEmpty() failed - %s\n", u_errorName(errorCode));
266         return;
267     }
268 
269     /* Add a pattern */
270     conflict = udatpg_addPattern(dtpg, redundantPattern, 5, FALSE, result, 20,
271                                  &length, &errorCode);
272     if(U_FAILURE(errorCode)) {
273         log_err("udatpg_addPattern() failed - %s\n", u_errorName(errorCode));
274         return;
275     }
276     /* Add a redundant pattern */
277     conflict = udatpg_addPattern(dtpg, redundantPattern, 5, FALSE, result, 20,
278                                  &length, &errorCode);
279     if(conflict == UDATPG_NO_CONFLICT) {
280         log_err("udatpg_addPattern() failed to find the duplicate pattern.\n");
281         return;
282     }
283     /* Test pattern == NULL */
284     s=NULL;
285     length = udatpg_addPattern(dtpg, s, 0, FALSE, result, 20,
286                                &length, &errorCode);
287     if(!U_FAILURE(errorCode)&&(length!=0) ) {
288         log_err("udatpg_addPattern failed in illegal argument - pattern is NULL.\n");
289         return;
290     }
291 
292     /* replace field type */
293     errorCode=U_ZERO_ERROR;
294     conflict = udatpg_addPattern(dtpg, testPattern2, 7, FALSE, result, 20,
295                                  &length, &errorCode);
296     if((conflict != UDATPG_NO_CONFLICT)||U_FAILURE(errorCode)) {
297         log_err("udatpg_addPattern() failed to add HH:mm v. - %s\n", u_errorName(errorCode));
298         return;
299     }
300     length = udatpg_replaceFieldTypes(dtpg, testPattern2, 7, replacedStr, 4,
301                                       result, 20, &errorCode);
302     if (U_FAILURE(errorCode) || (length==0) ) {
303         log_err("udatpg_replaceFieldTypes failed!\n");
304         return;
305     }
306 
307     /* Get all skeletons and the crroespong pattern for each skeleton. */
308     ptrResult[0] = testPattern2;
309     ptrResult[1] = redundantPattern;
310     count=0;
311     en = udatpg_openSkeletons(dtpg, &errorCode);
312     if (U_FAILURE(errorCode) || (length==0) ) {
313         log_err("udatpg_openSkeletons failed!\n");
314         return;
315     }
316     while ( (s=uenum_unext(en, &length, &errorCode))!= NULL) {
317         p = udatpg_getPatternForSkeleton(dtpg, s, length, &pLength);
318         if (U_FAILURE(errorCode) || p==NULL || u_memcmp(p, ptrResult[count], pLength)!=0 ) {
319             log_err("udatpg_getPatternForSkeleton failed!\n");
320             return;
321         }
322         count++;
323     }
324     uenum_close(en);
325 
326     /* Get all baseSkeletons */
327     en = udatpg_openBaseSkeletons(dtpg, &errorCode);
328     count=0;
329     while ( (s=uenum_unext(en, &length, &errorCode))!= NULL) {
330         p = udatpg_getPatternForSkeleton(dtpg, s, length, &pLength);
331         if (U_FAILURE(errorCode) || p==NULL || u_memcmp(p, resultBaseSkeletons[count], pLength)!=0 ) {
332             log_err("udatpg_getPatternForSkeleton failed!\n");
333             return;
334         }
335         count++;
336     }
337     if (U_FAILURE(errorCode) || (length==0) ) {
338         log_err("udatpg_openSkeletons failed!\n");
339         return;
340     }
341     uenum_close(en);
342 
343     udatpg_close(dtpg);
344 
345     /* sample code in Userguide */
346     patternCapacity = UPRV_LENGTHOF(pattern);
347     status=U_ZERO_ERROR;
348     generator=udatpg_open(locale, &status);
349     if(U_FAILURE(status)) {
350         return;
351     }
352 
353     /* get a pattern for an abbreviated month and day */
354     length = udatpg_getBestPattern(generator, skeleton, 4,
355                                    pattern, patternCapacity, &status);
356     formatter = udat_open(UDAT_PATTERN, UDAT_PATTERN, locale, timeZoneGMT, -1,
357                           pattern, length, &status);
358     if (formatter==NULL) {
359         log_err("Failed to initialize the UDateFormat of the sample code in Userguide.\n");
360         udatpg_close(generator);
361         return;
362     }
363 
364     /* use it to format (or parse) */
365     formattedCapacity = UPRV_LENGTHOF(formatted);
366     resultLen=udat_format(formatter, ucal_getNow(), formatted, formattedCapacity,
367                           NULL, &status);
368     /* for French, the result is "13 sept." */
369 
370     /* cannot use the result from ucal_getNow() because the value change evreyday. */
371     resultLen=udat_format(formatter, sampleDate, formatted, formattedCapacity,
372                           NULL, &status);
373     if ( u_memcmp(sampleFormatted, formatted, resultLen) != 0 ) {
374         log_err("Failed udat_format() of sample code in Userguide.\n");
375     }
376     udatpg_close(generator);
377     udat_close(formatter);
378 }
379 
380 typedef struct DTPtnGenOptionsData {
381     const char *                    locale;
382     const UChar *                   skel;
383     UDateTimePatternMatchOptions    options;
384     const UChar *                   expectedPattern;
385 } DTPtnGenOptionsData;
386 enum { kTestOptionsPatLenMax = 32 };
387 
388 static const UChar skel_Hmm[]     = { 0x0048, 0x006D, 0x006D, 0 };
389 static const UChar skel_HHmm[]    = { 0x0048, 0x0048, 0x006D, 0x006D, 0 };
390 static const UChar skel_hhmm[]    = { 0x0068, 0x0068, 0x006D, 0x006D, 0 };
391 static const UChar patn_hcmm_a[]  = { 0x0068, 0x003A, 0x006D, 0x006D, 0x0020, 0x0061, 0 }; /* h:mm a */
392 static const UChar patn_HHcmm[]   = { 0x0048, 0x0048, 0x003A, 0x006D, 0x006D, 0 }; /* HH:mm */
393 static const UChar patn_hhcmm_a[] = { 0x0068, 0x0068, 0x003A, 0x006D, 0x006D, 0x0020, 0x0061, 0 }; /* hh:mm a */
394 static const UChar patn_HHpmm[]   = { 0x0048, 0x0048, 0x002E, 0x006D, 0x006D, 0 }; /* HH.mm */
395 static const UChar patn_hpmm_a[]  = { 0x0068, 0x002E, 0x006D, 0x006D, 0x0020, 0x0061, 0 }; /* h.mm a */
396 static const UChar patn_Hpmm[]    = { 0x0048, 0x002E, 0x006D, 0x006D, 0 }; /* H.mm */
397 static const UChar patn_hhpmm_a[] = { 0x0068, 0x0068, 0x002E, 0x006D, 0x006D, 0x0020, 0x0061, 0 }; /* hh.mm a */
398 
TestOptions()399 static void TestOptions() {
400     const DTPtnGenOptionsData testData[] = {
401         /*loc   skel       options                       expectedPattern */
402         { "en", skel_Hmm,  UDATPG_MATCH_NO_OPTIONS,        patn_HHcmm   },
403         { "en", skel_HHmm, UDATPG_MATCH_NO_OPTIONS,        patn_HHcmm   },
404         { "en", skel_hhmm, UDATPG_MATCH_NO_OPTIONS,        patn_hcmm_a  },
405         { "en", skel_Hmm,  UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_HHcmm   },
406         { "en", skel_HHmm, UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_HHcmm   },
407         { "en", skel_hhmm, UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_hhcmm_a },
408         { "da", skel_Hmm,  UDATPG_MATCH_NO_OPTIONS,        patn_HHpmm   },
409         { "da", skel_HHmm, UDATPG_MATCH_NO_OPTIONS,        patn_HHpmm   },
410         { "da", skel_hhmm, UDATPG_MATCH_NO_OPTIONS,        patn_hpmm_a  },
411         { "da", skel_Hmm,  UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_Hpmm    },
412         { "da", skel_HHmm, UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_HHpmm   },
413         { "da", skel_hhmm, UDATPG_MATCH_HOUR_FIELD_LENGTH, patn_hhpmm_a },
414     };
415 
416     int count = UPRV_LENGTHOF(testData);
417     const DTPtnGenOptionsData * testDataPtr = testData;
418 
419     for (; count-- > 0; ++testDataPtr) {
420         UErrorCode status = U_ZERO_ERROR;
421         UDateTimePatternGenerator * dtpgen = udatpg_open(testDataPtr->locale, &status);
422         if ( U_SUCCESS(status) ) {
423             UChar pattern[kTestOptionsPatLenMax];
424             int32_t patLen = udatpg_getBestPatternWithOptions(dtpgen, testDataPtr->skel, -1,
425                                                               testDataPtr->options, pattern,
426                                                               kTestOptionsPatLenMax, &status);
427             if ( U_FAILURE(status) || u_strncmp(pattern, testDataPtr->expectedPattern, patLen+1) != 0 ) {
428                 char skelBytes[kTestOptionsPatLenMax];
429                 char expectedPatternBytes[kTestOptionsPatLenMax];
430                 char patternBytes[kTestOptionsPatLenMax];
431                 log_err("ERROR udatpg_getBestPatternWithOptions, locale %s, skeleton %s, options 0x%04X, expected pattern %s, got %s, status %d\n",
432                         testDataPtr->locale, u_austrncpy(skelBytes,testDataPtr->skel,kTestOptionsPatLenMax), testDataPtr->options,
433                         u_austrncpy(expectedPatternBytes,testDataPtr->expectedPattern,kTestOptionsPatLenMax),
434                         u_austrncpy(patternBytes,pattern,kTestOptionsPatLenMax), status );
435             }
436             udatpg_close(dtpgen);
437         } else {
438             log_data_err("ERROR udatpg_open failed for locale %s : %s - (Are you missing data?)\n", testDataPtr->locale, myErrorName(status));
439         }
440     }
441 }
442 
443 typedef struct FieldDisplayNameData {
444     const char *            locale;
445     UDateTimePatternField   field;
446     UDateTimePGDisplayWidth width;
447     const char *            expected;
448 } FieldDisplayNameData;
449 enum { kFieldDisplayNameMax = 32, kFieldDisplayNameBytesMax  = 64};
450 
TestGetFieldDisplayNames()451 static void TestGetFieldDisplayNames() {
452     const FieldDisplayNameData testData[] = {
453         /*loc      field                              width               expectedName */
454         { "de",    UDATPG_QUARTER_FIELD,              UDATPG_WIDE,        "Quartal" },
455         { "de",    UDATPG_QUARTER_FIELD,              UDATPG_ABBREVIATED, "Quart." },
456         { "de",    UDATPG_QUARTER_FIELD,              UDATPG_NARROW,      "Q" },
457         { "en",    UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_WIDE,        "weekday of the month" },
458         { "en",    UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_ABBREVIATED, "wkday. of mo." },
459         { "en",    UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_NARROW,      "wkday. of mo." }, // fallback
460         { "en_GB", UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_WIDE,        "weekday of the month" },
461         { "en_GB", UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_ABBREVIATED, "wkday of mo" }, // override
462         { "en_GB", UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, UDATPG_NARROW,      "wkday of mo" },
463         { "it",    UDATPG_SECOND_FIELD,               UDATPG_WIDE,        "secondo" },
464         { "it",    UDATPG_SECOND_FIELD,               UDATPG_ABBREVIATED, "s" },
465         { "it",    UDATPG_SECOND_FIELD,               UDATPG_NARROW,      "s" },
466     };
467 
468     int count = UPRV_LENGTHOF(testData);
469     const FieldDisplayNameData * testDataPtr = testData;
470     for (; count-- > 0; ++testDataPtr) {
471         UErrorCode status = U_ZERO_ERROR;
472         UDateTimePatternGenerator * dtpgen = udatpg_open(testDataPtr->locale, &status);
473         if ( U_FAILURE(status) ) {
474             log_data_err("ERROR udatpg_open failed for locale %s : %s - (Are you missing data?)\n", testDataPtr->locale, myErrorName(status));
475         } else {
476             UChar expName[kFieldDisplayNameMax];
477             UChar getName[kFieldDisplayNameMax];
478             u_unescape(testDataPtr->expected, expName, kFieldDisplayNameMax);
479 
480             int32_t getLen = udatpg_getFieldDisplayName(dtpgen, testDataPtr->field, testDataPtr->width,
481                                                         getName, kFieldDisplayNameMax, &status);
482             if ( U_FAILURE(status) ) {
483                 log_err("ERROR udatpg_getFieldDisplayName locale %s field %d width %d, got status %s, len %d\n",
484                         testDataPtr->locale, testDataPtr->field, testDataPtr->width, u_errorName(status), getLen);
485             } else if ( u_strncmp(expName, getName, kFieldDisplayNameMax) != 0 ) {
486                 char expNameB[kFieldDisplayNameBytesMax];
487                 char getNameB[kFieldDisplayNameBytesMax];
488                 log_err("ERROR udatpg_getFieldDisplayName locale %s field %d width %d, expected %s, got %s, status %s\n",
489                         testDataPtr->locale, testDataPtr->field, testDataPtr->width,
490                         u_austrncpy(expNameB,expName,kFieldDisplayNameBytesMax),
491                         u_austrncpy(getNameB,getName,kFieldDisplayNameBytesMax), u_errorName(status) );
492             } else if (testDataPtr->width == UDATPG_WIDE && getLen > 1) {
493                 // test preflight & inadequate buffer
494                 int32_t getNewLen;
495                 status = U_ZERO_ERROR;
496                 getNewLen = udatpg_getFieldDisplayName(dtpgen, testDataPtr->field, UDATPG_WIDE, NULL, 0, &status);
497                 if (U_FAILURE(status) || getNewLen != getLen) {
498                     log_err("ERROR udatpg_getFieldDisplayName locale %s field %d width %d, preflight expected len %d, got %d, status %s\n",
499                         testDataPtr->locale, testDataPtr->field, testDataPtr->width, getLen, getNewLen, u_errorName(status) );
500                 }
501                 status = U_ZERO_ERROR;
502                 getNewLen = udatpg_getFieldDisplayName(dtpgen, testDataPtr->field, UDATPG_WIDE, getName, getLen-1, &status);
503                 if (status!=U_BUFFER_OVERFLOW_ERROR || getNewLen != getLen) {
504                     log_err("ERROR udatpg_getFieldDisplayName locale %s field %d width %d, overflow expected len %d & BUFFER_OVERFLOW_ERROR, got %d & status %s\n",
505                         testDataPtr->locale, testDataPtr->field, testDataPtr->width, getLen, getNewLen, u_errorName(status) );
506                 }
507             }
508             udatpg_close(dtpgen);
509         }
510     }
511 }
512 
513 #endif
514