-
-
Notifications
You must be signed in to change notification settings - Fork 754
/
dtptngts.cpp
1821 lines (1689 loc) · 89.7 KB
/
dtptngts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2008-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include <stdio.h>
#include <stdlib.h>
#include "dtptngts.h"
#include "unicode/calendar.h"
#include "unicode/smpdtfmt.h"
#include "unicode/dtfmtsym.h"
#include "unicode/dtptngen.h"
#include "unicode/ustring.h"
#include "unicode/datefmt.h"
#include "cmemory.h"
#include "cstring.h"
#include "loctest.h"
// This is an API test, not a unit test. It doesn't test very many cases, and doesn't
// try to test the full functionality. It just calls each function in the class and
// verifies that it works on a basic level.
void IntlTestDateTimePatternGeneratorAPI::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
{
if (exec) logln("TestSuite DateTimePatternGeneratorAPI");
switch (index) {
TESTCASE(0, testAPI);
TESTCASE(1, testOptions);
TESTCASE(2, testAllFieldPatterns);
TESTCASE(3, testStaticGetSkeleton);
TESTCASE(4, testC);
TESTCASE(5, testSkeletonsWithDayPeriods);
TESTCASE(6, testGetFieldDisplayNames);
TESTCASE(7, testJjMapping);
TESTCASE(8, test20640_HourCyclArsEnNH);
TESTCASE(9, testFallbackWithDefaultRootLocale);
TESTCASE(10, testGetDefaultHourCycle_OnEmptyInstance);
TESTCASE(11, test_jConsistencyOddLocales);
TESTCASE(12, testBestPattern);
TESTCASE(13, testDateTimePatterns);
TESTCASE(14, testISO8601);
TESTCASE(15, testRegionOverride);
default: name = ""; break;
}
}
#define MAX_LOCALE 11
/**
* Test various generic API methods of DateTimePatternGenerator for API coverage.
*/
void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
{
UnicodeString patternData[] = {
UnicodeString("yM"), // 00
UnicodeString("yMMM"), // 01
UnicodeString("yMd"), // 02
UnicodeString("yMMMd"), // 03
UnicodeString("Md"), // 04
UnicodeString("MMMd"), // 05
UnicodeString("MMMMd"), // 06
UnicodeString("yQQQ"), // 07
UnicodeString("hhmm"), // 08
UnicodeString("HHmm"), // 09
UnicodeString("jjmm"), // 10
UnicodeString("mmss"), // 11
UnicodeString("yyyyMMMM"), // 12
UnicodeString("MMMEd"), // 13
UnicodeString("Ed"), // 14
UnicodeString("jmmssSSS"), // 15
UnicodeString("JJmm"), // 16
UnicodeString(),
};
const char* testLocale[MAX_LOCALE][4] = {
{"en", "US", "", ""}, // 0
{"en", "US", "", "calendar=japanese"}, // 1
{"de", "DE", "", ""}, // 2
{"fi", "", "", ""}, // 3
{"es", "", "", ""}, // 4
{"ja", "", "", ""}, // 5
{"ja", "", "", "calendar=japanese"}, // 6
{"zh", "Hans", "CN", ""}, // 7
{"zh", "TW", "", "calendar=roc"}, // 8
{"ru", "", "", ""}, // 9
{"zh", "", "", "calendar=chinese"}, // 10
};
// For Weds, Jan 13, 1999, 23:58:59
UnicodeString patternResults_en_US[] = {
// en_US // 0 en_US
UnicodeString("1/1999"), // 00: yM
UnicodeString("Jan 1999"), // 01: yMMM
UnicodeString("1/13/1999"), // 02: yMd
UnicodeString("Jan 13, 1999"), // 03: yMMMd
UnicodeString("1/13"), // 04: Md
UnicodeString("Jan 13"), // 05: MMMd
UnicodeString("January 13"), // 06: MMMMd
UnicodeString("Q1 1999"), // 07: yQQQ
UnicodeString(u"11:58\u202FPM", -1), // 08: hhmm
UnicodeString("23:58"), // 09: HHmm
UnicodeString(u"11:58\u202FPM", -1), // 10: jjmm
UnicodeString("58:59"), // 11: mmss
UnicodeString("January 1999"), // 12: yyyyMMMM
UnicodeString("Wed, Jan 13"), // 13: MMMEd -> EEE, MMM d
UnicodeString("13 Wed"), // 14: Ed -> d EEE
UnicodeString(u"11:58:59.123\u202FPM", -1), // 15: jmmssSSS -> "h:mm:ss.SSS a"
UnicodeString("11:58"), // 16: JJmm
};
UnicodeString patternResults_en_US_japanese[] = {
// en_US@calendar=japanese // 1 en_US@calendar=japanese
UnicodeString("1/11 H"), // 0: yM
UnicodeString("Jan 11 Heisei"), // 1: yMMM
UnicodeString("1/13/11 H"), // 2: yMd
UnicodeString("Jan 13, 11 Heisei"), // 3: yMMMd
UnicodeString("1/13"), // 4: Md
UnicodeString("Jan 13"), // 5: MMMd
UnicodeString("January 13"), // 6: MMMMd
UnicodeString("Q1 11 Heisei"), // 7: yQQQ
UnicodeString(u"11:58\u202FPM", -1), // 8: hhmm
UnicodeString("23:58"), // 9: HHmm
UnicodeString(u"11:58\u202FPM", -1), // 10: jjmm
UnicodeString("58:59"), // 11: mmss
UnicodeString("January 11 Heisei"), // 12: yyyyMMMM
UnicodeString("Wed, Jan 13"), // 13: MMMEd -> EEE, MMM d"
UnicodeString("13 Wed"), // 14: Ed -> d EEE
UnicodeString(u"11:58:59.123\u202FPM", -1), // 15: jmmssSSS -> "h:mm:ss.SSS a"
UnicodeString("11:58"), // 16: JJmm
};
UnicodeString patternResults_de_DE[] = {
// de_DE // 2 de_DE
UnicodeString("1/1999"), // 00: yM
UnicodeString("Jan. 1999"), // 01: yMMM
UnicodeString("13.1.1999"), // 02: yMd
UnicodeString("13. Jan. 1999"), // 03: yMMMd
UnicodeString("13.1."), // 04: Md
UnicodeString("13. Jan."), // 05: MMMd
UnicodeString("13. Januar"), // 06: MMMMd
UnicodeString("Q1 1999"), // 07: yQQQ
UnicodeString(u"11:58\u202FPM", -1), // 08: hhmm
UnicodeString("23:58"), // 09: HHmm
UnicodeString("23:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss
UnicodeString("Januar 1999"), // 12: yyyyMMMM
UnicodeString("Mi., 13. Jan."), // 13: MMMEd -> EEE, d. MMM
UnicodeString("Mi., 13."), // 14: Ed -> EEE d.
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "HH:mm:ss,SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_fi[] = {
// fi // 3 fi
UnicodeString("1.1999"), // 00: yM (fixed expected result per ticket:6626:)
UnicodeString("tammi 1999"), // 01: yMMM
UnicodeString("13.1.1999"), // 02: yMd
UnicodeString("13.1.1999"), // 03: yMMMd
UnicodeString("13.1."), // 04: Md
UnicodeString("13.1."), // 05: MMMd
UnicodeString("13. tammikuuta"), // 06: MMMMd
UnicodeString("1. nelj. 1999"), // 07: yQQQ
UnicodeString(u"11.58\u202Fip.", -1), // 08: hhmm
UnicodeString("23.58"), // 09: HHmm
UnicodeString("23.58"), // 10: jjmm
UnicodeString("58.59"), // 11: mmss
UnicodeString("tammikuu 1999"), // 12: yyyyMMMM
UnicodeString("ke 13.1."), // 13: MMMEd -> EEE d. MMM
UnicodeString("ke 13."), // 14: Ed -> ccc d.
UnicodeString("23.58.59,123"), // 15: jmmssSSS -> "H.mm.ss,SSS"
UnicodeString("23.58"), // 16: JJmm
};
UnicodeString patternResults_es[] = {
// es // 4 es
UnicodeString("1/1999"), // 00: yM -> "M/y"
UnicodeString("ene 1999"), // 01: yMMM -> "MMM y"
UnicodeString("13/1/1999"), // 02: yMd -> "d/M/y"
UnicodeString("13 ene 1999"), // 03: yMMMd -> "d MMM y"
UnicodeString("13/1"), // 04: Md -> "d/M"
UnicodeString("13 ene"), // 05: MMMd -> "d 'de' MMM"
UnicodeString("13 de enero"), // 06: MMMMd -> "d 'de' MMMM"
UnicodeString("T1 1999"), // 07: yQQQ -> "QQQ y"
UnicodeString(u"11:58\u202Fp.\u00A0m.", -1), // 08: hhmm -> "hh:mm a"
UnicodeString("23:58"), // 09: HHmm -> "HH:mm"
UnicodeString("23:58"), // 10: jjmm -> "HH:mm"
UnicodeString("58:59"), // 11: mmss -> "mm:ss"
UnicodeString("enero de 1999"), // 12: yyyyMMMM -> "MMMM 'de' yyyy"
CharsToUnicodeString("mi\\u00E9, 13 ene"), // 13: MMMEd -> "E, d MMM"
CharsToUnicodeString("mi\\u00E9 13"), // 14: Ed -> "EEE d"
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "H:mm:ss,SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_ja[] = {
// ja // 5 ja
UnicodeString("1999/1"), // 00: yM -> y/M
CharsToUnicodeString("1999\\u5E741\\u6708"), // 01: yMMM -> y\u5E74M\u6708
UnicodeString("1999/1/13"), // 02: yMd -> y/M/d
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> y\u5E74M\u6708d\u65E5
UnicodeString("1/13"), // 04: Md -> M/d
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
CharsToUnicodeString("1999/Q1"), // 07: yQQQ -> y/QQQ
CharsToUnicodeString("\\u5348\\u5F8C11:58"), // 08: hhmm
UnicodeString("23:58"), // 09: HHmm -> HH:mm
UnicodeString("23:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss -> mm:ss
CharsToUnicodeString("1999\\u5E741\\u6708"), // 12: yyyyMMMM -> y\u5E74M\u6708
CharsToUnicodeString("1\\u670813\\u65E5(\\u6C34)"), // 13: MMMEd -> M\u6708d\u65E5(EEE)
CharsToUnicodeString("13\\u65E5(\\u6C34)"), // 14: Ed -> d\u65E5(EEE)
UnicodeString("23:58:59.123"), // 15: jmmssSSS -> "H:mm:ss.SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_ja_japanese[] = {
// ja@calendar=japanese // 6 ja@calendar=japanese
UnicodeString("H11/1"), // 00: yM -> GGGGGy/m
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u6708"), // 01: yMMM -> Gy\u5E74M\u6708
UnicodeString("H11/1/13"), // 02: yMd -> GGGGGy/m/d
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> Gy\u5E74M\u6708d\u65E5
UnicodeString("1/13"), // 04: Md -> M/d
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
CharsToUnicodeString("\\u5E73\\u621011/Q1"), // 07: yQQQ -> Gy/QQQ
CharsToUnicodeString("\\u5348\\u5F8C11:58"), // 08: hhmm ->
UnicodeString("23:58"), // 09: HHmm -> HH:mm (as for ja)
UnicodeString("23:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss -> mm:ss (as for ja)
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u6708"), // 12: yyyyMMMM -> Gyyyy\u5E74M\u6708
CharsToUnicodeString("1\\u670813\\u65E5(\\u6C34)"), // 13: MMMEd -> M\u6708d\u65E5(EEE)
CharsToUnicodeString("13\\u65E5(\\u6C34)"), // 14: Ed -> d\u65E5(EEE)
UnicodeString("23:58:59.123"), // 15: jmmssSSS -> "H:mm:ss.SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_zh_Hans_CN[] = {
// zh_Hans_CN // 7 zh_Hans_CN
CharsToUnicodeString("1999/1"), // 00: yM
CharsToUnicodeString("1999\\u5E741\\u6708"), // 01: yMMM -> yyyy\u5E74MMM (fixed expected result per ticket:6626:)
CharsToUnicodeString("1999/1/13"), // 02: yMd
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> yyyy\u5E74MMMd\u65E5 (fixed expected result per ticket:6626:)
UnicodeString("1/13"), // 04: Md
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5 (fixed expected result per ticket:6626:)
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
CharsToUnicodeString("1999\\u5E74\\u7B2C1\\u5B63\\u5EA6"), // 07: yQQQ
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm
UnicodeString("23:58"), // 09: HHmm
CharsToUnicodeString("23:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss
CharsToUnicodeString("1999\\u5E741\\u6708"), // 12: yyyyMMMM -> yyyy\u5E74MMM
CharsToUnicodeString("1\\u670813\\u65E5\\u5468\\u4E09"), // 13: MMMEd -> MMMd\u65E5EEE
CharsToUnicodeString("13\\u65E5\\u5468\\u4E09"), // 14: Ed -> d\u65E5EEE
CharsToUnicodeString("23:58:59.123"), // 15: jmmssSSS -> "ah:mm:ss.SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_zh_TW_roc[] = {
// zh_TW@calendar=roc // 8 zh_TW@calendar=roc
CharsToUnicodeString("\\u6C11\\u570B88/1"), // 00: yM -> Gy/M
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // 01: yMMM -> Gy\u5E74M\u6708
CharsToUnicodeString("\\u6C11\\u570B88/1/13"), // 02: yMd -> Gy/M/d
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> Gy\u5E74M\u6708d\u65E5
UnicodeString("1/13"), // 04: Md -> M/d
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd ->M\u6708d\u65E5
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd ->M\u6708d\u65E5
CharsToUnicodeString("\\u6C11\\u570B88\\u5E74\\u7B2C1\\u5B63"), // 07: yQQQ -> Gy QQQ
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm ->
UnicodeString("23:58"), // 09: HHmm ->
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss ->
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // 12: yyyyMMMM -> Gy\u5E74M\u670
CharsToUnicodeString("1\\u670813\\u65E5\\u9031\\u4E09"), // 13: MMMEd -> M\u6708d\u65E5EEE
CharsToUnicodeString("13 \\u9031\\u4E09"), // 14: Ed -> d E
CharsToUnicodeString("\\u4E0B\\u534811:58:59.123"), // 15: jmmssSSS -> "ah:mm:ss.SSS"
UnicodeString("11:58"), // 16: JJmm
};
UnicodeString patternResults_ru[] = {
// ru // 9 ru
UnicodeString("01.1999"), // 00: yM -> MM.y
UnicodeString(u"\u044F\u043D\u0432. 1999\u202F\u0433.", -1), // 01: yMMM -> LLL y
UnicodeString("13.01.1999"), // 02: yMd -> dd.MM.y
UnicodeString(u"13 \u044F\u043D\u0432. 1999\u202F\u0433.",-1), // 03: yMMMd -> d MMM y
UnicodeString("13.01"), // 04: Md -> dd.MM
CharsToUnicodeString("13 \\u044F\\u043D\\u0432."), // 05: MMMd -> d MMM
CharsToUnicodeString("13 \\u044F\\u043D\\u0432\\u0430\\u0440\\u044F"), // 06: MMMMd -> d MMMM
UnicodeString(u"1-\u0439 \u043A\u0432. 1999\u202F\u0433.",-1), // 07: yQQQ -> y QQQ
UnicodeString(u"11:58\u202FPM", -1), // 08: hhmm -> hh:mm a
UnicodeString("23:58"), // 09: HHmm -> HH:mm
UnicodeString("23:58"), // 10: jjmm -> HH:mm
UnicodeString("58:59"), // 11: mmss -> mm:ss
UnicodeString(u"\u044F\u043D\u0432\u0430\u0440\u044C 1999\u202F\u0433.",-1), // 12: yyyyMMMM -> LLLL y
CharsToUnicodeString("\\u0441\\u0440, 13 \\u044F\\u043D\\u0432."), // 13: MMMEd -> ccc, d MMM
CharsToUnicodeString("\\u0441\\u0440, 13"), // 14: Ed -> EEE, d
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "H:mm:ss,SSS"
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString patternResults_zh_chinese[] = {
// zh@calendar=chinese // 10 zh@calendar=chinese
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u5341\\u4E00\\u6708"), // 00: yMMM
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u5341\\u4E00\\u6708"), // 01: yMMM
CharsToUnicodeString("1998\\u5E74\\u5341\\u4E00\\u670826"), // 02: yMMMd
CharsToUnicodeString("1998\\u5E74\\u5341\\u4E00\\u670826"), // 03: yMMMd
UnicodeString("11-26"), // 04: Md
CharsToUnicodeString("\\u5341\\u4E00\\u670826\\u65E5"), // 05: MMMd
CharsToUnicodeString("\\u5341\\u4E00\\u670826\\u65E5"), // 06: MMMMd
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u7b2c\\u56db\\u5B63\\u5EA6"), // 07: yQQQ
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm
UnicodeString("23:58"), // 09: HHmm
CharsToUnicodeString("23:58"), // 10: jjmm
UnicodeString("58:59"), // 11: mmss
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u5341\\u4E00\\u6708"), // 12: yyyyMMMM
CharsToUnicodeString("\\u5341\\u4E00\\u670826\\u65E5\\u5468\\u4E09"), // 13: MMMEd
CharsToUnicodeString("26\\u65E5\\u5468\\u4E09"), // 14: Ed -> d\u65E5EEE
CharsToUnicodeString("23:58:59.123"), // 15: jmmssSS
UnicodeString("23:58"), // 16: JJmm
};
UnicodeString* patternResults[MAX_LOCALE] = {
patternResults_en_US, // 0
patternResults_en_US_japanese, // 1
patternResults_de_DE, // 2
patternResults_fi, // 3
patternResults_es, // 4
patternResults_ja, // 5
patternResults_ja_japanese, // 6
patternResults_zh_Hans_CN, // 7
patternResults_zh_TW_roc, // 8
patternResults_ru, // 9
patternResults_zh_chinese, // 10
};
UnicodeString patternTests2[] = {
UnicodeString("yyyyMMMdd"),
UnicodeString("yyyyqqqq"),
UnicodeString("yMMMdd"),
UnicodeString("EyyyyMMMdd"),
UnicodeString("yyyyMMdd"),
UnicodeString("yyyyMMM"),
UnicodeString("yyyyMM"),
UnicodeString("yyMM"),
UnicodeString("yMMMMMd"),
UnicodeString("EEEEEMMMMMd"),
UnicodeString("MMMd"),
UnicodeString("MMMdhmm"),
UnicodeString("EMMMdhmms"),
UnicodeString("MMdhmm"),
UnicodeString("EEEEMMMdhmms"),
UnicodeString("yyyyMMMddhhmmss"),
UnicodeString("EyyyyMMMddhhmmss"),
UnicodeString("hmm"),
UnicodeString("hhmm"),
UnicodeString("hhmmVVVV"),
UnicodeString(""),
};
UnicodeString patternResults2[] = {
UnicodeString("Oct 14, 1999"),
UnicodeString("4th quarter 1999"),
UnicodeString("Oct 14, 1999"),
UnicodeString("Thu, Oct 14, 1999"),
UnicodeString("10/14/1999"),
UnicodeString("Oct 1999"),
UnicodeString("10/1999"),
UnicodeString("10/99"),
UnicodeString("O 14, 1999"),
UnicodeString("T, O 14"),
UnicodeString("Oct 14"),
UnicodeString(u"Oct 14, 6:58\u202FAM", -1),
UnicodeString(u"Thu, Oct 14, 6:58:59\u202FAM", -1),
UnicodeString(u"10/14, 6:58\u202FAM", -1),
UnicodeString(u"Thursday, Oct 14, 6:58:59\u202FAM", -1),
UnicodeString(u"Oct 14, 1999, 6:58:59\u202FAM", -1),
UnicodeString(u"Thu, Oct 14, 1999, 6:58:59\u202FAM", -1),
UnicodeString(u"6:58\u202FAM", -1),
UnicodeString(u"6:58\u202FAM", -1),
UnicodeString(u"6:58\u202FAM GMT", -1),
UnicodeString(""),
};
// results for getSkeletons() and getPatternForSkeleton()
const UnicodeString testSkeletonsResults[] = {
UnicodeString("HH:mm"),
UnicodeString("MMMMd"),
UnicodeString("MMMMMdd"),
};
const UnicodeString testBaseSkeletonsResults[] = {
UnicodeString("Hm"),
UnicodeString("MMMMd"),
UnicodeString("MMMMMd"),
};
const char* testGetSkeletonAndBase[][3] = {
// pattern skeleton baseSkeleton
{ "dd-MMM", "MMMdd", "MMMd" },
{ "dd/MMMM/yy", "yyMMMMdd", "yMMMMd" },
{ "h", "h", "h" },
{ "ah", "ah", "ah" },
{ "aaaah", "aaaah", "aaaah" },
{ "Bh", "Bh", "Bh" }
};
UnicodeString newDecimal(" "); // space
UnicodeString newAppendItemName("hrs.");
UnicodeString newAppendItemFormat("{1} {0}");
UnicodeString newDateTimeFormat("{1} {0}");
UErrorCode status = U_ZERO_ERROR;
UnicodeString conflictingPattern;
UDateTimePatternConflict conflictingStatus = UDATPG_NO_CONFLICT;
(void)conflictingStatus; // Suppress set but not used warning.
// ======= Test CreateInstance with default locale
logln("Testing DateTimePatternGenerator createInstance from default locale");
DateTimePatternGenerator *instFromDefaultLocale=DateTimePatternGenerator::createInstance(status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator (default) - exiting");
return;
}
else {
delete instFromDefaultLocale;
}
// ======= Test CreateInstance with given locale
logln("Testing DateTimePatternGenerator createInstance from French locale");
status = U_ZERO_ERROR;
DateTimePatternGenerator *instFromLocale=DateTimePatternGenerator::createInstance(Locale::getFrench(), status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exiting");
return;
}
// ======= Test clone DateTimePatternGenerator
logln("Testing DateTimePatternGenerator::clone()");
status = U_ZERO_ERROR;
UnicodeString decimalSymbol = instFromLocale->getDecimal();
UnicodeString newDecimalSymbol = UnicodeString("*");
decimalSymbol = instFromLocale->getDecimal();
instFromLocale->setDecimal(newDecimalSymbol);
DateTimePatternGenerator *cloneDTPatternGen=instFromLocale->clone();
decimalSymbol = cloneDTPatternGen->getDecimal();
if (decimalSymbol != newDecimalSymbol) {
errln("ERROR: inconsistency is found in cloned object.");
}
if ( !(*cloneDTPatternGen == *instFromLocale) ) {
errln("ERROR: inconsistency is found in cloned object.");
}
if ( *cloneDTPatternGen != *instFromLocale ) {
errln("ERROR: inconsistency is found in cloned object.");
}
delete instFromLocale;
delete cloneDTPatternGen;
// ======= Test simple use cases
logln("Testing simple use cases");
status = U_ZERO_ERROR;
Locale deLocale=Locale::getGermany();
UDate sampleDate=LocaleTest::date(99, 9, 13, 23, 58, 59);
DateTimePatternGenerator *gen = DateTimePatternGenerator::createInstance(deLocale, status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getGermany()) - exiting");
return;
}
UnicodeString findPattern = gen->getBestPattern(UnicodeString("MMMddHmm"), status);
SimpleDateFormat *format = new SimpleDateFormat(findPattern, deLocale, status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create SimpleDateFormat (Locale::getGermany())");
delete gen;
return;
}
TimeZone *zone = TimeZone::createTimeZone(UnicodeString("ECT"));
if (zone==nullptr) {
dataerrln("ERROR: Could not create TimeZone ECT");
delete gen;
delete format;
return;
}
format->setTimeZone(*zone);
UnicodeString dateReturned, expectedResult;
dateReturned.remove();
dateReturned = format->format(sampleDate, dateReturned, status);
expectedResult=UnicodeString("14. Okt., 08:58", -1, US_INV);
if ( dateReturned != expectedResult ) {
errln("ERROR: Simple test in getBestPattern with Locale::getGermany()).");
}
// add new pattern
status = U_ZERO_ERROR;
conflictingStatus = gen->addPattern(UnicodeString("d'. von' MMMM", -1, US_INV), true, conflictingPattern, status);
if (U_FAILURE(status)) {
errln("ERROR: Could not addPattern - d\'. von\' MMMM");
}
status = U_ZERO_ERROR;
UnicodeString testPattern=gen->getBestPattern(UnicodeString("MMMMdd"), status);
testPattern=gen->getBestPattern(UnicodeString("MMMddHmm"), status);
format->applyPattern(gen->getBestPattern(UnicodeString("MMMMdHmm"), status));
dateReturned.remove();
dateReturned = format->format(sampleDate, dateReturned, status);
expectedResult=UnicodeString("14. von Oktober um 08:58", -1, US_INV);
if ( dateReturned != expectedResult ) {
errln(UnicodeString("ERROR: Simple test addPattern failed!: d\'. von\' MMMM Got: ") + dateReturned + UnicodeString(" Expected: ") + expectedResult);
}
delete format;
// get a pattern and modify it
format = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull,
deLocale));
format->setTimeZone(*zone);
UnicodeString pattern;
pattern = format->toPattern(pattern);
dateReturned.remove();
dateReturned = format->format(sampleDate, dateReturned, status);
expectedResult=CharsToUnicodeString("Donnerstag, 14. Oktober 1999 um 08:58:59 Mitteleurop\\u00E4ische Sommerzeit");
if ( dateReturned != expectedResult ) {
errln("ERROR: Simple test uses full date format.");
errln(UnicodeString(" Got: ") + dateReturned + UnicodeString(" Expected: ") + expectedResult);
}
// modify it to change the zone.
UnicodeString newPattern = gen->replaceFieldTypes(pattern, UnicodeString("vvvv"), status);
format->applyPattern(newPattern);
dateReturned.remove();
dateReturned = format->format(sampleDate, dateReturned, status);
expectedResult=CharsToUnicodeString("Donnerstag, 14. Oktober 1999 um 08:58:59 Mitteleurop\\u00E4ische Zeit");
if ( dateReturned != expectedResult ) {
errln("ERROR: Simple test modify the timezone!");
errln(UnicodeString(" Got: ")+ dateReturned + UnicodeString(" Expected: ") + expectedResult);
}
// setDeciaml(), getDeciaml()
gen->setDecimal(newDecimal);
if (newDecimal != gen->getDecimal()) {
errln("ERROR: unexpected result from setDecimal() and getDecimal()!.\n");
}
// setAppenItemName() , getAppendItemName()
gen->setAppendItemName(UDATPG_HOUR_FIELD, newAppendItemName);
if (newAppendItemName != gen->getAppendItemName(UDATPG_HOUR_FIELD)) {
errln("ERROR: unexpected result from setAppendItemName() and getAppendItemName()!.\n");
}
// setAppenItemFormat() , getAppendItemFormat()
gen->setAppendItemFormat(UDATPG_HOUR_FIELD, newAppendItemFormat);
if (newAppendItemFormat != gen->getAppendItemFormat(UDATPG_HOUR_FIELD)) {
errln("ERROR: unexpected result from setAppendItemFormat() and getAppendItemFormat()!.\n");
}
// setDateTimeFormat() , getDateTimeFormat()
gen->setDateTimeFormat(newDateTimeFormat);
if (newDateTimeFormat != gen->getDateTimeFormat()) {
errln("ERROR: unexpected result from setDateTimeFormat() and getDateTimeFormat()!.\n");
}
// ======== Test getSkeleton and getBaseSkeleton
int32_t i, count = UPRV_LENGTHOF(testGetSkeletonAndBase);
for (i = 0; i < count; i++) {
status = U_ZERO_ERROR;
pattern = UnicodeString(testGetSkeletonAndBase[i][0]);
UnicodeString expectedSkeleton = UnicodeString(testGetSkeletonAndBase[i][1]);
UnicodeString expectedBaseSkeleton = UnicodeString(testGetSkeletonAndBase[i][2]);
UnicodeString retSkeleton = gen->getSkeleton(pattern, status);
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
errln("ERROR: Unexpected result from getSkeleton().\n");
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
}
retSkeleton = gen->getBaseSkeleton(pattern, status);
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
}
}
delete format;
delete zone;
delete gen;
{
// Trac# 6104
status = U_ZERO_ERROR;
pattern = UnicodeString("YYYYMMM");
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
Locale loc("ja");
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
if(U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator");
return;
}
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
UnicodeString rDate;
SimpleDateFormat sdf(bPattern, loc, status);
rDate.remove();
rDate = sdf.format(testDate1, rDate);
logln(UnicodeString(" ja locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
logln(UnicodeString(" Formatted date:") + rDate);
if ( expR!= rDate ) {
errln(UnicodeString("\nERROR: Test Japanese month hack Got: ") + rDate +
UnicodeString(" Expected: ") + expR );
}
delete patGen;
}
{ // Trac# 6104
Locale loc("zh");
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
if(U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator");
return;
}
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
UnicodeString rDate;
SimpleDateFormat sdf(bPattern, loc, status);
rDate.remove();
rDate = sdf.format(testDate1, rDate);
logln(UnicodeString(" zh locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
logln(UnicodeString(" Formatted date:") + rDate);
if ( expR!= rDate ) {
errln(UnicodeString("\nERROR: Test Chinese month hack Got: ") + rDate +
UnicodeString(" Expected: ") + expR );
}
delete patGen;
}
{
// Trac# 6172 duplicate time pattern
status = U_ZERO_ERROR;
pattern = UnicodeString("hmv");
UnicodeString expR = UnicodeString(u"h:mm\u202Fa v", -1);
Locale loc("en");
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
if(U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator");
return;
}
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
logln(UnicodeString(" en locale with skeleton: hmv Best Pattern:") + bPattern);
if ( expR!= bPattern ) {
errln(UnicodeString("\nERROR: Test EN time format Got: ") + bPattern +
UnicodeString(" Expected: ") + expR );
}
delete patGen;
}
// ======= Test various skeletons.
logln("Testing DateTimePatternGenerator with various skeleton");
status = U_ZERO_ERROR;
int32_t localeIndex=0;
int32_t resultIndex=0;
UnicodeString resultDate;
UDate testDate= LocaleTest::date(99, 0, 13, 23, 58, 59) + 123.0;
while (localeIndex < MAX_LOCALE )
{
resultIndex=0;
int32_t dataIndex=0;
UnicodeString bestPattern;
Locale loc(testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
logln("\n\n Locale: %s_%s_%s@%s", testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
if(U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale index:%d . - exiting\n", localeIndex);
return;
}
while (patternData[dataIndex].length() > 0) {
log(patternData[dataIndex]);
bestPattern = patGen->getBestPattern(patternData[dataIndex++], status);
logln(UnicodeString(" -> ") + bestPattern);
SimpleDateFormat sdf(bestPattern, loc, status);
resultDate.remove();
resultDate = sdf.format(testDate, resultDate);
if ( resultDate != patternResults[localeIndex][resultIndex] ) {
const auto* calendar = sdf.getCalendar();
errln(UnicodeString("\nERROR: Test various skeletons[") + (dataIndex-1) + UnicodeString("], localeIndex ") + localeIndex +
u". Got: \"" + resultDate +
u"\" with calendar " + calendar->getType() +
u" Expected: \"" + patternResults[localeIndex][resultIndex] + u"\"");
}
resultIndex++;
}
delete patGen;
localeIndex++;
}
// ======= More tests ticket#6110
logln("Testing DateTimePatternGenerator with various skeleton");
status = U_ZERO_ERROR;
localeIndex=0;
resultIndex=0;
testDate= LocaleTest::date(99, 9, 13, 23, 58, 59);
{
int32_t dataIndex=0;
UnicodeString bestPattern;
logln("\n\n Test various skeletons for English locale...");
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale English . - exiting\n");
return;
}
TimeZone *enZone = TimeZone::createTimeZone(UnicodeString("ECT/GMT"));
if (enZone==nullptr) {
dataerrln("ERROR: Could not create TimeZone ECT");
delete patGen;
return;
}
SimpleDateFormat *enFormat = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateTimeInstance(DateFormat::kFull,
DateFormat::kFull, Locale::getEnglish()));
enFormat->setTimeZone(*enZone);
while (patternTests2[dataIndex].length() > 0) {
logln(patternTests2[dataIndex]);
bestPattern = patGen->getBestPattern(patternTests2[dataIndex], status);
logln(UnicodeString(" -> ") + bestPattern);
enFormat->applyPattern(bestPattern);
resultDate.remove();
resultDate = enFormat->format(testDate, resultDate);
if ( resultDate != patternResults2[resultIndex] ) {
errln(UnicodeString("\nERROR: Test various skeletons[") + dataIndex
+ UnicodeString("]. Got: ") + resultDate + UnicodeString(" Expected: ") +
patternResults2[resultIndex] );
}
dataIndex++;
resultIndex++;
}
delete patGen;
delete enZone;
delete enFormat;
}
// ======= Test random skeleton
DateTimePatternGenerator *randDTGen= DateTimePatternGenerator::createInstance(status);
if (U_FAILURE(status)) {
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exiting");
return;
}
char16_t newChar;
for (i=0; i<10; ++i) {
UnicodeString randomSkeleton;
int32_t len = rand() % 20;
for (int32_t j=0; j<len; ++j ) {
while ((newChar = static_cast<char16_t>(rand() % 0x7f)) >= static_cast<char16_t>(0x20)) {
randomSkeleton += newChar;
}
}
UnicodeString bestPattern = randDTGen->getBestPattern(randomSkeleton, status);
}
delete randDTGen;
// UnicodeString randomString=Unicode
// ======= Test getStaticClassID()
logln("Testing getStaticClassID()");
status = U_ZERO_ERROR;
DateTimePatternGenerator *test= DateTimePatternGenerator::createInstance(status);
if(test->getDynamicClassID() != DateTimePatternGenerator::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
delete test;
// ====== Test createEmptyInstance()
logln("Testing createEmptyInstance()");
status = U_ZERO_ERROR;
test = DateTimePatternGenerator::createEmptyInstance(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to create an empty instance ! - exiting.\n");
delete test;
return;
}
conflictingStatus = test->addPattern(UnicodeString("MMMMd"), true, conflictingPattern, status);
status = U_ZERO_ERROR;
testPattern=test->getBestPattern(UnicodeString("MMMMdd"), status);
conflictingStatus = test->addPattern(UnicodeString("HH:mm"), true, conflictingPattern, status);
conflictingStatus = test->addPattern(UnicodeString("MMMMMdd"), true, conflictingPattern, status); //duplicate pattern
StringEnumeration *output=nullptr;
output = test->getRedundants(status);
expectedResult=UnicodeString("MMMMd");
if (output != nullptr) {
output->reset(status);
const UnicodeString *dupPattern=output->snext(status);
if ( (dupPattern==nullptr) || (*dupPattern != expectedResult) ) {
errln("ERROR: Fail in getRedundants !\n");
}
}
// ======== Test getSkeletons and getBaseSkeletons
StringEnumeration* ptrSkeletonEnum = test->getSkeletons(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to get skeletons !\n");
}
UnicodeString returnPattern, *ptrSkeleton;
ptrSkeletonEnum->reset(status);
count=ptrSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = const_cast<UnicodeString *>(ptrSkeletonEnum->snext(status));
returnPattern = test->getPatternForSkeleton(*ptrSkeleton);
if ( returnPattern != testSkeletonsResults[i] ) {
errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern
+ UnicodeString("\nExpected: ") + testSkeletonsResults[i]
+ UnicodeString("\n"));
}
}
StringEnumeration* ptrBaseSkeletonEnum = test->getBaseSkeletons(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to get base skeletons !\n");
}
count=ptrBaseSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = const_cast<UnicodeString *>(ptrBaseSkeletonEnum->snext(status));
if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) {
errln("ERROR: Unexpected result from getBaseSkeletons() !\n");
}
}
// ========= DateTimePatternGenerator sample code in Userguide
// set up the generator
Locale locale = Locale::getFrench();
status = U_ZERO_ERROR;
DateTimePatternGenerator *generator = DateTimePatternGenerator::createInstance( locale, status);
// get a pattern for an abbreviated month and day
pattern = generator->getBestPattern(UnicodeString("MMMd"), status);
SimpleDateFormat formatter(pattern, locale, status);
zone = TimeZone::createTimeZone(UnicodeString("GMT"));
formatter.setTimeZone(*zone);
// use it to format (or parse)
UnicodeString formatted;
formatted = formatter.format(Calendar::getNow(), formatted, status);
// for French, the result is "13 sept."
formatted.remove();
// cannot use the result from getNow() because the value change evreyday.
testDate= LocaleTest::date(99, 0, 13, 23, 58, 59);
formatted = formatter.format(testDate, formatted, status);
expectedResult=UnicodeString("14 janv.");
if ( formatted != expectedResult ) {
errln("ERROR: Userguide sample code result!");
errln(UnicodeString(" Got: ")+ formatted + UnicodeString(" Expected: ") + expectedResult);
}
delete zone;
delete output;
delete ptrSkeletonEnum;
delete ptrBaseSkeletonEnum;
delete test;
delete generator;
}
/**
* Test handling of options
*
* For reference, as of ICU 4.3.3,
* root/gregorian has
* Hm{"H:mm"}
* Hms{"H:mm:ss"}
* hm{"h:mm a"}
* hms{"h:mm:ss a"}
* en/gregorian has
* Hm{"H:mm"}
* Hms{"H:mm:ss"}
* hm{"h:mm a"}
* be/gregorian has
* HHmmss{"HH.mm.ss"}
* Hm{"HH.mm"}
* hm{"h.mm a"}
* hms{"h.mm.ss a"}
*/
typedef struct DTPtnGenOptionsData {
const char *locale;
const char *skel;
const char16_t *expectedPattern;
UDateTimePatternMatchOptions options;
} DTPtnGenOptionsData;
void IntlTestDateTimePatternGeneratorAPI::testOptions(/*char *par*/)
{
DTPtnGenOptionsData testData[] = {
// locale skel expectedPattern options
{ "en", "Hmm", u"HH:mm", UDATPG_MATCH_NO_OPTIONS },
{ "en", "HHmm", u"HH:mm", UDATPG_MATCH_NO_OPTIONS },
{ "en", "hhmm", u"h:mm\u202Fa", UDATPG_MATCH_NO_OPTIONS },
{ "en", "Hmm", u"HH:mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
{ "en", "HHmm", u"HH:mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
{ "en", "hhmm", u"hh:mm\u202Fa", UDATPG_MATCH_HOUR_FIELD_LENGTH },
{ "da", "Hmm", u"HH.mm", UDATPG_MATCH_NO_OPTIONS },
{ "da", "HHmm", u"HH.mm", UDATPG_MATCH_NO_OPTIONS },
{ "da", "hhmm", u"h.mm\u202Fa", UDATPG_MATCH_NO_OPTIONS },
{ "da", "Hmm", u"H.mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
{ "da", "HHmm", u"HH.mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
{ "da", "hhmm", u"hh.mm\u202Fa", UDATPG_MATCH_HOUR_FIELD_LENGTH },
//
{ "en", "yyyy", u"yyyy", UDATPG_MATCH_NO_OPTIONS },
{ "en", "YYYY", u"YYYY", UDATPG_MATCH_NO_OPTIONS },
{ "en", "U", u"y", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=japanese", "yyyy", u"y G", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=japanese", "YYYY", u"Y G", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=japanese", "U", u"y G", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "yyyy", u"r(U)", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "YYYY", u"Y(Y)", UDATPG_MATCH_NO_OPTIONS }, // not a good result, want r(Y) or r(U)
{ "en@calendar=chinese", "U", u"r(U)", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "Gy", u"r(U)", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "GU", u"r(U)", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "ULLL", u"MMM U", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "yMMM", u"MMM r", UDATPG_MATCH_NO_OPTIONS },
{ "en@calendar=chinese", "GUMMM", u"MMM r", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "yyyy", u"rU年", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "YYYY", u"YY年", UDATPG_MATCH_NO_OPTIONS }, // not a good result, may want r(Y) or r(U)
{ "zh@calendar=chinese", "U", u"rU年", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "Gy", u"rU年", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "GU", u"rU年", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "ULLL", u"U年MMM", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "yMMM", u"rU年MMM", UDATPG_MATCH_NO_OPTIONS },
{ "zh@calendar=chinese", "GUMMM", u"rU年MMM", UDATPG_MATCH_NO_OPTIONS },
};
int count = UPRV_LENGTHOF(testData);
const DTPtnGenOptionsData * testDataPtr = testData;
for (; count-- > 0; ++testDataPtr) {
UErrorCode status = U_ZERO_ERROR;
Locale locale(testDataPtr->locale);
UnicodeString skel(testDataPtr->skel);
UnicodeString expectedPattern(testDataPtr->expectedPattern, -1);
UDateTimePatternMatchOptions options = testDataPtr->options;
DateTimePatternGenerator * dtpgen = DateTimePatternGenerator::createInstance(locale, status);
if (U_FAILURE(status)) {
dataerrln("Unable to create DateTimePatternGenerator instance for locale(%s): %s", locale.getName(), u_errorName(status));
delete dtpgen;
continue;
}
UnicodeString pattern = dtpgen->getBestPattern(skel, options, status);
if (pattern.compare(expectedPattern) != 0) {
errln( UnicodeString("ERROR in getBestPattern, locale ") + UnicodeString(testDataPtr->locale) +
UnicodeString(", skeleton ") + skel +
((options)?UnicodeString(", options!=0"):UnicodeString(", options==0")) +
UnicodeString(", expected pattern ") + expectedPattern +
UnicodeString(", got ") + pattern );
}
delete dtpgen;
}
}
/**
* Test that DTPG can handle all valid pattern character / length combinations
*
*/
#define FIELD_LENGTHS_COUNT 6
#define FIELD_LENGTH_MAX 8
#define MUST_INCLUDE_COUNT 5
typedef struct AllFieldsTestItem {
char patternChar;
int8_t fieldLengths[FIELD_LENGTHS_COUNT+1]; // up to FIELD_LENGTHS_COUNT lengths to try
// (length <=FIELD_LENGTH_MAX) plus 0 terminator
char mustIncludeOneOf[MUST_INCLUDE_COUNT+1];// resulting pattern must include at least one of
// these as a pattern char (0-terminated list)
} AllFieldsTestItem;
void IntlTestDateTimePatternGeneratorAPI::testAllFieldPatterns(/*char *par*/)
{
const char * localeNames[] = {
"root",
"root@calendar=japanese",
"root@calendar=chinese",
"en",
"en@calendar=japanese",
"en@calendar=chinese",
nullptr // terminator
};