1
/********************************************************************
3
* Copyright (c) 1997-2001, International Business Machines Corporation and
4
* others. All Rights Reserved.
5
********************************************************************/
6
/********************************************************************************
10
* Madhu Katragadda Creation
12
* Modification History:
14
* Date Name Description
15
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
16
* 07/15/99 helena Ported to HPUX 10/11 CC.
17
*********************************************************************************
20
/* C API TEST FOR NUMBER FORMAT */
22
#include "unicode/uloc.h"
23
#include "unicode/utypes.h"
24
#include "unicode/unum.h"
25
#include "unicode/ustring.h"
30
#define LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
32
void addNumForTest(TestNode** root);
34
void addNumForTest(TestNode** root)
36
addTest(root, &TestNumberFormat, "tsformat/cnumtst/TestNumberFormat");
37
addTest(root, &TestNumberFormatPadding, "tsformat/cnumtst/TestNumberFormatPadding");
40
/** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
41
static int32_t ustrToAstr(const UChar* src, int32_t srcLength, char* dst, int32_t dstLength) {
42
static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
45
const char *e = p + dstLength;
51
while (p < e && --srcLength >= 0) {
53
if (c == 0xd || c == 0xa || c == 0x9 || (c>= 0x20 && c <= 0x7e)) {
54
*p++ = (char) c & 0x7f;
55
} else if (e - p >= 6) {
58
*p++ = hex[(c >> 12) & 0xf];
59
*p++ = hex[(c >> 8) & 0xf];
60
*p++ = hex[(c >> 4) & 0xf];
72
/* test Number Format API */
73
static void TestNumberFormat()
85
int32_t resultlengthneeded;
90
int32_t l = 100000000;
96
UNumberFormatAttribute attr;
97
UNumberFormatSymbol symType = UNUM_DECIMAL_SEPARATOR_SYMBOL;
99
UErrorCode status=U_ZERO_ERROR;
100
UNumberFormatStyle style= UNUM_DEFAULT;
101
UNumberFormat *pattern;
102
UNumberFormat *def, *fr, *cur_def, *cur_fr, *per_def, *per_fr,
103
*cur_frpattern, *myclone, *spellout_def;
105
/* Testing unum_open() with various Numberformat styles and locales*/
106
status = U_ZERO_ERROR;
107
log_verbose("Testing unum_open() with default style and locale\n");
108
def=unum_open(style, NULL,0,NULL, NULL,&status);
109
if(U_FAILURE(status))
110
log_err("Error in creating NumberFormat default using unum_open(): %s\n", myErrorName(status));
112
log_verbose("\nTesting unum_open() with french locale and default style(decimal)\n");
113
fr=unum_open(style,NULL,0, "fr_FR",NULL, &status);
114
if(U_FAILURE(status))
115
log_err("Error: could not create NumberFormat (french): %s\n", myErrorName(status));
117
log_verbose("\nTesting unum_open(currency,NULL,status)\n");
119
/* Can't hardcode the result to assume the default locale is "en_US". */
120
cur_def=unum_open(style, NULL,0,"en_US", NULL, &status);
121
if(U_FAILURE(status))
122
log_err("Error: could not create NumberFormat using \n unum_open(currency, NULL, &status) %s\n",
123
myErrorName(status) );
125
log_verbose("\nTesting unum_open(currency, frenchlocale, status)\n");
126
cur_fr=unum_open(style,NULL,0, "fr_FR", NULL, &status);
127
if(U_FAILURE(status))
128
log_err("Error: could not create NumberFormat using unum_open(currency, french, &status): %s\n",
129
myErrorName(status));
131
log_verbose("\nTesting unum_open(percent, NULL, status)\n");
133
per_def=unum_open(style,NULL,0, NULL,NULL, &status);
134
if(U_FAILURE(status))
135
log_err("Error: could not create NumberFormat using unum_open(percent, NULL, &status): %s\n", myErrorName(status));
137
log_verbose("\nTesting unum_open(percent,frenchlocale, status)\n");
138
per_fr=unum_open(style, NULL,0,"fr_FR", NULL,&status);
139
if(U_FAILURE(status))
140
log_err("Error: could not create NumberFormat using unum_open(percent, french, &status): %s\n", myErrorName(status));
142
log_verbose("\nTesting unum_open(spellout, NULL, status)");
144
spellout_def=unum_open(style, NULL, 0, "en_US", NULL, &status);
145
if(U_FAILURE(status))
146
log_err("Error: could not create NumberFormat using unum_open(spellout, NULL, &status): %s\n", myErrorName(status));
148
/* Testing unum_clone(..) */
149
log_verbose("\nTesting unum_clone(fmt, status)");
150
status = U_ZERO_ERROR;
151
myclone = unum_clone(def,&status);
152
if(U_FAILURE(status))
153
log_err("Error: could not clone unum_clone(def, &status): %s\n", myErrorName(status));
156
log_verbose("unum_clone() successful\n");
159
/*Testing unum_getAvailable() and unum_countAvailable()*/
160
log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
161
numlocales=unum_countAvailable();
163
log_err("error in countAvailable");
165
log_verbose("unum_countAvialable() successful\n");
166
log_verbose("The no: of locales where number formattting is applicable is %d\n", numlocales);
168
for(i=0;i<numlocales;i++)
170
log_verbose("%s\n", unum_getAvailable(i));
171
if (unum_getAvailable(i) == 0)
172
log_err("No locale for which number formatting patterns are applicable\n");
174
log_verbose("A locale %s for which number formatting patterns are applicable\n",unum_getAvailable(i));
178
/*Testing unum_format() and unum_formatdouble()*/
179
u_uastrcpy(temp1, "$100,000,000.00");
181
log_verbose("\nTesting unum_format() \n");
183
pos1.field = 0; /* Integer Section */
184
resultlengthneeded=unum_format(cur_def, l, NULL, resultlength, &pos1, &status);
185
if(status==U_BUFFER_OVERFLOW_ERROR)
188
resultlength=resultlengthneeded+1;
189
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
190
/* for (i = 0; i < 100000; i++) */
192
unum_format(cur_def, l, result, resultlength, &pos1, &status);
196
if(U_FAILURE(status))
198
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) );
200
if(u_strcmp(result, temp1)==0)
201
log_verbose("Pass: Number formatting using unum_format() successful\n");
203
log_err("Fail: Error in number Formatting using unum_format()\n");
204
if(pos1.beginIndex == 1 && pos1.endIndex == 12)
205
log_verbose("Pass: Complete number formatting using unum_format() successful\n");
207
log_err("Fail: Error in complete number Formatting using unum_format()\nGot: b=%d end=%d\nExpected: b=1 end=12\n",
208
pos1.beginIndex, pos1.endIndex);
213
log_verbose("\nTesting unum_formatDouble()\n");
214
u_uastrcpy(temp1, "($10,456.37)");
216
pos2.field = 1; /* Fractional Section */
217
resultlengthneeded=unum_formatDouble(cur_def, d, NULL, resultlength, &pos2, &status);
218
if(status==U_BUFFER_OVERFLOW_ERROR)
221
resultlength=resultlengthneeded+1;
222
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
223
/* for (i = 0; i < 100000; i++) */
225
unum_formatDouble(cur_def, d, result, resultlength, &pos2, &status);
228
if(U_FAILURE(status))
230
log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status));
232
if(u_strcmp(result, temp1)==0)
233
log_verbose("Pass: Number Formatting using unum_formatDouble() Successful\n");
235
log_err("FAIL: Error in number formatting using unum_formatDouble()\n");
236
if(pos2.beginIndex == 9 && pos2.endIndex == 11)
237
log_verbose("Pass: Complete number formatting using unum_format() successful\n");
239
log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=9 end=11",
240
pos1.beginIndex, pos1.endIndex);
243
/* Testing unum_parse() and unum_parseDouble() */
244
log_verbose("\nTesting unum_parseDouble()\n");
245
/* for (i = 0; i < 100000; i++)*/
248
d1=unum_parseDouble(cur_def, result, u_strlen(result), &parsepos, &status);
250
if(U_FAILURE(status))
252
log_err("parse failed. The error is : %s\n", myErrorName(status));
256
log_err("Fail: Error in parsing\n");
258
log_verbose("Pass: parsing successful\n");
260
/* performance testing */
261
u_uastrcpy(temp1, "$462.12345");
262
resultlength=u_strlen(temp1);
263
/* for (i = 0; i < 100000; i++) */
266
d1=unum_parseDouble(cur_def, temp1, resultlength, &parsepos, &status);
268
if(U_FAILURE(status))
270
log_err("parse failed. The error is : %s\n", myErrorName(status));
274
log_err("Fail: Error in parsing\n");
276
log_verbose("Pass: parsing successful\n");
280
u_uastrcpy(temp1, "($10,456.3E1])");
282
d1=unum_parseDouble(cur_def, temp1, u_strlen(temp1), &parsepos, &status);
283
if(U_SUCCESS(status))
285
log_err("Error in unum_parseDouble(..., %s, ...): %s\n", temp1, myErrorName(status));
289
log_verbose("\nTesting unum_format()\n");
293
resultlengthneeded=unum_format(per_fr, l, NULL, resultlength, &pos1, &status);
294
if(status==U_BUFFER_OVERFLOW_ERROR)
297
resultlength=resultlengthneeded+1;
298
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
299
/* for (i = 0; i < 100000; i++)*/
301
unum_format(per_fr, l, result, resultlength, &pos1, &status);
304
if(U_FAILURE(status))
306
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
310
log_verbose("\nTesting unum_parse()\n");
311
/* for (i = 0; i < 100000; i++) */
314
l1=unum_parse(per_fr, result, u_strlen(result), &parsepos, &status);
316
if(U_FAILURE(status))
318
log_err("parse failed. The error is : %s\n", myErrorName(status));
322
log_err("Fail: Error in parsing\n");
324
log_verbose("Pass: parsing successful\n");
328
/* create a number format using unum_openPattern(....)*/
329
log_verbose("\nTesting unum_openPattern()\n");
330
u_uastrcpy(temp1, "#,##0.0#;(#,##0.0#)");
331
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), NULL, NULL,&status);
332
if(U_FAILURE(status))
334
log_err("error in unum_openPattern(): %s\n", myErrorName(status) );;
337
log_verbose("Pass: unum_openPattern() works fine\n");
339
/*test for unum_toPattern()*/
340
log_verbose("\nTesting unum_toPattern()\n");
342
resultlengthneeded=unum_toPattern(pattern, FALSE, NULL, resultlength, &status);
343
if(status==U_BUFFER_OVERFLOW_ERROR)
346
resultlength=resultlengthneeded+1;
347
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
348
unum_toPattern(pattern, FALSE, result, resultlength, &status);
350
if(U_FAILURE(status))
352
log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status));
356
if(u_strcmp(result, temp1)!=0)
357
log_err("FAIL: Error in extracting the pattern using unum_toPattern()\n");
359
log_verbose("Pass: extracted the pattern correctly using unum_toPattern()\n");
363
/*Testing unum_getSymbols() and unum_setSymbols()*/
364
log_verbose("\nTesting unum_getSymbols and unum_setSymbols()\n");
365
/*when we try to change the symbols of french to default we need to apply the pattern as well to fetch correct results */
367
resultlengthneeded=unum_toPattern(cur_def, FALSE, NULL, resultlength, &status);
368
if(status==U_BUFFER_OVERFLOW_ERROR)
371
resultlength=resultlengthneeded+1;
372
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
373
unum_toPattern(cur_def, FALSE, result, resultlength, &status);
375
if(U_FAILURE(status))
377
log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status));
381
cur_frpattern=unum_open(UNUM_IGNORE,result, u_strlen(result), "fr_FR",NULL, &status);
382
if(U_FAILURE(status))
384
log_err("error in unum_openPattern(): %s\n", myErrorName(status));
389
/*getting the symbols of cur_def */
390
/*set the symbols of cur_frpattern to cur_def */
391
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
393
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
394
unum_setSymbol(cur_frpattern, symType, temp1, -1, &status);
395
if(U_FAILURE(status))
397
log_err("Error in get/set symbols: %s\n", myErrorName(status));
401
/*format to check the result */
403
resultlengthneeded=unum_format(cur_def, l, NULL, resultlength, &pos1, &status);
404
if(status==U_BUFFER_OVERFLOW_ERROR)
407
resultlength=resultlengthneeded+1;
408
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
409
unum_format(cur_def, l, result, resultlength, &pos1, &status);
411
if(U_FAILURE(status))
413
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
416
if(U_FAILURE(status)){
417
log_err("Fail: error in unum_setSymbols: %s\n", myErrorName(status));
419
unum_applyPattern(cur_frpattern, FALSE, result, u_strlen(result),NULL,NULL);
421
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
423
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
424
unum_getSymbol(cur_frpattern, symType, temp2, sizeof(temp2), &status);
425
if(U_FAILURE(status) || u_strcmp(temp1, temp2) != 0)
427
log_err("Fail: error in getting symbols\n");
430
log_verbose("Pass: get and set symbols successful\n");
433
/*format and check with the previous result */
436
resultlengthneeded=unum_format(cur_frpattern, l, NULL, resultlength, &pos1, &status);
437
if(status==U_BUFFER_OVERFLOW_ERROR)
440
resultlength=resultlengthneeded+1;
441
unum_format(cur_frpattern, l, temp1, resultlength, &pos1, &status);
443
if(U_FAILURE(status))
445
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
448
* This test fails because we have not called unum_applyPattern().
449
* Currently, such an applyPattern() does not exist on the C API, and
450
* we have jitterbug 411 for it.
451
* Since it is close to the 1.5 release, I (markus) am disabling this test just
452
* for this release (I added the test itself only last week).
453
* For the next release, we need to fix this.
454
* Then, remove the uprv_strcmp("1.5", ...) and this comment, and the include "cstring.h" at the beginning of this file.
456
if(u_strcmp(result, temp1) != 0) {
457
log_err("Formatting failed after setting symbols. result=%s temp1=%s\n", result, temp1);
465
/* Testing unum_get/setSymbol() */
466
for(i = 0; i < UNUM_FORMAT_SYMBOL_COUNT; ++i) {
467
symbol[0] = (UChar)(0x41 + i);
468
symbol[1] = (UChar)(0x61 + i);
469
unum_setSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, 2, &status);
470
if(U_FAILURE(status)) {
471
log_err("Error from unum_setSymbol(%d): %s\n", i, myErrorName(status));
475
for(i = 0; i < UNUM_FORMAT_SYMBOL_COUNT; ++i) {
476
resultlength = unum_getSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
477
if(U_FAILURE(status)) {
478
log_err("Error from unum_getSymbol(%d): %s\n", i, myErrorName(status));
481
if(resultlength != 2 || symbol[0] != 0x41 + i || symbol[1] != 0x61 + i) {
482
log_err("Failure in unum_getSymbol(%d): got unexpected symbol\n", i);
485
/*try getting from a bogus symbol*/
486
unum_getSymbol(cur_frpattern, (UNumberFormatSymbol)i, symbol, sizeof(symbol)/U_SIZEOF_UCHAR, &status);
487
if(U_SUCCESS(status)){
488
log_err("Error : Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol");
490
if(U_FAILURE(status)){
491
if(status != U_ILLEGAL_ARGUMENT_ERROR){
492
log_err("Error: Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol, Got %s\n", myErrorName(status));
497
/* Testing unum_getTextAttribute() and unum_setTextAttribute()*/
498
log_verbose("\nTesting getting and setting text attributes\n");
500
unum_getTextAttribute(cur_fr, UNUM_NEGATIVE_SUFFIX, temp, resultlength, &status);
501
if(U_FAILURE(status))
503
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
505
unum_setTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, temp, u_strlen(temp), &status);
506
if(U_FAILURE(status))
508
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
510
unum_getTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, suffix, resultlength, &status);
511
if(U_FAILURE(status))
513
log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status));
515
if(u_strcmp(suffix,temp)!=0)
516
log_err("Fail:Error in setTextAttribute or getTextAttribute in setting and getting suffix\n");
518
log_verbose("Pass: setting and getting suffix works fine\n");
519
/*set it back to normal */
520
u_uastrcpy(temp,"$");
521
unum_setTextAttribute(cur_def, UNUM_NEGATIVE_SUFFIX, temp, u_strlen(temp), &status);
523
/*checking some more text setter conditions */
524
u_uastrcpy(prefix, "+");
525
unum_setTextAttribute(def, UNUM_POSITIVE_PREFIX, prefix, u_strlen(prefix) , &status);
526
if(U_FAILURE(status))
528
log_err("error in setting the text attributes : %s\n", myErrorName(status));
530
unum_getTextAttribute(def, UNUM_POSITIVE_PREFIX, temp, resultlength, &status);
531
if(U_FAILURE(status))
533
log_err("error in getting the text attributes : %s\n", myErrorName(status));
536
if(u_strcmp(prefix, temp)!=0)
537
log_err("ERROR: get and setTextAttributes with positive prefix failed\n");
539
log_verbose("Pass: get and setTextAttributes with positive prefix works fine\n");
541
u_uastrcpy(prefix, "+");
542
unum_setTextAttribute(def, UNUM_NEGATIVE_PREFIX, prefix, u_strlen(prefix), &status);
543
if(U_FAILURE(status))
545
log_err("error in setting the text attributes : %s\n", myErrorName(status));
547
unum_getTextAttribute(def, UNUM_NEGATIVE_PREFIX, temp, resultlength, &status);
548
if(U_FAILURE(status))
550
log_err("error in getting the text attributes : %s\n", myErrorName(status));
552
if(u_strcmp(prefix, temp)!=0)
553
log_err("ERROR: get and setTextAttributes with negative prefix failed\n");
555
log_verbose("Pass: get and setTextAttributes with negative prefix works fine\n");
557
u_uastrcpy(suffix, "+");
558
unum_setTextAttribute(def, UNUM_NEGATIVE_SUFFIX, suffix, u_strlen(suffix) , &status);
559
if(U_FAILURE(status))
561
log_err("error in setting the text attributes: %s\n", myErrorName(status));
564
unum_getTextAttribute(def, UNUM_NEGATIVE_SUFFIX, temp, resultlength, &status);
565
if(U_FAILURE(status))
567
log_err("error in getting the text attributes : %s\n", myErrorName(status));
569
if(u_strcmp(suffix, temp)!=0)
570
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
572
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
574
u_uastrcpy(suffix, "++");
575
unum_setTextAttribute(def, UNUM_POSITIVE_SUFFIX, suffix, u_strlen(suffix) , &status);
576
if(U_FAILURE(status))
578
log_err("error in setting the text attributes: %s\n", myErrorName(status));
581
unum_getTextAttribute(def, UNUM_POSITIVE_SUFFIX, temp, resultlength, &status);
582
if(U_FAILURE(status))
584
log_err("error in getting the text attributes : %s\n", myErrorName(status));
586
if(u_strcmp(suffix, temp)!=0)
587
log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
589
log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
594
/*Testing unum_getAttribute and unum_setAttribute() */
595
log_verbose("\nTesting get and set Attributes\n");
596
attr=UNUM_GROUPING_SIZE;
597
newvalue=unum_getAttribute(def, attr);
599
unum_setAttribute(def, attr, newvalue);
600
if(unum_getAttribute(def,attr)!=2)
601
log_err("Fail: error in setting and getting attributes for UNUM_GROUPING_SIZE\n");
603
log_verbose("Pass: setting and getting attributes for UNUM_GROUPING_SIZE works fine\n");
605
attr=UNUM_MULTIPLIER;
606
newvalue=unum_getAttribute(def, attr);
608
unum_setAttribute(def, attr, newvalue);
609
if(unum_getAttribute(def,attr) != 8)
610
log_err("error in setting and getting attributes for UNUM_MULTIPLIER\n");
612
log_verbose("Pass:setting and getting attributes for UNUM_MULTIPLIER works fine\n");
614
/*testing set and get Attributes extensively */
615
log_verbose("\nTesting get and set attributes extensively\n");
616
for(attr=UNUM_PARSE_INT_ONLY; attr<= UNUM_PADDING_POSITION; attr=(UNumberFormatAttribute)((int32_t)attr + 1) )
618
newvalue=unum_getAttribute(fr, attr);
619
unum_setAttribute(def, attr, newvalue);
620
if(unum_getAttribute(def,attr)!=unum_getAttribute(fr, attr))
621
log_err("error in setting and getting attributes\n");
623
log_verbose("Pass: attributes set and retrieved successfully\n");
626
/*testing spellout format to make sure we can use it successfully.*/
627
log_verbose("\nTesting spellout format\n");
629
static const int32_t values[] = { 0, -5, 105, 1005, 105050 };
630
for (i = 0; i < LENGTH(values); ++i) {
633
int32_t value = values[i];
634
status = U_ZERO_ERROR;
635
len = unum_format(spellout_def, value, buffer, LENGTH(buffer), NULL, &status);
636
if(U_FAILURE(status)) {
637
log_err("Error in formatting using unum_format(spellout_fmt, ...): %s\n", myErrorName(status));
642
ustrToAstr(buffer, len, logbuf, LENGTH(logbuf));
643
log_verbose("formatted %d as '%s', length: %d\n", value, logbuf, len);
645
parseResult = unum_parse(spellout_def, buffer, len, &pp, &status);
646
if (U_FAILURE(status)) {
647
log_err("Error in parsing using unum_format(spellout_fmt, ...): %s\n", myErrorName(status));
648
} else if (parseResult != value) {
649
log_err("unum_format result %d != value %d\n", parseResult, value);
655
/*closing the NumberFormat() using unum_close(UNumberFormat*)")*/
662
unum_close(spellout_def);
664
unum_close(cur_frpattern);
669
static void TestNumberFormatPadding()
674
UErrorCode status=U_ZERO_ERROR;
675
int32_t resultlength;
676
int32_t resultlengthneeded;
677
UNumberFormat *pattern;
679
double d = -10456.37;
683
/* create a number format using unum_openPattern(....)*/
684
log_verbose("\nTesting unum_openPattern() with padding\n");
685
u_uastrcpy(temp1, "*#,##0.0#*;(#,##0.0#)");
687
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), NULL, NULL,&status);
688
if(U_SUCCESS(status))
690
log_err("error in unum_openPattern(%s): %s\n", temp1, myErrorName(status) );;
697
/* u_uastrcpy(temp1, "*x#,###,###,##0.0#;(*x#,###,###,##0.0#)"); */
698
u_uastrcpy(temp1, "*x#,###,###,##0.0#;*x(###,###,##0.0#)");
700
pattern=unum_open(UNUM_IGNORE,temp1, u_strlen(temp1), "en_US",NULL, &status);
701
if(U_FAILURE(status))
703
log_err("error in padding unum_openPattern(%s): %s\n", temp1, myErrorName(status) );;
706
log_verbose("Pass: padding unum_openPattern() works fine\n");
708
/*test for unum_toPattern()*/
709
log_verbose("\nTesting padding unum_toPattern()\n");
711
resultlengthneeded=unum_toPattern(pattern, FALSE, NULL, resultlength, &status);
712
if(status==U_BUFFER_OVERFLOW_ERROR)
715
resultlength=resultlengthneeded+1;
716
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
717
unum_toPattern(pattern, FALSE, result, resultlength, &status);
719
if(U_FAILURE(status))
721
log_err("error in extracting the padding pattern from UNumberFormat: %s\n", myErrorName(status));
725
if(u_strcmp(result, temp1)!=0)
726
log_err("FAIL: Error in extracting the padding pattern using unum_toPattern()\n");
728
log_verbose("Pass: extracted the padding pattern correctly using unum_toPattern()\n");
731
/* u_uastrcpy(temp1, "(xxxxxxx10,456.37)"); */
732
u_uastrcpy(temp1, "xxxxx(10,456.37)");
734
pos1.field = 1; /* Fraction field */
735
resultlengthneeded=unum_formatDouble(pattern, d, NULL, resultlength, &pos1, &status);
736
if(status==U_BUFFER_OVERFLOW_ERROR)
739
resultlength=resultlengthneeded+1;
740
result=(UChar*)uprv_malloc(sizeof(UChar) * resultlength);
741
unum_formatDouble(pattern, d, result, resultlength, NULL, &status);
743
if(U_FAILURE(status))
745
log_err("Error in formatting using unum_formatDouble(.....) with padding : %s\n", myErrorName(status));
749
if(u_strcmp(result, temp1)==0)
750
log_verbose("Pass: Number Formatting using unum_formatDouble() padding Successful\n");
752
log_err("FAIL: Error in number formatting using unum_formatDouble() with padding\n");
753
if(pos1.beginIndex == 13 && pos1.endIndex == 15)
754
log_verbose("Pass: Complete number formatting using unum_formatDouble() successful\n");
756
log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=13 end=15\n",
757
pos1.beginIndex, pos1.endIndex);
760
/* Testing unum_parse() and unum_parseDouble() */
761
log_verbose("\nTesting padding unum_parseDouble()\n");
763
d1=unum_parseDouble(pattern, result, u_strlen(result), &parsepos, &status);
764
if(U_FAILURE(status))
766
log_err("padding parse failed. The error is : %s\n", myErrorName(status));
770
log_err("Fail: Error in padding parsing\n");
772
log_verbose("Pass: padding parsing successful\n");