1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2009-2012, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 */
11
12 #include <unicode/datefmt.h>
13 #include <unicode/udat.h>
14 #include <unicode/uclean.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdlib.h>
18
19
20 /* String to use. */
21 const UDate stuff = 1299977771000.0L;
22
23 #include "provider_version.h"
24
25
26 #define LOCALE_COUNT 4
27 const char *locale[LOCALE_COUNT] = { "fi", "en_US", "ja", "ml" }; /* List of locales to test */
28
29 /**
30 * Set up ICU, print # of available collators
31 */
setup(UErrorCode & status)32 void setup(UErrorCode &status) {
33 u_init(&status);
34
35 fprintf(stderr, "ICU %s init: %s\n", U_ICU_VERSION, u_errorName(status));
36
37 // int32_t count;
38 // StringEnumeration *se = DateFormat::getAvailableLocales();
39 // count = se->count(status);
40 // fprintf(stderr, "# DateFormats now available: %d,\t%s - %d providers expected.\n", count, u_errorName(status), (int32_t)PROVIDER_COUNT);
41 }
42
main(int,const char * [])43 int main(int /* argc*/ , const char * /*argv*/ []) {
44 #if (U_ICU_VERSION_MAJOR_NUM < 49)
45 fprintf(stderr, "Warning: ICU %s doesn't support date providers. Need at least 49.\n", U_ICU_VERSION );
46 return 0;
47 #else
48 UErrorCode status = U_ZERO_ERROR;
49 int diffs = 0;
50 int gbaddiffs =0;
51 UDateFormatStyle styles[] = { UDAT_FULL, UDAT_SHORT };
52 setup(status);
53 if(U_FAILURE(status)) return 1;
54
55 int expected = PROVIDER_COUNT;
56
57 for(uint32_t s=0;s<sizeof(styles)/sizeof(styles[0]);s++) {
58 for(int l=0;l<LOCALE_COUNT;l++) {
59 printf("\n");
60 UChar oldChars[200];
61 int32_t oldLen = -1;
62 for(int v=0;v<=expected;v++) {
63
64 // Construct the locale ID
65 char locID[200];
66 strcpy(locID, locale[l]);
67 if((v!=expected)) { // -1 = no version
68 strcat(locID, "@sp=icu");
69 strcat(locID, provider_version[v]);
70 }
71
72 printf("%18s : ", locID);
73
74 UErrorCode subStatus = U_ZERO_ERROR;
75 UChar outchars[200];
76
77 UDateFormat *dat = udat_open(styles[s],styles[s], locID, NULL, -1, NULL, 0, &subStatus);
78
79 if(U_FAILURE(subStatus)) {
80 printf("ERR: %s\n", u_errorName(subStatus));
81 continue;
82 }
83
84 int32_t len = udat_format(dat, stuff, outchars, 200, NULL, &subStatus);
85
86 //printf("\n");
87 char utf8[200];
88 u_strToUTF8(utf8, 200, NULL, outchars, len, &subStatus);
89 if(oldLen!=len || memcmp(outchars,oldChars,len*sizeof(outchars[0]))) {
90 putchar ('!');
91 diffs++;
92 } else {
93 putchar ('=');
94 }
95 printf(" %s ", utf8);
96
97 // for(int i=0;i<len;i++) {
98 // if((i<oldLen)&&(outchars[i]!=oldChars[i])) {
99 // diffs++;
100 // printf("*", oldChars[i]);
101 // } else {
102 // printf(" ");
103 // }
104 // // printf("U+%04X", (outchars[i]));
105 // }
106 putchar('\n');
107 udat_close(dat);
108
109 oldLen = len;
110 memcpy(oldChars, outchars, len*sizeof(oldChars[0]));
111 }
112 }
113 }
114
115 if(diffs==0) {
116 printf("ERROR: 0 differences found between platforms.. are the platforms installed? Try 'icuinfo -L'\n");
117 return 1;
118 } else {
119 printf("%d differences found among provider versions!\n", diffs);
120 }
121
122 // if(gbaddiffs>0) {
123 // printf("ERROR: %d diffs found between a collator and it's reopened (from shortstring) variant.\n", gbaddiffs);
124 // return 2;
125 // } else {
126 // printf("Collator and reopened (shortstring) are OK.\n");
127 // }
128
129 printf("Success!\n");
130
131 return 0;
132 #endif
133 }
134