2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2001-02-28 22:26:09 +00:00
|
|
|
* COPYRIGHT:
|
2001-03-21 19:46:49 +00:00
|
|
|
* Copyright (c) 1997-2001, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CNUMTST.C
|
|
|
|
*
|
|
|
|
* Madhu Katragadda Creation
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
|
|
|
|
* 07/15/99 helena Ported to HPUX 10/11 CC.
|
|
|
|
*********************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* C API TEST FOR NUMBER FORMAT */
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unum.h"
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
|
|
|
#include "cnumtst.h"
|
2001-06-01 17:17:21 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
|
2001-11-07 00:02:41 +00:00
|
|
|
#define LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
|
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
void addNumForTest(TestNode** root);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
void addNumForTest(TestNode** root)
|
|
|
|
{
|
|
|
|
addTest(root, &TestNumberFormat, "tsformat/cnumtst/TestNumberFormat");
|
2000-11-07 18:56:35 +00:00
|
|
|
addTest(root, &TestNumberFormatPadding, "tsformat/cnumtst/TestNumberFormatPadding");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
2001-11-07 00:02:41 +00:00
|
|
|
/** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
|
|
|
|
static int32_t ustrToAstr(const UChar* src, int32_t srcLength, char* dst, int32_t dstLength) {
|
2002-04-02 02:55:31 +00:00
|
|
|
static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
|
|
|
|
|
|
char *p = dst;
|
|
|
|
const char *e = p + dstLength;
|
|
|
|
if (srcLength < 0) {
|
|
|
|
const UChar* s = src;
|
2002-05-24 17:22:53 +00:00
|
|
|
while (*s) {
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
srcLength = (int32_t)(s - src);
|
2002-04-02 02:55:31 +00:00
|
|
|
}
|
|
|
|
while (p < e && --srcLength >= 0) {
|
|
|
|
UChar c = *src++;
|
|
|
|
if (c == 0xd || c == 0xa || c == 0x9 || (c>= 0x20 && c <= 0x7e)) {
|
|
|
|
*p++ = (char) c & 0x7f;
|
|
|
|
} else if (e - p >= 6) {
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'u';
|
|
|
|
*p++ = hex[(c >> 12) & 0xf];
|
|
|
|
*p++ = hex[(c >> 8) & 0xf];
|
|
|
|
*p++ = hex[(c >> 4) & 0xf];
|
|
|
|
*p++ = hex[c & 0xf];
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p < e) {
|
|
|
|
*p = 0;
|
|
|
|
}
|
2002-05-24 17:22:53 +00:00
|
|
|
return (int32_t)(p - dst);
|
2001-11-07 00:02:41 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* test Number Format API */
|
2000-11-07 18:56:35 +00:00
|
|
|
static void TestNumberFormat()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-08-14 17:13:09 +00:00
|
|
|
UChar *result=NULL;
|
2000-11-02 02:44:22 +00:00
|
|
|
UChar temp1[512];
|
2001-09-17 21:50:19 +00:00
|
|
|
UChar temp2[512];
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UChar temp[5];
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar prefix[5];
|
|
|
|
UChar suffix[5];
|
2000-05-25 01:10:55 +00:00
|
|
|
UChar symbol[20];
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t resultlength;
|
|
|
|
int32_t resultlengthneeded;
|
|
|
|
int32_t parsepos;
|
|
|
|
double d1;
|
|
|
|
int32_t l1;
|
|
|
|
double d = -10456.37;
|
|
|
|
int32_t l = 100000000;
|
|
|
|
UFieldPosition pos1;
|
|
|
|
UFieldPosition pos2;
|
|
|
|
int32_t numlocales;
|
2000-05-25 01:10:55 +00:00
|
|
|
int32_t i;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UNumberFormatAttribute attr;
|
2001-09-17 21:50:19 +00:00
|
|
|
UNumberFormatSymbol symType = UNUM_DECIMAL_SEPARATOR_SYMBOL;
|
2001-02-28 22:26:09 +00:00
|
|
|
int32_t newvalue;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UNumberFormatStyle style= UNUM_DEFAULT;
|
|
|
|
UNumberFormat *pattern;
|
2000-11-07 18:56:35 +00:00
|
|
|
UNumberFormat *def, *fr, *cur_def, *cur_fr, *per_def, *per_fr,
|
2001-11-07 00:02:41 +00:00
|
|
|
*cur_frpattern, *myclone, *spellout_def;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Testing unum_open() with various Numberformat styles and locales*/
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("Testing unum_open() with default style and locale\n");
|
2001-08-16 00:58:53 +00:00
|
|
|
def=unum_open(style, NULL,0,NULL, NULL,&status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error in creating NumberFormat default using unum_open(): %s\n", myErrorName(status));
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open() with french locale and default style(decimal)\n");
|
2001-08-16 00:58:53 +00:00
|
|
|
fr=unum_open(style,NULL,0, "fr_FR",NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat (french): %s\n", myErrorName(status));
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open(currency,NULL,status)\n");
|
|
|
|
style=UNUM_CURRENCY;
|
|
|
|
/* Can't hardcode the result to assume the default locale is "en_US". */
|
2001-08-16 00:58:53 +00:00
|
|
|
cur_def=unum_open(style, NULL,0,"en_US", NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat using \n unum_open(currency, NULL, &status) %s\n",
|
|
|
|
myErrorName(status) );
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open(currency, frenchlocale, status)\n");
|
2001-08-16 00:58:53 +00:00
|
|
|
cur_fr=unum_open(style,NULL,0, "fr_FR", NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat using unum_open(currency, french, &status): %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open(percent, NULL, status)\n");
|
|
|
|
style=UNUM_PERCENT;
|
2001-08-16 00:58:53 +00:00
|
|
|
per_def=unum_open(style,NULL,0, NULL,NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat using unum_open(percent, NULL, &status): %s\n", myErrorName(status));
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open(percent,frenchlocale, status)\n");
|
2001-08-16 00:58:53 +00:00
|
|
|
per_fr=unum_open(style, NULL,0,"fr_FR", NULL,&status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat using unum_open(percent, french, &status): %s\n", myErrorName(status));
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_open(spellout, NULL, status)");
|
|
|
|
style=UNUM_SPELLOUT;
|
2002-04-12 16:53:04 +00:00
|
|
|
spellout_def=unum_open(style, NULL, 0, "en_US", NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Error: could not create NumberFormat using unum_open(spellout, NULL, &status): %s\n", myErrorName(status));
|
2001-11-07 00:02:41 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
/* Testing unum_clone(..) */
|
|
|
|
log_verbose("\nTesting unum_clone(fmt, status)");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
myclone = unum_clone(def,&status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
log_err("Error: could not clone unum_clone(def, &status): %s\n", myErrorName(status));
|
|
|
|
else
|
2000-08-11 01:27:17 +00:00
|
|
|
{
|
2000-06-22 01:09:15 +00:00
|
|
|
log_verbose("unum_clone() successful\n");
|
2000-08-11 01:27:17 +00:00
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
|
|
|
/*Testing unum_getAvailable() and unum_countAvailable()*/
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
|
|
|
|
numlocales=unum_countAvailable();
|
|
|
|
if(numlocales < 0)
|
|
|
|
log_err("error in countAvailable");
|
|
|
|
else{
|
|
|
|
log_verbose("unum_countAvialable() successful\n");
|
|
|
|
log_verbose("The no: of locales where number formattting is applicable is %d\n", numlocales);
|
|
|
|
}
|
2000-06-22 01:09:15 +00:00
|
|
|
for(i=0;i<numlocales;i++)
|
2000-08-11 01:27:17 +00:00
|
|
|
{
|
2001-02-28 22:26:09 +00:00
|
|
|
log_verbose("%s\n", unum_getAvailable(i));
|
2000-08-11 01:27:17 +00:00
|
|
|
if (unum_getAvailable(i) == 0)
|
|
|
|
log_err("No locale for which number formatting patterns are applicable\n");
|
2001-02-28 22:26:09 +00:00
|
|
|
else
|
2000-08-11 01:27:17 +00:00
|
|
|
log_verbose("A locale %s for which number formatting patterns are applicable\n",unum_getAvailable(i));
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*Testing unum_format() and unum_formatdouble()*/
|
|
|
|
u_uastrcpy(temp1, "$100,000,000.00");
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
log_verbose("\nTesting unum_format() \n");
|
|
|
|
resultlength=0;
|
2001-03-08 23:41:16 +00:00
|
|
|
pos1.field = 0; /* Integer Section */
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlengthneeded=unum_format(cur_def, l, NULL, resultlength, &pos1, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
2000-11-07 18:56:35 +00:00
|
|
|
/* for (i = 0; i < 100000; i++) */
|
2000-11-02 02:44:22 +00:00
|
|
|
{
|
|
|
|
unum_format(cur_def, l, result, resultlength, &pos1, &status);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) );
|
|
|
|
}
|
|
|
|
if(u_strcmp(result, temp1)==0)
|
2000-11-02 02:44:22 +00:00
|
|
|
log_verbose("Pass: Number formatting using unum_format() successful\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
else
|
2000-11-02 02:44:22 +00:00
|
|
|
log_err("Fail: Error in number Formatting using unum_format()\n");
|
2001-03-08 23:41:16 +00:00
|
|
|
if(pos1.beginIndex == 1 && pos1.endIndex == 12)
|
|
|
|
log_verbose("Pass: Complete number formatting using unum_format() successful\n");
|
|
|
|
else
|
|
|
|
log_err("Fail: Error in complete number Formatting using unum_format()\nGot: b=%d end=%d\nExpected: b=1 end=12\n",
|
|
|
|
pos1.beginIndex, pos1.endIndex);
|
2001-02-28 22:26:09 +00:00
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_formatDouble()\n");
|
|
|
|
u_uastrcpy(temp1, "($10,456.37)");
|
|
|
|
resultlength=0;
|
2001-03-08 23:41:16 +00:00
|
|
|
pos2.field = 1; /* Fractional Section */
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlengthneeded=unum_formatDouble(cur_def, d, NULL, resultlength, &pos2, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
2000-11-07 18:56:35 +00:00
|
|
|
/* for (i = 0; i < 100000; i++) */
|
2000-11-02 02:44:22 +00:00
|
|
|
{
|
|
|
|
unum_formatDouble(cur_def, d, result, resultlength, &pos2, &status);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-02 02:44:22 +00:00
|
|
|
log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
if(u_strcmp(result, temp1)==0)
|
|
|
|
log_verbose("Pass: Number Formatting using unum_formatDouble() Successful\n");
|
|
|
|
else
|
2000-11-07 18:56:35 +00:00
|
|
|
log_err("FAIL: Error in number formatting using unum_formatDouble()\n");
|
2001-03-08 23:41:16 +00:00
|
|
|
if(pos2.beginIndex == 9 && pos2.endIndex == 11)
|
|
|
|
log_verbose("Pass: Complete number formatting using unum_format() successful\n");
|
|
|
|
else
|
|
|
|
log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=9 end=11",
|
|
|
|
pos1.beginIndex, pos1.endIndex);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Testing unum_parse() and unum_parseDouble() */
|
|
|
|
log_verbose("\nTesting unum_parseDouble()\n");
|
2000-10-25 16:57:32 +00:00
|
|
|
/* for (i = 0; i < 100000; i++)*/
|
2000-10-24 16:18:36 +00:00
|
|
|
{
|
2000-08-07 23:09:41 +00:00
|
|
|
parsepos=0;
|
|
|
|
d1=unum_parseDouble(cur_def, result, u_strlen(result), &parsepos, &status);
|
2000-10-24 16:18:36 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("parse failed. The error is : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d1!=d)
|
|
|
|
log_err("Fail: Error in parsing\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: parsing successful\n");
|
|
|
|
|
2000-10-24 16:18:36 +00:00
|
|
|
/* performance testing */
|
|
|
|
u_uastrcpy(temp1, "$462.12345");
|
|
|
|
resultlength=u_strlen(temp1);
|
2000-10-25 16:57:32 +00:00
|
|
|
/* for (i = 0; i < 100000; i++) */
|
2000-10-24 16:18:36 +00:00
|
|
|
{
|
|
|
|
parsepos=0;
|
|
|
|
d1=unum_parseDouble(cur_def, temp1, resultlength, &parsepos, &status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("parse failed. The error is : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d1!=462.12345)
|
|
|
|
log_err("Fail: Error in parsing\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: parsing successful\n");
|
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-07 23:09:41 +00:00
|
|
|
u_uastrcpy(temp1, "($10,456.3E1])");
|
|
|
|
parsepos=0;
|
|
|
|
d1=unum_parseDouble(cur_def, temp1, u_strlen(temp1), &parsepos, &status);
|
|
|
|
if(U_SUCCESS(status))
|
|
|
|
{
|
|
|
|
log_err("Error in unum_parseDouble(..., %s, ...): %s\n", temp1, myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log_verbose("\nTesting unum_format()\n");
|
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=0;
|
|
|
|
parsepos=0;
|
|
|
|
resultlengthneeded=unum_format(per_fr, l, NULL, resultlength, &pos1, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
2000-11-02 02:44:22 +00:00
|
|
|
/* for (i = 0; i < 100000; i++)*/
|
|
|
|
{
|
|
|
|
unum_format(per_fr, l, result, resultlength, &pos1, &status);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
|
|
|
|
}
|
2000-11-02 02:44:22 +00:00
|
|
|
|
|
|
|
|
2000-08-07 23:09:41 +00:00
|
|
|
log_verbose("\nTesting unum_parse()\n");
|
2000-10-25 16:57:32 +00:00
|
|
|
/* for (i = 0; i < 100000; i++) */
|
2000-10-24 16:18:36 +00:00
|
|
|
{
|
2000-08-07 23:09:41 +00:00
|
|
|
parsepos=0;
|
|
|
|
l1=unum_parse(per_fr, result, u_strlen(result), &parsepos, &status);
|
2000-10-24 16:18:36 +00:00
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("parse failed. The error is : %s\n", myErrorName(status));
|
|
|
|
}
|
2000-11-02 02:44:22 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if(l1!=l)
|
|
|
|
log_err("Fail: Error in parsing\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: parsing successful\n");
|
2000-11-02 02:44:22 +00:00
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* create a number format using unum_openPattern(....)*/
|
|
|
|
log_verbose("\nTesting unum_openPattern()\n");
|
|
|
|
u_uastrcpy(temp1, "#,##0.0#;(#,##0.0#)");
|
2001-08-16 00:58:53 +00:00
|
|
|
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), NULL, NULL,&status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-02 02:44:22 +00:00
|
|
|
log_err("error in unum_openPattern(): %s\n", myErrorName(status) );;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
log_verbose("Pass: unum_openPattern() works fine\n");
|
2000-11-02 02:44:22 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*test for unum_toPattern()*/
|
|
|
|
log_verbose("\nTesting unum_toPattern()\n");
|
|
|
|
resultlength=0;
|
|
|
|
resultlengthneeded=unum_toPattern(pattern, FALSE, NULL, resultlength, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_toPattern(pattern, FALSE, result, resultlength, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
2000-11-02 02:44:22 +00:00
|
|
|
{
|
|
|
|
if(u_strcmp(result, temp1)!=0)
|
|
|
|
log_err("FAIL: Error in extracting the pattern using unum_toPattern()\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: extracted the pattern correctly using unum_toPattern()\n");
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
2000-11-02 02:44:22 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*Testing unum_getSymbols() and unum_setSymbols()*/
|
|
|
|
log_verbose("\nTesting unum_getSymbols and unum_setSymbols()\n");
|
|
|
|
/*when we try to change the symbols of french to default we need to apply the pattern as well to fetch correct results */
|
|
|
|
resultlength=0;
|
|
|
|
resultlengthneeded=unum_toPattern(cur_def, FALSE, NULL, resultlength, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_toPattern(cur_def, FALSE, result, resultlength, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
|
2000-11-02 02:44:22 +00:00
|
|
|
status=U_ZERO_ERROR;
|
2001-08-16 00:58:53 +00:00
|
|
|
cur_frpattern=unum_open(UNUM_IGNORE,result, u_strlen(result), "fr_FR",NULL, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in unum_openPattern(): %s\n", myErrorName(status));
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*getting the symbols of cur_def */
|
2001-09-17 21:50:19 +00:00
|
|
|
/*set the symbols of cur_frpattern to cur_def */
|
|
|
|
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
|
|
|
|
unum_setSymbol(cur_frpattern, symType, temp1, -1, &status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("Error in get/set symbols: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*format to check the result */
|
|
|
|
resultlength=0;
|
|
|
|
resultlengthneeded=unum_format(cur_def, l, NULL, resultlength, &pos1, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_format(cur_def, l, result, resultlength, &pos1, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("Fail: error in unum_setSymbols: %s\n", myErrorName(status));
|
|
|
|
}
|
2001-08-16 00:58:53 +00:00
|
|
|
unum_applyPattern(cur_frpattern, FALSE, result, u_strlen(result),NULL,NULL);
|
2001-09-17 21:50:19 +00:00
|
|
|
|
|
|
|
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
|
|
|
|
unum_getSymbol(cur_frpattern, symType, temp2, sizeof(temp2), &status);
|
|
|
|
if(U_FAILURE(status) || u_strcmp(temp1, temp2) != 0)
|
|
|
|
{
|
|
|
|
log_err("Fail: error in getting symbols\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log_verbose("Pass: get and set symbols successful\n");
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*format and check with the previous result */
|
|
|
|
|
|
|
|
resultlength=0;
|
|
|
|
resultlengthneeded=unum_format(cur_frpattern, l, NULL, resultlength, &pos1, &status);
|
1999-10-07 00:07:53 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status=U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
resultlength=resultlengthneeded+1;
|
|
|
|
unum_format(cur_frpattern, l, temp1, resultlength, &pos1, &status);
|
|
|
|
}
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
|
|
|
|
}
|
2000-10-24 16:18:36 +00:00
|
|
|
/* TODO:
|
2000-05-30 17:21:22 +00:00
|
|
|
* This test fails because we have not called unum_applyPattern().
|
|
|
|
* Currently, such an applyPattern() does not exist on the C API, and
|
|
|
|
* we have jitterbug 411 for it.
|
|
|
|
* Since it is close to the 1.5 release, I (markus) am disabling this test just
|
|
|
|
* for this release (I added the test itself only last week).
|
|
|
|
* For the next release, we need to fix this.
|
|
|
|
* Then, remove the uprv_strcmp("1.5", ...) and this comment, and the include "cstring.h" at the beginning of this file.
|
|
|
|
*/
|
2000-07-21 23:27:47 +00:00
|
|
|
if(u_strcmp(result, temp1) != 0) {
|
2000-08-07 23:09:41 +00:00
|
|
|
log_err("Formatting failed after setting symbols. result=%s temp1=%s\n", result, temp1);
|
2000-05-25 01:10:55 +00:00
|
|
|
}
|
|
|
|
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*----------- */
|
2001-02-28 22:26:09 +00:00
|
|
|
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
2000-05-25 01:10:55 +00:00
|
|
|
|
|
|
|
/* Testing unum_get/setSymbol() */
|
|
|
|
for(i = 0; i < UNUM_FORMAT_SYMBOL_COUNT; ++i) {
|
|
|
|
symbol[0] = (UChar)(0x41 + i);
|
|
|
|
symbol[1] = (UChar)(0x61 + i);
|
2000-08-14 23:35:57 +00:00
|
|
|
unum_setSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, 2, &status);
|
2000-05-25 01:10:55 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
log_err("Error from unum_setSymbol(%d): %s\n", i, myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i = 0; i < UNUM_FORMAT_SYMBOL_COUNT; ++i) {
|
2000-08-14 23:35:57 +00:00
|
|
|
resultlength = unum_getSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
|
2000-05-25 01:10:55 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
log_err("Error from unum_getSymbol(%d): %s\n", i, myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(resultlength != 2 || symbol[0] != 0x41 + i || symbol[1] != 0x61 + i) {
|
|
|
|
log_err("Failure in unum_getSymbol(%d): got unexpected symbol\n", i);
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 01:09:15 +00:00
|
|
|
/*try getting from a bogus symbol*/
|
2000-08-14 23:35:57 +00:00
|
|
|
unum_getSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
|
2000-06-22 01:09:15 +00:00
|
|
|
if(U_SUCCESS(status)){
|
|
|
|
log_err("Error : Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol");
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
if(status != U_ILLEGAL_ARGUMENT_ERROR){
|
2001-02-28 22:26:09 +00:00
|
|
|
log_err("Error: Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol, Got %s\n", myErrorName(status));
|
2000-06-22 01:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
status=U_ZERO_ERROR;
|
2000-05-25 01:10:55 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Testing unum_getTextAttribute() and unum_setTextAttribute()*/
|
|
|
|
log_verbose("\nTesting getting and setting text attributes\n");
|
|
|
|
resultlength=5;
|
|
|
|
unum_getTextAttribute(cur_fr, UNUM_NEGATIVE_SUFFIX, temp, resultlength, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
unum_setTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, temp, u_strlen(temp), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
unum_getTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, suffix, resultlength, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if(u_strcmp(suffix,temp)!=0)
|
|
|
|
log_err("Fail:Error in setTextAttribute or getTextAttribute in setting and getting suffix\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: setting and getting suffix works fine\n");
|
|
|
|
/*set it back to normal */
|
|
|
|
u_uastrcpy(temp,"$");
|
|
|
|
unum_setTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, temp, u_strlen(temp), &status);
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*checking some more text setter conditions */
|
|
|
|
u_uastrcpy(prefix, "+");
|
|
|
|
unum_setTextAttribute(def, UNUM_POSITIVE_PREFIX, prefix, u_strlen(prefix) , &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in setting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
unum_getTextAttribute(def, UNUM_POSITIVE_PREFIX, temp, resultlength, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in getting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if(u_strcmp(prefix, temp)!=0)
|
|
|
|
log_err("ERROR: get and setTextAttributes with positive prefix failed\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: get and setTextAttributes with positive prefix works fine\n");
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_uastrcpy(prefix, "+");
|
|
|
|
unum_setTextAttribute(def, UNUM_NEGATIVE_PREFIX, prefix, u_strlen(prefix), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in setting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
unum_getTextAttribute(def, UNUM_NEGATIVE_PREFIX, temp, resultlength, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in getting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if(u_strcmp(prefix, temp)!=0)
|
|
|
|
log_err("ERROR: get and setTextAttributes with negative prefix failed\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: get and setTextAttributes with negative prefix works fine\n");
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_uastrcpy(suffix, "+");
|
|
|
|
unum_setTextAttribute(def, UNUM_NEGATIVE_SUFFIX, suffix, u_strlen(suffix) , &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in setting the text attributes: %s\n", myErrorName(status));
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_getTextAttribute(def, UNUM_NEGATIVE_SUFFIX, temp, resultlength, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("error in getting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if(u_strcmp(suffix, temp)!=0)
|
|
|
|
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
u_uastrcpy(suffix, "++");
|
|
|
|
unum_setTextAttribute(def, UNUM_POSITIVE_SUFFIX, suffix, u_strlen(suffix) , &status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("error in setting the text attributes: %s\n", myErrorName(status));
|
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
unum_getTextAttribute(def, UNUM_POSITIVE_SUFFIX, temp, resultlength, &status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("error in getting the text attributes : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
if(u_strcmp(suffix, temp)!=0)
|
|
|
|
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
|
2001-02-28 22:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*Testing unum_getAttribute and unum_setAttribute() */
|
|
|
|
log_verbose("\nTesting get and set Attributes\n");
|
|
|
|
attr=UNUM_GROUPING_SIZE;
|
|
|
|
newvalue=unum_getAttribute(def, attr);
|
|
|
|
newvalue=2;
|
|
|
|
unum_setAttribute(def, attr, newvalue);
|
|
|
|
if(unum_getAttribute(def,attr)!=2)
|
|
|
|
log_err("Fail: error in setting and getting attributes for UNUM_GROUPING_SIZE\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: setting and getting attributes for UNUM_GROUPING_SIZE works fine\n");
|
|
|
|
|
|
|
|
attr=UNUM_MULTIPLIER;
|
|
|
|
newvalue=unum_getAttribute(def, attr);
|
|
|
|
newvalue=8;
|
|
|
|
unum_setAttribute(def, attr, newvalue);
|
|
|
|
if(unum_getAttribute(def,attr) != 8)
|
|
|
|
log_err("error in setting and getting attributes for UNUM_MULTIPLIER\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass:setting and getting attributes for UNUM_MULTIPLIER works fine\n");
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*testing set and get Attributes extensively */
|
|
|
|
log_verbose("\nTesting get and set attributes extensively\n");
|
2000-11-07 18:56:35 +00:00
|
|
|
for(attr=UNUM_PARSE_INT_ONLY; attr<= UNUM_PADDING_POSITION; attr=(UNumberFormatAttribute)((int32_t)attr + 1) )
|
|
|
|
{
|
|
|
|
newvalue=unum_getAttribute(fr, attr);
|
|
|
|
unum_setAttribute(def, attr, newvalue);
|
|
|
|
if(unum_getAttribute(def,attr)!=unum_getAttribute(fr, attr))
|
|
|
|
log_err("error in setting and getting attributes\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: attributes set and retrieved successfully\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
/*testing spellout format to make sure we can use it successfully.*/
|
|
|
|
log_verbose("\nTesting spellout format\n");
|
2002-07-15 19:01:17 +00:00
|
|
|
if (spellout_def)
|
|
|
|
{
|
|
|
|
static const int32_t values[] = { 0, -5, 105, 1005, 105050 };
|
|
|
|
for (i = 0; i < LENGTH(values); ++i) {
|
|
|
|
UChar buffer[128];
|
|
|
|
int32_t len;
|
|
|
|
int32_t value = values[i];
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
len = unum_format(spellout_def, value, buffer, LENGTH(buffer), NULL, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
log_err("Error in formatting using unum_format(spellout_fmt, ...): %s\n", myErrorName(status));
|
|
|
|
} else {
|
|
|
|
int32_t pp = 0;
|
|
|
|
int32_t parseResult;
|
|
|
|
char logbuf[256];
|
|
|
|
ustrToAstr(buffer, len, logbuf, LENGTH(logbuf));
|
|
|
|
log_verbose("formatted %d as '%s', length: %d\n", value, logbuf, len);
|
|
|
|
|
|
|
|
parseResult = unum_parse(spellout_def, buffer, len, &pp, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error in parsing using unum_format(spellout_fmt, ...): %s\n", myErrorName(status));
|
|
|
|
} else if (parseResult != value) {
|
|
|
|
log_err("unum_format result %d != value %d\n", parseResult, value);
|
|
|
|
}
|
2002-04-02 02:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-15 19:01:17 +00:00
|
|
|
else {
|
|
|
|
log_err("Spellout format is unavailable\n");
|
2002-04-02 02:55:31 +00:00
|
|
|
}
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*closing the NumberFormat() using unum_close(UNumberFormat*)")*/
|
|
|
|
unum_close(def);
|
|
|
|
unum_close(fr);
|
|
|
|
unum_close(cur_def);
|
|
|
|
unum_close(cur_fr);
|
|
|
|
unum_close(per_def);
|
|
|
|
unum_close(per_fr);
|
2001-11-07 00:02:41 +00:00
|
|
|
unum_close(spellout_def);
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_close(pattern);
|
|
|
|
unum_close(cur_frpattern);
|
2000-07-06 23:01:50 +00:00
|
|
|
unum_close(myclone);
|
2001-02-28 22:26:09 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-07 18:56:35 +00:00
|
|
|
|
|
|
|
static void TestNumberFormatPadding()
|
|
|
|
{
|
|
|
|
UChar *result=NULL;
|
|
|
|
UChar temp1[512];
|
|
|
|
|
|
|
|
UErrorCode status=U_ZERO_ERROR;
|
|
|
|
int32_t resultlength;
|
|
|
|
int32_t resultlengthneeded;
|
|
|
|
UNumberFormat *pattern;
|
|
|
|
double d1;
|
|
|
|
double d = -10456.37;
|
2001-03-08 23:41:16 +00:00
|
|
|
UFieldPosition pos1;
|
2000-11-07 18:56:35 +00:00
|
|
|
int32_t parsepos;
|
|
|
|
|
|
|
|
/* create a number format using unum_openPattern(....)*/
|
|
|
|
log_verbose("\nTesting unum_openPattern() with padding\n");
|
|
|
|
u_uastrcpy(temp1, "*#,##0.0#*;(#,##0.0#)");
|
|
|
|
status=U_ZERO_ERROR;
|
2001-08-16 00:58:53 +00:00
|
|
|
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), NULL, NULL,&status);
|
2000-11-07 18:56:35 +00:00
|
|
|
if(U_SUCCESS(status))
|
|
|
|
{
|
|
|
|
log_err("error in unum_openPattern(%s): %s\n", temp1, myErrorName(status) );;
|
|
|
|
}
|
2000-12-14 01:19:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unum_close(pattern);
|
|
|
|
}
|
2000-11-07 18:56:35 +00:00
|
|
|
|
|
|
|
/* u_uastrcpy(temp1, "*x#,###,###,##0.0#;(*x#,###,###,##0.0#)"); */
|
2000-12-06 18:42:36 +00:00
|
|
|
u_uastrcpy(temp1, "*x#,###,###,##0.0#;*x(###,###,##0.0#)");
|
2000-11-07 18:56:35 +00:00
|
|
|
status=U_ZERO_ERROR;
|
2001-08-16 00:58:53 +00:00
|
|
|
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), "en_US",NULL, &status);
|
2000-11-07 18:56:35 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("error in padding unum_openPattern(%s): %s\n", temp1, myErrorName(status) );;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_verbose("Pass: padding unum_openPattern() works fine\n");
|
|
|
|
|
|
|
|
/*test for unum_toPattern()*/
|
|
|
|
log_verbose("\nTesting padding unum_toPattern()\n");
|
|
|
|
resultlength=0;
|
|
|
|
resultlengthneeded=unum_toPattern(pattern, FALSE, NULL, resultlength, &status);
|
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
|
|
|
{
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
2000-11-07 18:56:35 +00:00
|
|
|
unum_toPattern(pattern, FALSE, result, resultlength, &status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("error in extracting the padding pattern from UNumberFormat: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(u_strcmp(result, temp1)!=0)
|
|
|
|
log_err("FAIL: Error in extracting the padding pattern using unum_toPattern()\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: extracted the padding pattern correctly using unum_toPattern()\n");
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
2000-11-07 18:56:35 +00:00
|
|
|
}
|
|
|
|
/* u_uastrcpy(temp1, "(xxxxxxx10,456.37)"); */
|
2000-12-06 18:42:36 +00:00
|
|
|
u_uastrcpy(temp1, "xxxxx(10,456.37)");
|
2000-11-07 18:56:35 +00:00
|
|
|
resultlength=0;
|
2001-03-08 23:41:16 +00:00
|
|
|
pos1.field = 1; /* Fraction field */
|
|
|
|
resultlengthneeded=unum_formatDouble(pattern, d, NULL, resultlength, &pos1, &status);
|
2000-11-07 18:56:35 +00:00
|
|
|
if(status==U_BUFFER_OVERFLOW_ERROR)
|
|
|
|
{
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
resultlength=resultlengthneeded+1;
|
2001-06-01 17:17:21 +00:00
|
|
|
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
|
2001-03-08 23:41:16 +00:00
|
|
|
unum_formatDouble(pattern, d, result, resultlength, NULL, &status);
|
2000-11-07 18:56:35 +00:00
|
|
|
}
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("Error in formatting using unum_formatDouble(.....) with padding : %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
2000-12-14 01:19:54 +00:00
|
|
|
{
|
|
|
|
if(u_strcmp(result, temp1)==0)
|
|
|
|
log_verbose("Pass: Number Formatting using unum_formatDouble() padding Successful\n");
|
|
|
|
else
|
|
|
|
log_err("FAIL: Error in number formatting using unum_formatDouble() with padding\n");
|
2001-03-08 23:41:16 +00:00
|
|
|
if(pos1.beginIndex == 13 && pos1.endIndex == 15)
|
|
|
|
log_verbose("Pass: Complete number formatting using unum_formatDouble() successful\n");
|
|
|
|
else
|
|
|
|
log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=13 end=15\n",
|
|
|
|
pos1.beginIndex, pos1.endIndex);
|
2000-11-07 18:56:35 +00:00
|
|
|
|
|
|
|
|
2000-12-14 01:19:54 +00:00
|
|
|
/* Testing unum_parse() and unum_parseDouble() */
|
|
|
|
log_verbose("\nTesting padding unum_parseDouble()\n");
|
|
|
|
parsepos=0;
|
|
|
|
d1=unum_parseDouble(pattern, result, u_strlen(result), &parsepos, &status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("padding parse failed. The error is : %s\n", myErrorName(status));
|
|
|
|
}
|
2000-11-07 18:56:35 +00:00
|
|
|
|
2000-12-14 01:19:54 +00:00
|
|
|
if(d1!=d)
|
|
|
|
log_err("Fail: Error in padding parsing\n");
|
|
|
|
else
|
|
|
|
log_verbose("Pass: padding parsing successful\n");
|
2001-06-01 17:17:21 +00:00
|
|
|
uprv_free(result);
|
2000-12-14 01:19:54 +00:00
|
|
|
}
|
2000-11-07 18:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unum_close(pattern);
|
2000-11-30 20:55:12 +00:00
|
|
|
}
|
|
|
|
|