*******************************************************************************
*
* Copyright (C) 2009-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
*/
#include <unicode/datefmt.h>
#include <unicode/udat.h>
#include <unicode/uclean.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const UDate stuff = 1299977771000.0L;
#include "provider_version.h"
#define LOCALE_COUNT 4
const char *locale[LOCALE_COUNT] = { "fi", "en_US", "ja", "ml" };
* Set up ICU, print # of available collators
*/
void setup(UErrorCode &status) {
u_init(&status);
fprintf(stderr, "ICU %s init: %s\n", U_ICU_VERSION, u_errorName(status));
}
int main(int , const char * []) {
#if (U_ICU_VERSION_MAJOR_NUM < 49)
fprintf(stderr, "Warning: ICU %s doesn't support date providers. Need at least 49.\n", U_ICU_VERSION );
return 0;
#else
UErrorCode status = U_ZERO_ERROR;
int diffs = 0;
int gbaddiffs =0;
UDateFormatStyle styles[] = { UDAT_FULL, UDAT_SHORT };
setup(status);
if(U_FAILURE(status)) return 1;
int expected = PROVIDER_COUNT;
for(uint32_t s=0;s<sizeof(styles)/sizeof(styles[0]);s++) {
for(int l=0;l<LOCALE_COUNT;l++) {
printf("\n");
char16_t oldChars[200];
int32_t oldLen = -1;
for(int v=0;v<=expected;v++) {
char locID[200];
strcpy(locID, locale[l]);
if((v!=expected)) {
strcat(locID, "@sp=icu");
strcat(locID, provider_version[v]);
}
printf("%18s : ", locID);
UErrorCode subStatus = U_ZERO_ERROR;
char16_t outchars[200];
UDateFormat *dat = udat_open(styles[s],styles[s], locID, nullptr, -1, nullptr, 0, &subStatus);
if(U_FAILURE(subStatus)) {
printf("ERR: %s\n", u_errorName(subStatus));
continue;
}
int32_t len = udat_format(dat, stuff, outchars, 200, nullptr, &subStatus);
char utf8[200];
u_strToUTF8(utf8, 200, nullptr, outchars, len, &subStatus);
if(oldLen!=len || memcmp(outchars,oldChars,len*sizeof(outchars[0]))) {
putchar ('!');
diffs++;
} else {
putchar ('=');
}
printf(" %s ", utf8);
putchar('\n');
udat_close(dat);
oldLen = len;
memcpy(oldChars, outchars, len*sizeof(oldChars[0]));
}
}
}
if(diffs==0) {
printf("ERROR: 0 differences found between platforms.. are the platforms installed? Try 'icuinfo -L'\n");
return 1;
} else {
printf("%d differences found among provider versions!\n", diffs);
}
printf("Success!\n");
return 0;
#endif
}