2004-09-03 20:51:11 +00:00
/********************************************************************
* COPYRIGHT :
2013-02-13 13:26:23 +00:00
* Copyright ( c ) 1997 - 2013 , International Business Machines Corporation and
2004-09-03 20:51:11 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "cintltst.h"
# include "unicode/ures.h"
2005-06-16 21:04:40 +00:00
# include "unicode/ucurr.h"
2004-09-03 20:51:11 +00:00
# include "unicode/ustring.h"
# include "unicode/uset.h"
# include "unicode/udat.h"
# include "unicode/uscript.h"
# include "unicode/ulocdata.h"
# include "cstring.h"
# include "locmap.h"
# include "uresimp.h"
2006-06-23 16:31:07 +00:00
/*
returns a new UnicodeSet that is a flattened form of the original
UnicodeSet .
*/
static USet *
createFlattenSet ( USet * origSet , UErrorCode * status ) {
USet * newSet = NULL ;
int32_t origItemCount = 0 ;
int32_t idx , graphmeSize ;
UChar32 start , end ;
UChar graphme [ 64 ] ;
if ( U_FAILURE ( * status ) ) {
log_err ( " createFlattenSet called with %s \n " , u_errorName ( * status ) ) ;
return NULL ;
}
newSet = uset_open ( 1 , 0 ) ;
origItemCount = uset_getItemCount ( origSet ) ;
for ( idx = 0 ; idx < origItemCount ; idx + + ) {
graphmeSize = uset_getItem ( origSet , idx ,
2009-02-21 00:31:21 +00:00
& start , & end ,
2006-06-23 16:31:07 +00:00
graphme , ( int32_t ) ( sizeof ( graphme ) / sizeof ( graphme [ 0 ] ) ) ,
status ) ;
if ( U_FAILURE ( * status ) ) {
log_err ( " ERROR: uset_getItem returned %s \n " , u_errorName ( * status ) ) ;
* status = U_ZERO_ERROR ;
}
if ( graphmeSize ) {
uset_addAllCodePoints ( newSet , graphme , graphmeSize ) ;
}
else {
uset_addRange ( newSet , start , end ) ;
}
}
2011-05-05 18:12:27 +00:00
uset_closeOver ( newSet , USET_CASE_INSENSITIVE ) ;
2006-06-23 16:31:07 +00:00
return newSet ;
}
2011-05-05 18:12:27 +00:00
2009-02-21 00:31:21 +00:00
static UBool
2006-06-23 16:31:07 +00:00
isCurrencyPreEuro ( const char * currencyKey ) {
2004-09-03 20:51:11 +00:00
if ( strcmp ( currencyKey , " PTE " ) = = 0 | |
strcmp ( currencyKey , " ESP " ) = = 0 | |
strcmp ( currencyKey , " LUF " ) = = 0 | |
strcmp ( currencyKey , " GRD " ) = = 0 | |
strcmp ( currencyKey , " BEF " ) = = 0 | |
2005-03-22 01:38:18 +00:00
strcmp ( currencyKey , " ITL " ) = = 0 | |
strcmp ( currencyKey , " EEK " ) = = 0 ) {
2004-09-03 20:51:11 +00:00
return TRUE ;
}
return FALSE ;
}
2012-10-18 19:51:28 +00:00
# if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
2004-09-03 20:51:11 +00:00
static void
TestKeyInRootRecursive ( UResourceBundle * root , const char * rootName ,
UResourceBundle * currentBundle , const char * locale ) {
UErrorCode errorCode = U_ZERO_ERROR ;
2009-02-09 18:11:52 +00:00
UResourceBundle * subRootBundle = NULL , * subBundle = NULL , * arr = NULL ;
2004-09-03 20:51:11 +00:00
ures_resetIterator ( root ) ;
ures_resetIterator ( currentBundle ) ;
while ( ures_hasNext ( currentBundle ) ) {
const char * subBundleKey = NULL ;
const char * currentBundleKey = NULL ;
errorCode = U_ZERO_ERROR ;
currentBundleKey = ures_getKey ( currentBundle ) ;
2013-03-21 05:48:52 +00:00
( void ) currentBundleKey ; /* Suppress set but not used warning. */
2004-09-03 20:51:11 +00:00
subBundle = ures_getNextResource ( currentBundle , NULL , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
2009-04-23 00:23:57 +00:00
log_err ( " Can't open a resource for lnocale %s. Error: %s \n " , locale , u_errorName ( errorCode ) ) ;
2004-09-03 20:51:11 +00:00
continue ;
}
subBundleKey = ures_getKey ( subBundle ) ;
2009-02-21 00:31:21 +00:00
2004-09-03 20:51:11 +00:00
subRootBundle = ures_getByKey ( root , subBundleKey , NULL , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Can't open a resource with key \" %s \" in \" %s \" from %s for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
rootName ,
locale ) ;
ures_close ( subBundle ) ;
continue ;
}
if ( ures_getType ( subRootBundle ) ! = ures_getType ( subBundle ) ) {
log_err ( " key \" %s \" in \" %s \" has a different type from root for locale \" %s \" \n "
" \t root=%d, locale=%d \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ,
ures_getType ( subRootBundle ) ,
ures_getType ( subBundle ) ) ;
2007-07-05 21:47:39 +00:00
ures_close ( subBundle ) ;
2004-09-03 20:51:11 +00:00
continue ;
}
else if ( ures_getType ( subBundle ) = = URES_INT_VECTOR ) {
int32_t minSize ;
int32_t subBundleSize ;
int32_t idx ;
UBool sameArray = TRUE ;
const int32_t * subRootBundleArr = ures_getIntVector ( subRootBundle , & minSize , & errorCode ) ;
const int32_t * subBundleArr = ures_getIntVector ( subBundle , & subBundleSize , & errorCode ) ;
if ( minSize > subBundleSize ) {
minSize = subBundleSize ;
log_err ( " Arrays are different size with key \" %s \" in \" %s \" from root for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
for ( idx = 0 ; idx < minSize & & sameArray ; idx + + ) {
if ( subRootBundleArr [ idx ] ! = subBundleArr [ idx ] ) {
sameArray = FALSE ;
}
if ( strcmp ( subBundleKey , " DateTimeElements " ) = = 0
& & ( subBundleArr [ idx ] < 1 | | 7 < subBundleArr [ idx ] ) )
{
log_err ( " Value out of range with key \" %s \" at index %d in \" %s \" for locale \" %s \" \n " ,
subBundleKey ,
idx ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
}
/* Special exception es_US and DateTimeElements */
if ( sameArray
& & ! ( strcmp ( locale , " es_US " ) = = 0 & & strcmp ( subBundleKey , " DateTimeElements " ) = = 0 ) )
{
log_err ( " Integer vectors are the same with key \" %s \" in \" %s \" from root for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
}
else if ( ures_getType ( subBundle ) = = URES_ARRAY ) {
UResourceBundle * subSubBundle = ures_getByIndex ( subBundle , 0 , NULL , & errorCode ) ;
UResourceBundle * subSubRootBundle = ures_getByIndex ( subRootBundle , 0 , NULL , & errorCode ) ;
if ( U_SUCCESS ( errorCode )
& & ( ures_getType ( subSubBundle ) = = URES_ARRAY | | ures_getType ( subSubRootBundle ) = = URES_ARRAY ) )
{
2006-06-23 16:31:07 +00:00
/* Here is one of the recursive parts */
TestKeyInRootRecursive ( subRootBundle , rootName , subBundle , locale ) ;
2004-09-03 20:51:11 +00:00
}
else {
int32_t minSize = ures_getSize ( subRootBundle ) ;
int32_t idx ;
UBool sameArray = TRUE ;
if ( minSize > ures_getSize ( subBundle ) ) {
minSize = ures_getSize ( subBundle ) ;
}
if ( ( subBundleKey = = NULL
| | ( subBundleKey ! = NULL & & strcmp ( subBundleKey , " LocaleScript " ) ! = 0 & & ! isCurrencyPreEuro ( subBundleKey ) ) )
& & ures_getSize ( subRootBundle ) ! = ures_getSize ( subBundle ) )
{
log_err ( " Different size array with key \" %s \" in \" %s \" from root for locale \" %s \" \n "
" \t root array size=%d, locale array size=%d \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ,
ures_getSize ( subRootBundle ) ,
ures_getSize ( subBundle ) ) ;
}
/*
if ( isCurrencyPreEuro ( subBundleKey ) & & ures_getSize ( subBundle ) ! = 3 ) {
log_err ( " Different size array with key \" %s \" in \" %s \" for locale \" %s \" the expected size is 3 got size=%d \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ,
ures_getSize ( subBundle ) ) ;
}
*/
for ( idx = 0 ; idx < minSize ; idx + + ) {
int32_t rootStrLen , localeStrLen ;
const UChar * rootStr = ures_getStringByIndex ( subRootBundle , idx , & rootStrLen , & errorCode ) ;
const UChar * localeStr = ures_getStringByIndex ( subBundle , idx , & localeStrLen , & errorCode ) ;
if ( rootStr & & localeStr & & U_SUCCESS ( errorCode ) ) {
if ( u_strcmp ( rootStr , localeStr ) ! = 0 ) {
sameArray = FALSE ;
}
}
else {
2009-02-09 18:11:52 +00:00
if ( rootStrLen > 1 & & rootStr [ 0 ] = = 0x41 & & rootStr [ 1 ] > = 0x30 & & rootStr [ 1 ] < = 0x39 ) {
/* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
/* string. Attempt to read it as an array. */
errorCode = U_ZERO_ERROR ;
arr = ures_getByIndex ( subBundle , idx , NULL , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Got a NULL string with key \" %s \" in \" %s \" at index %d for root or locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
idx ,
locale ) ;
continue ;
}
if ( ures_getType ( arr ) ! = URES_ARRAY | | ures_getSize ( arr ) ! = ( int32_t ) rootStr [ 1 ] - 0x30 ) {
log_err ( " Got something other than a string or array of size %d for key \" %s \" in \" %s \" at index %d for root or locale \" %s \" \n " ,
rootStr [ 1 ] - 0x30 ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
idx ,
locale ) ;
ures_close ( arr ) ;
continue ;
}
localeStr = ures_getStringByIndex ( arr , 0 , & localeStrLen , & errorCode ) ;
ures_close ( arr ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Got something other than a string or array for key \" %s \" in \" %s \" at index %d for root or locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
idx ,
locale ) ;
continue ;
}
} else {
log_err ( " Got a NULL string with key \" %s \" in \" %s \" at index %d for root or locale \" %s \" \n " ,
2004-09-03 20:51:11 +00:00
subBundleKey ,
ures_getKey ( currentBundle ) ,
idx ,
locale ) ;
2009-02-09 18:11:52 +00:00
continue ;
}
2004-09-03 20:51:11 +00:00
}
if ( localeStr [ 0 ] = = ( UChar ) 0x20 ) {
log_err ( " key \" %s \" at index %d in \" %s \" starts with a space in locale \" %s \" \n " ,
subBundleKey ,
idx ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
2008-06-20 22:19:23 +00:00
else if ( ( localeStr [ localeStrLen - 1 ] = = ( UChar ) 0x20 ) & & ( strcmp ( subBundleKey , " separator " ) ! = 0 ) ) {
2004-09-03 20:51:11 +00:00
log_err ( " key \" %s \" at index %d in \" %s \" ends with a space in locale \" %s \" \n " ,
subBundleKey ,
idx ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
else if ( subBundleKey ! = NULL
& & strcmp ( subBundleKey , " DateTimePatterns " ) = = 0 )
{
int32_t quoted = 0 ;
const UChar * localeStrItr = localeStr ;
while ( * localeStrItr ) {
if ( * localeStrItr = = ( UChar ) 0x27 /* ' */ ) {
quoted + + ;
}
else if ( ( quoted % 2 ) = = 0 ) {
/* Search for unquoted characters */
if ( 4 < = idx & & idx < = 7
& & ( * localeStrItr = = ( UChar ) 0x6B /* k */
| | * localeStrItr = = ( UChar ) 0x48 /* H */
| | * localeStrItr = = ( UChar ) 0x6D /* m */
| | * localeStrItr = = ( UChar ) 0x73 /* s */
| | * localeStrItr = = ( UChar ) 0x53 /* S */
| | * localeStrItr = = ( UChar ) 0x61 /* a */
| | * localeStrItr = = ( UChar ) 0x68 /* h */
| | * localeStrItr = = ( UChar ) 0x7A /* z */ ) )
{
log_err ( " key \" %s \" at index %d has time pattern chars in date for locale \" %s \" \n " ,
subBundleKey ,
idx ,
locale ) ;
}
else if ( 0 < = idx & & idx < = 3
& & ( * localeStrItr = = ( UChar ) 0x47 /* G */
| | * localeStrItr = = ( UChar ) 0x79 /* y */
| | * localeStrItr = = ( UChar ) 0x4D /* M */
| | * localeStrItr = = ( UChar ) 0x64 /* d */
| | * localeStrItr = = ( UChar ) 0x45 /* E */
| | * localeStrItr = = ( UChar ) 0x44 /* D */
| | * localeStrItr = = ( UChar ) 0x46 /* F */
| | * localeStrItr = = ( UChar ) 0x77 /* w */
| | * localeStrItr = = ( UChar ) 0x57 /* W */ ) )
{
log_err ( " key \" %s \" at index %d has date pattern chars in time for locale \" %s \" \n " ,
subBundleKey ,
idx ,
locale ) ;
}
}
localeStrItr + + ;
}
}
else if ( idx = = 4 & & subBundleKey ! = NULL
& & strcmp ( subBundleKey , " NumberElements " ) = = 0
& & u_charDigitValue ( localeStr [ 0 ] ) ! = 0 )
{
log_err ( " key \" %s \" at index %d has a non-zero based number for locale \" %s \" \n " ,
subBundleKey ,
idx ,
locale ) ;
}
}
2013-03-21 05:48:52 +00:00
( void ) sameArray ; /* Suppress set but not used warning. */
2004-09-03 20:51:11 +00:00
/* if (sameArray && strcmp(rootName, "root") == 0) {
log_err ( " Arrays are the same with key \" %s \" in \" %s \" from root for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
} */
}
ures_close ( subSubBundle ) ;
ures_close ( subSubRootBundle ) ;
}
else if ( ures_getType ( subBundle ) = = URES_STRING ) {
int32_t len = 0 ;
const UChar * string = ures_getString ( subBundle , & len , & errorCode ) ;
if ( U_FAILURE ( errorCode ) | | string = = NULL ) {
log_err ( " Can't open a string with key \" %s \" in \" %s \" for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
} else if ( string [ 0 ] = = ( UChar ) 0x20 ) {
log_err ( " key \" %s \" in \" %s \" starts with a space in locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
2008-06-20 22:19:23 +00:00
/* localeDisplayPattern/separator can end with a space */
} else if ( string [ len - 1 ] = = ( UChar ) 0x20 & & ( strcmp ( subBundleKey , " separator " ) ) ) {
2004-09-03 20:51:11 +00:00
log_err ( " key \" %s \" in \" %s \" ends with a space in locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
2007-02-22 23:44:11 +00:00
} else if ( strcmp ( subBundleKey , " localPatternChars " ) = = 0 ) {
/* Note: We no longer import localPatternChars data starting
* ICU 3.8 . So it never comes into this else if block . ( ticket # 5597 )
*/
2004-09-03 20:51:11 +00:00
/* Check well-formedness of localPatternChars. First, the
* length must match the number of fields defined by
* DateFormat . Second , each character in the string must
* be in the set [ A - Za - z ] . Finally , each character must be
* unique .
*/
int32_t i , j ;
# if !UCONFIG_NO_FORMATTING
if ( len ! = UDAT_FIELD_COUNT ) {
log_err ( " key \" %s \" has the wrong number of characters in locale \" %s \" \n " ,
subBundleKey ,
locale ) ;
}
# endif
/* Check char validity. */
for ( i = 0 ; i < len ; + + i ) {
if ( ! ( ( string [ i ] > = 65 /*'A'*/ & & string [ i ] < = 90 /*'Z'*/ ) | |
( string [ i ] > = 97 /*'a'*/ & & string [ i ] < = 122 /*'z'*/ ) ) ) {
log_err ( " key \" %s \" has illegal character '%c' in locale \" %s \" \n " ,
subBundleKey ,
( char ) string [ i ] ,
locale ) ;
}
/* Do O(n^2) check for duplicate chars. */
for ( j = 0 ; j < i ; + + j ) {
if ( string [ j ] = = string [ i ] ) {
log_err ( " key \" %s \" has duplicate character '%c' in locale \" %s \" \n " ,
subBundleKey ,
( char ) string [ i ] ,
locale ) ;
}
}
}
}
/* No fallback was done. Check for duplicate data */
/* The ures_* API does not do fallback of sub-resource bundles,
So we can ' t do this now . */
#if 0
else if ( strcmp ( locale , " root " ) ! = 0 & & errorCode = = U_ZERO_ERROR ) {
const UChar * rootString = ures_getString ( subRootBundle , & len , & errorCode ) ;
if ( U_FAILURE ( errorCode ) | | rootString = = NULL ) {
log_err ( " Can't open a string with key \" %s \" in \" %s \" in root \n " ,
ures_getKey ( subRootBundle ) ,
ures_getKey ( currentBundle ) ) ;
continue ;
} else if ( u_strcmp ( string , rootString ) = = 0 ) {
2009-02-21 00:31:21 +00:00
if ( strcmp ( locale , " de_CH " ) ! = 0 & & strcmp ( subBundleKey , " Countries " ) ! = 0 & &
2004-09-03 20:51:11 +00:00
strcmp ( subBundleKey , " Version " ) ! = 0 ) {
log_err ( " Found duplicate data with key \" %s \" in \" %s \" in locale \" %s \" \n " ,
ures_getKey ( subRootBundle ) ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
else {
/* Ignore for now. */
/* Can be fixed if fallback through de locale was done. */
log_verbose ( " Skipping key %s in %s \n " , subBundleKey , locale ) ;
}
}
}
# endif
}
else if ( ures_getType ( subBundle ) = = URES_TABLE ) {
2006-06-23 16:31:07 +00:00
if ( strcmp ( subBundleKey , " availableFormats " ) ! = 0 ) {
/* Here is one of the recursive parts */
TestKeyInRootRecursive ( subRootBundle , rootName , subBundle , locale ) ;
}
else {
log_verbose ( " Skipping key %s in %s \n " , subBundleKey , locale ) ;
}
2004-09-03 20:51:11 +00:00
}
else if ( ures_getType ( subBundle ) = = URES_BINARY | | ures_getType ( subBundle ) = = URES_INT ) {
/* Can't do anything to check it */
/* We'll assume it's all correct */
2004-09-08 23:28:51 +00:00
if ( strcmp ( subBundleKey , " MeasurementSystem " ) ! = 0 ) {
2004-09-03 20:51:11 +00:00
log_verbose ( " Skipping key \" %s \" in \" %s \" for locale \" %s \" \n " ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
2004-09-08 23:28:51 +00:00
/* Testing for MeasurementSystem is done in VerifyTranslation */
2004-09-03 20:51:11 +00:00
}
else {
log_err ( " Type %d for key \" %s \" in \" %s \" is unknown for locale \" %s \" \n " ,
ures_getType ( subBundle ) ,
subBundleKey ,
ures_getKey ( currentBundle ) ,
locale ) ;
}
ures_close ( subRootBundle ) ;
ures_close ( subBundle ) ;
}
}
2012-10-18 19:51:28 +00:00
# endif
2004-09-03 20:51:11 +00:00
static void
testLCID ( UResourceBundle * currentBundle ,
const char * localeName )
{
UErrorCode status = U_ZERO_ERROR ;
uint32_t expectedLCID ;
char lcidStringC [ 64 ] = { 0 } ;
2013-05-03 21:36:03 +00:00
int32_t len ;
2004-09-03 20:51:11 +00:00
expectedLCID = uloc_getLCID ( localeName ) ;
2004-09-08 23:28:51 +00:00
if ( expectedLCID = = 0 ) {
log_verbose ( " INFO: %-5s does not have any LCID mapping \n " ,
localeName ) ;
2004-09-03 20:51:11 +00:00
return ;
}
status = U_ZERO_ERROR ;
2013-05-03 21:36:03 +00:00
len = uprv_convertToPosix ( expectedLCID , lcidStringC , sizeof ( lcidStringC ) / sizeof ( lcidStringC [ 0 ] ) - 1 , & status ) ;
2004-09-03 20:51:11 +00:00
if ( U_FAILURE ( status ) ) {
log_err ( " ERROR: %.4x does not have a POSIX mapping due to %s \n " ,
expectedLCID , u_errorName ( status ) ) ;
}
2013-05-03 21:36:03 +00:00
lcidStringC [ len ] = 0 ;
2004-09-03 20:51:11 +00:00
if ( strcmp ( localeName , lcidStringC ) ! = 0 ) {
char langName [ 1024 ] ;
char langLCID [ 1024 ] ;
uloc_getLanguage ( localeName , langName , sizeof ( langName ) , & status ) ;
uloc_getLanguage ( lcidStringC , langLCID , sizeof ( langLCID ) , & status ) ;
2004-09-08 23:28:51 +00:00
if ( strcmp ( langName , langLCID ) = = 0 ) {
2004-09-03 20:51:11 +00:00
log_verbose ( " WARNING: %-5s resolves to %s (0x%.4x) \n " ,
2004-09-08 23:28:51 +00:00
localeName , lcidStringC , expectedLCID ) ;
2004-09-03 20:51:11 +00:00
}
2004-09-08 23:28:51 +00:00
else {
2004-09-03 20:51:11 +00:00
log_err ( " ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s \n " ,
localeName , expectedLCID , lcidStringC ) ;
}
}
}
2012-10-18 19:51:28 +00:00
# if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
2004-09-03 20:51:11 +00:00
static void
TestLocaleStructure ( void ) {
2013-05-30 20:20:17 +00:00
// This test checks the locale structure against a key file located
// at source/test/testdata/structLocale.txt. When adding new data to
// a loale file such as en.txt, the structLocale.txt file must be changed
// too to include the the template of the new data. Otherwise this test
// will fail!
2004-09-03 20:51:11 +00:00
UResourceBundle * root , * currentLocale ;
int32_t locCount = uloc_countAvailable ( ) ;
int32_t locIndex ;
UErrorCode errorCode = U_ZERO_ERROR ;
2005-01-06 16:31:36 +00:00
const char * currLoc , * resolvedLoc ;
2004-09-03 20:51:11 +00:00
/* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
/* char locName[ULOC_FULLNAME_CAPACITY];
char * locNamePtr ;
for ( locIndex = 0 ; locIndex < locCount ; locIndex + + ) {
errorCode = U_ZERO_ERROR ;
strcpy ( locName , uloc_getAvailable ( locIndex ) ) ;
locNamePtr = strrchr ( locName , ' _ ' ) ;
if ( locNamePtr ) {
* locNamePtr = 0 ;
}
else {
strcpy ( locName , " root " ) ;
}
root = ures_openDirect ( NULL , locName , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Can't open %s \n " , locName ) ;
continue ;
}
*/
if ( locCount < = 1 ) {
log_data_err ( " At least root needs to be installed \n " ) ;
}
root = ures_openDirect ( loadTestData ( & errorCode ) , " structLocale " , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_data_err ( " Can't open structLocale \n " ) ;
return ;
}
for ( locIndex = 0 ; locIndex < locCount ; locIndex + + ) {
errorCode = U_ZERO_ERROR ;
currLoc = uloc_getAvailable ( locIndex ) ;
currentLocale = ures_open ( NULL , currLoc , & errorCode ) ;
if ( errorCode ! = U_ZERO_ERROR ) {
if ( U_SUCCESS ( errorCode ) ) {
/* It's installed, but there is no data.
It ' s installed for the g18n white paper [ grhoten ] */
2008-09-15 19:29:43 +00:00
log_err ( " ERROR: Locale %-5s not installed, and it should be, err %s \n " ,
uloc_getAvailable ( locIndex ) , u_errorName ( errorCode ) ) ;
2004-09-03 20:51:11 +00:00
} else {
log_err ( " %%%%%%% Unexpected error %d in %s %%%%%%% " ,
u_errorName ( errorCode ) ,
uloc_getAvailable ( locIndex ) ) ;
}
ures_close ( currentLocale ) ;
continue ;
}
ures_getStringByKey ( currentLocale , " Version " , NULL , & errorCode ) ;
if ( errorCode ! = U_ZERO_ERROR ) {
log_err ( " No version information is available for locale %s, and it should be! \n " ,
currLoc ) ;
}
else if ( ures_getStringByKey ( currentLocale , " Version " , NULL , & errorCode ) [ 0 ] = = ( UChar ) ( 0x78 ) ) {
log_verbose ( " WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale. \n " ,
currLoc ) ;
}
2005-01-06 16:31:36 +00:00
resolvedLoc = ures_getLocaleByType ( currentLocale , ULOC_ACTUAL_LOCALE , & errorCode ) ;
2011-12-15 17:02:43 +00:00
if ( strcmp ( resolvedLoc , currLoc ) ! = 0 ) {
2005-01-06 16:31:36 +00:00
/* All locales have at least a Version resource.
If it ' s absolutely empty , then the previous test will fail too . */
log_err ( " Locale resolves to different locale. Is %s an alias of %s? \n " ,
currLoc , resolvedLoc ) ;
}
2004-09-03 20:51:11 +00:00
TestKeyInRootRecursive ( root , " root " , currentLocale , currLoc ) ;
testLCID ( currentLocale , currLoc ) ;
ures_close ( currentLocale ) ;
}
ures_close ( root ) ;
}
2012-10-18 19:51:28 +00:00
# endif
2004-09-03 20:51:11 +00:00
static void
compareArrays ( const char * keyName ,
UResourceBundle * fromArray , const char * fromLocale ,
UResourceBundle * toArray , const char * toLocale ,
int32_t start , int32_t end )
{
int32_t fromSize = ures_getSize ( fromArray ) ;
int32_t toSize = ures_getSize ( fromArray ) ;
int32_t idx ;
UErrorCode errorCode = U_ZERO_ERROR ;
if ( fromSize > toSize ) {
fromSize = toSize ;
log_err ( " Arrays are different size from \" %s \" to \" %s \" \n " ,
fromLocale ,
toLocale ) ;
}
for ( idx = start ; idx < = end ; idx + + ) {
const UChar * fromBundleStr = ures_getStringByIndex ( fromArray , idx , NULL , & errorCode ) ;
const UChar * toBundleStr = ures_getStringByIndex ( toArray , idx , NULL , & errorCode ) ;
if ( fromBundleStr & & toBundleStr & & u_strcmp ( fromBundleStr , toBundleStr ) ! = 0 )
{
log_err ( " Difference for %s at index %d from %s= \" %s \" to %s= \" %s \" \n " ,
keyName ,
idx ,
fromLocale ,
austrdup ( fromBundleStr ) ,
toLocale ,
austrdup ( toBundleStr ) ) ;
}
}
}
static void
compareConsistentCountryInfo ( const char * fromLocale , const char * toLocale ) {
UErrorCode errorCode = U_ZERO_ERROR ;
UResourceBundle * fromArray , * toArray ;
UResourceBundle * fromLocaleBund = ures_open ( NULL , fromLocale , & errorCode ) ;
UResourceBundle * toLocaleBund = ures_open ( NULL , toLocale , & errorCode ) ;
UResourceBundle * toCalendar , * fromCalendar , * toGregorian , * fromGregorian ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Can't open resource bundle %s or %s - %s \n " , fromLocale , toLocale , u_errorName ( errorCode ) ) ;
return ;
}
fromCalendar = ures_getByKey ( fromLocaleBund , " calendar " , NULL , & errorCode ) ;
fromGregorian = ures_getByKeyWithFallback ( fromCalendar , " gregorian " , NULL , & errorCode ) ;
2009-02-21 00:31:21 +00:00
2004-09-03 20:51:11 +00:00
toCalendar = ures_getByKey ( toLocaleBund , " calendar " , NULL , & errorCode ) ;
toGregorian = ures_getByKeyWithFallback ( toCalendar , " gregorian " , NULL , & errorCode ) ;
fromArray = ures_getByKey ( fromLocaleBund , " CurrencyElements " , NULL , & errorCode ) ;
toArray = ures_getByKey ( toLocaleBund , " CurrencyElements " , NULL , & errorCode ) ;
if ( strcmp ( fromLocale , " en_CA " ) ! = 0 )
{
/* The first one is probably localized. */
compareArrays ( " CurrencyElements " , fromArray , fromLocale , toArray , toLocale , 1 , 2 ) ;
}
ures_close ( fromArray ) ;
ures_close ( toArray ) ;
fromArray = ures_getByKey ( fromLocaleBund , " NumberPatterns " , NULL , & errorCode ) ;
toArray = ures_getByKey ( toLocaleBund , " NumberPatterns " , NULL , & errorCode ) ;
if ( strcmp ( fromLocale , " en_CA " ) ! = 0 )
{
compareArrays ( " NumberPatterns " , fromArray , fromLocale , toArray , toLocale , 0 , 3 ) ;
}
ures_close ( fromArray ) ;
ures_close ( toArray ) ;
/* Difficult to test properly */
/*
fromArray = ures_getByKey ( fromLocaleBund , " DateTimePatterns " , NULL , & errorCode ) ;
toArray = ures_getByKey ( toLocaleBund , " DateTimePatterns " , NULL , & errorCode ) ;
{
compareArrays ( " DateTimePatterns " , fromArray , fromLocale , toArray , toLocale ) ;
}
ures_close ( fromArray ) ;
ures_close ( toArray ) ; */
fromArray = ures_getByKey ( fromLocaleBund , " NumberElements " , NULL , & errorCode ) ;
toArray = ures_getByKey ( toLocaleBund , " NumberElements " , NULL , & errorCode ) ;
if ( strcmp ( fromLocale , " en_CA " ) ! = 0 )
{
compareArrays ( " NumberElements " , fromArray , fromLocale , toArray , toLocale , 0 , 3 ) ;
/* Index 4 is a script based 0 */
compareArrays ( " NumberElements " , fromArray , fromLocale , toArray , toLocale , 5 , 10 ) ;
}
ures_close ( fromArray ) ;
ures_close ( toArray ) ;
2004-10-12 19:03:54 +00:00
ures_close ( fromCalendar ) ;
ures_close ( toCalendar ) ;
ures_close ( fromGregorian ) ;
ures_close ( toGregorian ) ;
2004-09-03 20:51:11 +00:00
ures_close ( fromLocaleBund ) ;
ures_close ( toLocaleBund ) ;
}
static void
TestConsistentCountryInfo ( void ) {
/* UResourceBundle *fromLocale, *toLocale;*/
int32_t locCount = uloc_countAvailable ( ) ;
int32_t fromLocIndex , toLocIndex ;
int32_t fromCountryLen , toCountryLen ;
char fromCountry [ ULOC_FULLNAME_CAPACITY ] , toCountry [ ULOC_FULLNAME_CAPACITY ] ;
int32_t fromVariantLen , toVariantLen ;
char fromVariant [ ULOC_FULLNAME_CAPACITY ] , toVariant [ ULOC_FULLNAME_CAPACITY ] ;
UErrorCode errorCode = U_ZERO_ERROR ;
for ( fromLocIndex = 0 ; fromLocIndex < locCount ; fromLocIndex + + ) {
const char * fromLocale = uloc_getAvailable ( fromLocIndex ) ;
errorCode = U_ZERO_ERROR ;
fromCountryLen = uloc_getCountry ( fromLocale , fromCountry , ULOC_FULLNAME_CAPACITY , & errorCode ) ;
if ( fromCountryLen < = 0 ) {
/* Ignore countryless locales */
continue ;
}
fromVariantLen = uloc_getVariant ( fromLocale , fromVariant , ULOC_FULLNAME_CAPACITY , & errorCode ) ;
if ( fromVariantLen > 0 ) {
/* Most variants are ignorable like PREEURO, or collation variants. */
continue ;
}
/* Start comparing only after the current index.
Previous loop should have already compared fromLocIndex .
*/
for ( toLocIndex = fromLocIndex + 1 ; toLocIndex < locCount ; toLocIndex + + ) {
const char * toLocale = uloc_getAvailable ( toLocIndex ) ;
toCountryLen = uloc_getCountry ( toLocale , toCountry , ULOC_FULLNAME_CAPACITY , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " Unknown failure fromLocale=%s toLocale=%s errorCode=%s \n " ,
fromLocale , toLocale , u_errorName ( errorCode ) ) ;
continue ;
}
if ( toCountryLen < = 0 ) {
/* Ignore countryless locales */
continue ;
}
toVariantLen = uloc_getVariant ( toLocale , toVariant , ULOC_FULLNAME_CAPACITY , & errorCode ) ;
if ( toVariantLen > 0 ) {
/* Most variants are ignorable like PREEURO, or collation variants. */
/* They're a variant for a reason. */
continue ;
}
if ( strcmp ( fromCountry , toCountry ) = = 0 ) {
log_verbose ( " comparing fromLocale=%s toLocale=%s \n " ,
fromLocale , toLocale ) ;
compareConsistentCountryInfo ( fromLocale , toLocale ) ;
}
}
}
}
static int32_t
2004-10-01 21:04:48 +00:00
findStringSetMismatch ( const char * currLoc , const UChar * string , int32_t langSize ,
2004-09-03 20:51:11 +00:00
const UChar * exemplarCharacters , int32_t exemplarLen ,
2010-10-21 07:26:06 +00:00
UBool ignoreNumbers , UChar * badCharPtr ) {
2004-09-03 20:51:11 +00:00
UErrorCode errorCode = U_ZERO_ERROR ;
2006-06-23 16:31:07 +00:00
USet * origSet = uset_openPatternOptions ( exemplarCharacters , exemplarLen , USET_CASE_INSENSITIVE , & errorCode ) ;
USet * exemplarSet = createFlattenSet ( origSet , & errorCode ) ;
2004-09-03 20:51:11 +00:00
int32_t strIdx ;
2006-06-23 16:31:07 +00:00
uset_close ( origSet ) ;
2004-09-03 20:51:11 +00:00
if ( U_FAILURE ( errorCode ) ) {
2005-11-17 21:40:18 +00:00
log_err ( " %s: error uset_openPattern returned %s \n " , currLoc , u_errorName ( errorCode ) ) ;
2004-09-03 20:51:11 +00:00
return - 1 ;
}
for ( strIdx = 0 ; strIdx < langSize ; strIdx + + ) {
if ( ! uset_contains ( exemplarSet , string [ strIdx ] )
2012-08-28 21:56:06 +00:00
& & string [ strIdx ] ! = 0x0020 & & string [ strIdx ] ! = 0x00A0 & & string [ strIdx ] ! = 0x002e & & string [ strIdx ] ! = 0x002c & & string [ strIdx ] ! = 0x002d & & string [ strIdx ] ! = 0x0027 & & string [ strIdx ] ! = 0x005B & & string [ strIdx ] ! = 0x005D & & string [ strIdx ] ! = 0x2019 & & string [ strIdx ] ! = 0x0f0b
2006-07-07 21:01:30 +00:00
& & string [ strIdx ] ! = 0x200C & & string [ strIdx ] ! = 0x200D ) {
2004-09-03 20:51:11 +00:00
if ( ! ignoreNumbers | | ( ignoreNumbers & & ( string [ strIdx ] < 0x30 | | string [ strIdx ] > 0x39 ) ) ) {
2005-11-17 21:40:18 +00:00
uset_close ( exemplarSet ) ;
2010-10-21 07:26:06 +00:00
if ( badCharPtr ) {
* badCharPtr = string [ strIdx ] ;
}
2004-09-03 20:51:11 +00:00
return strIdx ;
}
}
}
uset_close ( exemplarSet ) ;
2010-10-21 07:26:06 +00:00
if ( badCharPtr ) {
* badCharPtr = 0 ;
}
2004-09-03 20:51:11 +00:00
return - 1 ;
}
2006-04-21 01:18:35 +00:00
/* include non-invariant chars */
static int32_t
myUCharsToChars ( const UChar * us , char * cs , int32_t len ) {
int32_t i = 0 ;
for ( ; i < len ; i + + ) {
if ( us [ i ] < 0x7f ) {
cs [ i ] = ( char ) us [ i ] ;
} else {
return - 1 ;
}
}
return i ;
}
2009-02-21 00:31:21 +00:00
static void
findSetMatch ( UScriptCode * scriptCodes , int32_t scriptsLen ,
2004-09-03 20:51:11 +00:00
USet * exemplarSet ,
const char * locale ) {
USet * scripts [ 10 ] = { 0 } ;
char pattern [ 256 ] = { ' [ ' , ' : ' , 0x000 } ;
2004-11-04 22:24:46 +00:00
int32_t patternLen ;
2004-09-03 20:51:11 +00:00
UChar uPattern [ 256 ] = { 0 } ;
UErrorCode status = U_ZERO_ERROR ;
int32_t i ;
/* create the sets with script codes */
for ( i = 0 ; i < scriptsLen ; i + + ) {
strcat ( pattern , uscript_getShortName ( scriptCodes [ i ] ) ) ;
strcat ( pattern , " :] " ) ;
2004-11-04 22:24:46 +00:00
patternLen = ( int32_t ) strlen ( pattern ) ;
u_charsToUChars ( pattern , uPattern , patternLen ) ;
scripts [ i ] = uset_openPattern ( uPattern , patternLen , & status ) ;
2004-09-03 20:51:11 +00:00
if ( U_FAILURE ( status ) ) {
2008-02-16 12:17:48 +00:00
log_err ( " Could not create set for pattern %s. Error: %s \n " , pattern , u_errorName ( status ) ) ;
return ;
2004-09-03 20:51:11 +00:00
}
2009-02-21 00:31:21 +00:00
pattern [ 2 ] = 0 ;
2004-09-03 20:51:11 +00:00
}
if ( strcmp ( locale , " uk " ) = = 0 | | strcmp ( locale , " uk_UA " ) = = 0 ) {
/* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
uset_add ( scripts [ 0 ] , 0x2bc ) ;
}
if ( U_SUCCESS ( status ) ) {
UBool existsInScript = FALSE ;
/* iterate over the exemplarSet and ascertain if all
* UChars in exemplarSet belong to the scripts returned
* by getScript
*/
int32_t count = uset_getItemCount ( exemplarSet ) ;
for ( i = 0 ; i < count ; i + + ) {
UChar32 start = 0 ;
UChar32 end = 0 ;
UChar * str = NULL ;
int32_t strCapacity = 0 ;
2009-02-21 00:31:21 +00:00
2004-09-03 20:51:11 +00:00
strCapacity = uset_getItem ( exemplarSet , i , & start , & end , str , strCapacity , & status ) ;
if ( U_SUCCESS ( status ) ) {
int32_t j ;
if ( strCapacity = = 0 ) {
/* ok the item is a range */
for ( j = 0 ; j < scriptsLen ; j + + ) {
if ( uset_containsRange ( scripts [ j ] , start , end ) = = TRUE ) {
existsInScript = TRUE ;
}
}
if ( existsInScript = = FALSE ) {
2006-04-21 01:18:35 +00:00
for ( j = 0 ; j < scriptsLen ; j + + ) {
2006-05-22 05:29:53 +00:00
UChar toPattern [ 500 ] = { ' \0 ' } ;
2006-04-21 01:18:35 +00:00
char pat [ 500 ] = { ' \0 ' } ;
2006-07-12 00:17:21 +00:00
int32_t len = uset_toPattern ( scripts [ j ] , toPattern , 500 , TRUE , & status ) ;
2006-05-22 05:29:53 +00:00
len = myUCharsToChars ( toPattern , pat , len ) ;
2006-04-21 01:18:35 +00:00
log_err ( " uset_indexOf( \\ u%04X)=%i uset_indexOf( \\ u%04X)=%i \n " , start , uset_indexOf ( scripts [ 0 ] , start ) , end , uset_indexOf ( scripts [ 0 ] , end ) ) ;
if ( len ! = - 1 ) {
log_err ( " Pattern: %s \n " , pat ) ;
}
}
2004-09-03 20:51:11 +00:00
log_err ( " ExemplarCharacters and LocaleScript containment test failed for locale %s. \n " , locale ) ;
}
} else {
strCapacity + + ; /* increment for NUL termination */
/* allocate the str and call the api again */
str = ( UChar * ) malloc ( U_SIZEOF_UCHAR * strCapacity ) ;
strCapacity = uset_getItem ( exemplarSet , i , & start , & end , str , strCapacity , & status ) ;
/* iterate over the scripts and figure out if the string contained is actually
* in the script set
*/
for ( j = 0 ; j < scriptsLen ; j + + ) {
if ( uset_containsString ( scripts [ j ] , str , strCapacity ) = = TRUE ) {
existsInScript = TRUE ;
}
}
if ( existsInScript = = FALSE ) {
log_err ( " ExemplarCharacters and LocaleScript containment test failed for locale %s. \n " , locale ) ;
}
}
}
}
}
/* close the sets */
for ( i = 0 ; i < scriptsLen ; i + + ) {
uset_close ( scripts [ i ] ) ;
}
}
static void VerifyTranslation ( void ) {
UResourceBundle * root , * currentLocale ;
int32_t locCount = uloc_countAvailable ( ) ;
int32_t locIndex ;
UErrorCode errorCode = U_ZERO_ERROR ;
int32_t exemplarLen ;
const UChar * exemplarCharacters ;
const char * currLoc ;
UScriptCode scripts [ USCRIPT_CODE_LIMIT ] ;
int32_t numScripts ;
int32_t idx ;
int32_t end ;
UResourceBundle * resArray ;
if ( locCount < = 1 ) {
log_data_err ( " At least root needs to be installed \n " ) ;
}
root = ures_openDirect ( NULL , " root " , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_data_err ( " Can't open root \n " ) ;
return ;
}
for ( locIndex = 0 ; locIndex < locCount ; locIndex + + ) {
errorCode = U_ZERO_ERROR ;
currLoc = uloc_getAvailable ( locIndex ) ;
currentLocale = ures_open ( NULL , currLoc , & errorCode ) ;
if ( errorCode ! = U_ZERO_ERROR ) {
if ( U_SUCCESS ( errorCode ) ) {
/* It's installed, but there is no data.
It ' s installed for the g18n white paper [ grhoten ] */
log_err ( " ERROR: Locale %-5s not installed, and it should be! \n " ,
uloc_getAvailable ( locIndex ) ) ;
} else {
log_err ( " %%%%%%% Unexpected error %d in %s %%%%%%% " ,
u_errorName ( errorCode ) ,
uloc_getAvailable ( locIndex ) ) ;
}
ures_close ( currentLocale ) ;
continue ;
}
exemplarCharacters = ures_getStringByKey ( currentLocale , " ExemplarCharacters " , & exemplarLen , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error ures_getStringByKey returned %s \n " , u_errorName ( errorCode ) ) ;
}
2010-04-07 16:18:38 +00:00
else if ( getTestOption ( QUICK_OPTION ) & & exemplarLen > 2048 ) {
2004-09-03 20:51:11 +00:00
log_verbose ( " skipping test for %s \n " , currLoc ) ;
}
2012-08-28 21:56:06 +00:00
else if ( uprv_strncmp ( currLoc , " bem " , 3 ) = = 0 | | uprv_strncmp ( currLoc , " mgo " , 3 ) = = 0 | | uprv_strncmp ( currLoc , " nl " , 2 ) = = 0 ) {
2010-02-18 14:30:15 +00:00
log_verbose ( " skipping test for %s, some month and country names known to use aux exemplars \n " , currLoc ) ;
}
2004-09-03 20:51:11 +00:00
else {
UChar langBuffer [ 128 ] ;
int32_t langSize ;
int32_t strIdx ;
2010-10-21 07:26:06 +00:00
UChar badChar ;
2004-09-03 20:51:11 +00:00
langSize = uloc_getDisplayLanguage ( currLoc , currLoc , langBuffer , sizeof ( langBuffer ) / sizeof ( langBuffer [ 0 ] ) , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error uloc_getDisplayLanguage returned %s \n " , u_errorName ( errorCode ) ) ;
}
else {
2010-10-21 07:26:06 +00:00
strIdx = findStringSetMismatch ( currLoc , langBuffer , langSize , exemplarCharacters , exemplarLen , FALSE , & badChar ) ;
2004-09-03 20:51:11 +00:00
if ( strIdx > = 0 ) {
2010-10-21 07:26:06 +00:00
log_err ( " getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X. \n " ,
currLoc , strIdx , badChar ) ;
2004-09-03 20:51:11 +00:00
}
}
langSize = uloc_getDisplayCountry ( currLoc , currLoc , langBuffer , sizeof ( langBuffer ) / sizeof ( langBuffer [ 0 ] ) , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error uloc_getDisplayCountry returned %s \n " , u_errorName ( errorCode ) ) ;
}
2013-05-07 19:53:34 +00:00
else if ( uprv_strstr ( currLoc , " ti_ " ) ! = currLoc | | isICUVersionAtLeast ( 52 , 0 , 2 ) ) { /* TODO: FIX or REMOVE this test! Was: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) - but CldrBug:3058 is wontfix */
2010-10-21 07:26:06 +00:00
strIdx = findStringSetMismatch ( currLoc , langBuffer , langSize , exemplarCharacters , exemplarLen , FALSE , & badChar ) ;
2004-09-03 20:51:11 +00:00
if ( strIdx > = 0 ) {
2010-10-21 07:26:06 +00:00
log_err ( " getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X. \n " ,
currLoc , strIdx , badChar ) ;
2004-09-03 20:51:11 +00:00
}
}
{
UResourceBundle * cal = ures_getByKey ( currentLocale , " calendar " , NULL , & errorCode ) ;
UResourceBundle * greg = ures_getByKeyWithFallback ( cal , " gregorian " , NULL , & errorCode ) ;
UResourceBundle * names = ures_getByKeyWithFallback ( greg , " dayNames " , NULL , & errorCode ) ;
UResourceBundle * format = ures_getByKeyWithFallback ( names , " format " , NULL , & errorCode ) ;
resArray = ures_getByKeyWithFallback ( format , " wide " , NULL , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error ures_getByKey returned %s \n " , u_errorName ( errorCode ) ) ;
}
2010-04-07 16:18:38 +00:00
if ( getTestOption ( QUICK_OPTION ) ) {
2004-09-03 20:51:11 +00:00
end = 1 ;
}
else {
end = ures_getSize ( resArray ) ;
}
for ( idx = 0 ; idx < end ; idx + + ) {
const UChar * fromBundleStr = ures_getStringByIndex ( resArray , idx , & langSize , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error ures_getStringByIndex(%d) returned %s \n " , idx , u_errorName ( errorCode ) ) ;
continue ;
}
2013-05-07 19:53:34 +00:00
if ( uprv_strstr ( currLoc , " uz_Arab " ) ! = currLoc | | isICUVersionAtLeast ( 52 , 0 , 2 ) ) { /* TODO: FIX or REMOVE this test! */
2013-02-13 13:26:23 +00:00
strIdx = findStringSetMismatch ( currLoc , fromBundleStr , langSize , exemplarCharacters , exemplarLen , TRUE , & badChar ) ;
if ( strIdx > = 0 ) {
log_err ( " getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X. \n " ,
currLoc , idx , strIdx , badChar ) ;
}
2004-09-03 20:51:11 +00:00
}
}
ures_close ( resArray ) ;
ures_close ( format ) ;
ures_close ( names ) ;
names = ures_getByKeyWithFallback ( greg , " monthNames " , NULL , & errorCode ) ;
format = ures_getByKeyWithFallback ( names , " format " , NULL , & errorCode ) ;
resArray = ures_getByKeyWithFallback ( format , " wide " , NULL , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error ures_getByKey returned %s \n " , u_errorName ( errorCode ) ) ;
}
2010-04-07 16:18:38 +00:00
if ( getTestOption ( QUICK_OPTION ) ) {
2004-09-03 20:51:11 +00:00
end = 1 ;
}
else {
end = ures_getSize ( resArray ) ;
}
for ( idx = 0 ; idx < end ; idx + + ) {
const UChar * fromBundleStr = ures_getStringByIndex ( resArray , idx , & langSize , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " error ures_getStringByIndex(%d) returned %s \n " , idx , u_errorName ( errorCode ) ) ;
continue ;
}
2013-05-07 19:53:34 +00:00
if ( uprv_strstr ( currLoc , " uz_Arab " ) ! = currLoc | | isICUVersionAtLeast ( 52 , 0 , 2 ) ) { /* TODO: FIX or REMOVE this test! */
2013-02-13 13:26:23 +00:00
strIdx = findStringSetMismatch ( currLoc , fromBundleStr , langSize , exemplarCharacters , exemplarLen , TRUE , & badChar ) ;
if ( strIdx > = 0 ) {
log_err ( " getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X. \n " ,
currLoc , idx , strIdx , badChar ) ;
}
2004-09-03 20:51:11 +00:00
}
}
ures_close ( resArray ) ;
ures_close ( format ) ;
ures_close ( names ) ;
ures_close ( greg ) ;
ures_close ( cal ) ;
}
errorCode = U_ZERO_ERROR ;
numScripts = uscript_getCode ( currLoc , scripts , sizeof ( scripts ) / sizeof ( scripts [ 0 ] ) , & errorCode ) ;
if ( numScripts = = 0 ) {
log_err ( " uscript_getCode(%s) doesn't work. \n " , currLoc ) ;
} else if ( scripts [ 0 ] = = USCRIPT_COMMON ) {
2009-02-21 00:31:21 +00:00
log_err ( " uscript_getCode(%s) returned USCRIPT_COMMON. \n " , currLoc ) ;
2004-09-03 20:51:11 +00:00
}
/* test that the scripts are a superset of exemplar characters. */
{
2005-06-24 22:13:07 +00:00
ULocaleData * uld = ulocdata_open ( currLoc , & errorCode ) ;
USet * exemplarSet = ulocdata_getExemplarSet ( uld , NULL , 0 , ULOCDATA_ES_STANDARD , & errorCode ) ;
2004-09-03 20:51:11 +00:00
/* test if exemplar characters are part of script code */
findSetMatch ( scripts , numScripts , exemplarSet , currLoc ) ;
uset_close ( exemplarSet ) ;
2005-06-24 22:13:07 +00:00
ulocdata_close ( uld ) ;
2004-09-03 20:51:11 +00:00
}
/* test that the paperSize API works */
{
int32_t height = 0 , width = 0 ;
ulocdata_getPaperSize ( currLoc , & height , & width , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " ulocdata_getPaperSize failed for locale %s with error: %s \n " , currLoc , u_errorName ( errorCode ) ) ;
}
if ( strstr ( currLoc , " _US " ) ! = NULL & & height ! = 279 & & width ! = 216 ) {
log_err ( " ulocdata_getPaperSize did not return expected data for locale %s \n " , currLoc ) ;
}
}
/* test that the MeasurementSystem works API works */
{
UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem ( currLoc , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_err ( " ulocdata_getMeasurementSystem failed for locale %s with error: %s \n " , currLoc , u_errorName ( errorCode ) ) ;
}
2010-10-21 07:26:06 +00:00
if ( strstr ( currLoc , " _US " ) ! = NULL | | strstr ( currLoc , " _MM " ) ! = NULL | | strstr ( currLoc , " _LR " ) ! = NULL ) {
2004-09-03 20:51:11 +00:00
if ( measurementSystem ! = UMS_US ) {
log_err ( " ulocdata_getMeasurementSystem did not return expected data for locale %s \n " , currLoc ) ;
}
} else if ( measurementSystem ! = UMS_SI ) {
log_err ( " ulocdata_getMeasurementSystem did not return expected data for locale %s \n " , currLoc ) ;
}
}
}
ures_close ( currentLocale ) ;
}
ures_close ( root ) ;
}
/* adjust this limit as appropriate */
# define MAX_SCRIPTS_PER_LOCALE 8
static void TestExemplarSet ( void ) {
int32_t i , j , k , m , n ;
int32_t equalCount = 0 ;
UErrorCode ec = U_ZERO_ERROR ;
UEnumeration * avail ;
USet * exemplarSets [ 2 ] ;
2005-11-17 21:40:18 +00:00
USet * unassignedSet ;
2004-09-03 20:51:11 +00:00
UScriptCode code [ MAX_SCRIPTS_PER_LOCALE ] ;
USet * codeSets [ MAX_SCRIPTS_PER_LOCALE ] ;
int32_t codeLen ;
char cbuf [ 32 ] ; /* 9 should be enough */
UChar ubuf [ 64 ] ; /* adjust as needed */
UBool existsInScript ;
int32_t itemCount ;
int32_t strLen ;
UChar32 start , end ;
2009-02-21 00:31:21 +00:00
2005-11-17 21:40:18 +00:00
unassignedSet = NULL ;
exemplarSets [ 0 ] = NULL ;
exemplarSets [ 1 ] = NULL ;
2004-09-03 20:51:11 +00:00
for ( i = 0 ; i < MAX_SCRIPTS_PER_LOCALE ; + + i ) {
codeSets [ i ] = NULL ;
}
avail = ures_openAvailableLocales ( NULL , & ec ) ;
if ( ! assertSuccess ( " ures_openAvailableLocales " , & ec ) ) goto END ;
n = uenum_count ( avail , & ec ) ;
if ( ! assertSuccess ( " uenum_count " , & ec ) ) goto END ;
2005-11-17 21:40:18 +00:00
u_uastrcpy ( ubuf , " [:unassigned:] " ) ;
unassignedSet = uset_openPattern ( ubuf , - 1 , & ec ) ;
if ( ! assertSuccess ( " uset_openPattern " , & ec ) ) goto END ;
2004-09-03 20:51:11 +00:00
for ( i = 0 ; i < n ; i + + ) {
const char * locale = uenum_next ( avail , NULL , & ec ) ;
if ( ! assertSuccess ( " uenum_next " , & ec ) ) goto END ;
log_verbose ( " %s \n " , locale ) ;
for ( k = 0 ; k < 2 ; + + k ) {
uint32_t option = ( k = = 0 ) ? 0 : USET_CASE_INSENSITIVE ;
2009-02-21 00:31:21 +00:00
ULocaleData * uld = ulocdata_open ( locale , & ec ) ;
2005-06-24 22:13:07 +00:00
USet * exemplarSet = ulocdata_getExemplarSet ( uld , NULL , option , ULOCDATA_ES_STANDARD , & ec ) ;
2004-09-03 20:51:11 +00:00
uset_close ( exemplarSets [ k ] ) ;
2005-06-24 22:13:07 +00:00
ulocdata_close ( uld ) ;
2004-09-03 20:51:11 +00:00
exemplarSets [ k ] = exemplarSet ;
if ( ! assertSuccess ( " ulocaledata_getExemplarSet " , & ec ) ) goto END ;
2005-11-17 21:40:18 +00:00
if ( uset_containsSome ( exemplarSet , unassignedSet ) ) {
log_err ( " ExemplarSet contains unassigned characters for locale : %s \n " , locale ) ;
}
2004-09-03 20:51:11 +00:00
codeLen = uscript_getCode ( locale , code , 8 , & ec ) ;
if ( ! assertSuccess ( " uscript_getCode " , & ec ) ) goto END ;
for ( j = 0 ; j < MAX_SCRIPTS_PER_LOCALE ; + + j ) {
uset_close ( codeSets [ j ] ) ;
codeSets [ j ] = NULL ;
}
for ( j = 0 ; j < codeLen ; + + j ) {
uprv_strcpy ( cbuf , " [: " ) ;
2005-12-27 22:23:05 +00:00
if ( code [ j ] = = - 1 ) {
log_err ( " USCRIPT_INVALID_CODE returned for locale: %s \n " , locale ) ;
continue ;
}
2004-09-03 20:51:11 +00:00
uprv_strcat ( cbuf , uscript_getShortName ( code [ j ] ) ) ;
uprv_strcat ( cbuf , " :] " ) ;
u_uastrcpy ( ubuf , cbuf ) ;
codeSets [ j ] = uset_openPattern ( ubuf , - 1 , & ec ) ;
}
if ( ! assertSuccess ( " uset_openPattern " , & ec ) ) goto END ;
existsInScript = FALSE ;
itemCount = uset_getItemCount ( exemplarSet ) ;
for ( m = 0 ; m < itemCount & & ! existsInScript ; + + m ) {
strLen = uset_getItem ( exemplarSet , m , & start , & end , ubuf ,
sizeof ( ubuf ) / sizeof ( ubuf [ 0 ] ) , & ec ) ;
/* failure here might mean str[] needs to be larger */
if ( ! assertSuccess ( " uset_getItem " , & ec ) ) goto END ;
if ( strLen = = 0 ) {
for ( j = 0 ; j < codeLen ; + + j ) {
2005-12-27 22:23:05 +00:00
if ( codeSets [ j ] ! = NULL & & uset_containsRange ( codeSets [ j ] , start , end ) ) {
2004-09-03 20:51:11 +00:00
existsInScript = TRUE ;
break ;
}
}
} else {
for ( j = 0 ; j < codeLen ; + + j ) {
2005-12-27 22:23:05 +00:00
if ( codeSets [ j ] ! = NULL & & uset_containsString ( codeSets [ j ] , ubuf , strLen ) ) {
2004-09-03 20:51:11 +00:00
existsInScript = TRUE ;
break ;
}
}
}
}
if ( existsInScript = = FALSE ) {
2005-03-22 01:38:18 +00:00
log_err ( " ExemplarSet containment failed for locale : %s \n " , locale ) ;
2004-09-03 20:51:11 +00:00
}
}
assertTrue ( " case-folded is a superset " ,
uset_containsAll ( exemplarSets [ 1 ] , exemplarSets [ 0 ] ) ) ;
if ( uset_equals ( exemplarSets [ 1 ] , exemplarSets [ 0 ] ) ) {
+ + equalCount ;
}
}
/* Note: The case-folded set should sometimes be a strict superset
and sometimes be equal . */
assertTrue ( " case-folded is sometimes a strict superset, and sometimes equal " ,
equalCount > 0 & & equalCount < n ) ;
2009-02-21 00:31:21 +00:00
2004-09-03 20:51:11 +00:00
END :
uenum_close ( avail ) ;
uset_close ( exemplarSets [ 0 ] ) ;
uset_close ( exemplarSets [ 1 ] ) ;
2005-11-17 21:40:18 +00:00
uset_close ( unassignedSet ) ;
2004-09-03 20:51:11 +00:00
for ( i = 0 ; i < MAX_SCRIPTS_PER_LOCALE ; + + i ) {
uset_close ( codeSets [ i ] ) ;
}
}
2009-02-21 00:31:21 +00:00
static void TestLocaleDisplayPattern ( void ) {
UErrorCode status = U_ZERO_ERROR ;
UChar pattern [ 32 ] = { 0 , } ;
UChar separator [ 32 ] = { 0 , } ;
ULocaleData * uld = ulocdata_open ( uloc_getDefault ( ) , & status ) ;
if ( U_FAILURE ( status ) ) {
2010-07-14 16:09:03 +00:00
log_data_err ( " ulocdata_open error " ) ;
2009-02-21 00:31:21 +00:00
return ;
}
ulocdata_getLocaleDisplayPattern ( uld , pattern , 32 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ulocdata_getLocaleDisplayPattern error! " ) ;
}
status = U_ZERO_ERROR ;
ulocdata_getLocaleSeparator ( uld , separator , 32 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ulocdata_getLocaleSeparator error! " ) ;
}
ulocdata_close ( uld ) ;
}
2005-07-14 23:24:38 +00:00
static void TestCoverage ( void ) {
ULocaleDataDelimiterType types [ ] = {
ULOCDATA_QUOTATION_START , /* Quotation start */
ULOCDATA_QUOTATION_END , /* Quotation end */
ULOCDATA_ALT_QUOTATION_START , /* Alternate quotation start */
ULOCDATA_ALT_QUOTATION_END , /* Alternate quotation end */
ULOCDATA_DELIMITER_COUNT
} ;
int i ;
UBool sub ;
UErrorCode status = U_ZERO_ERROR ;
ULocaleData * uld = ulocdata_open ( uloc_getDefault ( ) , & status ) ;
if ( U_FAILURE ( status ) ) {
2010-07-14 16:09:03 +00:00
log_data_err ( " ulocdata_open error " ) ;
2005-07-14 23:24:38 +00:00
return ;
}
for ( i = 0 ; i < ULOCDATA_DELIMITER_COUNT ; i + + ) {
UChar result [ 32 ] = { 0 , } ;
2006-03-23 05:53:36 +00:00
status = U_ZERO_ERROR ;
2005-07-14 23:24:38 +00:00
ulocdata_getDelimiter ( uld , types [ i ] , result , 32 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ulocdata_getgetDelimiter error with type %d " , types [ i ] ) ;
}
}
sub = ulocdata_getNoSubstitute ( uld ) ;
ulocdata_setNoSubstitute ( uld , sub ) ;
ulocdata_close ( uld ) ;
}
2011-02-25 22:21:30 +00:00
static void TestIndexChars ( void ) {
/* Very basic test of ULOCDATA_ES_INDEX.
* No comprehensive test of data , just basic check that the code path is alive .
*/
UErrorCode status = U_ZERO_ERROR ;
ULocaleData * uld ;
USet * exemplarChars ;
USet * indexChars ;
uld = ulocdata_open ( " en " , & status ) ;
exemplarChars = uset_openEmpty ( ) ;
indexChars = uset_openEmpty ( ) ;
ulocdata_getExemplarSet ( uld , exemplarChars , 0 , ULOCDATA_ES_STANDARD , & status ) ;
ulocdata_getExemplarSet ( uld , indexChars , 0 , ULOCDATA_ES_INDEX , & status ) ;
if ( U_FAILURE ( status ) ) {
2011-03-03 19:29:57 +00:00
log_data_err ( " File %s, line %d, Failure opening exemplar chars: %s " , __FILE__ , __LINE__ , u_errorName ( status ) ) ;
2011-02-25 22:21:30 +00:00
goto close_sets ;
}
/* en data, standard exemplars are [a-z], lower case. */
/* en data, index characters are [A-Z], upper case. */
if ( ( uset_contains ( exemplarChars , ( UChar32 ) 0x41 ) | | uset_contains ( indexChars , ( UChar32 ) 0x61 ) ) ) {
log_err ( " File %s, line %d, Exemplar characters incorrect. " , __FILE__ , __LINE__ ) ;
goto close_sets ;
}
if ( ! ( uset_contains ( exemplarChars , ( UChar32 ) 0x61 ) & & uset_contains ( indexChars , ( UChar32 ) 0x41 ) ) ) {
log_err ( " File %s, line %d, Exemplar characters incorrect. " , __FILE__ , __LINE__ ) ;
goto close_sets ;
}
close_sets :
uset_close ( exemplarChars ) ;
uset_close ( indexChars ) ;
ulocdata_close ( uld ) ;
}
2012-10-18 19:51:28 +00:00
# if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
2005-06-16 21:04:40 +00:00
static void TestCurrencyList ( void ) {
2005-07-09 03:15:06 +00:00
# if !UCONFIG_NO_FORMATTING
2005-06-16 21:04:40 +00:00
UErrorCode errorCode = U_ZERO_ERROR ;
int32_t structLocaleCount , currencyCount ;
UEnumeration * en = ucurr_openISOCurrencies ( UCURR_ALL , & errorCode ) ;
const char * isoCode , * structISOCode ;
UResourceBundle * subBundle ;
UResourceBundle * currencies = ures_openDirect ( loadTestData ( & errorCode ) , " structLocale " , & errorCode ) ;
if ( U_FAILURE ( errorCode ) ) {
log_data_err ( " Can't open structLocale \n " ) ;
return ;
}
currencies = ures_getByKey ( currencies , " Currencies " , currencies , & errorCode ) ;
currencyCount = uenum_count ( en , & errorCode ) ;
structLocaleCount = ures_getSize ( currencies ) ;
if ( currencyCount ! = structLocaleCount ) {
log_err ( " structLocale(%d) and ISO4217(%d) currency list are out of sync. \n " , structLocaleCount , currencyCount ) ;
# if U_CHARSET_FAMILY == U_ASCII_FAMILY
ures_resetIterator ( currencies ) ;
while ( ( isoCode = uenum_next ( en , NULL , & errorCode ) ) ! = NULL & & ures_hasNext ( currencies ) ) {
subBundle = ures_getNextResource ( currencies , NULL , & errorCode ) ;
structISOCode = ures_getKey ( subBundle ) ;
ures_close ( subBundle ) ;
if ( strcmp ( structISOCode , isoCode ) ! = 0 ) {
log_err ( " First difference found at structLocale(%s) and ISO4217(%s). \n " , structISOCode , isoCode ) ;
break ;
}
}
# endif
}
ures_close ( currencies ) ;
uenum_close ( en ) ;
2005-07-09 03:15:06 +00:00
# endif
2005-06-16 21:04:40 +00:00
}
2012-10-18 19:51:28 +00:00
# endif
2005-06-16 21:04:40 +00:00
2011-04-04 15:00:03 +00:00
static void TestAvailableIsoCodes ( void ) {
2011-08-13 02:45:09 +00:00
# if !UCONFIG_NO_FORMATTING
2011-04-04 15:00:03 +00:00
UErrorCode errorCode = U_ZERO_ERROR ;
2011-04-06 18:45:24 +00:00
const char * eurCode = " EUR " ;
const char * usdCode = " USD " ;
const char * lastCode = " RHD " ;
const char * zzzCode = " ZZZ " ;
2011-04-04 15:00:03 +00:00
UDate date1950 = ( UDate ) - 630720000000.0 ; /* year 1950 */
UDate date1970 = ( UDate ) 0.0 ; /* year 1970 */
UDate date1975 = ( UDate ) 173448000000.0 ; /* year 1975 */
UDate date1978 = ( UDate ) 260172000000.0 ; /* year 1978 */
UDate date1981 = ( UDate ) 346896000000.0 ; /* year 1981 */
UDate date1992 = ( UDate ) 693792000000.0 ; /* year 1992 */
2011-04-06 18:45:24 +00:00
UChar * isoCode = ( UChar * ) malloc ( sizeof ( UChar ) * ( uprv_strlen ( usdCode ) + 1 ) ) ;
2011-04-04 15:00:03 +00:00
/* testing available codes with no time ranges */
2011-04-06 21:45:44 +00:00
u_charsToUChars ( eurCode , isoCode , uprv_strlen ( usdCode ) + 1 ) ;
2011-04-04 15:00:03 +00:00
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , U_DATE_MAX , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) is not found. \n " , eurCode ) ;
2011-04-04 15:00:03 +00:00
}
2011-04-06 21:45:44 +00:00
u_charsToUChars ( usdCode , isoCode , uprv_strlen ( zzzCode ) + 1 ) ;
2011-04-04 15:00:03 +00:00
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , U_DATE_MAX , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) is not found. \n " , usdCode ) ;
2011-04-04 15:00:03 +00:00
}
2011-04-06 21:45:44 +00:00
u_charsToUChars ( zzzCode , isoCode , uprv_strlen ( zzzCode ) + 1 ) ;
2011-04-04 15:00:03 +00:00
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , U_DATE_MAX , & errorCode ) = = TRUE ) {
log_err ( " FAIL: ISO code (%s) is reported as available, but it doesn't exist. \n " , zzzCode ) ;
}
2011-04-06 21:45:44 +00:00
u_charsToUChars ( lastCode , isoCode , uprv_strlen ( zzzCode ) + 1 ) ;
2011-04-04 15:00:03 +00:00
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , U_DATE_MAX , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) is not found. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
/* RHD was used from 1970-02-17 to 1980-04-18*/
/* to = null */
if ( ucurr_isAvailable ( isoCode , date1970 , U_DATE_MAX , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range >1970-01-01. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1975 , U_DATE_MAX , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range >1975. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1981 , U_DATE_MAX , & errorCode ) = = TRUE ) {
log_err ( " FAIL: ISO code (%s) was not available in time range >1981. \n " , lastCode ) ;
}
/* from = null */
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , date1970 , & errorCode ) = = TRUE ) {
log_err ( " FAIL: ISO code (%s) was not available in time range <1970. \n " , lastCode ) ;
}
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , date1975 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range <1975. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , U_DATE_MIN , date1981 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range <1981. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
/* full ranges */
if ( ucurr_isAvailable ( isoCode , date1975 , date1978 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range 1975-1978. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1970 , date1975 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range 1970-1975. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1975 , date1981 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range 1975-1981. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1970 , date1981 , & errorCode ) = = FALSE ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: ISO code (%s) was available in time range 1970-1981. \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
if ( ucurr_isAvailable ( isoCode , date1981 , date1992 , & errorCode ) = = TRUE ) {
log_err ( " FAIL: ISO code (%s) was not available in time range 1981-1992. \n " , lastCode ) ;
}
if ( ucurr_isAvailable ( isoCode , date1950 , date1970 , & errorCode ) = = TRUE ) {
log_err ( " FAIL: ISO code (%s) was not available in time range 1950-1970. \n " , lastCode ) ;
}
/* wrong range - from > to*/
if ( ucurr_isAvailable ( isoCode , date1975 , date1970 , & errorCode ) = = TRUE ) {
log_err ( " FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported. \n " , lastCode ) ;
} else if ( errorCode ! = U_ILLEGAL_ARGUMENT_ERROR ) {
2011-05-10 22:01:46 +00:00
log_data_err ( " FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s). \n " , lastCode ) ;
2011-04-04 15:00:03 +00:00
}
free ( isoCode ) ;
2011-08-13 02:45:09 +00:00
# endif
2011-04-04 15:00:03 +00:00
}
2004-09-03 20:51:11 +00:00
# define TESTCASE(name) addTest(root, &name, "tsutil / cldrtest / " #name)
void addCLDRTest ( TestNode * * root ) ;
void addCLDRTest ( TestNode * * root )
{
2009-08-04 21:09:17 +00:00
# if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
2004-09-03 20:51:11 +00:00
TESTCASE ( TestLocaleStructure ) ;
2009-08-04 21:09:17 +00:00
TESTCASE ( TestCurrencyList ) ;
# endif
2004-09-03 20:51:11 +00:00
TESTCASE ( TestConsistentCountryInfo ) ;
TESTCASE ( VerifyTranslation ) ;
TESTCASE ( TestExemplarSet ) ;
2009-02-21 00:31:21 +00:00
TESTCASE ( TestLocaleDisplayPattern ) ;
2005-07-14 23:24:38 +00:00
TESTCASE ( TestCoverage ) ;
2011-02-25 22:21:30 +00:00
TESTCASE ( TestIndexChars ) ;
2011-04-04 15:00:03 +00:00
TESTCASE ( TestAvailableIsoCodes ) ;
2004-09-03 20:51:11 +00:00
}
2011-02-25 22:21:30 +00:00