+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2014, International Business Machines Corporation
+ * Copyright (c) 1997-2016, International Business Machines Corporation
* and others. All Rights Reserved.
********************************************************************/
/*******************************************************************************
#include "unicode/uloc.h"
#include "unicode/unum.h"
#include "unicode/ustring.h"
+#include "unicode/putil.h"
#include "cintltst.h"
#include "cnmdptst.h"
#include "cmemory.h"
#define CHECK(status,str) if (U_FAILURE(status)) { log_err("FAIL: %s\n", str); return; }
void addNumFrDepTest(TestNode** root);
-static void TestCurrencyPreEuro(void);
static void TestCurrencyObject(void);
void addNumFrDepTest(TestNode** root)
addTest(root, &TestExponential, "tsformat/cnmdptst/TestExponential");
addTest(root, &TestCurrencySign, "tsformat/cnmdptst/TestCurrencySign");
addTest(root, &TestCurrency, "tsformat/cnmdptst/TestCurrency");
- addTest(root, &TestCurrencyPreEuro, "tsformat/cnmdptst/TestCurrencyPreEuro");
addTest(root, &TestCurrencyObject, "tsformat/cnmdptst/TestCurrencyObject");
addTest(root, &TestRounding487, "tsformat/cnmdptst/TestRounding487");
addTest(root, &TestDoubleAttribute, "tsformat/cnmdptst/TestDoubleAttribute");
UChar *str=NULL;
UErrorCode status = U_ZERO_ERROR;
const char* pat[] = { "#.#", "#.", ".#", "#" };
- const char* newpat[] = { "#0.#", "#0.", "#.0", "#" };
+ const char* newpat[] = { "0.#", "0.", "#.0", "0" };
const char* num[] = { "0", "0.", ".0", "0" };
log_verbose("\nTesting different format patterns\n");
- pat_length = sizeof(pat) / sizeof(pat[0]);
+ pat_length = UPRV_LENGTHOF(pat);
for (i=0; i < pat_length; ++i)
{
status = U_ZERO_ERROR;
};
- pat_length = sizeof(pat) / sizeof(pat[0]);
- val_length = sizeof(val) / sizeof(val[0]);
- lval_length = sizeof(lval) / sizeof(lval[0]);
+ pat_length = UPRV_LENGTHOF(pat);
+ val_length = UPRV_LENGTHOF(val);
+ lval_length = UPRV_LENGTHOF(lval);
ival = 0;
ilval = 0;
for (p=0; p < pat_length; ++p)
fmt=unum_open(UNUM_IGNORE,upat, u_strlen(upat), "en_US",NULL, &status);
if (U_FAILURE(status)) {
log_err_status(status, "FAIL: Bad status returned by Number format construction with pattern %s -> %s\n", pat[p], u_errorName(status));
+ free(upat);
+ upat = NULL;
continue;
}
lneed= u_strlen(upat) + 1;
UFieldPosition pos;
UChar res[100];
UErrorCode status = U_ZERO_ERROR;
- const char* locale[]={"fr_CA", "de_DE_PREEURO", "fr_FR_PREEURO"};
+ const char* locale[]={"fr_CA", "de_DE@currency=DEM", "fr_FR@currency=FRF"};
const char* result[]={"1,50\\u00a0$", "1,50\\u00a0DM", "1,50\\u00a0F"};
log_verbose("\nTesting the number format with different currency patterns\n");
for(i=0; i < 3; i++)
free(str);
}
}
-/**
- * Test localized currency patterns for PREEURO variants.
- */
-static void TestCurrencyPreEuro(void)
-{
- UNumberFormat *currencyFmt;
- UChar *str=NULL, *res=NULL;
- int32_t lneed, i;
- UFieldPosition pos;
- UErrorCode status = U_ZERO_ERROR;
-
- const char* locale[]={
- "ca_ES_PREEURO", "de_LU_PREEURO", "en_IE_PREEURO", "fi_FI_PREEURO", "fr_LU_PREEURO", "it_IT_PREEURO",
- "pt_PT_PREEURO", "de_AT_PREEURO", "el_GR_PREEURO", "es_ES_PREEURO", "fr_BE_PREEURO", "ga_IE_PREEURO",
- "nl_BE_PREEURO", "de_DE_PREEURO", "en_BE_PREEURO", "eu_ES_PREEURO", "fr_FR_PREEURO", "gl_ES_PREEURO",
- "nl_NL_PREEURO",
- };
-
- const char* result[]={
- "\\u20A7\\u00A02", "2\\u00A0F", "IEP1.50", "1,50\\u00A0mk", "2\\u00A0F", "ITL\\u00A02",
- "1$50\\u00A0\\u200B", "\\u00F6S\\u00A01,50", "1,50\\u00A0\\u0394\\u03C1\\u03C7", "2\\u00A0\\u20A7", "1,50\\u00A0FB", "IEP1.50",
- "1,50\\u00A0BEF", "1,50\\u00A0DM", "1,50\\u00A0BEF", "\\u20A7\\u00A02", "1,50\\u00A0F", "2\\u00A0\\u20A7",
- "NLG\\u00A01,50"
- };
-
- log_verbose("\nTesting the number format with different currency patterns\n");
- for(i=0; i < 19; i++)
- {
- char curID[256] = {0};
- uloc_canonicalize(locale[i], curID, 256, &status);
- if(U_FAILURE(status)){
- log_data_err("Could not canonicalize %s. Error: %s (Are you missing data?)\n", locale[i], u_errorName(status));
- continue;
- }
- currencyFmt = unum_open(UNUM_CURRENCY, NULL,0,curID,NULL, &status);
-
- if(U_FAILURE(status)){
- log_data_err("Error in the construction of number format with style currency: %s (Are you missing data?)\n",
- myErrorName(status));
- } else {
- lneed=0;
- lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status);
-
- if(status==U_BUFFER_OVERFLOW_ERROR){
- status=U_ZERO_ERROR;
- str=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
- pos.field = 0;
- unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status);
- }
-
- if(U_FAILURE(status)) {
- log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) );
- } else {
- res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) );
- u_unescape(result[i],res,(int32_t)(strlen(result[i])+1));
-
- if (u_strcmp(str, res) != 0){
- log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]);
- }
- }
- }
-
- unum_close(currencyFmt);
- free(str);
- free(res);
- }
-}
/**
* Test currency "object" (we use this name to match the other C++
};
const char* result[]={
- "1\\u00A0234,56\\u00A0\\u20AC",
- "1\\u00A0235\\u00A0JPY",
+ "1\\u202F234,56\\u00A0\\u20AC",
+ "1\\u202F235\\u00A0JPY",
};
log_verbose("\nTesting the number format with different currency codes\n");
u_uastrcpy(buffer, "12,34,56,789");
if ((u_strcmp(resultBuffer, buffer) != 0) || U_FAILURE(status))
{
- log_err("Fail: Formatting \"#,##,###\" pattern with 123456789 got %s, expected %s\n", resultBuffer, "12,34,56,789");
+ log_err("Fail: Formatting \"#,##,###\" pattern with 123456789 got %s, expected %s\n", austrdup(resultBuffer), "12,34,56,789");
}
if (pos.beginIndex != 0 && pos.endIndex != 12) {
log_err("Fail: Formatting \"#,##,###\" pattern pos = (%d, %d) expected pos = (0, 12)\n", pos.beginIndex, pos.endIndex);
}
memset(resultBuffer,0, sizeof(UChar)*512);
unum_toPattern(f, FALSE, resultBuffer, 512, &status);
- u_uastrcpy(buffer, "#,##,###");
+ u_uastrcpy(buffer, "#,##,##0");
if ((u_strcmp(resultBuffer, buffer) != 0) || U_FAILURE(status))
{
- log_err("Fail: toPattern() got %s, expected %s\n", resultBuffer, "#,##,###");
+ log_err("Fail: toPattern() got %s, expected %s\n", austrdup(resultBuffer), "#,##,##0");
}
memset(resultBuffer,0, sizeof(UChar)*512);
u_uastrcpy(buffer, "#,###");
u_uastrcpy(buffer, "12,3456,789");
if ((u_strcmp(resultBuffer, buffer) != 0) || U_FAILURE(status))
{
- log_err("Fail: Formatting \"#,###\" pattern with 123456789 got %s, expected %s\n", resultBuffer, "12,3456,789");
+ log_err("Fail: Formatting \"#,###\" pattern with 123456789 got %s, expected %s\n", austrdup(resultBuffer), "12,3456,789");
}
memset(resultBuffer,0, sizeof(UChar)*512);
unum_toPattern(f, FALSE, resultBuffer, 512, &status);
- u_uastrcpy(buffer, "#,####,###");
+ u_uastrcpy(buffer, "#,####,##0");
if ((u_strcmp(resultBuffer, buffer) != 0) || U_FAILURE(status))
{
- log_err("Fail: toPattern() got %s, expected %s\n", resultBuffer, "#,####,###");
+ log_err("Fail: toPattern() got %s, expected %s\n", austrdup(resultBuffer), "#,####,##0");
}
memset(resultBuffer,0, sizeof(UChar)*512);
g = unum_open(UNUM_DECIMAL, NULL,0,"hi_IN",NULL, &status);
for(i = 0; i < noLocales; i++) {
strcpy(currLoc, uloc_getAvailable(i));
- for(j = 0; j < sizeof(currencies)/sizeof(currencies[0]); j++) {
+ for(j = 0; j < UPRV_LENGTHOF(currencies); j++) {
strcpy(locale, currLoc);
strcat(locale, "@currency=");
strcat(locale, currencies[j]);
}
static void TestGetKeywordValuesForLocale(void) {
-#define PREFERRED_SIZE 12
+#define PREFERRED_SIZE 15
#define MAX_NUMBER_OF_KEYWORDS 4
const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS] = {
{ "root", "USD", "USN", NULL },
{ "en@currency=CAD", "USD", "USN", NULL },
{ "fr@currency=zzz", "EUR", NULL, NULL },
{ "de_DE@currency=DEM", "EUR", NULL, NULL },
+ { "en_US@rg=THZZZZ", "THB", NULL, NULL },
+ { "de@rg=USZZZZ", "USD", "USN", NULL },
+ { "en_US@currency=CAD;rg=THZZZZ", "THB", NULL, NULL },
};
const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = {
- 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1
+ 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1
+ };
+ /* ucurr_forLocale results for same locales; "" if no result expected */
+ const char *FORLOCALE[PREFERRED_SIZE] = {
+ "", "", "USD", "",
+ "THB", "", "EUR", "",
+ "ILS", "CAD", "ZZZ", "DEM",
+ "THB", "USD", "CAD"
};
UErrorCode status = U_ZERO_ERROR;
int32_t i, j, size;
}
for (i = 0; i < PREFERRED_SIZE; i++) {
+ UChar getCurrU[4];
+ int32_t getCurrLen;
+
+ status = U_ZERO_ERROR;
pref = NULL;
all = NULL;
loc = PREFERRED[i][0];
ALLList = ulist_getListFromEnum(ALL);
for (j = 0; j < size; j++) {
if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
- if (!ulist_containsString(ALLList, value, uprv_strlen(value))) {
+ if (!ulist_containsString(ALLList, value, (int32_t)uprv_strlen(value))) {
log_err("Locale %s have %s not in ALL\n", loc, value);
matchAll = FALSE;
break;
}
uenum_close(all);
+
+ status = U_ZERO_ERROR;
+ getCurrLen = ucurr_forLocale(loc, getCurrU, 4, &status);
+ if(U_FAILURE(status)) {
+ if (FORLOCALE[i][0] != 0) {
+ log_err("ERROR: ucurr_forLocale %s, status %s\n", loc, u_errorName(status));
+ }
+ } else if (getCurrLen != 3) {
+ if (FORLOCALE[i][0] != 0 || getCurrLen != -1) {
+ log_err("ERROR: ucurr_forLocale %s, returned len %d\n", loc, getCurrLen);
+ }
+ } else {
+ char getCurrB[4];
+ u_UCharsToChars(getCurrU, getCurrB, 4);
+ if ( uprv_strncmp(getCurrB, FORLOCALE[i], 4) != 0 ) {
+ log_err("ERROR: ucurr_forLocale %s, expected %s, got %s\n", loc, FORLOCALE[i], getCurrB);
+ }
+ }
}
uenum_close(ALL);