mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 15:05:53 +00:00
ICU-8093 Add API function call ucurr_isAvailable() and changes for tests and data.
X-SVN-Rev: 29727
This commit is contained in:
parent
5eb8e3e2d8
commit
c00813396a
6 changed files with 553 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1996-2010, International Business Machines
|
||||
* Copyright (C) 1996-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*
|
||||
|
@ -37,6 +37,7 @@
|
|||
#include "unicode/utf.h"
|
||||
#include "unicode/uversion.h"
|
||||
#include "unicode/uconfig.h"
|
||||
#include "float.h"
|
||||
|
||||
/*!
|
||||
* \file
|
||||
|
@ -315,6 +316,13 @@ typedef double UDate;
|
|||
/** The number of milliseconds per day @stable ICU 2.0 */
|
||||
#define U_MILLIS_PER_DAY (86400000)
|
||||
|
||||
/** Maximum and minimum UDate value
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
#define U_DATE_MAX DBL_MAX
|
||||
#define U_DATE_MIN -U_DATE_MAX
|
||||
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
/* UClassID-based RTTI */
|
||||
|
|
|
@ -205,6 +205,11 @@ supplementalData:table(nofallback){
|
|||
}
|
||||
AQ{
|
||||
{
|
||||
id{"XXX"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
AR{
|
||||
|
@ -514,6 +519,20 @@ supplementalData:table(nofallback){
|
|||
-761470784,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"BEL"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"BEC"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
BF{
|
||||
{
|
||||
|
@ -672,6 +691,13 @@ supplementalData:table(nofallback){
|
|||
-1881407904,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"BOV"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
BR{
|
||||
{
|
||||
|
@ -945,6 +971,20 @@ supplementalData:table(nofallback){
|
|||
-336896224,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"CHE"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"CHW"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
CI{
|
||||
{
|
||||
|
@ -983,6 +1023,13 @@ supplementalData:table(nofallback){
|
|||
1272350048,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"CLF"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
CM{
|
||||
{
|
||||
|
@ -1001,6 +1048,13 @@ supplementalData:table(nofallback){
|
|||
413492000,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"CNX"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
CO{
|
||||
{
|
||||
|
@ -1010,6 +1064,13 @@ supplementalData:table(nofallback){
|
|||
1772027488,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"COU"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
CR{
|
||||
{
|
||||
|
@ -1259,6 +1320,13 @@ supplementalData:table(nofallback){
|
|||
1878994880,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"ECV"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
EE{
|
||||
{
|
||||
|
@ -1348,6 +1416,20 @@ supplementalData:table(nofallback){
|
|||
-1436161856,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"ESA"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"ESB"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
ET{
|
||||
{
|
||||
|
@ -2337,6 +2419,20 @@ supplementalData:table(nofallback){
|
|||
-1436161856,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"LUC"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"LUL"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
LV{
|
||||
{
|
||||
|
@ -2753,6 +2849,13 @@ supplementalData:table(nofallback){
|
|||
1032018048,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"MXV"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
MY{
|
||||
{
|
||||
|
@ -4018,6 +4121,20 @@ supplementalData:table(nofallback){
|
|||
694083168,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"USN"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"USS"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
UY{
|
||||
{
|
||||
|
@ -4038,6 +4155,13 @@ supplementalData:table(nofallback){
|
|||
-2893024,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"UYI"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
UZ{
|
||||
{
|
||||
|
@ -4269,6 +4393,13 @@ supplementalData:table(nofallback){
|
|||
594361536,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"ZAL"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
ZM{
|
||||
{
|
||||
|
@ -4356,6 +4487,113 @@ supplementalData:table(nofallback){
|
|||
}
|
||||
}
|
||||
}
|
||||
ZZ{
|
||||
{
|
||||
id{"XAG"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XAU"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XBA"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XBB"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XBC"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XBD"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XDR"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XEU"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XFO"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XFU"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XPD"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XPT"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XRE"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XTS"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
{
|
||||
id{"XXX"}
|
||||
from:intvector{ /** 9999-12-31 */
|
||||
58993,
|
||||
351827072,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Currency metadata. Unlike the "Currencies" element, this is
|
||||
|
|
|
@ -92,9 +92,41 @@ static const UChar CHOICE_FORMAT_MARK = 0x003D; // Equals sign
|
|||
|
||||
static const UChar EUR_STR[] = {0x0045,0x0055,0x0052,0};
|
||||
|
||||
// ISO codes mapping table
|
||||
static UHashtable* gIsoCodes = NULL;
|
||||
static UBool gIsoCodesInitialized = FALSE;
|
||||
|
||||
static UMTX gIsoCodesLock = NULL;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Code
|
||||
|
||||
/**
|
||||
* Cleanup callback func
|
||||
*/
|
||||
static UBool U_CALLCONV
|
||||
isoCodes_cleanup(void)
|
||||
{
|
||||
umtx_destroy(&gIsoCodesLock);
|
||||
|
||||
if (gIsoCodes != NULL) {
|
||||
uhash_close(gIsoCodes);
|
||||
gIsoCodes = NULL;
|
||||
}
|
||||
gIsoCodesInitialized = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleter for OlsonToMetaMappingEntry
|
||||
*/
|
||||
static void U_CALLCONV
|
||||
deleteIsoCodeEntry(void *obj) {
|
||||
IsoCodeEntry *entry = (IsoCodeEntry*)obj;
|
||||
uprv_free(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unfortunately, we have to convert the UChar* currency code to char*
|
||||
* to use it as a resource key.
|
||||
|
@ -1798,6 +1830,81 @@ ucurr_closeCurrencyList(UEnumeration *enumerator) {
|
|||
uprv_free(enumerator);
|
||||
}
|
||||
|
||||
static void U_CALLCONV
|
||||
ucurr_createCurrencyList(UErrorCode* status){
|
||||
UErrorCode localStatus = U_ZERO_ERROR;
|
||||
|
||||
// Look up the CurrencyMap element in the root bundle.
|
||||
UResourceBundle *rb = ures_openDirect(U_ICUDATA_CURR, CURRENCY_DATA, &localStatus);
|
||||
UResourceBundle *currencyMapArray = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
|
||||
|
||||
if (U_SUCCESS(localStatus)) {
|
||||
// process each entry in currency map
|
||||
for (int32_t i=0; i<ures_getSize(currencyMapArray); i++) {
|
||||
// get the currency resource
|
||||
UResourceBundle *currencyArray = ures_getByIndex(currencyMapArray, i, NULL, &localStatus);
|
||||
// process each currency
|
||||
if (U_SUCCESS(localStatus)) {
|
||||
for (int32_t j=0; j<ures_getSize(currencyArray); j++) {
|
||||
// get the currency resource
|
||||
UResourceBundle *currencyRes = ures_getByIndex(currencyArray, j, NULL, &localStatus);
|
||||
IsoCodeEntry *entry = (IsoCodeEntry*)uprv_malloc(sizeof(IsoCodeEntry));
|
||||
if (entry == NULL) {
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
// get the ISO code
|
||||
int32_t isoLength = 0;
|
||||
UResourceBundle *idRes = ures_getByKey(currencyRes, "id", NULL, &localStatus);
|
||||
if (idRes == NULL) {
|
||||
continue;
|
||||
}
|
||||
const UChar *isoCode = ures_getString(idRes, &isoLength, &localStatus);
|
||||
|
||||
// get the from date
|
||||
int32_t fromLength = 0;
|
||||
UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", NULL, &localStatus);
|
||||
const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
|
||||
int64_t currDate64 = (int64_t)fromArray[0] << 32;
|
||||
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
|
||||
UDate fromDate = (UDate)currDate64;
|
||||
UDate toDate = U_DATE_MAX;
|
||||
|
||||
if (ures_getSize(currencyRes)> 2) {
|
||||
int32_t toLength = 0;
|
||||
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", NULL, &localStatus);
|
||||
const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus);
|
||||
|
||||
currDate64 = (int64_t)toArray[0] << 32;
|
||||
currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
|
||||
toDate = (UDate)currDate64;
|
||||
|
||||
ures_close(toRes);
|
||||
}
|
||||
|
||||
ures_close(fromRes);
|
||||
ures_close(idRes);
|
||||
ures_close(currencyRes);
|
||||
|
||||
entry->isoCode = isoCode;
|
||||
entry->from = fromDate;
|
||||
entry->to = toDate;
|
||||
|
||||
uhash_put(gIsoCodes, (UChar *)isoCode, entry, &localStatus);
|
||||
}
|
||||
} else {
|
||||
*status = localStatus;
|
||||
}
|
||||
ures_close(currencyArray);
|
||||
}
|
||||
} else {
|
||||
*status = localStatus;
|
||||
}
|
||||
|
||||
ures_close(currencyMapArray);
|
||||
}
|
||||
|
||||
static const UEnumeration gEnumCurrencyList = {
|
||||
NULL,
|
||||
NULL,
|
||||
|
@ -1809,6 +1916,47 @@ static const UEnumeration gEnumCurrencyList = {
|
|||
};
|
||||
U_CDECL_END
|
||||
|
||||
U_CAPI UBool U_EXPORT2
|
||||
ucurr_isAvailable(const UChar* isoCode, UDate from, UDate to, UErrorCode* eErrorCode) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool initialized;
|
||||
UMTX_CHECK(&gIsoCodesLock, gIsoCodesInitialized, initialized);
|
||||
|
||||
if (!initialized) {
|
||||
umtx_lock(&gIsoCodesLock);
|
||||
gIsoCodes = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
umtx_unlock(&gIsoCodesLock);
|
||||
return FALSE;
|
||||
}
|
||||
uhash_setValueDeleter(gIsoCodes, deleteIsoCodeEntry);
|
||||
|
||||
ucurr_createCurrencyList(&status);
|
||||
if (U_FAILURE(status)) {
|
||||
umtx_unlock(&gIsoCodesLock);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gIsoCodesInitialized = TRUE;
|
||||
umtx_unlock(&gIsoCodesLock);
|
||||
}
|
||||
|
||||
umtx_lock(&gIsoCodesLock);
|
||||
IsoCodeEntry* result = (IsoCodeEntry *) uhash_get(gIsoCodes, isoCode);
|
||||
umtx_unlock(&gIsoCodesLock);
|
||||
|
||||
if (result == NULL) {
|
||||
return FALSE;
|
||||
} else if (from > to) {
|
||||
*eErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return FALSE;
|
||||
} else if ((from > result->to) || (to < result->from)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
U_CAPI UEnumeration * U_EXPORT2
|
||||
ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode) {
|
||||
UEnumeration *myEnum = NULL;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2002-2010, International Business Machines
|
||||
* Copyright (c) 2002-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
@ -243,6 +243,45 @@ typedef enum UCurrCurrencyType {
|
|||
U_STABLE UEnumeration * U_EXPORT2
|
||||
ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode);
|
||||
|
||||
typedef struct IsoCodeEntry {
|
||||
const UChar *isoCode; /* const because it's a reference to a resource bundle string. */
|
||||
UDate from;
|
||||
UDate to;
|
||||
} IsoCodeEntry;
|
||||
|
||||
/**
|
||||
* Queries if the given ISO 4217 3-letter code is available on the specified date range.
|
||||
*
|
||||
* Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
|
||||
*
|
||||
* When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time.
|
||||
* If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date.
|
||||
*
|
||||
* @param code
|
||||
* The ISO 4217 3-letter code.
|
||||
*
|
||||
* @param from
|
||||
* The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability
|
||||
* of the currency any date before 'to'
|
||||
*
|
||||
* @param to
|
||||
* The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of
|
||||
* the currency any date after 'from'
|
||||
*
|
||||
* @param errorCode
|
||||
* ICU error code
|
||||
*
|
||||
* @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range.
|
||||
*
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
U_DRAFT UBool U_EXPORT2
|
||||
ucurr_isAvailable(const UChar* isoCode,
|
||||
UDate from,
|
||||
UDate to,
|
||||
UErrorCode* eErrorCode);
|
||||
|
||||
|
||||
/**
|
||||
* Finds the number of valid currency codes for the
|
||||
* given locale and date.
|
||||
|
|
|
@ -1306,6 +1306,106 @@ static void TestCurrencyList(void){
|
|||
#endif
|
||||
}
|
||||
|
||||
static void TestAvailableIsoCodes(void){
|
||||
UErrorCode errorCode = U_ZERO_ERROR;
|
||||
UDate date = 1295568000000.0;
|
||||
char* eurCode = "EUR";
|
||||
char* usdCode = "USD";
|
||||
char* lastCode = "RHD";
|
||||
char* zzzCode = "ZZZ";
|
||||
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 */
|
||||
UChar* isoCode = (UChar*)malloc(sizeof(usdCode) + 1);
|
||||
UDate test = U_MILLIS_PER_SECOND;
|
||||
|
||||
/* testing available codes with no time ranges */
|
||||
u_charsToUChars(eurCode, isoCode, sizeof(usdCode));
|
||||
if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) is not found.\n", eurCode);
|
||||
}
|
||||
|
||||
u_charsToUChars(usdCode, isoCode, sizeof(zzzCode));
|
||||
if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) is not found.\n", usdCode);
|
||||
}
|
||||
|
||||
u_charsToUChars(zzzCode, isoCode, sizeof(zzzCode));
|
||||
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);
|
||||
}
|
||||
|
||||
u_charsToUChars(lastCode, isoCode, sizeof(zzzCode));
|
||||
if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) is not found.\n", lastCode);
|
||||
}
|
||||
|
||||
/* RHD was used from 1970-02-17 to 1980-04-18*/
|
||||
|
||||
/* to = null */
|
||||
if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
|
||||
}
|
||||
|
||||
if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
|
||||
}
|
||||
|
||||
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) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
|
||||
}
|
||||
|
||||
if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
|
||||
}
|
||||
|
||||
/* full ranges */
|
||||
if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
|
||||
}
|
||||
|
||||
if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
|
||||
}
|
||||
|
||||
if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
|
||||
}
|
||||
|
||||
if (ucurr_isAvailable(isoCode, date1970, date1981, &errorCode) == FALSE) {
|
||||
log_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
|
||||
}
|
||||
|
||||
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) {
|
||||
log_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
|
||||
}
|
||||
|
||||
free(isoCode);
|
||||
}
|
||||
|
||||
#define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
|
||||
|
||||
void addCLDRTest(TestNode** root);
|
||||
|
@ -1322,5 +1422,6 @@ void addCLDRTest(TestNode** root)
|
|||
TESTCASE(TestLocaleDisplayPattern);
|
||||
TESTCASE(TestCoverage);
|
||||
TESTCASE(TestIndexChars);
|
||||
TESTCASE(TestAvailableIsoCodes);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2011, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/*******************************************************************************
|
||||
|
@ -868,25 +868,25 @@ static void TestCurrencyKeywords(void)
|
|||
}
|
||||
|
||||
static void TestGetKeywordValuesForLocale(void) {
|
||||
#define PREFERRED_SIZE 13
|
||||
#define MAX_NUMBER_OF_KEYWORDS 3
|
||||
#define PREFERRED_SIZE 12
|
||||
#define MAX_NUMBER_OF_KEYWORDS 4
|
||||
const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS] = {
|
||||
{ "root", "USD", NULL },
|
||||
{ "und", "USD", NULL },
|
||||
{ "und_ZZ", "USD", NULL },
|
||||
{ "en_US", "USD", NULL },
|
||||
{ "en_029", "USD", NULL },
|
||||
{ "en_TH", "THB", NULL },
|
||||
{ "de", "EUR", NULL },
|
||||
{ "de_DE", "EUR", NULL },
|
||||
{ "ar", "EGP", NULL },
|
||||
{ "ar_PS", "JOD", "ILS" },
|
||||
{ "en@currency=CAD", "USD", NULL },
|
||||
{ "fr@currency=zzz", "EUR", NULL },
|
||||
{ "de_DE@currency=DEM", "EUR", NULL },
|
||||
{ "root", "USD", "USN", "USS" },
|
||||
{ "und", "USD", "USN", "USS" },
|
||||
/* { "und_ZZ", "USD", NULL, NULL }, -- temporaary remove as this locale now has 15 entries */
|
||||
{ "en_US", "USD", "USN", "USS" },
|
||||
{ "en_029", "USD", "USN", "USS" },
|
||||
{ "en_TH", "THB", NULL, NULL },
|
||||
{ "de", "EUR", NULL, NULL },
|
||||
{ "de_DE", "EUR", NULL, NULL },
|
||||
{ "ar", "EGP", NULL, NULL },
|
||||
{ "ar_PS", "JOD", "ILS", NULL },
|
||||
{ "en@currency=CAD", "USD", "USN", "USS" },
|
||||
{ "fr@currency=zzz", "EUR", NULL, NULL },
|
||||
{ "de_DE@currency=DEM", "EUR", NULL, NULL },
|
||||
};
|
||||
const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1
|
||||
3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 1, 1
|
||||
};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t i, j, size;
|
||||
|
|
Loading…
Add table
Reference in a new issue