1 /********************************************************************
3 * Copyright (c) 1997-2004, 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/utypes.h"
24 #if !UCONFIG_NO_FORMATTING
26 #include "unicode/uloc.h"
27 #include "unicode/unum.h"
28 #include "unicode/ustring.h"
34 #define LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
36 void addNumForTest(TestNode
** root
);
38 #define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x)
40 void addNumForTest(TestNode
** root
)
42 TESTCASE(TestNumberFormat
);
43 TESTCASE(TestSignificantDigits
);
44 TESTCASE(TestNumberFormatPadding
);
45 TESTCASE(TestInt64Format
);
46 TESTCASE(TestNonExistentCurrency
);
47 TESTCASE(TestRBNFFormat
);
50 /** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
51 static int32_t ustrToAstr(const UChar
* src
, int32_t srcLength
, char* dst
, int32_t dstLength
) {
52 static const char hex
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
55 const char *e
= p
+ dstLength
;
61 srcLength
= (int32_t)(s
- src
);
63 while (p
< e
&& --srcLength
>= 0) {
65 if (c
== 0xd || c
== 0xa || c
== 0x9 || (c
>= 0x20 && c
<= 0x7e)) {
66 *p
++ = (char) c
& 0x7f;
67 } else if (e
- p
>= 6) {
70 *p
++ = hex
[(c
>> 12) & 0xf];
71 *p
++ = hex
[(c
>> 8) & 0xf];
72 *p
++ = hex
[(c
>> 4) & 0xf];
81 return (int32_t)(p
- dst
);
84 /* test Number Format API */
85 static void TestNumberFormat()
97 int32_t resultlengthneeded
;
101 double d
= -10456.37;
102 double a
= 1234.56, a1
= 1235.0;
103 int32_t l
= 100000000;
109 UNumberFormatAttribute attr
;
110 UNumberFormatSymbol symType
= UNUM_DECIMAL_SEPARATOR_SYMBOL
;
112 UErrorCode status
=U_ZERO_ERROR
;
113 UNumberFormatStyle style
= UNUM_DEFAULT
;
114 UNumberFormat
*pattern
;
115 UNumberFormat
*def
, *fr
, *cur_def
, *cur_fr
, *per_def
, *per_fr
,
116 *cur_frpattern
, *myclone
, *spellout_def
;
118 /* Testing unum_open() with various Numberformat styles and locales*/
119 status
= U_ZERO_ERROR
;
120 log_verbose("Testing unum_open() with default style and locale\n");
121 def
=unum_open(style
, NULL
,0,NULL
, NULL
,&status
);
122 if(U_FAILURE(status
))
123 log_err("Error in creating NumberFormat default using unum_open(): %s\n", myErrorName(status
));
125 log_verbose("\nTesting unum_open() with french locale and default style(decimal)\n");
126 fr
=unum_open(style
,NULL
,0, "fr_FR",NULL
, &status
);
127 if(U_FAILURE(status
))
128 log_err("Error: could not create NumberFormat (french): %s\n", myErrorName(status
));
130 log_verbose("\nTesting unum_open(currency,NULL,status)\n");
132 /* Can't hardcode the result to assume the default locale is "en_US". */
133 cur_def
=unum_open(style
, NULL
,0,"en_US", NULL
, &status
);
134 if(U_FAILURE(status
))
135 log_err("Error: could not create NumberFormat using \n unum_open(currency, NULL, &status) %s\n",
136 myErrorName(status
) );
138 log_verbose("\nTesting unum_open(currency, frenchlocale, status)\n");
139 cur_fr
=unum_open(style
,NULL
,0, "fr_FR", NULL
, &status
);
140 if(U_FAILURE(status
))
141 log_err("Error: could not create NumberFormat using unum_open(currency, french, &status): %s\n",
142 myErrorName(status
));
144 log_verbose("\nTesting unum_open(percent, NULL, status)\n");
146 per_def
=unum_open(style
,NULL
,0, NULL
,NULL
, &status
);
147 if(U_FAILURE(status
))
148 log_err("Error: could not create NumberFormat using unum_open(percent, NULL, &status): %s\n", myErrorName(status
));
150 log_verbose("\nTesting unum_open(percent,frenchlocale, status)\n");
151 per_fr
=unum_open(style
, NULL
,0,"fr_FR", NULL
,&status
);
152 if(U_FAILURE(status
))
153 log_err("Error: could not create NumberFormat using unum_open(percent, french, &status): %s\n", myErrorName(status
));
155 log_verbose("\nTesting unum_open(spellout, NULL, status)");
157 spellout_def
=unum_open(style
, NULL
, 0, "en_US", NULL
, &status
);
158 if(U_FAILURE(status
))
159 log_err("Error: could not create NumberFormat using unum_open(spellout, NULL, &status): %s\n", myErrorName(status
));
161 /* Testing unum_clone(..) */
162 log_verbose("\nTesting unum_clone(fmt, status)");
163 status
= U_ZERO_ERROR
;
164 myclone
= unum_clone(def
,&status
);
165 if(U_FAILURE(status
))
166 log_err("Error: could not clone unum_clone(def, &status): %s\n", myErrorName(status
));
169 log_verbose("unum_clone() successful\n");
172 /*Testing unum_getAvailable() and unum_countAvailable()*/
173 log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
174 numlocales
=unum_countAvailable();
176 log_err("error in countAvailable");
178 log_verbose("unum_countAvialable() successful\n");
179 log_verbose("The no: of locales where number formattting is applicable is %d\n", numlocales
);
181 for(i
=0;i
<numlocales
;i
++)
183 log_verbose("%s\n", unum_getAvailable(i
));
184 if (unum_getAvailable(i
) == 0)
185 log_err("No locale for which number formatting patterns are applicable\n");
187 log_verbose("A locale %s for which number formatting patterns are applicable\n",unum_getAvailable(i
));
191 /*Testing unum_format() and unum_formatdouble()*/
192 u_uastrcpy(temp1
, "$100,000,000.00");
194 log_verbose("\nTesting unum_format() \n");
196 pos1
.field
= 0; /* Integer Section */
197 resultlengthneeded
=unum_format(cur_def
, l
, NULL
, resultlength
, &pos1
, &status
);
198 if(status
==U_BUFFER_OVERFLOW_ERROR
)
201 resultlength
=resultlengthneeded
+1;
202 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
203 /* for (i = 0; i < 100000; i++) */
205 unum_format(cur_def
, l
, result
, resultlength
, &pos1
, &status
);
209 if(U_FAILURE(status
))
211 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status
) );
213 if(u_strcmp(result
, temp1
)==0)
214 log_verbose("Pass: Number formatting using unum_format() successful\n");
216 log_err("Fail: Error in number Formatting using unum_format()\n");
217 if(pos1
.beginIndex
== 1 && pos1
.endIndex
== 12)
218 log_verbose("Pass: Complete number formatting using unum_format() successful\n");
220 log_err("Fail: Error in complete number Formatting using unum_format()\nGot: b=%d end=%d\nExpected: b=1 end=12\n",
221 pos1
.beginIndex
, pos1
.endIndex
);
226 log_verbose("\nTesting unum_formatDouble()\n");
227 u_uastrcpy(temp1
, "($10,456.37)");
229 pos2
.field
= 1; /* Fractional Section */
230 resultlengthneeded
=unum_formatDouble(cur_def
, d
, NULL
, resultlength
, &pos2
, &status
);
231 if(status
==U_BUFFER_OVERFLOW_ERROR
)
234 resultlength
=resultlengthneeded
+1;
235 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
236 /* for (i = 0; i < 100000; i++) */
238 unum_formatDouble(cur_def
, d
, result
, resultlength
, &pos2
, &status
);
241 if(U_FAILURE(status
))
243 log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status
));
245 if(u_strcmp(result
, temp1
)==0)
246 log_verbose("Pass: Number Formatting using unum_formatDouble() Successful\n");
248 log_err("FAIL: Error in number formatting using unum_formatDouble()\n");
249 if(pos2
.beginIndex
== 9 && pos2
.endIndex
== 11)
250 log_verbose("Pass: Complete number formatting using unum_format() successful\n");
252 log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=9 end=11",
253 pos1
.beginIndex
, pos1
.endIndex
);
256 /* Testing unum_parse() and unum_parseDouble() */
257 log_verbose("\nTesting unum_parseDouble()\n");
258 /* for (i = 0; i < 100000; i++)*/
261 d1
=unum_parseDouble(cur_def
, result
, u_strlen(result
), &parsepos
, &status
);
263 if(U_FAILURE(status
))
265 log_err("parse failed. The error is : %s\n", myErrorName(status
));
269 log_err("Fail: Error in parsing\n");
271 log_verbose("Pass: parsing successful\n");
277 /* Testing unum_formatDoubleCurrency / unum_parseDoubleCurrency */
278 log_verbose("\nTesting unum_formatDoubleCurrency\n");
279 u_uastrcpy(temp1
, "Y1,235");
280 temp1
[0] = 0xA5; /* Yen sign */
281 u_uastrcpy(temp
, "JPY");
283 pos2
.field
= 0; /* integer part */
284 resultlengthneeded
=unum_formatDoubleCurrency(cur_def
, a
, temp
, NULL
, resultlength
, &pos2
, &status
);
285 if (status
==U_BUFFER_OVERFLOW_ERROR
) {
287 resultlength
=resultlengthneeded
+1;
288 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
289 unum_formatDoubleCurrency(cur_def
, a
, temp
, result
, resultlength
, &pos2
, &status
);
291 if (U_FAILURE(status
)) {
292 log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status
));
294 if (result
&& u_strcmp(result
, temp1
)==0) {
295 log_verbose("Pass: Number Formatting using unum_formatDouble() Successful\n");
297 log_err("FAIL: Error in number formatting using unum_formatDouble()\n");
299 if (pos2
.beginIndex
== 1 && pos2
.endIndex
== 6) {
300 log_verbose("Pass: Complete number formatting using unum_format() successful\n");
302 log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=1 end=6",
303 pos1
.beginIndex
, pos1
.endIndex
);
306 log_verbose("\nTesting unum_parseDoubleCurrency\n");
308 d1
=unum_parseDoubleCurrency(cur_def
, result
, u_strlen(result
), &parsepos
, temp2
, &status
);
309 if (U_FAILURE(status
)) {
310 log_err("parse failed. The error is : %s\n", myErrorName(status
));
312 /* Note: a==1234.56, but on parse expect a1=1235.0 */
314 log_err("Fail: Error in parsing currency, got %f, expected %f\n", d1
, a1
);
316 log_verbose("Pass: parsed currency ammount successfully\n");
318 if (u_strcmp(temp2
, temp
)==0) {
319 log_verbose("Pass: parsed correct currency\n");
321 log_err("Fail: parsed incorrect currency\n");
328 /* performance testing */
329 u_uastrcpy(temp1
, "$462.12345");
330 resultlength
=u_strlen(temp1
);
331 /* for (i = 0; i < 100000; i++) */
334 d1
=unum_parseDouble(cur_def
, temp1
, resultlength
, &parsepos
, &status
);
336 if(U_FAILURE(status
))
338 log_err("parse failed. The error is : %s\n", myErrorName(status
));
342 log_err("Fail: Error in parsing\n");
344 log_verbose("Pass: parsing successful\n");
348 u_uastrcpy(temp1
, "($10,456.3E1])");
350 d1
=unum_parseDouble(cur_def
, temp1
, u_strlen(temp1
), &parsepos
, &status
);
351 if(U_SUCCESS(status
))
353 log_err("Error in unum_parseDouble(..., %s, ...): %s\n", temp1
, myErrorName(status
));
357 log_verbose("\nTesting unum_format()\n");
361 resultlengthneeded
=unum_format(per_fr
, l
, NULL
, resultlength
, &pos1
, &status
);
362 if(status
==U_BUFFER_OVERFLOW_ERROR
)
365 resultlength
=resultlengthneeded
+1;
366 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
367 /* for (i = 0; i < 100000; i++)*/
369 unum_format(per_fr
, l
, result
, resultlength
, &pos1
, &status
);
372 if(U_FAILURE(status
))
374 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status
));
378 log_verbose("\nTesting unum_parse()\n");
379 /* for (i = 0; i < 100000; i++) */
382 l1
=unum_parse(per_fr
, result
, u_strlen(result
), &parsepos
, &status
);
384 if(U_FAILURE(status
))
386 log_err("parse failed. The error is : %s\n", myErrorName(status
));
390 log_err("Fail: Error in parsing\n");
392 log_verbose("Pass: parsing successful\n");
396 /* create a number format using unum_openPattern(....)*/
397 log_verbose("\nTesting unum_openPattern()\n");
398 u_uastrcpy(temp1
, "#,##0.0#;(#,##0.0#)");
399 pattern
=unum_open(UNUM_IGNORE
,temp1
, u_strlen(temp1
), NULL
, NULL
,&status
);
400 if(U_FAILURE(status
))
402 log_err("error in unum_openPattern(): %s\n", myErrorName(status
) );;
405 log_verbose("Pass: unum_openPattern() works fine\n");
407 /*test for unum_toPattern()*/
408 log_verbose("\nTesting unum_toPattern()\n");
410 resultlengthneeded
=unum_toPattern(pattern
, FALSE
, NULL
, resultlength
, &status
);
411 if(status
==U_BUFFER_OVERFLOW_ERROR
)
414 resultlength
=resultlengthneeded
+1;
415 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
416 unum_toPattern(pattern
, FALSE
, result
, resultlength
, &status
);
418 if(U_FAILURE(status
))
420 log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status
));
424 if(u_strcmp(result
, temp1
)!=0)
425 log_err("FAIL: Error in extracting the pattern using unum_toPattern()\n");
427 log_verbose("Pass: extracted the pattern correctly using unum_toPattern()\n");
431 /*Testing unum_getSymbols() and unum_setSymbols()*/
432 log_verbose("\nTesting unum_getSymbols and unum_setSymbols()\n");
433 /*when we try to change the symbols of french to default we need to apply the pattern as well to fetch correct results */
435 resultlengthneeded
=unum_toPattern(cur_def
, FALSE
, NULL
, resultlength
, &status
);
436 if(status
==U_BUFFER_OVERFLOW_ERROR
)
439 resultlength
=resultlengthneeded
+1;
440 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
441 unum_toPattern(cur_def
, FALSE
, result
, resultlength
, &status
);
443 if(U_FAILURE(status
))
445 log_err("error in extracting the pattern from UNumberFormat: %s\n", myErrorName(status
));
449 cur_frpattern
=unum_open(UNUM_IGNORE
,result
, u_strlen(result
), "fr_FR",NULL
, &status
);
450 if(U_FAILURE(status
))
452 log_err("error in unum_openPattern(): %s\n", myErrorName(status
));
457 /*getting the symbols of cur_def */
458 /*set the symbols of cur_frpattern to cur_def */
459 for (symType
= UNUM_DECIMAL_SEPARATOR_SYMBOL
; symType
< UNUM_FORMAT_SYMBOL_COUNT
; symType
++) {
461 unum_getSymbol(cur_def
, symType
, temp1
, sizeof(temp1
), &status
);
462 unum_setSymbol(cur_frpattern
, symType
, temp1
, -1, &status
);
463 if(U_FAILURE(status
))
465 log_err("Error in get/set symbols: %s\n", myErrorName(status
));
469 /*format to check the result */
471 resultlengthneeded
=unum_format(cur_def
, l
, NULL
, resultlength
, &pos1
, &status
);
472 if(status
==U_BUFFER_OVERFLOW_ERROR
)
475 resultlength
=resultlengthneeded
+1;
476 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
477 unum_format(cur_def
, l
, result
, resultlength
, &pos1
, &status
);
479 if(U_FAILURE(status
))
481 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status
));
484 if(U_FAILURE(status
)){
485 log_err("Fail: error in unum_setSymbols: %s\n", myErrorName(status
));
487 unum_applyPattern(cur_frpattern
, FALSE
, result
, u_strlen(result
),NULL
,NULL
);
489 for (symType
= UNUM_DECIMAL_SEPARATOR_SYMBOL
; symType
< UNUM_FORMAT_SYMBOL_COUNT
; symType
++) {
491 unum_getSymbol(cur_def
, symType
, temp1
, sizeof(temp1
), &status
);
492 unum_getSymbol(cur_frpattern
, symType
, temp2
, sizeof(temp2
), &status
);
493 if(U_FAILURE(status
) || u_strcmp(temp1
, temp2
) != 0)
495 log_err("Fail: error in getting symbols\n");
498 log_verbose("Pass: get and set symbols successful\n");
501 /*format and check with the previous result */
504 resultlengthneeded
=unum_format(cur_frpattern
, l
, NULL
, resultlength
, &pos1
, &status
);
505 if(status
==U_BUFFER_OVERFLOW_ERROR
)
508 resultlength
=resultlengthneeded
+1;
509 unum_format(cur_frpattern
, l
, temp1
, resultlength
, &pos1
, &status
);
511 if(U_FAILURE(status
))
513 log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status
));
516 * This test fails because we have not called unum_applyPattern().
517 * Currently, such an applyPattern() does not exist on the C API, and
518 * we have jitterbug 411 for it.
519 * Since it is close to the 1.5 release, I (markus) am disabling this test just
520 * for this release (I added the test itself only last week).
521 * For the next release, we need to fix this.
522 * Then, remove the uprv_strcmp("1.5", ...) and this comment, and the include "cstring.h" at the beginning of this file.
524 if(u_strcmp(result
, temp1
) != 0) {
525 log_err("Formatting failed after setting symbols. result=%s temp1=%s\n", result
, temp1
);
533 /* Testing unum_get/setSymbol() */
534 for(i
= 0; i
< UNUM_FORMAT_SYMBOL_COUNT
; ++i
) {
535 symbol
[0] = (UChar
)(0x41 + i
);
536 symbol
[1] = (UChar
)(0x61 + i
);
537 unum_setSymbol(cur_frpattern
, (UNumberFormatSymbol
)i
, symbol
, 2, &status
);
538 if(U_FAILURE(status
)) {
539 log_err("Error from unum_setSymbol(%d): %s\n", i
, myErrorName(status
));
543 for(i
= 0; i
< UNUM_FORMAT_SYMBOL_COUNT
; ++i
) {
544 resultlength
= unum_getSymbol(cur_frpattern
, (UNumberFormatSymbol
)i
, symbol
, sizeof(symbol
)/U_SIZEOF_UCHAR
, &status
);
545 if(U_FAILURE(status
)) {
546 log_err("Error from unum_getSymbol(%d): %s\n", i
, myErrorName(status
));
549 if(resultlength
!= 2 || symbol
[0] != 0x41 + i
|| symbol
[1] != 0x61 + i
) {
550 log_err("Failure in unum_getSymbol(%d): got unexpected symbol\n", i
);
553 /*try getting from a bogus symbol*/
554 unum_getSymbol(cur_frpattern
, (UNumberFormatSymbol
)i
, symbol
, sizeof(symbol
)/U_SIZEOF_UCHAR
, &status
);
555 if(U_SUCCESS(status
)){
556 log_err("Error : Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol");
558 if(U_FAILURE(status
)){
559 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
560 log_err("Error: Expected U_ILLEGAL_ARGUMENT_ERROR for bogus symbol, Got %s\n", myErrorName(status
));
565 /* Testing unum_getTextAttribute() and unum_setTextAttribute()*/
566 log_verbose("\nTesting getting and setting text attributes\n");
568 unum_getTextAttribute(cur_fr
, UNUM_NEGATIVE_SUFFIX
, temp
, resultlength
, &status
);
569 if(U_FAILURE(status
))
571 log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status
));
573 unum_setTextAttribute(cur_def
, UNUM_NEGATIVE_SUFFIX
, temp
, u_strlen(temp
), &status
);
574 if(U_FAILURE(status
))
576 log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status
));
578 unum_getTextAttribute(cur_def
, UNUM_NEGATIVE_SUFFIX
, suffix
, resultlength
, &status
);
579 if(U_FAILURE(status
))
581 log_err("Failure in gettting the Text attributes of number format: %s\n", myErrorName(status
));
583 if(u_strcmp(suffix
,temp
)!=0)
584 log_err("Fail:Error in setTextAttribute or getTextAttribute in setting and getting suffix\n");
586 log_verbose("Pass: setting and getting suffix works fine\n");
587 /*set it back to normal */
588 u_uastrcpy(temp
,"$");
589 unum_setTextAttribute(cur_def
, UNUM_NEGATIVE_SUFFIX
, temp
, u_strlen(temp
), &status
);
591 /*checking some more text setter conditions */
592 u_uastrcpy(prefix
, "+");
593 unum_setTextAttribute(def
, UNUM_POSITIVE_PREFIX
, prefix
, u_strlen(prefix
) , &status
);
594 if(U_FAILURE(status
))
596 log_err("error in setting the text attributes : %s\n", myErrorName(status
));
598 unum_getTextAttribute(def
, UNUM_POSITIVE_PREFIX
, temp
, resultlength
, &status
);
599 if(U_FAILURE(status
))
601 log_err("error in getting the text attributes : %s\n", myErrorName(status
));
604 if(u_strcmp(prefix
, temp
)!=0)
605 log_err("ERROR: get and setTextAttributes with positive prefix failed\n");
607 log_verbose("Pass: get and setTextAttributes with positive prefix works fine\n");
609 u_uastrcpy(prefix
, "+");
610 unum_setTextAttribute(def
, UNUM_NEGATIVE_PREFIX
, prefix
, u_strlen(prefix
), &status
);
611 if(U_FAILURE(status
))
613 log_err("error in setting the text attributes : %s\n", myErrorName(status
));
615 unum_getTextAttribute(def
, UNUM_NEGATIVE_PREFIX
, temp
, resultlength
, &status
);
616 if(U_FAILURE(status
))
618 log_err("error in getting the text attributes : %s\n", myErrorName(status
));
620 if(u_strcmp(prefix
, temp
)!=0)
621 log_err("ERROR: get and setTextAttributes with negative prefix failed\n");
623 log_verbose("Pass: get and setTextAttributes with negative prefix works fine\n");
625 u_uastrcpy(suffix
, "+");
626 unum_setTextAttribute(def
, UNUM_NEGATIVE_SUFFIX
, suffix
, u_strlen(suffix
) , &status
);
627 if(U_FAILURE(status
))
629 log_err("error in setting the text attributes: %s\n", myErrorName(status
));
632 unum_getTextAttribute(def
, UNUM_NEGATIVE_SUFFIX
, temp
, resultlength
, &status
);
633 if(U_FAILURE(status
))
635 log_err("error in getting the text attributes : %s\n", myErrorName(status
));
637 if(u_strcmp(suffix
, temp
)!=0)
638 log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
640 log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
642 u_uastrcpy(suffix
, "++");
643 unum_setTextAttribute(def
, UNUM_POSITIVE_SUFFIX
, suffix
, u_strlen(suffix
) , &status
);
644 if(U_FAILURE(status
))
646 log_err("error in setting the text attributes: %s\n", myErrorName(status
));
649 unum_getTextAttribute(def
, UNUM_POSITIVE_SUFFIX
, temp
, resultlength
, &status
);
650 if(U_FAILURE(status
))
652 log_err("error in getting the text attributes : %s\n", myErrorName(status
));
654 if(u_strcmp(suffix
, temp
)!=0)
655 log_err("ERROR: get and setTextAttributes with negative suffix failed\n");
657 log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
659 /*Testing unum_getAttribute and unum_setAttribute() */
660 log_verbose("\nTesting get and set Attributes\n");
661 attr
=UNUM_GROUPING_SIZE
;
662 newvalue
=unum_getAttribute(def
, attr
);
664 unum_setAttribute(def
, attr
, newvalue
);
665 if(unum_getAttribute(def
,attr
)!=2)
666 log_err("Fail: error in setting and getting attributes for UNUM_GROUPING_SIZE\n");
668 log_verbose("Pass: setting and getting attributes for UNUM_GROUPING_SIZE works fine\n");
670 attr
=UNUM_MULTIPLIER
;
671 newvalue
=unum_getAttribute(def
, attr
);
673 unum_setAttribute(def
, attr
, newvalue
);
674 if(unum_getAttribute(def
,attr
) != 8)
675 log_err("error in setting and getting attributes for UNUM_MULTIPLIER\n");
677 log_verbose("Pass:setting and getting attributes for UNUM_MULTIPLIER works fine\n");
679 attr
=UNUM_SECONDARY_GROUPING_SIZE
;
680 newvalue
=unum_getAttribute(def
, attr
);
682 unum_setAttribute(def
, attr
, newvalue
);
683 if(unum_getAttribute(def
,attr
) != 2)
684 log_err("error in setting and getting attributes for UNUM_SECONDARY_GROUPING_SIZE\n");
686 log_verbose("Pass:setting and getting attributes for UNUM_SECONDARY_GROUPING_SIZE works fine\n");
688 /*testing set and get Attributes extensively */
689 log_verbose("\nTesting get and set attributes extensively\n");
690 for(attr
=UNUM_PARSE_INT_ONLY
; attr
<= UNUM_PADDING_POSITION
; attr
=(UNumberFormatAttribute
)((int32_t)attr
+ 1) )
692 newvalue
=unum_getAttribute(fr
, attr
);
693 unum_setAttribute(def
, attr
, newvalue
);
694 if(unum_getAttribute(def
,attr
)!=unum_getAttribute(fr
, attr
))
695 log_err("error in setting and getting attributes\n");
697 log_verbose("Pass: attributes set and retrieved successfully\n");
700 /*testing spellout format to make sure we can use it successfully.*/
701 log_verbose("\nTesting spellout format\n");
704 static const int32_t values
[] = { 0, -5, 105, 1005, 105050 };
705 for (i
= 0; i
< LENGTH(values
); ++i
) {
708 int32_t value
= values
[i
];
709 status
= U_ZERO_ERROR
;
710 len
= unum_format(spellout_def
, value
, buffer
, LENGTH(buffer
), NULL
, &status
);
711 if(U_FAILURE(status
)) {
712 log_err("Error in formatting using unum_format(spellout_fmt, ...): %s\n", myErrorName(status
));
717 ustrToAstr(buffer
, len
, logbuf
, LENGTH(logbuf
));
718 log_verbose("formatted %d as '%s', length: %d\n", value
, logbuf
, len
);
720 parseResult
= unum_parse(spellout_def
, buffer
, len
, &pp
, &status
);
721 if (U_FAILURE(status
)) {
722 log_err("Error in parsing using unum_format(spellout_fmt, ...): %s\n", myErrorName(status
));
723 } else if (parseResult
!= value
) {
724 log_err("unum_format result %d != value %d\n", parseResult
, value
);
730 log_err("Spellout format is unavailable\n");
733 /*closing the NumberFormat() using unum_close(UNumberFormat*)")*/
740 unum_close(spellout_def
);
742 unum_close(cur_frpattern
);
747 static void TestSignificantDigits()
750 int32_t resultlengthneeded
;
751 int32_t resultlength
;
752 UErrorCode status
= U_ZERO_ERROR
;
753 UChar
*result
= NULL
;
755 double d
= 123456.789;
757 u_uastrcpy(temp
, "###0.0#");
758 fmt
=unum_open(UNUM_IGNORE
, temp
, -1, NULL
, NULL
,&status
);
759 if (U_FAILURE(status
)) {
760 log_err("got unexpected error for unum_open: '%s'\n", u_errorName(status
));
762 unum_setAttribute(fmt
, UNUM_SIGNIFICANT_DIGITS_USED
, TRUE
);
763 unum_setAttribute(fmt
, UNUM_MAX_SIGNIFICANT_DIGITS
, 6);
765 u_uastrcpy(temp
, "123457");
767 resultlengthneeded
=unum_formatDouble(fmt
, d
, NULL
, resultlength
, NULL
, &status
);
768 if(status
==U_BUFFER_OVERFLOW_ERROR
)
771 resultlength
=resultlengthneeded
+1;
772 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
773 unum_formatDouble(fmt
, d
, result
, resultlength
, NULL
, &status
);
775 if(U_FAILURE(status
))
777 log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status
));
780 if(u_strcmp(result
, temp
)==0)
781 log_verbose("Pass: Number Formatting using unum_formatDouble() Successful\n");
783 log_err("FAIL: Error in number formatting using unum_formatDouble()\n");
788 static void TestNumberFormatPadding()
793 UErrorCode status
=U_ZERO_ERROR
;
794 int32_t resultlength
;
795 int32_t resultlengthneeded
;
796 UNumberFormat
*pattern
;
798 double d
= -10456.37;
802 /* create a number format using unum_openPattern(....)*/
803 log_verbose("\nTesting unum_openPattern() with padding\n");
804 u_uastrcpy(temp1
, "*#,##0.0#*;(#,##0.0#)");
806 pattern
=unum_open(UNUM_IGNORE
,temp1
, u_strlen(temp1
), NULL
, NULL
,&status
);
807 if(U_SUCCESS(status
))
809 log_err("error in unum_openPattern(%s): %s\n", temp1
, myErrorName(status
) );;
816 /* u_uastrcpy(temp1, "*x#,###,###,##0.0#;(*x#,###,###,##0.0#)"); */
817 u_uastrcpy(temp1
, "*x#,###,###,##0.0#;*x(###,###,##0.0#)");
819 pattern
=unum_open(UNUM_IGNORE
,temp1
, u_strlen(temp1
), "en_US",NULL
, &status
);
820 if(U_FAILURE(status
))
822 log_err("error in padding unum_openPattern(%s): %s\n", temp1
, myErrorName(status
) );;
825 log_verbose("Pass: padding unum_openPattern() works fine\n");
827 /*test for unum_toPattern()*/
828 log_verbose("\nTesting padding unum_toPattern()\n");
830 resultlengthneeded
=unum_toPattern(pattern
, FALSE
, NULL
, resultlength
, &status
);
831 if(status
==U_BUFFER_OVERFLOW_ERROR
)
834 resultlength
=resultlengthneeded
+1;
835 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
836 unum_toPattern(pattern
, FALSE
, result
, resultlength
, &status
);
838 if(U_FAILURE(status
))
840 log_err("error in extracting the padding pattern from UNumberFormat: %s\n", myErrorName(status
));
844 if(u_strcmp(result
, temp1
)!=0)
845 log_err("FAIL: Error in extracting the padding pattern using unum_toPattern()\n");
847 log_verbose("Pass: extracted the padding pattern correctly using unum_toPattern()\n");
850 /* u_uastrcpy(temp1, "(xxxxxxx10,456.37)"); */
851 u_uastrcpy(temp1
, "xxxxx(10,456.37)");
853 pos1
.field
= 1; /* Fraction field */
854 resultlengthneeded
=unum_formatDouble(pattern
, d
, NULL
, resultlength
, &pos1
, &status
);
855 if(status
==U_BUFFER_OVERFLOW_ERROR
)
858 resultlength
=resultlengthneeded
+1;
859 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
860 unum_formatDouble(pattern
, d
, result
, resultlength
, NULL
, &status
);
862 if(U_FAILURE(status
))
864 log_err("Error in formatting using unum_formatDouble(.....) with padding : %s\n", myErrorName(status
));
868 if(u_strcmp(result
, temp1
)==0)
869 log_verbose("Pass: Number Formatting using unum_formatDouble() padding Successful\n");
871 log_err("FAIL: Error in number formatting using unum_formatDouble() with padding\n");
872 if(pos1
.beginIndex
== 13 && pos1
.endIndex
== 15)
873 log_verbose("Pass: Complete number formatting using unum_formatDouble() successful\n");
875 log_err("Fail: Error in complete number Formatting using unum_formatDouble()\nGot: b=%d end=%d\nExpected: b=13 end=15\n",
876 pos1
.beginIndex
, pos1
.endIndex
);
879 /* Testing unum_parse() and unum_parseDouble() */
880 log_verbose("\nTesting padding unum_parseDouble()\n");
882 d1
=unum_parseDouble(pattern
, result
, u_strlen(result
), &parsepos
, &status
);
883 if(U_FAILURE(status
))
885 log_err("padding parse failed. The error is : %s\n", myErrorName(status
));
889 log_err("Fail: Error in padding parsing\n");
891 log_verbose("Pass: padding parsing successful\n");
900 withinErr(double a
, double b
, double err
) {
901 return uprv_fabs(a
- b
) < uprv_fabs(a
* err
);
904 static void TestInt64Format() {
908 UErrorCode status
= U_ZERO_ERROR
;
909 const double doubleInt64Max
= (double)U_INT64_MAX
;
910 const double doubleInt64Min
= (double)U_INT64_MIN
;
911 const double doubleBig
= 10.0 * (double)U_INT64_MAX
;
917 /* create a number format using unum_openPattern(....) */
918 log_verbose("\nTesting Int64Format\n");
919 u_uastrcpy(temp1
, "#.#E0");
920 fmt
= unum_open(UNUM_IGNORE
, temp1
, u_strlen(temp1
), NULL
, NULL
, &status
);
921 if(U_FAILURE(status
)) {
922 log_err("error in unum_openPattern(): %s\n", myErrorName(status
));
924 unum_setAttribute(fmt
, UNUM_MAX_FRACTION_DIGITS
, 20);
925 unum_formatInt64(fmt
, U_INT64_MAX
, result
, 512, NULL
, &status
);
926 if (U_FAILURE(status
)) {
927 log_err("error in unum_format(): %s\n", myErrorName(status
));
929 log_verbose("format int64max: '%s'\n", result
);
931 val32
= unum_parse(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
932 if (status
!= U_INVALID_FORMAT_ERROR
) {
933 log_err("parse didn't report error: %s\n", myErrorName(status
));
934 } else if (val32
!= INT32_MAX
) {
935 log_err("parse didn't pin return value, got: %d\n", val32
);
938 status
= U_ZERO_ERROR
;
940 val64
= unum_parseInt64(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
941 if (U_FAILURE(status
)) {
942 log_err("parseInt64 returned error: %s\n", myErrorName(status
));
943 } else if (val64
!= U_INT64_MAX
) {
944 log_err("parseInt64 returned incorrect value, got: %ld\n", val64
);
947 status
= U_ZERO_ERROR
;
949 valDouble
= unum_parseDouble(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
950 if (U_FAILURE(status
)) {
951 log_err("parseDouble returned error: %s\n", myErrorName(status
));
952 } else if (valDouble
!= doubleInt64Max
) {
953 log_err("parseDouble returned incorrect value, got: %g\n", valDouble
);
957 unum_formatInt64(fmt
, U_INT64_MIN
, result
, 512, NULL
, &status
);
958 if (U_FAILURE(status
)) {
959 log_err("error in unum_format(): %s\n", myErrorName(status
));
961 log_verbose("format int64min: '%s'\n", result
);
963 val32
= unum_parse(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
964 if (status
!= U_INVALID_FORMAT_ERROR
) {
965 log_err("parse didn't report error: %s\n", myErrorName(status
));
966 } else if (val32
!= INT32_MIN
) {
967 log_err("parse didn't pin return value, got: %d\n", val32
);
970 status
= U_ZERO_ERROR
;
972 val64
= unum_parseInt64(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
973 if (U_FAILURE(status
)) {
974 log_err("parseInt64 returned error: %s\n", myErrorName(status
));
975 } else if (val64
!= U_INT64_MIN
) {
976 log_err("parseInt64 returned incorrect value, got: %ld\n", val64
);
979 status
= U_ZERO_ERROR
;
981 valDouble
= unum_parseDouble(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
982 if (U_FAILURE(status
)) {
983 log_err("parseDouble returned error: %s\n", myErrorName(status
));
984 } else if (valDouble
!= doubleInt64Min
) {
985 log_err("parseDouble returned incorrect value, got: %g\n", valDouble
);
989 unum_formatDouble(fmt
, doubleBig
, result
, 512, NULL
, &status
);
990 if (U_FAILURE(status
)) {
991 log_err("error in unum_format(): %s\n", myErrorName(status
));
993 log_verbose("format doubleBig: '%s'\n", result
);
995 val32
= unum_parse(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
996 if (status
!= U_INVALID_FORMAT_ERROR
) {
997 log_err("parse didn't report error: %s\n", myErrorName(status
));
998 } else if (val32
!= INT32_MAX
) {
999 log_err("parse didn't pin return value, got: %d\n", val32
);
1002 status
= U_ZERO_ERROR
;
1004 val64
= unum_parseInt64(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
1005 if (status
!= U_INVALID_FORMAT_ERROR
) {
1006 log_err("parseInt64 didn't report error error: %s\n", myErrorName(status
));
1007 } else if (val64
!= U_INT64_MAX
) {
1008 log_err("parseInt64 returned incorrect value, got: %ld\n", val64
);
1011 status
= U_ZERO_ERROR
;
1013 valDouble
= unum_parseDouble(fmt
, result
, u_strlen(result
), &parsepos
, &status
);
1014 if (U_FAILURE(status
)) {
1015 log_err("parseDouble returned error: %s\n", myErrorName(status
));
1016 } else if (!withinErr(valDouble
, doubleBig
, 1e-15)) {
1017 log_err("parseDouble returned incorrect value, got: %g\n", valDouble
);
1025 static void test_fmt(UNumberFormat
* fmt
, UBool isDecimal
) {
1028 int32_t BUFSIZE
= sizeof(buffer
)/sizeof(buffer
[0]);
1030 -.2, 0, .2, 5.5, 15.2, 250, 123456789
1034 for (i
= 0; i
< sizeof(vals
)/sizeof(vals
[0]); ++i
) {
1035 UErrorCode status
= U_ZERO_ERROR
;
1036 unum_formatDouble(fmt
, vals
[i
], buffer
, BUFSIZE
, NULL
, &status
);
1037 if (U_FAILURE(status
)) {
1038 log_err("failed to format: %g, returned %s\n", vals
[i
], u_errorName(status
));
1040 u_austrcpy(temp
, buffer
);
1041 log_verbose("formatting %g returned '%s'\n", vals
[i
], temp
);
1045 /* check APIs now */
1047 UErrorCode status
= U_ZERO_ERROR
;
1049 u_uastrcpy(buffer
, "#,##0.0#");
1050 unum_applyPattern(fmt
, FALSE
, buffer
, -1, &perr
, &status
);
1051 if (isDecimal
? U_FAILURE(status
) : (status
!= U_UNSUPPORTED_ERROR
)) {
1052 log_err("got unexpected error for applyPattern: '%s'\n", u_errorName(status
));
1057 int isLenient
= unum_getAttribute(fmt
, UNUM_LENIENT_PARSE
);
1058 log_verbose("lenient: 0x%x\n", isLenient
);
1059 if (isDecimal
? (isLenient
!= -1) : (isLenient
== TRUE
)) {
1060 log_err("didn't expect lenient value: %d\n", isLenient
);
1063 unum_setAttribute(fmt
, UNUM_LENIENT_PARSE
, TRUE
);
1064 isLenient
= unum_getAttribute(fmt
, UNUM_LENIENT_PARSE
);
1065 if (isDecimal
? (isLenient
!= -1) : (isLenient
== FALSE
)) {
1066 log_err("didn't expect lenient value after set: %d\n", isLenient
);
1072 double val
= unum_getDoubleAttribute(fmt
, UNUM_LENIENT_PARSE
);
1074 log_err("didn't expect double attribute\n");
1076 val
= unum_getDoubleAttribute(fmt
, UNUM_ROUNDING_INCREMENT
);
1077 if ((val
== -1) == isDecimal
) {
1078 log_err("didn't expect -1 rounding increment\n");
1080 unum_setDoubleAttribute(fmt
, UNUM_ROUNDING_INCREMENT
, val
+.5);
1081 val2
= unum_getDoubleAttribute(fmt
, UNUM_ROUNDING_INCREMENT
);
1082 if (isDecimal
&& (val2
- val
!= .5)) {
1083 log_err("set rounding increment had no effect on decimal format");
1088 UErrorCode status
= U_ZERO_ERROR
;
1089 int len
= unum_getTextAttribute(fmt
, UNUM_DEFAULT_RULESET
, buffer
, BUFSIZE
, &status
);
1090 if (isDecimal
? (status
!= U_UNSUPPORTED_ERROR
) : U_FAILURE(status
)) {
1091 log_err("got unexpected error for get default ruleset: '%s'\n", u_errorName(status
));
1093 if (U_SUCCESS(status
)) {
1094 u_austrcpy(temp
, buffer
);
1095 log_verbose("default ruleset: '%s'\n", temp
);
1098 status
= U_ZERO_ERROR
;
1099 len
= unum_getTextAttribute(fmt
, UNUM_PUBLIC_RULESETS
, buffer
, BUFSIZE
, &status
);
1100 if (isDecimal
? (status
!= U_UNSUPPORTED_ERROR
) : U_FAILURE(status
)) {
1101 log_err("got unexpected error for get public rulesets: '%s'\n", u_errorName(status
));
1103 if (U_SUCCESS(status
)) {
1104 u_austrcpy(temp
, buffer
);
1105 log_verbose("public rulesets: '%s'\n", temp
);
1107 /* set the default ruleset to the first one found, and retry */
1110 for (i
= 0; i
< len
&& temp
[i
] != ';'; ++i
){};
1113 unum_setTextAttribute(fmt
, UNUM_DEFAULT_RULESET
, buffer
, -1, &status
);
1114 if (U_FAILURE(status
)) {
1115 log_err("unexpected error setting default ruleset: '%s'\n", u_errorName(status
));
1117 int len2
= unum_getTextAttribute(fmt
, UNUM_DEFAULT_RULESET
, buffer
, BUFSIZE
, &status
);
1118 if (U_FAILURE(status
)) {
1119 log_err("could not fetch default ruleset: '%s'\n", u_errorName(status
));
1120 } else if (len2
!= i
) {
1121 u_austrcpy(temp
, buffer
);
1122 log_err("unexpected ruleset len: %d ex: %d val: %s\n", len2
, i
, temp
);
1124 for (i
= 0; i
< sizeof(vals
)/sizeof(vals
[0]); ++i
) {
1125 status
= U_ZERO_ERROR
;
1126 unum_formatDouble(fmt
, vals
[i
], buffer
, BUFSIZE
, NULL
, &status
);
1127 if (U_FAILURE(status
)) {
1128 log_err("failed to format: %g, returned %s\n", vals
[i
], u_errorName(status
));
1130 u_austrcpy(temp
, buffer
);
1131 log_verbose("formatting %g returned '%s'\n", vals
[i
], temp
);
1142 UErrorCode status
= U_ZERO_ERROR
;
1143 unum_toPattern(fmt
, FALSE
, buffer
, BUFSIZE
, &status
);
1144 if (U_SUCCESS(status
)) {
1145 u_austrcpy(temp
, buffer
);
1146 log_verbose("pattern: '%s'\n", temp
);
1147 } else if (status
!= U_BUFFER_OVERFLOW_ERROR
) {
1148 log_err("toPattern failed unexpectedly: %s\n", u_errorName(status
));
1150 log_verbose("pattern too long to display\n");
1155 UErrorCode status
= U_ZERO_ERROR
;
1156 int len
= unum_getSymbol(fmt
, UNUM_CURRENCY_SYMBOL
, buffer
, BUFSIZE
, &status
);
1157 if (isDecimal
? U_FAILURE(status
) : (status
!= U_UNSUPPORTED_ERROR
)) {
1158 log_err("unexpected error getting symbol: '%s'\n", u_errorName(status
));
1161 unum_setSymbol(fmt
, UNUM_CURRENCY_SYMBOL
, buffer
, len
, &status
);
1162 if (isDecimal
? U_FAILURE(status
) : (status
!= U_UNSUPPORTED_ERROR
)) {
1163 log_err("unexpected error setting symbol: '%s'\n", u_errorName(status
));
1168 static void TestNonExistentCurrency() {
1169 UNumberFormat
*format
;
1170 UErrorCode status
= U_ZERO_ERROR
;
1171 UChar currencySymbol
[8];
1172 static const UChar QQQ
[] = {0x51, 0x51, 0x51, 0};
1174 /* Get a non-existent currency and make sure it returns the correct currency code. */
1175 format
= unum_open(UNUM_CURRENCY
, NULL
, 0, "th_TH@currency=QQQ", NULL
, &status
);
1176 if (format
== NULL
|| U_FAILURE(status
)) {
1177 log_err("unum_open did not return expected result for non-existent requested currency: '%s'\n", u_errorName(status
));
1180 unum_getSymbol(format
,
1181 UNUM_CURRENCY_SYMBOL
,
1183 sizeof(currencySymbol
)/sizeof(currencySymbol
[0]),
1185 if (u_strcmp(currencySymbol
, QQQ
) != 0) {
1186 log_err("unum_open set the currency to QQQ\n");
1192 static void TestRBNFFormat() {
1196 UChar tempUChars
[512];
1197 UNumberFormat
*formats
[5];
1198 int COUNT
= sizeof(formats
)/sizeof(formats
[0]);
1201 for (i
= 0; i
< COUNT
; ++i
) {
1206 status
= U_ZERO_ERROR
;
1207 u_uastrcpy(pat
, "#,##0.0#;(#,##0.0#)");
1208 formats
[0] = unum_open(UNUM_PATTERN_DECIMAL
, pat
, -1, "en_US", &perr
, &status
);
1209 if (U_FAILURE(status
)) {
1210 log_err("unable to open decimal pattern");
1213 status
= U_ZERO_ERROR
;
1214 formats
[1] = unum_open(UNUM_SPELLOUT
, NULL
, 0, "en_US", &perr
, &status
);
1215 if (U_FAILURE(status
)) {
1216 log_err("unable to open spellout");
1219 status
= U_ZERO_ERROR
;
1220 formats
[2] = unum_open(UNUM_ORDINAL
, NULL
, 0, "en_US", &perr
, &status
);
1221 if (U_FAILURE(status
)) {
1222 log_err("unable to open ordinal");
1225 status
= U_ZERO_ERROR
;
1226 formats
[3] = unum_open(UNUM_DURATION
, NULL
, 0, "en_US", &perr
, &status
);
1227 if (U_FAILURE(status
)) {
1228 log_err("unable to open duration");
1231 status
= U_ZERO_ERROR
;
1235 "x.x: << point >>;\n"
1236 "zero; one; two; three; four; five; six; seven; eight; nine;\n"
1237 "ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n"
1238 "seventeen; eighteen; nineteen;\n"
1239 "20: twenty[->>];\n"
1240 "30: thirty[->>];\n"
1244 "70: seventy[->>];\n"
1245 "80: eighty[->>];\n"
1246 "90: ninety[->>];\n"
1248 u_uastrcpy(tempUChars
,
1251 "20: twenty[ and change];\n"
1252 "30: thirty[ and change];\n"
1253 "40: forty[ and change];\n"
1254 "50: fifty[ and change];\n"
1255 "60: sixty[ and change];\n"
1256 "70: seventy[ and change];\n"
1257 "80: eighty[ and change];\n"
1258 "90: ninety[ and change];\n"
1262 "x.x: << point something;\n"
1264 "20: some reasonable number;\n"
1265 "100: some substantial number;\n"
1266 "100,000,000: some huge number;\n");
1267 /* This is to get around some compiler warnings about char * string length. */
1268 u_strcat(pat
, tempUChars
);
1269 formats
[4] = unum_open(UNUM_PATTERN_RULEBASED
, pat
, -1, "en_US", &perr
, &status
);
1270 if (U_FAILURE(status
)) {
1271 log_err("unable to open rulebased pattern");
1274 for (i
= 0; i
< COUNT
; ++i
) {
1275 log_verbose("\n\ntesting format %d\n", i
);
1276 test_fmt(formats
[i
], (UBool
)(i
== 0));
1279 for (i
= 0; i
< COUNT
; ++i
) {
1280 unum_close(formats
[i
]);
1284 #endif /* #if !UCONFIG_NO_FORMATTING */