• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 int err=0;
24 #include "provider_version.h"
25 
26 
27 #define LOCALE_COUNT 4
28 const char *locale[LOCALE_COUNT] = { "es_GU", "fr_AD", "et_AM", "en_IE" }; /* List of locales to test */
29 
30 /**
31  * Set up ICU, print # of available collators
32  */
setup(UErrorCode & status)33 void setup(UErrorCode &status) {
34     u_init(&status);
35 
36     fprintf(stderr, "ICU %s init: %s\n", U_ICU_VERSION, u_errorName(status));
37 
38      int32_t count;
39      const Locale *se = Calendar::getAvailableLocales(count);
40      fprintf(stderr, "# Calendars 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 0
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         char 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           char outchars[200];
76 
77           LocalPointer<Calendar> cal(Calendar::createInstance(Locale(locID), subStatus));
78 
79           if(U_FAILURE(subStatus)) {
80             printf("ERR: %s\n", u_errorName(subStatus));
81             err++;
82             continue;
83           }
84 
85           // int32_t len = udat_format(dat, stuff, outchars, 200, NULL, &subStatus);
86 
87           // //printf("\n");
88           //char utf8[200];
89           // u_strToUTF8(utf8, 200, NULL, outchars, len, &subStatus);
90 
91           sprintf(outchars, " cal: mindays=%d firstday=%d ", (int)cal->getMinimalDaysInFirstWeek(), (int)cal->getFirstDayOfWeek());
92           int32_t len = strlen(outchars);
93 
94           if(oldLen!=len || memcmp(outchars,oldChars,len*sizeof(outchars[0]))) {
95             if(v==0) {
96               putchar(' ');
97             } else {
98               putchar ('!');
99               diffs++;
100             }
101           } else {
102             putchar ('=');
103           }
104           printf(" %s ", outchars);
105 
106           for(int i=0;i<len;i++) {
107                if((i<oldLen)&&(outchars[i]!=oldChars[i])) {
108                         diffs++;
109                         printf("*", oldChars[i]);
110                } else {
111                  printf(" ");
112                }
113           //   //                printf("U+%04X", (outchars[i]));
114           }
115           putchar('\n');
116 
117           oldLen = len;
118           memcpy(oldChars, outchars, len*sizeof(oldChars[0]));
119         }
120       }
121     }
122 
123     if(diffs==0) {
124       printf("ERROR: 0 differences found between platforms.. are the platforms installed? Try 'icuinfo -L'\n");
125       return 1;
126     } else {
127       printf("%d differences found among provider versions! Provider is working!\n", diffs);
128     }
129 
130     // if(gbaddiffs>0) {
131     //   printf("ERROR: %d diffs found between a collator and it's reopened (from shortstring) variant.\n", gbaddiffs);
132     //   return 2;
133     // } else {
134     //   printf("Collator and reopened (shortstring) are OK.\n");
135     // }
136 
137     if(err) {
138       printf("%d errors - FAIL!\n", err);
139       return 1;
140     }
141 
142     printf("Success!\n");
143 
144     return 0;
145 #endif
146 }
147