OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2013, International Business Machines Corporation and | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ********************************************************************/ | 5 ********************************************************************/ |
6 /*******************************************************************************
* | 6 /*******************************************************************************
* |
7 * | 7 * |
8 * File CDATTST.C | 8 * File CDATTST.C |
9 * | 9 * |
10 * Modification History: | 10 * Modification History: |
11 * Name Description | 11 * Name Description |
12 * Madhu Katragadda Creation | 12 * Madhu Katragadda Creation |
13 ********************************************************************************
* | 13 ********************************************************************************
* |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 { | 48 { |
49 TESTCASE(TestDateFormat); | 49 TESTCASE(TestDateFormat); |
50 TESTCASE(TestRelativeDateFormat); | 50 TESTCASE(TestRelativeDateFormat); |
51 TESTCASE(TestSymbols); | 51 TESTCASE(TestSymbols); |
52 TESTCASE(TestDateFormatCalendar); | 52 TESTCASE(TestDateFormatCalendar); |
53 TESTCASE(TestExtremeDates); | 53 TESTCASE(TestExtremeDates); |
54 TESTCASE(TestAllLocales); | 54 TESTCASE(TestAllLocales); |
55 TESTCASE(TestRelativeCrash); | 55 TESTCASE(TestRelativeCrash); |
56 TESTCASE(TestContext); | 56 TESTCASE(TestContext); |
57 TESTCASE(TestCalendarDateParse); | 57 TESTCASE(TestCalendarDateParse); |
| 58 TESTCASE(TestOverrideNumberFormat); |
58 } | 59 } |
59 /* Testing the DateFormat API */ | 60 /* Testing the DateFormat API */ |
60 static void TestDateFormat() | 61 static void TestDateFormat() |
61 { | 62 { |
62 UDateFormat *def, *fr, *it, *de, *def1, *fr_pat; | 63 UDateFormat *def, *fr, *it, *de, *def1, *fr_pat; |
63 UDateFormat *any; | 64 UDateFormat *any; |
64 UDateFormat *copy; | 65 UDateFormat *copy; |
65 UErrorCode status = U_ZERO_ERROR; | 66 UErrorCode status = U_ZERO_ERROR; |
66 UChar* result = NULL; | 67 UChar* result = NULL; |
67 const UCalendar *cal; | 68 const UCalendar *cal; |
68 const UNumberFormat *numformat1, *numformat2; | 69 const UNumberFormat *numformat1, *numformat2; |
| 70 UNumberFormat *adoptNF; |
69 UChar temp[50]; | 71 UChar temp[50]; |
70 int32_t numlocales; | 72 int32_t numlocales; |
71 UDate d1; | 73 UDate d1; |
72 int i; | 74 int i; |
73 int32_t resultlength; | 75 int32_t resultlength; |
74 int32_t resultlengthneeded; | 76 int32_t resultlengthneeded; |
75 int32_t parsepos; | 77 int32_t parsepos; |
76 UDate d = 837039928046.0; | 78 UDate d = 837039928046.0; |
77 double num = -10456.37; | 79 double num = -10456.37; |
78 /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z"; | 80 /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z"; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 log_verbose("PASS: Date Format for US locale successful using udat_forma
t()\n"); | 180 log_verbose("PASS: Date Format for US locale successful using udat_forma
t()\n"); |
179 else { | 181 else { |
180 char xbuf[2048]; | 182 char xbuf[2048]; |
181 char gbuf[2048]; | 183 char gbuf[2048]; |
182 u_austrcpy(xbuf, temp); | 184 u_austrcpy(xbuf, temp); |
183 u_austrcpy(gbuf, result); | 185 u_austrcpy(gbuf, result); |
184 log_err("FAIL: Date Format for US locale failed using udat_format() - ex
pected %s got %s\n", xbuf, gbuf); | 186 log_err("FAIL: Date Format for US locale failed using udat_format() - ex
pected %s got %s\n", xbuf, gbuf); |
185 } | 187 } |
186 /*format using fr */ | 188 /*format using fr */ |
187 | 189 |
188 u_unescape("10 juil. 1996 16:05:28 heure avanc\\u00E9e du Pacifique", temp,
50); | 190 u_unescape("10 juil. 1996 16:05:28 heure d\\u2019\\u00E9t\\u00E9 du Pacifiqu
e", temp, 50); |
189 if(result != NULL) { | 191 if(result != NULL) { |
190 free(result); | 192 free(result); |
191 result = NULL; | 193 result = NULL; |
192 } | 194 } |
193 result=myDateFormat(fr, d); | 195 result=myDateFormat(fr, d); |
194 if(u_strcmp(result, temp)==0) | 196 if(u_strcmp(result, temp)==0) |
195 log_verbose("PASS: Date Format for french locale successful using udat_f
ormat()\n"); | 197 log_verbose("PASS: Date Format for french locale successful using udat_f
ormat()\n"); |
196 else | 198 else |
197 log_data_err("FAIL: Date Format for french locale failed using udat_form
at().\n" ); | 199 log_data_err("FAIL: Date Format for french locale failed using udat_form
at().\n" ); |
198 | 200 |
199 /*format using it */ | 201 /*format using it */ |
200 u_uastrcpy(temp, "10/lug/1996 16:05:28"); | 202 u_uastrcpy(temp, "10 lug 1996, 16:05:28"); |
201 | 203 |
202 { | 204 { |
203 UChar *fmtted; | 205 UChar *fmtted; |
204 char g[100]; | 206 char g[100]; |
205 char x[100]; | 207 char x[100]; |
206 | 208 |
207 fmtted = myDateFormat(it,d); | 209 fmtted = myDateFormat(it,d); |
208 u_austrcpy(g, fmtted); | 210 u_austrcpy(g, fmtted); |
209 u_austrcpy(x, temp); | 211 u_austrcpy(x, temp); |
210 if(u_strcmp(fmtted, temp)==0) { | 212 if(u_strcmp(fmtted, temp)==0) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 333 |
332 /*Test getNumberFormat() and setNumberFormat() */ | 334 /*Test getNumberFormat() and setNumberFormat() */ |
333 log_verbose("\nTesting the get and set NumberFormat properties of date forma
t\n"); | 335 log_verbose("\nTesting the get and set NumberFormat properties of date forma
t\n"); |
334 numformat1=udat_getNumberFormat(fr_pat); | 336 numformat1=udat_getNumberFormat(fr_pat); |
335 udat_setNumberFormat(def1, numformat1); | 337 udat_setNumberFormat(def1, numformat1); |
336 numformat2=udat_getNumberFormat(def1); | 338 numformat2=udat_getNumberFormat(def1); |
337 if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) | 339 if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) |
338 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); | 340 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); |
339 else | 341 else |
340 log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n"); | 342 log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n"); |
| 343 |
| 344 /*Test getNumberFormat() and adoptNumberFormat() */ |
| 345 log_verbose("\nTesting the get and adopt NumberFormat properties of date for
mat\n"); |
| 346 adoptNF= unum_open(UNUM_DEFAULT, NULL, 0, NULL, NULL, &status); |
| 347 udat_adoptNumberFormat(def1, adoptNF); |
| 348 numformat2=udat_getNumberFormat(def1); |
| 349 if(u_strcmp(myNumformat(adoptNF, num), myNumformat(numformat2, num)) !=0) |
| 350 log_err("FAIL: error in adoptNumberFormat or getNumberFormat()\n"); |
| 351 else |
| 352 log_verbose("PASS:adoptNumberFormat and getNumberFormat succesful\n"); |
341 | 353 |
342 /*try setting the number format to another format */ | 354 /*try setting the number format to another format */ |
343 numformat1=udat_getNumberFormat(def); | 355 numformat1=udat_getNumberFormat(def); |
344 udat_setNumberFormat(def1, numformat1); | 356 udat_setNumberFormat(def1, numformat1); |
345 numformat2=udat_getNumberFormat(def1); | 357 numformat2=udat_getNumberFormat(def1); |
346 if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) | 358 if(u_strcmp(myNumformat(numformat1, num), myNumformat(numformat2, num)) !=0) |
347 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); | 359 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); |
348 else | 360 else |
349 log_verbose("PASS: setNumberFormat and getNumberFormat succesful\n"); | 361 log_verbose("PASS: setNumberFormat and getNumberFormat succesful\n"); |
350 | 362 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 558 |
547 udat_close(fmtRelDateTime); | 559 udat_close(fmtRelDateTime); |
548 udat_close(fmtRelDate); | 560 udat_close(fmtRelDate); |
549 udat_close(fmtTime); | 561 udat_close(fmtTime); |
550 } | 562 } |
551 } | 563 } |
552 | 564 |
553 /*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/ | 565 /*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/ |
554 static void TestSymbols() | 566 static void TestSymbols() |
555 { | 567 { |
556 UDateFormat *def, *fr; | 568 UDateFormat *def, *fr, *zhChiCal; |
557 UErrorCode status = U_ZERO_ERROR; | 569 UErrorCode status = U_ZERO_ERROR; |
558 UChar *value=NULL; | 570 UChar *value=NULL; |
559 UChar *result = NULL; | 571 UChar *result = NULL; |
560 int32_t resultlength; | 572 int32_t resultlength; |
561 int32_t resultlengthout; | 573 int32_t resultlengthout; |
562 UChar *pattern; | 574 UChar *pattern; |
563 | 575 |
564 | 576 |
565 /*creating a dateformat with french locale */ | 577 /*creating a dateformat with french locale */ |
566 log_verbose("\ncreating a date format with french locale\n"); | 578 log_verbose("\ncreating a date format with french locale\n"); |
567 fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL, 0, NULL, 0, &status); | 579 fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL, 0, NULL, 0, &status); |
568 if(U_FAILURE(status)) | 580 if(U_FAILURE(status)) |
569 { | 581 { |
570 log_data_err("error in creating the dateformat using full time style wit
h french locale -> %s (Are you missing data?)\n", | 582 log_data_err("error in creating the dateformat using full time style wit
h french locale -> %s (Are you missing data?)\n", |
571 myErrorName(status) ); | 583 myErrorName(status) ); |
572 return; | 584 return; |
573 } | 585 } |
574 /*creating a default dateformat */ | 586 /*creating a default dateformat */ |
575 log_verbose("\ncreating a date format with default locale\n"); | 587 log_verbose("\ncreating a date format with default locale\n"); |
576 /* this is supposed to open default date format, but later on it treats it l
ike it is "en_US" | 588 /* this is supposed to open default date format, but later on it treats it l
ike it is "en_US" |
577 - very bad if you try to run the tests on machine where default locale is
NOT "en_US" */ | 589 - very bad if you try to run the tests on machine where default locale is
NOT "en_US" */ |
578 /* def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, &status); */ | 590 /* def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, &status); */ |
579 def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &statu
s); | 591 def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &statu
s); |
580 if(U_FAILURE(status)) | 592 if(U_FAILURE(status)) |
581 { | 593 { |
582 log_err("error in creating the dateformat using short date and time styl
e\n %s\n", | 594 log_err("error in creating the dateformat using short date and time styl
e\n %s\n", |
583 myErrorName(status) ); | 595 myErrorName(status) ); |
584 return; | 596 return; |
585 } | 597 } |
| 598 /*creating a dateformat with zh locale */ |
| 599 log_verbose("\ncreating a date format with zh locale for chinese calendar\n"
); |
| 600 zhChiCal = udat_open(UDAT_NONE, UDAT_FULL, "zh@calendar=chinese", NULL, 0, N
ULL, 0, &status); |
| 601 if(U_FAILURE(status)) |
| 602 { |
| 603 log_data_err("error in creating the dateformat using full date, no time,
locale zh@calendar=chinese -> %s (Are you missing data?)\n", |
| 604 myErrorName(status) ); |
| 605 return; |
| 606 } |
586 | 607 |
587 | 608 |
588 /*Testing countSymbols, getSymbols and setSymbols*/ | 609 /*Testing countSymbols, getSymbols and setSymbols*/ |
589 log_verbose("\nTesting countSymbols\n"); | 610 log_verbose("\nTesting countSymbols\n"); |
590 /*since the month names has the last string empty and week names are 1 based
1.e first string in the weeknames array is empty */ | 611 /*since the month names has the last string empty and week names are 1 based
1.e first string in the weeknames array is empty */ |
591 if(udat_countSymbols(def, UDAT_ERAS)!=2 || udat_countSymbols(def, UDAT_MONTH
S)!=12 || | 612 if(udat_countSymbols(def, UDAT_ERAS)!=2 || udat_countSymbols(def, UDAT_MONTH
S)!=12 || |
592 udat_countSymbols(def, UDAT_SHORT_MONTHS)!=12 || udat_countSymbols(def,
UDAT_WEEKDAYS)!=8 || | 613 udat_countSymbols(def, UDAT_SHORT_MONTHS)!=12 || udat_countSymbols(def,
UDAT_WEEKDAYS)!=8 || |
593 udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def,
UDAT_AM_PMS)!=2 || | 614 udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def,
UDAT_AM_PMS)!=2 || |
594 udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDA
T_SHORT_QUARTERS) != 4 || | 615 udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDA
T_SHORT_QUARTERS) != 4 || |
595 udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1 || udat_countSymbols(def
, UDAT_SHORTER_WEEKDAYS)!=8) | 616 udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1 || udat_countSymbols(def
, UDAT_SHORTER_WEEKDAYS)!=8 || |
| 617 udat_countSymbols(zhChiCal, UDAT_CYCLIC_YEARS_NARROW)!=60 || udat_countS
ymbols(zhChiCal, UDAT_ZODIAC_NAMES_NARROW)!=12) |
596 { | 618 { |
597 log_err("FAIL: error in udat_countSymbols\n"); | 619 log_err("FAIL: error in udat_countSymbols\n"); |
598 } | 620 } |
599 else | 621 else |
600 log_verbose("PASS: udat_countSymbols() successful\n"); | 622 log_verbose("PASS: udat_countSymbols() successful\n"); |
601 | 623 |
602 /*testing getSymbols*/ | 624 /*testing getSymbols*/ |
603 log_verbose("\nTesting getSymbols\n"); | 625 log_verbose("\nTesting getSymbols\n"); |
604 pattern=(UChar*)malloc(sizeof(UChar) * 10); | 626 pattern=(UChar*)malloc(sizeof(UChar) * 10); |
605 u_uastrcpy(pattern, "jeudi"); | 627 u_uastrcpy(pattern, "jeudi"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 VerifygetSymbols(def, UDAT_MONTHS, 0, "January"); | 662 VerifygetSymbols(def, UDAT_MONTHS, 0, "January"); |
641 VerifygetSymbols(fr, UDAT_ERAS, 0, "av. J.-C."); | 663 VerifygetSymbols(fr, UDAT_ERAS, 0, "av. J.-C."); |
642 VerifygetSymbols(def, UDAT_AM_PMS, 0, "AM"); | 664 VerifygetSymbols(def, UDAT_AM_PMS, 0, "AM"); |
643 VerifygetSymbols(def, UDAT_AM_PMS, 1, "PM"); | 665 VerifygetSymbols(def, UDAT_AM_PMS, 1, "PM"); |
644 VerifygetSymbols(fr, UDAT_SHORT_MONTHS, 0, "janv."); | 666 VerifygetSymbols(fr, UDAT_SHORT_MONTHS, 0, "janv."); |
645 VerifygetSymbols(def, UDAT_SHORT_MONTHS, 11, "Dec"); | 667 VerifygetSymbols(def, UDAT_SHORT_MONTHS, 11, "Dec"); |
646 VerifygetSymbols(fr, UDAT_QUARTERS, 0, "1er trimestre"); | 668 VerifygetSymbols(fr, UDAT_QUARTERS, 0, "1er trimestre"); |
647 VerifygetSymbols(def, UDAT_QUARTERS, 3, "4th quarter"); | 669 VerifygetSymbols(def, UDAT_QUARTERS, 3, "4th quarter"); |
648 VerifygetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "T2"); | 670 VerifygetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "T2"); |
649 VerifygetSymbols(def, UDAT_SHORT_QUARTERS, 2, "Q3"); | 671 VerifygetSymbols(def, UDAT_SHORT_QUARTERS, 2, "Q3"); |
650 VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQq
VUOXx"); | 672 VerifygetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_ABBREVIATED, 0, "\\u7532\\u5B50
"); |
| 673 VerifygetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_NARROW, 59, "\\u7678\\u4EA5"); |
| 674 VerifygetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_ABBREVIATED, 0, "\\u9F20"); |
| 675 VerifygetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_WIDE, 11, "\\u732A"); |
| 676 VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQq
VUOXxr"); |
651 | 677 |
652 | 678 |
653 if(result != NULL) { | 679 if(result != NULL) { |
654 free(result); | 680 free(result); |
655 result = NULL; | 681 result = NULL; |
656 } | 682 } |
657 free(pattern); | 683 free(pattern); |
658 | 684 |
659 log_verbose("\nTesting setSymbols\n"); | 685 log_verbose("\nTesting setSymbols\n"); |
660 /*applying the pattern so that setSymbolss works */ | 686 /*applying the pattern so that setSymbolss works */ |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 VerifysetSymbols(fr, UDAT_MONTHS, 11, "december"); | 780 VerifysetSymbols(fr, UDAT_MONTHS, 11, "december"); |
755 VerifysetSymbols(fr, UDAT_SHORT_MONTHS, 0, "Jan"); | 781 VerifysetSymbols(fr, UDAT_SHORT_MONTHS, 0, "Jan"); |
756 VerifysetSymbols(fr, UDAT_NARROW_MONTHS, 1, "R"); | 782 VerifysetSymbols(fr, UDAT_NARROW_MONTHS, 1, "R"); |
757 VerifysetSymbols(fr, UDAT_STANDALONE_MONTHS, 11, "dezember"); | 783 VerifysetSymbols(fr, UDAT_STANDALONE_MONTHS, 11, "dezember"); |
758 VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_MONTHS, 7, "Aug"); | 784 VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_MONTHS, 7, "Aug"); |
759 VerifysetSymbols(fr, UDAT_STANDALONE_NARROW_MONTHS, 2, "M"); | 785 VerifysetSymbols(fr, UDAT_STANDALONE_NARROW_MONTHS, 2, "M"); |
760 VerifysetSymbols(fr, UDAT_QUARTERS, 0, "1. Quart"); | 786 VerifysetSymbols(fr, UDAT_QUARTERS, 0, "1. Quart"); |
761 VerifysetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "QQ2"); | 787 VerifysetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "QQ2"); |
762 VerifysetSymbols(fr, UDAT_STANDALONE_QUARTERS, 2, "3rd Quar."); | 788 VerifysetSymbols(fr, UDAT_STANDALONE_QUARTERS, 2, "3rd Quar."); |
763 VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_QUARTERS, 3, "4QQ"); | 789 VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_QUARTERS, 3, "4QQ"); |
| 790 VerifysetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_ABBREVIATED, 1, "yi-chou"); |
| 791 VerifysetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_ABBREVIATED, 1, "Ox"); |
764 | 792 |
765 | 793 |
766 /*run series of tests to test get and setSymbols regressively*/ | 794 /*run series of tests to test get and setSymbols regressively*/ |
767 log_verbose("\nTesting get and set symbols regressively\n"); | 795 log_verbose("\nTesting get and set symbols regressively\n"); |
768 VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 1); | 796 VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 1); |
769 VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 7); | 797 VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 7); |
770 VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 1); | 798 VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 1); |
771 VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 7); | 799 VerifygetsetSymbols(fr, def, UDAT_SHORT_WEEKDAYS, 7); |
772 VerifygetsetSymbols(fr, def, UDAT_MONTHS, 0); | 800 VerifygetsetSymbols(fr, def, UDAT_MONTHS, 0); |
773 VerifygetsetSymbols(fr, def, UDAT_SHORT_MONTHS, 0); | 801 VerifygetsetSymbols(fr, def, UDAT_SHORT_MONTHS, 0); |
774 VerifygetsetSymbols(fr, def, UDAT_ERAS,1); | 802 VerifygetsetSymbols(fr, def, UDAT_ERAS,1); |
775 VerifygetsetSymbols(fr, def, UDAT_LOCALIZED_CHARS, 0); | 803 VerifygetsetSymbols(fr, def, UDAT_LOCALIZED_CHARS, 0); |
776 VerifygetsetSymbols(fr, def, UDAT_AM_PMS, 1); | 804 VerifygetsetSymbols(fr, def, UDAT_AM_PMS, 1); |
777 | 805 |
778 | 806 |
779 /*closing*/ | 807 /*closing*/ |
780 | 808 |
781 udat_close(fr); | 809 udat_close(fr); |
782 udat_close(def); | 810 udat_close(def); |
| 811 udat_close(zhChiCal); |
783 if(result != NULL) { | 812 if(result != NULL) { |
784 free(result); | 813 free(result); |
785 result = NULL; | 814 result = NULL; |
786 } | 815 } |
787 free(value); | 816 free(value); |
788 | 817 |
789 } | 818 } |
790 | 819 |
791 /** | 820 /** |
792 * Test DateFormat(Calendar) API | 821 * Test DateFormat(Calendar) API |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 return currentYear; | 1012 return currentYear; |
984 } | 1013 } |
985 | 1014 |
986 /* N.B.: use idx instead of index to avoid 'shadow' warnings in strict mode. */ | 1015 /* N.B.: use idx instead of index to avoid 'shadow' warnings in strict mode. */ |
987 static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in
t32_t idx, const char* expected) | 1016 static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in
t32_t idx, const char* expected) |
988 { | 1017 { |
989 UChar *pattern=NULL; | 1018 UChar *pattern=NULL; |
990 UErrorCode status = U_ZERO_ERROR; | 1019 UErrorCode status = U_ZERO_ERROR; |
991 UChar *result=NULL; | 1020 UChar *result=NULL; |
992 int32_t resultlength, resultlengthout; | 1021 int32_t resultlength, resultlengthout; |
993 | 1022 int32_t patternSize = strlen(expected) + 1; |
994 | 1023 |
995 pattern=(UChar*)malloc(sizeof(UChar) * (strlen(expected)+1)); | 1024 pattern=(UChar*)malloc(sizeof(UChar) * patternSize); |
996 u_uastrcpy(pattern, expected); | 1025 u_unescape(expected, pattern, patternSize); |
997 resultlength=0; | 1026 resultlength=0; |
998 resultlengthout=udat_getSymbols(datfor, type, idx , NULL, resultlength, &sta
tus); | 1027 resultlengthout=udat_getSymbols(datfor, type, idx , NULL, resultlength, &sta
tus); |
999 if(status==U_BUFFER_OVERFLOW_ERROR) | 1028 if(status==U_BUFFER_OVERFLOW_ERROR) |
1000 { | 1029 { |
1001 status=U_ZERO_ERROR; | 1030 status=U_ZERO_ERROR; |
1002 resultlength=resultlengthout+1; | 1031 resultlength=resultlengthout+1; |
1003 result=(UChar*)malloc(sizeof(UChar) * resultlength); | 1032 result=(UChar*)malloc(sizeof(UChar) * resultlength); |
1004 udat_getSymbols(datfor, type, idx, result, resultlength, &status); | 1033 udat_getSymbols(datfor, type, idx, result, resultlength, &status); |
1005 | 1034 |
1006 } | 1035 } |
1007 if(U_FAILURE(status)) | 1036 if(U_FAILURE(status)) |
1008 { | 1037 { |
1009 log_err("FAIL: Error in udat_getSymbols()... %s\n", myErrorName(status)
); | 1038 log_err("FAIL: Error in udat_getSymbols()... %s\n", myErrorName(status)
); |
1010 return; | 1039 return; |
1011 } | 1040 } |
1012 if(u_strcmp(result, pattern)==0) | 1041 if(u_strcmp(result, pattern)==0) |
1013 log_verbose("PASS: getSymbols retrieved the right value\n"); | 1042 log_verbose("PASS: getSymbols retrieved the right value\n"); |
1014 else{ | 1043 else{ |
1015 log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s G
ot %s\n", austrdup(pattern), | 1044 log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s G
ot %s\n", expected, |
1016 austrdup(result) ); | 1045 aescstrdup(result,-1) ); |
1017 } | 1046 } |
1018 free(result); | 1047 free(result); |
1019 free(pattern); | 1048 free(pattern); |
1020 } | 1049 } |
1021 | 1050 |
1022 static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in
t32_t idx, const char* expected) | 1051 static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in
t32_t idx, const char* expected) |
1023 { | 1052 { |
1024 UChar *result=NULL; | 1053 UChar *result=NULL; |
1025 UChar *value=NULL; | 1054 UChar *value=NULL; |
1026 int32_t resultlength, resultlengthout; | 1055 int32_t resultlength, resultlengthout; |
1027 UErrorCode status = U_ZERO_ERROR; | 1056 UErrorCode status = U_ZERO_ERROR; |
| 1057 int32_t valueLen, valueSize = strlen(expected) + 1; |
1028 | 1058 |
1029 value=(UChar*)malloc(sizeof(UChar) * (strlen(expected) + 1)); | 1059 value=(UChar*)malloc(sizeof(UChar) * valueSize); |
1030 u_uastrcpy(value, expected); | 1060 valueLen = u_unescape(expected, value, valueSize); |
1031 udat_setSymbols(datfor, type, idx, value, u_strlen(value), &status); | 1061 udat_setSymbols(datfor, type, idx, value, valueLen, &status); |
1032 if(U_FAILURE(status)) | 1062 if(U_FAILURE(status)) |
1033 { | 1063 { |
1034 log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status
) ); | 1064 log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status
) ); |
1035 return; | 1065 return; |
1036 } | 1066 } |
1037 | 1067 |
1038 resultlength=0; | 1068 resultlength=0; |
1039 resultlengthout=udat_getSymbols(datfor, type, idx, NULL, resultlength, &stat
us); | 1069 resultlengthout=udat_getSymbols(datfor, type, idx, NULL, resultlength, &stat
us); |
1040 if(status==U_BUFFER_OVERFLOW_ERROR){ | 1070 if(status==U_BUFFER_OVERFLOW_ERROR){ |
1041 status=U_ZERO_ERROR; | 1071 status=U_ZERO_ERROR; |
1042 resultlength=resultlengthout+1; | 1072 resultlength=resultlengthout+1; |
1043 result=(UChar*)malloc(sizeof(UChar) * resultlength); | 1073 result=(UChar*)malloc(sizeof(UChar) * resultlength); |
1044 udat_getSymbols(datfor, type, idx, result, resultlength, &status); | 1074 udat_getSymbols(datfor, type, idx, result, resultlength, &status); |
1045 } | 1075 } |
1046 if(U_FAILURE(status)){ | 1076 if(U_FAILURE(status)){ |
1047 log_err("FAIL: error in retrieving the value using getSymbols after sett
ing it previously\n %s\n", | 1077 log_err("FAIL: error in retrieving the value using getSymbols after sett
ing it previously\n %s\n", |
1048 myErrorName(status) ); | 1078 myErrorName(status) ); |
1049 return; | 1079 return; |
1050 } | 1080 } |
1051 | 1081 |
1052 if(u_strcmp(result, value)!=0){ | 1082 if(u_strcmp(result, value)!=0){ |
1053 log_err("FAIL:Error in setting and then getting symbols\n Expected %s Go
t %s\n", austrdup(value), | 1083 log_err("FAIL:Error in setting and then getting symbols\n Expected %s Go
t %s\n", expected, |
1054 austrdup(result) ); | 1084 aescstrdup(result,-1) ); |
1055 } | 1085 } |
1056 else | 1086 else |
1057 log_verbose("PASS: setSymbols successful\n"); | 1087 log_verbose("PASS: setSymbols successful\n"); |
1058 | 1088 |
1059 free(value); | 1089 free(value); |
1060 free(result); | 1090 free(result); |
1061 } | 1091 } |
1062 | 1092 |
1063 | 1093 |
1064 static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatS
ymbolType type, int32_t idx) | 1094 static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatS
ymbolType type, int32_t idx) |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_NONE, july
2008_csDefault }, | 1413 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_NONE, july
2008_csDefault }, |
1384 #if !UCONFIG_NO_BREAK_ITERATION | 1414 #if !UCONFIG_NO_BREAK_ITERATION |
1385 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july
2008_csDefault }, | 1415 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july
2008_csDefault }, |
1386 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, j
uly2008_csTitle }, | 1416 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, j
uly2008_csTitle }, |
1387 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july
2008_csTitle }, | 1417 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july
2008_csTitle }, |
1388 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, july
2008_csDefault }, | 1418 { "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, july
2008_csDefault }, |
1389 #endif | 1419 #endif |
1390 { NULL, NULL, (UDisplayContext)0, NULL } | 1420 { NULL, NULL, (UDisplayContext)0, NULL } |
1391 }; | 1421 }; |
1392 | 1422 |
1393 static const UDate july022008 = 1215000001979.0; | 1423 static const UChar today_enDefault[] = { 0x74,0x6F,0x64,0x61,0x79,0 }; /* "t
oday" */ |
| 1424 static const UChar today_enTitle[] = { 0x54,0x6F,0x64,0x61,0x79,0 }; /* "
Today" sentence-begin, uiListOrMenu, standalone */ |
| 1425 static const UChar yesterday_enDefault[] = { 0x79,0x65,0x73,0x74,0x65,0x72,0x64,
0x61,0x79,0 }; /* "yesterday" */ |
| 1426 static const UChar yesterday_enTitle[] = { 0x59,0x65,0x73,0x74,0x65,0x72,0x64,
0x61,0x79,0 }; /* "Yesterday" sentence-begin, uiListOrMenu, standalone */ |
| 1427 static const UChar today_nbDefault[] = { 0x69,0x20,0x64,0x61,0x67,0 }; /* "i
dag" */ |
| 1428 static const UChar today_nbTitle[] = { 0x49,0x20,0x64,0x61,0x67,0 }; /* "
I dag" sentence-begin, standalone */ |
| 1429 static const UChar yesterday_nbDefault[] = { 0x69,0x20,0x67,0xE5,0x72,0 }; |
| 1430 static const UChar yesterday_nbTitle[] = { 0x49,0x20,0x67,0xE5,0x72,0 }; |
| 1431 |
| 1432 typedef struct { |
| 1433 const char * locale; |
| 1434 UDisplayContext capitalizationContext; |
| 1435 const UChar * expectedFormatToday; |
| 1436 const UChar * expectedFormatYesterday; |
| 1437 } TestRelativeContextItem; |
| 1438 |
| 1439 static const TestRelativeContextItem textContextRelativeItems[] = { |
| 1440 { "en", UDISPCTX_CAPITALIZATION_NONE, today_enDefault, yes
terday_enDefault }, |
| 1441 #if !UCONFIG_NO_BREAK_ITERATION |
| 1442 { "en", UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, today_enDefault, yes
terday_enDefault }, |
| 1443 { "en", UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, today_enTitle, ye
sterday_enTitle }, |
| 1444 { "en", UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, today_enTitle, yeste
rday_enTitle }, |
| 1445 { "en", UDISPCTX_CAPITALIZATION_FOR_STANDALONE, today_enTitle, yeste
rday_enTitle }, |
| 1446 #endif |
| 1447 { "nb", UDISPCTX_CAPITALIZATION_NONE, today_nbDefault, yes
terday_nbDefault }, |
| 1448 #if !UCONFIG_NO_BREAK_ITERATION |
| 1449 { "nb", UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, today_nbDefault, yes
terday_nbDefault }, |
| 1450 { "nb", UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, today_nbTitle, ye
sterday_nbTitle }, |
| 1451 { "nb", UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, today_nbDefault, yes
terday_nbDefault }, |
| 1452 { "nb", UDISPCTX_CAPITALIZATION_FOR_STANDALONE, today_nbTitle, yeste
rday_nbTitle }, |
| 1453 #endif |
| 1454 { NULL, (UDisplayContext)0, NULL, NULL } |
| 1455 }; |
| 1456 |
| 1457 static const UChar zoneGMT[] = { 0x47,0x4D,0x54,0 }; /* "GMT" */ |
| 1458 static const UDate july022008 = 1215000000000.0; |
1394 enum { kUbufMax = 64, kBbufMax = 3*kUbufMax }; | 1459 enum { kUbufMax = 64, kBbufMax = 3*kUbufMax }; |
1395 | 1460 |
1396 static void TestContext(void) { | 1461 static void TestContext(void) { |
1397 const TestContextItem* textContextItemPtr = textContextItems; | 1462 const TestContextItem* textContextItemPtr; |
1398 for (; textContextItemPtr->locale != NULL; ++textContextItemPtr) { | 1463 const TestRelativeContextItem* textRelContextItemPtr; |
| 1464 for (textContextItemPtr = textContextItems; textContextItemPtr->locale != NU
LL; ++textContextItemPtr) { |
1399 UErrorCode status = U_ZERO_ERROR; | 1465 UErrorCode status = U_ZERO_ERROR; |
1400 UDateFormat* udfmt = udat_open(UDAT_NONE, UDAT_MEDIUM, textContextItemPt
r->locale, NULL, 0, NULL, 0, &status); | 1466 UDateTimePatternGenerator* udtpg = udatpg_open(textContextItemPtr->local
e, &status); |
1401 if ( U_FAILURE(status) ) { | 1467 if ( U_SUCCESS(status) ) { |
1402 log_data_err("FAIL: udat_open for locale %s, status %s\n", textConte
xtItemPtr->locale, u_errorName(status) ); | 1468 UChar ubuf[kUbufMax]; |
1403 } else { | 1469 int32_t len = udatpg_getBestPattern(udtpg, textContextItemPtr->skele
ton, -1, ubuf, kUbufMax, &status); |
1404 UDateTimePatternGenerator* udtpg = udatpg_open(textContextItemPtr->l
ocale, &status); | 1470 if ( U_SUCCESS(status) ) { |
1405 if ( U_FAILURE(status) ) { | 1471 UDateFormat* udfmt = udat_open(UDAT_PATTERN, UDAT_PATTERN, textC
ontextItemPtr->locale, zoneGMT, -1, ubuf, len, &status); |
1406 log_err("FAIL: udatpg_open for locale %s, status %s\n", textCont
extItemPtr->locale, u_errorName(status) ); | 1472 if ( U_SUCCESS(status) ) { |
1407 } else { | |
1408 UChar ubuf[kUbufMax]; | |
1409 int32_t len = udatpg_getBestPattern(udtpg, textContextItemPtr->s
keleton, -1, ubuf, kUbufMax, &status); | |
1410 if ( U_FAILURE(status) ) { | |
1411 log_err("FAIL: udatpg_getBestPattern for locale %s, status %
s\n", textContextItemPtr->locale, u_errorName(status) ); | |
1412 } else { | |
1413 udat_applyPattern(udfmt, FALSE, ubuf, len); | |
1414 udat_setContext(udfmt, textContextItemPtr->capitalizationCon
text, &status); | 1473 udat_setContext(udfmt, textContextItemPtr->capitalizationCon
text, &status); |
1415 if ( U_FAILURE(status) ) { | 1474 if ( U_SUCCESS(status) ) { |
1416 log_err("FAIL: udat_setContext for locale %s, capitaliza
tionContext %d, status %s\n", | |
1417 textContextItemPtr->locale, (int)textContextItem
Ptr->capitalizationContext, u_errorName(status) ); | |
1418 } else { | |
1419 UDisplayContext getContext; | 1475 UDisplayContext getContext; |
1420 len = udat_format(udfmt, july022008, ubuf, kUbufMax, NUL
L, &status); | 1476 len = udat_format(udfmt, july022008, ubuf, kUbufMax, NUL
L, &status); |
1421 if ( U_FAILURE(status) ) { | 1477 if ( U_FAILURE(status) ) { |
1422 log_err("FAIL: udat_format for locale %s, capitaliza
tionContext %d, status %s\n", | 1478 log_err("FAIL: udat_format for locale %s, capitaliza
tionContext %d, status %s\n", |
1423 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, u_errorName(status) ); | 1479 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, u_errorName(status) ); |
1424 status = U_ZERO_ERROR; | 1480 status = U_ZERO_ERROR; |
1425 } else if (u_strncmp(ubuf, textContextItemPtr->expectedF
ormat, kUbufMax) != 0) { | 1481 } else if (u_strncmp(ubuf, textContextItemPtr->expectedF
ormat, kUbufMax) != 0) { |
1426 char bbuf1[kBbufMax]; | 1482 char bbuf1[kBbufMax]; |
1427 char bbuf2[kBbufMax]; | 1483 char bbuf2[kBbufMax]; |
1428 log_err("FAIL: udat_format for locale %s, capitaliza
tionContext %d, expected %s, got %s\n", | 1484 log_err("FAIL: udat_format for locale %s, capitaliza
tionContext %d, expected %s, got %s\n", |
1429 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, | 1485 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, |
1430 u_austrncpy(bbuf1,textContextItemPtr->expect
edFormat,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); | 1486 u_austrncpy(bbuf1,textContextItemPtr->expect
edFormat,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
1431 } | 1487 } |
1432 getContext = udat_getContext(udfmt, UDISPCTX_TYPE_CAPITA
LIZATION, &status); | 1488 getContext = udat_getContext(udfmt, UDISPCTX_TYPE_CAPITA
LIZATION, &status); |
1433 if ( U_FAILURE(status) ) { | 1489 if ( U_FAILURE(status) ) { |
1434 log_err("FAIL: udat_getContext for locale %s, capita
lizationContext %d, status %s\n", | 1490 log_err("FAIL: udat_getContext for locale %s, capita
lizationContext %d, status %s\n", |
1435 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, u_errorName(status) ); | 1491 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, u_errorName(status) ); |
1436 } else if (getContext != textContextItemPtr->capitalizat
ionContext) { | 1492 } else if (getContext != textContextItemPtr->capitalizat
ionContext) { |
1437 log_err("FAIL: udat_getContext for locale %s, capita
lizationContext %d, got context %d\n", | 1493 log_err("FAIL: udat_getContext for locale %s, capita
lizationContext %d, got context %d\n", |
1438 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, (int)getContext ); | 1494 textContextItemPtr->locale, (int)textContext
ItemPtr->capitalizationContext, (int)getContext ); |
1439 } | 1495 } |
| 1496 } else { |
| 1497 log_err("FAIL: udat_setContext for locale %s, capitaliza
tionContext %d, status %s\n", |
| 1498 textContextItemPtr->locale, (int)textContextItem
Ptr->capitalizationContext, u_errorName(status) ); |
1440 } | 1499 } |
| 1500 udat_close(udfmt); |
| 1501 } else { |
| 1502 log_data_err("FAIL: udat_open for locale %s, status %s\n", t
extContextItemPtr->locale, u_errorName(status) ); |
1441 } | 1503 } |
1442 udatpg_close(udtpg); | 1504 } else { |
| 1505 log_err("FAIL: udatpg_getBestPattern for locale %s, status %s\n"
, textContextItemPtr->locale, u_errorName(status) ); |
1443 } | 1506 } |
1444 udat_close(udfmt); | 1507 udatpg_close(udtpg); |
| 1508 } else { |
| 1509 log_data_err("FAIL: udatpg_open for locale %s, status %s\n", textCon
textItemPtr->locale, u_errorName(status) ); |
| 1510 } |
| 1511 } |
| 1512 for (textRelContextItemPtr = textContextRelativeItems; textRelContextItemPtr
->locale != NULL; ++textRelContextItemPtr) { |
| 1513 UErrorCode status = U_ZERO_ERROR; |
| 1514 UCalendar* ucal = ucal_open(zoneGMT, -1, "root", UCAL_GREGORIAN, &status
); |
| 1515 if ( U_SUCCESS(status) ) { |
| 1516 UDateFormat* udfmt = udat_open(UDAT_NONE, UDAT_LONG_RELATIVE, textRe
lContextItemPtr->locale, zoneGMT, -1, NULL, 0, &status); |
| 1517 if ( U_SUCCESS(status) ) { |
| 1518 udat_setContext(udfmt, textRelContextItemPtr->capitalizationCont
ext, &status); |
| 1519 if ( U_SUCCESS(status) ) { |
| 1520 UDate yesterday, today = ucal_getNow(); |
| 1521 UChar ubuf[kUbufMax]; |
| 1522 char bbuf1[kBbufMax]; |
| 1523 char bbuf2[kBbufMax]; |
| 1524 int32_t len = udat_format(udfmt, today, ubuf, kUbufMax, NULL
, &status); |
| 1525 (void)len; |
| 1526 if ( U_FAILURE(status) ) { |
| 1527 log_err("FAIL: udat_format today for locale %s, capitali
zationContext %d, status %s\n", |
| 1528 textRelContextItemPtr->locale, (int)textRelConte
xtItemPtr->capitalizationContext, u_errorName(status) ); |
| 1529 } else if (u_strncmp(ubuf, textRelContextItemPtr->expectedFo
rmatToday, kUbufMax) != 0) { |
| 1530 log_err("FAIL: udat_format today for locale %s, capitali
zationContext %d, expected %s, got %s\n", |
| 1531 textRelContextItemPtr->locale, (int)textRelConte
xtItemPtr->capitalizationContext, |
| 1532 u_austrncpy(bbuf1,textRelContextItemPtr->expecte
dFormatToday,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
| 1533 } |
| 1534 status = U_ZERO_ERROR; |
| 1535 ucal_setMillis(ucal, today, &status); |
| 1536 ucal_add(ucal, UCAL_DATE, -1, &status); |
| 1537 yesterday = ucal_getMillis(ucal, &status); |
| 1538 if ( U_SUCCESS(status) ) { |
| 1539 len = udat_format(udfmt, yesterday, ubuf, kUbufMax, NULL
, &status); |
| 1540 if ( U_FAILURE(status) ) { |
| 1541 log_err("FAIL: udat_format yesterday for locale %s,
capitalizationContext %d, status %s\n", |
| 1542 textRelContextItemPtr->locale, (int)textRelC
ontextItemPtr->capitalizationContext, u_errorName(status) ); |
| 1543 } else if (u_strncmp(ubuf, textRelContextItemPtr->expect
edFormatYesterday, kUbufMax) != 0) { |
| 1544 log_err("FAIL: udat_format yesterday for locale %s,
capitalizationContext %d, expected %s, got %s\n", |
| 1545 textRelContextItemPtr->locale, (int)textRelC
ontextItemPtr->capitalizationContext, |
| 1546 u_austrncpy(bbuf1,textRelContextItemPtr->exp
ectedFormatYesterday,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
| 1547 } |
| 1548 } |
| 1549 } else { |
| 1550 log_err("FAIL: udat_setContext relative for locale %s, capit
alizationContext %d, status %s\n", |
| 1551 textRelContextItemPtr->locale, (int)textRelContextIt
emPtr->capitalizationContext, u_errorName(status) ); |
| 1552 } |
| 1553 udat_close(udfmt); |
| 1554 } else { |
| 1555 log_data_err("FAIL: udat_open relative for locale %s, status %s\
n", textRelContextItemPtr->locale, u_errorName(status) ); |
| 1556 } |
| 1557 ucal_close(ucal); |
| 1558 } else { |
| 1559 log_data_err("FAIL: ucal_open for locale root, status %s\n", u_error
Name(status) ); |
1445 } | 1560 } |
1446 } | 1561 } |
1447 } | 1562 } |
1448 | 1563 |
| 1564 |
| 1565 // overrideNumberFormat[i][0] is to tell which field to set, |
| 1566 // overrideNumberFormat[i][1] is the expected result |
| 1567 static const char * overrideNumberFormat[][2] = { |
| 1568 {"", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
| 1569 {"d", "07 \\u521D\\u4E8C"}, |
| 1570 {"do", "07 \\u521D\\u4E8C"}, |
| 1571 {"Md", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
| 1572 {"MdMMd", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
| 1573 {"mixed", "\\u521D\\u4E03 \\u521D\\u4E8C"} |
| 1574 }; |
| 1575 |
| 1576 static void TestOverrideNumberFormat(void) { |
| 1577 UErrorCode status = U_ZERO_ERROR; |
| 1578 UChar pattern[50]; |
| 1579 UChar* expected; |
| 1580 UChar* fields; |
| 1581 char bbuf1[kBbufMax]; |
| 1582 char bbuf2[kBbufMax]; |
| 1583 const char* localeString = "zh@numbers=hanidays"; |
| 1584 UDateFormat* fmt; |
| 1585 const UNumberFormat* getter_result; |
| 1586 int32_t i; |
| 1587 unsigned j; |
| 1588 |
| 1589 expected=(UChar*)malloc(sizeof(UChar) * 10); |
| 1590 fields=(UChar*)malloc(sizeof(UChar) * 10); |
| 1591 u_uastrcpy(fields, "d"); |
| 1592 u_uastrcpy(pattern,"MM d"); |
| 1593 |
| 1594 fmt=udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pa
ttern), &status); |
| 1595 if (!assertSuccess("udat_open()", &status)) { |
| 1596 return; |
| 1597 } |
| 1598 |
| 1599 |
| 1600 // loop 50 times to check getter/setter |
| 1601 for (i = 0; i < 5; i++){ |
| 1602 UNumberFormat* overrideFmt; |
| 1603 overrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &stat
us); |
| 1604 assertSuccess("unum_open()", &status); |
| 1605 |
| 1606 udat_adoptNumberFormatForFields(fmt, fields, overrideFmt, &status); |
| 1607 overrideFmt = NULL; // no longer valid |
| 1608 assertSuccess("udat_setNumberFormatForField()", &status); |
| 1609 |
| 1610 getter_result = udat_getNumberFormatForField(fmt, 'd'); |
| 1611 if(getter_result == NULL) { |
| 1612 log_err("FAIL: udat_getNumberFormatForField did not return a valid p
ointer\n"); |
| 1613 } |
| 1614 } |
| 1615 |
| 1616 { |
| 1617 UNumberFormat* overrideFmt; |
| 1618 overrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &status
); |
| 1619 assertSuccess("unum_open()", &status); |
| 1620 udat_setNumberFormat(fmt, overrideFmt); // test the same override NF will
not crash |
| 1621 unum_close(overrideFmt); |
| 1622 } |
| 1623 udat_close(fmt); |
| 1624 |
| 1625 for (j=0; i<sizeof(overrideNumberFormat)/sizeof(overrideNumberFormat[0]); i+
+){ |
| 1626 UChar ubuf[kUbufMax]; |
| 1627 UDateFormat* fmt2; |
| 1628 UNumberFormat* overrideFmt2; |
| 1629 |
| 1630 fmt2 =udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_str
len(pattern), &status); |
| 1631 assertSuccess("udat_open() with en_US", &status); |
| 1632 |
| 1633 overrideFmt2 = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &sta
tus); |
| 1634 assertSuccess("unum_open() in loop", &status); |
| 1635 |
| 1636 u_uastrcpy(fields, overrideNumberFormat[i][0]); |
| 1637 u_unescape(overrideNumberFormat[i][1], expected, 50); |
| 1638 |
| 1639 if ( strcmp(overrideNumberFormat[i][0], "") == 0 ) { // use the one w/o
field |
| 1640 udat_setNumberFormat(fmt2, overrideFmt2); |
| 1641 } else if ( strcmp(overrideNumberFormat[i][0], "mixed") == 0 ) { // set
1 field at first but then full override, both(M & d) should be override |
| 1642 const char* singleLocale = "en@numbers=hebr"; |
| 1643 UNumberFormat* singleOverrideFmt; |
| 1644 u_uastrcpy(fields, "d"); |
| 1645 |
| 1646 singleOverrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, singleLocale, N
ULL, &status); |
| 1647 assertSuccess("unum_open() in mixed", &status); |
| 1648 |
| 1649 udat_adoptNumberFormatForFields(fmt2, fields, singleOverrideFmt, &st
atus); |
| 1650 assertSuccess("udat_setNumberFormatForField() in mixed", &status); |
| 1651 |
| 1652 udat_setNumberFormat(fmt2, overrideFmt2); |
| 1653 } else if ( strcmp(overrideNumberFormat[i][0], "do") == 0 ) { // o is an
invalid field |
| 1654 udat_adoptNumberFormatForFields(fmt2, fields, overrideFmt2, &status)
; |
| 1655 if(status == U_INVALID_FORMAT_ERROR) { |
| 1656 udat_close(fmt2); |
| 1657 status = U_ZERO_ERROR; |
| 1658 continue; |
| 1659 } |
| 1660 } else { |
| 1661 udat_adoptNumberFormatForFields(fmt2, fields, overrideFmt2, &status)
; |
| 1662 assertSuccess("udat_setNumberFormatForField() in loop", &status); |
| 1663 } |
| 1664 |
| 1665 udat_format(fmt2, july022008, ubuf, kUbufMax, NULL, &status); |
| 1666 assertSuccess("udat_format() july022008", &status); |
| 1667 |
| 1668 if (u_strncmp(ubuf, expected, kUbufMax) != 0) |
| 1669 log_err("fail: udat_format for locale, expected %s, got %s\n", |
| 1670 u_austrncpy(bbuf1,expected,kUbufMax), u_austrncpy(bbuf2,ubuf
,kUbufMax) ); |
| 1671 |
| 1672 udat_close(overrideFmt2); |
| 1673 udat_close(fmt2); |
| 1674 } |
| 1675 free(expected); |
| 1676 free(fields); |
| 1677 } |
| 1678 |
1449 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1679 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |