~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/test/intltest/itrbnf.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *******************************************************************************
3
 
 * Copyright (C) 1996-2000, International Business Machines Corporation and    *
4
 
 * others. All Rights Reserved.                                                *
5
 
 *******************************************************************************
6
 
 */
7
 
#include "itrbnf.h"
8
 
 
9
 
#include "unicode/umachine.h"
10
 
 
11
 
#include "unicode/tblcoll.h"
12
 
#include "unicode/coleitr.h"
13
 
#include "unicode/ures.h"
14
 
#include "unicode/ustring.h"
15
 
//#include "llong.h"
16
 
 
17
 
#include <string.h>
18
 
 
19
 
// import com.ibm.text.RuleBasedNumberFormat;
20
 
// import com.ibm.test.TestFmwk;
21
 
 
22
 
// import java.util.Locale;
23
 
// import java.text.NumberFormat;
24
 
 
25
 
// current macro not in icu1.8.1
26
 
#define TESTCASE(id,test)             \
27
 
    case id:                          \
28
 
        name = #test;                 \
29
 
        if (exec) {                   \
30
 
            logln(#test "---");       \
31
 
            logln((UnicodeString)""); \
32
 
            test();                   \
33
 
        }                             \
34
 
        break
35
 
 
36
 
void IntlTestRBNF::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par*/)
37
 
{
38
 
    if (exec) logln("TestSuite RuleBasedNumberFormat");
39
 
    switch (index) {
40
 
#if U_HAVE_RBNF
41
 
      TESTCASE(0, TestEnglishSpellout);
42
 
      TESTCASE(1, TestOrdinalAbbreviations);
43
 
      TESTCASE(2, TestDurations);
44
 
      TESTCASE(3, TestSpanishSpellout);
45
 
      TESTCASE(4, TestFrenchSpellout);
46
 
      TESTCASE(5, TestSwissFrenchSpellout);
47
 
      TESTCASE(6, TestItalianSpellout);
48
 
      TESTCASE(7, TestGermanSpellout);
49
 
      TESTCASE(8, TestThaiSpellout);
50
 
      TESTCASE(9, TestAPI);
51
 
      TESTCASE(10, TestFractionalRuleSet);
52
 
      // TESTCASE(11, TestLLong);
53
 
#else
54
 
      TESTCASE(0, TestRBNFDisabled);
55
 
#endif
56
 
    default:
57
 
      name = "";
58
 
      break;
59
 
    }
60
 
}
61
 
 
62
 
#if U_HAVE_RBNF
63
 
 
64
 
void 
65
 
IntlTestRBNF::TestAPI() {
66
 
  // This test goes through the APIs that were not tested before. 
67
 
  // These tests are too small to have separate test classes/functions
68
 
 
69
 
  UErrorCode status = U_ZERO_ERROR;
70
 
  RuleBasedNumberFormat* formatter
71
 
      = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getUS(), status);
72
 
 
73
 
  logln("RBNF API test starting");
74
 
  // test clone
75
 
  {
76
 
    logln("Testing Clone");
77
 
    RuleBasedNumberFormat* rbnfClone = (RuleBasedNumberFormat *)formatter->clone();
78
 
    if(rbnfClone != NULL) {
79
 
      if(!(*rbnfClone == *formatter)) {
80
 
        errln("Clone should be semantically equivalent to the original!");
81
 
      }
82
 
      delete rbnfClone;
83
 
    } else {
84
 
      errln("Cloning failed!");
85
 
    }
86
 
  }
87
 
 
88
 
  // test assignment
89
 
  {
90
 
    logln("Testing assignment operator");
91
 
    RuleBasedNumberFormat assignResult(URBNF_SPELLOUT, Locale("es", "ES", ""), status);
92
 
    assignResult = *formatter;
93
 
    if(!(assignResult == *formatter)) {
94
 
      errln("Assignment result should be semantically equivalent to the original!");
95
 
    }
96
 
  }
97
 
 
98
 
  // test rule constructor
99
 
  {
100
 
    logln("Testing rule constructor");
101
 
    UResourceBundle *en = ures_open(NULL, "en", &status);
102
 
    if(U_FAILURE(status)) {
103
 
      errln("Unable to access resource bundle with data!");
104
 
    } else {
105
 
      int32_t ruleLen = 0;
106
 
      const UChar *spelloutRules = ures_getStringByKey(en, "SpelloutRules", &ruleLen, &status);
107
 
      if(U_FAILURE(status) || ruleLen == 0 || spelloutRules == NULL) {
108
 
        errln("Unable to access the rules string!");
109
 
      } else {
110
 
        UParseError perror;
111
 
        RuleBasedNumberFormat ruleCtorResult(spelloutRules, Locale::getUS(), perror, status);
112
 
        if(!(ruleCtorResult == *formatter)) {
113
 
          errln("Formatter constructed from the original rules should be semantically equivalent to the original!");
114
 
        }
115
 
      }
116
 
      ures_close(en);
117
 
    }
118
 
  }
119
 
 
120
 
  // test getRules
121
 
  {
122
 
    logln("Testing getRules function");
123
 
    UnicodeString rules = formatter->getRules();
124
 
    UParseError perror;
125
 
    RuleBasedNumberFormat fromRulesResult(rules, Locale::getUS(), perror, status);
126
 
 
127
 
    if(!(fromRulesResult == *formatter)) {
128
 
      errln("Formatter constructed from rules obtained by getRules should be semantically equivalent to the original!");
129
 
    }
130
 
  }
131
 
 
132
 
 
133
 
  {
134
 
    logln("Testing copy constructor");
135
 
    RuleBasedNumberFormat copyCtorResult(*formatter);
136
 
    if(!(copyCtorResult == *formatter)) {
137
 
      errln("Copy constructor result result should be semantically equivalent to the original!");
138
 
    }
139
 
  }
140
 
 
141
 
  // test ruleset names
142
 
  {
143
 
    logln("Testing getNumberOfRuleSetNames, getRuleSetName and format using rule set names");
144
 
    int32_t noOfRuleSetNames = formatter->getNumberOfRuleSetNames();
145
 
    if(noOfRuleSetNames == 0) {
146
 
      errln("Number of rule set names should be more than zero");
147
 
    }
148
 
    UnicodeString ruleSetName;
149
 
    int32_t i = 0;
150
 
    int32_t intFormatNum = 34567;
151
 
    double doubleFormatNum = 893411.234;
152
 
    logln("number of rule set names is %i", noOfRuleSetNames);
153
 
    for(i = 0; i < noOfRuleSetNames; i++) {
154
 
      FieldPosition pos1, pos2;
155
 
      UnicodeString intFormatResult, doubleFormatResult; 
156
 
      Formattable intParseResult, doubleParseResult;
157
 
 
158
 
      ruleSetName = formatter->getRuleSetName(i);
159
 
      log("Rule set name %i is ", i);
160
 
      log(ruleSetName);
161
 
      logln(". Format results are: ");
162
 
      intFormatResult = formatter->format(intFormatNum, ruleSetName, intFormatResult, pos1, status);
163
 
      doubleFormatResult = formatter->format(doubleFormatNum, ruleSetName, doubleFormatResult, pos2, status);
164
 
      if(U_FAILURE(status)) {
165
 
        errln("Format using a rule set failed");
166
 
        break;
167
 
      }
168
 
      logln(intFormatResult);
169
 
      logln(doubleFormatResult);
170
 
      formatter->setLenient(TRUE);
171
 
      formatter->parse(intFormatResult, intParseResult, status);
172
 
      formatter->parse(doubleFormatResult, doubleParseResult, status);
173
 
 
174
 
      logln("Parse results for lenient = TRUE, %i, %f", intParseResult.getLong(), doubleParseResult.getDouble());
175
 
 
176
 
      formatter->setLenient(FALSE);
177
 
      formatter->parse(intFormatResult, intParseResult, status);
178
 
      formatter->parse(doubleFormatResult, doubleParseResult, status);
179
 
 
180
 
      logln("Parse results for lenient = FALSE, %i, %f", intParseResult.getLong(), doubleParseResult.getDouble());
181
 
 
182
 
      if(U_FAILURE(status)) {
183
 
        errln("Error during parsing");
184
 
      }
185
 
 
186
 
      intFormatResult = formatter->format(intFormatNum, "BLABLA", intFormatResult, pos1, status);
187
 
      if(U_SUCCESS(status)) {
188
 
        errln("Using invalid rule set name should have failed");
189
 
        break;
190
 
      }
191
 
      status = U_ZERO_ERROR;
192
 
      doubleFormatResult = formatter->format(doubleFormatNum, "TRUC", doubleFormatResult, pos2, status);
193
 
      if(U_SUCCESS(status)) {
194
 
        errln("Using invalid rule set name should have failed");
195
 
        break;
196
 
      }
197
 
      status = U_ZERO_ERROR;
198
 
    }   
199
 
    status = U_ZERO_ERROR;
200
 
  }
201
 
 
202
 
  // clean up
203
 
  logln("Cleaning up");
204
 
  delete formatter;
205
 
}
206
 
 
207
 
void IntlTestRBNF::TestFractionalRuleSet()
208
 
{
209
 
    UnicodeString fracRules(
210
 
        "%main:\n"
211
 
               // this rule formats the number if it's 1 or more.  It formats
212
 
               // the integral part using a DecimalFormat ("#,##0" puts
213
 
               // thousands separators in the right places) and the fractional
214
 
               // part using %%frac.  If there is no fractional part, it
215
 
               // just shows the integral part.
216
 
        "    x.0: <#,##0<[ >%%frac>];\n"
217
 
               // this rule formats the number if it's between 0 and 1.  It
218
 
               // shows only the fractional part (0.5 shows up as "1/2," not
219
 
               // "0 1/2")
220
 
        "    0.x: >%%frac>;\n"
221
 
        // the fraction rule set.  This works the same way as the one in the
222
 
        // preceding example: We multiply the fractional part of the number
223
 
        // being formatted by each rule's base value and use the rule that
224
 
        // produces the result closest to 0 (or the first rule that produces 0).
225
 
        // Since we only provide rules for the numbers from 2 to 10, we know
226
 
        // we'll get a fraction with a denominator between 2 and 10.
227
 
        // "<0<" causes the numerator of the fraction to be formatted
228
 
        // using numerals
229
 
        "%%frac:\n"
230
 
        "    2: 1/2;\n"
231
 
        "    3: <0</3;\n"
232
 
        "    4: <0</4;\n"
233
 
        "    5: <0</5;\n"
234
 
        "    6: <0</6;\n"
235
 
        "    7: <0</7;\n"
236
 
        "    8: <0</8;\n"
237
 
        "    9: <0</9;\n"
238
 
        "   10: <0</10;\n");
239
 
 
240
 
    UErrorCode status = U_ZERO_ERROR;
241
 
    UParseError perror;
242
 
    RuleBasedNumberFormat formatter(fracRules, Locale::getEnglish(), perror, status);
243
 
    if (U_FAILURE(status)) {
244
 
        errln("FAIL: could not construct formatter");
245
 
    } else {
246
 
        static const char* testData[][2] = {
247
 
            { "0", "0" },
248
 
            { ".1", "1/10" },
249
 
            { ".11", "1/9" },
250
 
            { ".125", "1/8" },
251
 
            { ".1428", "1/7" },
252
 
            { ".1667", "1/6" },
253
 
            { ".2", "1/5" },
254
 
            { ".25", "1/4" },
255
 
            { ".333", "1/3" },
256
 
            { ".5", "1/2" },
257
 
            { "1.1", "1 1/10" },
258
 
            { "2.11", "2 1/9" },
259
 
            { "3.125", "3 1/8" },
260
 
            { "4.1428", "4 1/7" },
261
 
            { "5.1667", "5 1/6" },
262
 
            { "6.2", "6 1/5" },
263
 
            { "7.25", "7 1/4" },
264
 
            { "8.333", "8 1/3" },
265
 
            { "9.5", "9 1/2" },
266
 
            { ".2222", "2/9" },
267
 
            { ".4444", "4/9" },
268
 
            { ".5555", "5/9" },
269
 
            { "1.2856", "1 2/7" },
270
 
            { NULL, NULL }
271
 
        };
272
 
       doTest(&formatter, testData, FALSE); // exact values aren't parsable from fractions
273
 
    }
274
 
}
275
 
 
276
 
#if 0
277
 
#define LLAssert(a) \
278
 
  if (!(a)) errln("FAIL: " #a)
279
 
 
280
 
void IntlTestRBNF::TestLLongConstructors()
281
 
{
282
 
    logln("Testing constructors");
283
 
 
284
 
    // constant (shouldn't really be public)
285
 
    LLAssert(llong(llong::kD32).asDouble() == llong::kD32);
286
 
 
287
 
    // internal constructor (shouldn't really be public)
288
 
    LLAssert(llong(0, 1).asDouble() == 1);
289
 
    LLAssert(llong(1, 0).asDouble() == llong::kD32);
290
 
    LLAssert(llong((uint32_t)-1, (uint32_t)-1).asDouble() == -1);
291
 
 
292
 
    // public empty constructor
293
 
    LLAssert(llong().asDouble() == 0);
294
 
    
295
 
    // public int32_t constructor
296
 
    LLAssert(llong((int32_t)0).asInt() == (int32_t)0);
297
 
    LLAssert(llong((int32_t)1).asInt() == (int32_t)1);
298
 
    LLAssert(llong((int32_t)-1).asInt() == (int32_t)-1);
299
 
    LLAssert(llong((int32_t)0x7fffffff).asInt() == (int32_t)0x7fffffff);
300
 
    LLAssert(llong((int32_t)0xffffffff).asInt() == (int32_t)-1);
301
 
    LLAssert(llong((int32_t)0x80000000).asInt() == (int32_t)0x80000000);
302
 
 
303
 
    // public int16_t constructor
304
 
    LLAssert(llong((int16_t)0).asInt() == (int16_t)0);
305
 
    LLAssert(llong((int16_t)1).asInt() == (int16_t)1);
306
 
    LLAssert(llong((int16_t)-1).asInt() == (int16_t)-1);
307
 
    LLAssert(llong((int16_t)0x7fff).asInt() == (int16_t)0x7fff);
308
 
    LLAssert(llong((int16_t)0xffff).asInt() == (int16_t)0xffff);
309
 
    LLAssert(llong((int16_t)0x8000).asInt() == (int16_t)0x8000);
310
 
 
311
 
    // public int8_t constructor
312
 
    LLAssert(llong((int8_t)0).asInt() == (int8_t)0);
313
 
    LLAssert(llong((int8_t)1).asInt() == (int8_t)1);
314
 
    LLAssert(llong((int8_t)-1).asInt() == (int8_t)-1);
315
 
    LLAssert(llong((int8_t)0x7f).asInt() == (int8_t)0x7f);
316
 
    LLAssert(llong((int8_t)0xff).asInt() == (int8_t)0xff);
317
 
    LLAssert(llong((int8_t)0x80).asInt() == (int8_t)0x80);
318
 
 
319
 
    // public uint16_t constructor
320
 
    LLAssert(llong((uint16_t)0).asUInt() == (uint16_t)0);
321
 
    LLAssert(llong((uint16_t)1).asUInt() == (uint16_t)1);
322
 
    LLAssert(llong((uint16_t)-1).asUInt() == (uint16_t)-1);
323
 
    LLAssert(llong((uint16_t)0x7fff).asUInt() == (uint16_t)0x7fff);
324
 
    LLAssert(llong((uint16_t)0xffff).asUInt() == (uint16_t)0xffff);
325
 
    LLAssert(llong((uint16_t)0x8000).asUInt() == (uint16_t)0x8000);
326
 
 
327
 
    // public uint32_t constructor
328
 
    LLAssert(llong((uint32_t)0).asUInt() == (uint32_t)0);
329
 
    LLAssert(llong((uint32_t)1).asUInt() == (uint32_t)1);
330
 
    LLAssert(llong((uint32_t)-1).asUInt() == (uint32_t)-1);
331
 
    LLAssert(llong((uint32_t)0x7fffffff).asUInt() == (uint32_t)0x7fffffff);
332
 
    LLAssert(llong((uint32_t)0xffffffff).asUInt() == (uint32_t)-1);
333
 
    LLAssert(llong((uint32_t)0x80000000).asUInt() == (uint32_t)0x80000000);
334
 
 
335
 
    // public double constructor
336
 
    LLAssert(llong((double)0).asDouble() == (double)0);
337
 
    LLAssert(llong((double)1).asDouble() == (double)1);
338
 
    LLAssert(llong((double)0x7fffffff).asDouble() == (double)0x7fffffff);
339
 
    LLAssert(llong((double)0x80000000).asDouble() == (double)0x80000000);
340
 
    LLAssert(llong((double)0x80000001).asDouble() == (double)0x80000001);
341
 
 
342
 
    // can't access uprv_maxmantissa, so fake it
343
 
    double maxmantissa = (llong((int32_t)1) << 40).asDouble();
344
 
    LLAssert(llong(maxmantissa).asDouble() == maxmantissa);
345
 
    LLAssert(llong(-maxmantissa).asDouble() == -maxmantissa);
346
 
 
347
 
    // copy constructor
348
 
    LLAssert(llong(llong(0, 1)).asDouble() == 1);
349
 
    LLAssert(llong(llong(1, 0)).asDouble() == llong::kD32);
350
 
    LLAssert(llong(llong(-1, (uint32_t)-1)).asDouble() == -1);
351
 
 
352
 
    // asInt - test unsigned to signed narrowing conversion
353
 
    LLAssert(llong((uint32_t)-1).asInt() == (int32_t)0x7fffffff);
354
 
    LLAssert(llong(-1, 0).asInt() == (int32_t)0x80000000);
355
 
 
356
 
    // asUInt - test signed to unsigned narrowing conversion
357
 
    LLAssert(llong((int32_t)-1).asUInt() == (uint32_t)-1);
358
 
    LLAssert(llong((int32_t)0x80000000).asUInt() == (uint32_t)0x80000000);
359
 
 
360
 
    // asDouble already tested
361
 
 
362
 
}
363
 
 
364
 
void IntlTestRBNF::TestLLongSimpleOperators()
365
 
{
366
 
    logln("Testing simple operators");
367
 
 
368
 
    // operator==
369
 
    LLAssert(llong() == llong(0, 0));
370
 
    LLAssert(llong(1,0) == llong(1, 0));
371
 
    LLAssert(llong(0,1) == llong(0, 1));
372
 
 
373
 
    // operator!=
374
 
    LLAssert(llong(1,0) != llong(1,1));
375
 
    LLAssert(llong(0,1) != llong(1,1));
376
 
    LLAssert(llong(0xffffffff,0xffffffff) != llong(0x7fffffff, 0xffffffff));
377
 
 
378
 
    // unsigned >
379
 
    LLAssert(llong((int32_t)-1).ugt(llong(0x7fffffff, 0xffffffff)));
380
 
 
381
 
    // unsigned <
382
 
    LLAssert(llong(0x7fffffff, 0xffffffff).ult(llong((int32_t)-1)));
383
 
 
384
 
    // unsigned >=
385
 
    LLAssert(llong((int32_t)-1).uge(llong(0x7fffffff, 0xffffffff)));
386
 
    LLAssert(llong((int32_t)-1).uge(llong((int32_t)-1)));
387
 
 
388
 
    // unsigned <=
389
 
    LLAssert(llong(0x7fffffff, 0xffffffff).ule(llong((int32_t)-1)));
390
 
    LLAssert(llong((int32_t)-1).ule(llong((int32_t)-1)));
391
 
 
392
 
    // operator>
393
 
    LLAssert(llong(1, 1) > llong(1, 0));
394
 
    LLAssert(llong(0, 0x80000000) > llong(0, 0x7fffffff));
395
 
    LLAssert(llong(0x80000000, 1) > llong(0x80000000, 0));
396
 
    LLAssert(llong(1, 0) > llong(0, 0x7fffffff));
397
 
    LLAssert(llong(1, 0) > llong(0, 0xffffffff));
398
 
    LLAssert(llong(0, 0) > llong(0x80000000, 1));
399
 
 
400
 
    // operator<
401
 
    LLAssert(llong(1, 0) < llong(1, 1));
402
 
    LLAssert(llong(0, 0x7fffffff) < llong(0, 0x80000000));
403
 
    LLAssert(llong(0x80000000, 0) < llong(0x80000000, 1));
404
 
    LLAssert(llong(0, 0x7fffffff) < llong(1, 0));
405
 
    LLAssert(llong(0, 0xffffffff) < llong(1, 0));
406
 
    LLAssert(llong(0x80000000, 1) < llong(0, 0));
407
 
 
408
 
    // operator>=
409
 
    LLAssert(llong(1, 1) >= llong(1, 0));
410
 
    LLAssert(llong(0, 0x80000000) >= llong(0, 0x7fffffff));
411
 
    LLAssert(llong(0x80000000, 1) >= llong(0x80000000, 0));
412
 
    LLAssert(llong(1, 0) >= llong(0, 0x7fffffff));
413
 
    LLAssert(llong(1, 0) >= llong(0, 0xffffffff));
414
 
    LLAssert(llong(0, 0) >= llong(0x80000000, 1));
415
 
    LLAssert(llong() >= llong(0, 0));
416
 
    LLAssert(llong(1,0) >= llong(1, 0));
417
 
    LLAssert(llong(0,1) >= llong(0, 1));
418
 
 
419
 
    // operator<=
420
 
    LLAssert(llong(1, 0) <= llong(1, 1));
421
 
    LLAssert(llong(0, 0x7fffffff) <= llong(0, 0x80000000));
422
 
    LLAssert(llong(0x80000000, 0) <= llong(0x80000000, 1));
423
 
    LLAssert(llong(0, 0x7fffffff) <= llong(1, 0));
424
 
    LLAssert(llong(0, 0xffffffff) <= llong(1, 0));
425
 
    LLAssert(llong(0x80000000, 1) <= llong(0, 0));
426
 
    LLAssert(llong() <= llong(0, 0));
427
 
    LLAssert(llong(1,0) <= llong(1, 0));
428
 
    LLAssert(llong(0,1) <= llong(0, 1));
429
 
 
430
 
    // operator==(int32)
431
 
    LLAssert(llong() == (int32_t)0);
432
 
    LLAssert(llong(0,1) == (int32_t)1);
433
 
 
434
 
    // operator!=(int32)
435
 
    LLAssert(llong(1,0) != (int32_t)0);
436
 
    LLAssert(llong(0,1) != (int32_t)2);
437
 
    LLAssert(llong(0,0xffffffff) != (int32_t)-1);
438
 
 
439
 
    llong negOne(0xffffffff, 0xffffffff);
440
 
 
441
 
    // operator>(int32)
442
 
    LLAssert(llong(0, 0x80000000) > (int32_t)0x7fffffff);
443
 
    LLAssert(negOne > (int32_t)-2);
444
 
    LLAssert(llong(1, 0) > (int32_t)0x7fffffff);
445
 
    LLAssert(llong(0, 0) > (int32_t)-1);
446
 
 
447
 
    // operator<(int32)
448
 
    LLAssert(llong(0, 0x7ffffffe) < (int32_t)0x7fffffff);
449
 
    LLAssert(llong(0xffffffff, 0xfffffffe) < (int32_t)-1);
450
 
 
451
 
    // operator>=(int32)
452
 
    LLAssert(llong(0, 0x80000000) >= (int32_t)0x7fffffff);
453
 
    LLAssert(negOne >= (int32_t)-2);
454
 
    LLAssert(llong(1, 0) >= (int32_t)0x7fffffff);
455
 
    LLAssert(llong(0, 0) >= (int32_t)-1);
456
 
    LLAssert(llong() >= (int32_t)0);
457
 
    LLAssert(llong(0,1) >= (int32_t)1);
458
 
 
459
 
    // operator<=(int32)
460
 
    LLAssert(llong(0, 0x7ffffffe) <= (int32_t)0x7fffffff);
461
 
    LLAssert(llong(0xffffffff, 0xfffffffe) <= (int32_t)-1);
462
 
    LLAssert(llong() <= (int32_t)0);
463
 
    LLAssert(llong(0,1) <= (int32_t)1);
464
 
 
465
 
    // operator=
466
 
    LLAssert((llong(2,3) = llong((uint32_t)-1)).asUInt() == (uint32_t)-1);
467
 
 
468
 
    // operator <<=
469
 
    LLAssert((llong(1, 1) <<= 0) ==  llong(1, 1));
470
 
    LLAssert((llong(1, 1) <<= 31) == llong(0x80000000, 0x80000000));
471
 
    LLAssert((llong(1, 1) <<= 32) == llong(1, 0));
472
 
    LLAssert((llong(1, 1) <<= 63) == llong(0x80000000, 0));
473
 
    LLAssert((llong(1, 1) <<= 64) == llong(1, 1)); // only lower 6 bits are used
474
 
    LLAssert((llong(1, 1) <<= -1) == llong(0x80000000, 0)); // only lower 6 bits are used
475
 
 
476
 
    // operator <<
477
 
    LLAssert((llong((int32_t)1) << 5).asUInt() == 32);
478
 
 
479
 
    // operator >>= (sign extended)
480
 
    LLAssert((llong(0x7fffa0a0, 0xbcbcdfdf) >>= 16) == llong(0x7fff,0xa0a0bcbc));
481
 
    LLAssert((llong(0x8000789a, 0xbcde0000) >>= 16) == llong(0xffff8000,0x789abcde));
482
 
    LLAssert((llong(0x80000000, 0) >>= 63) == llong(0xffffffff, 0xffffffff));
483
 
    LLAssert((llong(0x80000000, 0) >>= 47) == llong(0xffffffff, 0xffff0000));
484
 
    LLAssert((llong(0x80000000, 0x80000000) >> 64) == llong(0x80000000, 0x80000000)); // only lower 6 bits are used
485
 
    LLAssert((llong(0x80000000, 0) >>= -1) == llong(0xffffffff, 0xffffffff)); // only lower 6 bits are used
486
 
 
487
 
    // operator >> sign extended)
488
 
    LLAssert((llong(0x8000789a, 0xbcde0000) >> 16) == llong(0xffff8000,0x789abcde));
489
 
 
490
 
    // ushr (right shift without sign extension)
491
 
    LLAssert(llong(0x7fffa0a0, 0xbcbcdfdf).ushr(16) == llong(0x7fff,0xa0a0bcbc));
492
 
    LLAssert(llong(0x8000789a, 0xbcde0000).ushr(16) == llong(0x00008000,0x789abcde));
493
 
    LLAssert(llong(0x80000000, 0).ushr(63) == llong(0, 1));
494
 
    LLAssert(llong(0x80000000, 0).ushr(47) == llong(0, 0x10000));
495
 
    LLAssert(llong(0x80000000, 0x80000000).ushr(64) == llong(0x80000000, 0x80000000)); // only lower 6 bits are used
496
 
    LLAssert(llong(0x80000000, 0).ushr(-1) == llong(0, 1)); // only lower 6 bits are used
497
 
 
498
 
    // operator&(llong)
499
 
    LLAssert((llong(0x55555555, 0x55555555) & llong(0xaaaaffff, 0xffffaaaa)) == llong(0x00005555, 0x55550000));
500
 
 
501
 
    // operator|(llong)
502
 
    LLAssert((llong(0x55555555, 0x55555555) | llong(0xaaaaffff, 0xffffaaaa)) == llong(0xffffffff, 0xffffffff));
503
 
 
504
 
    // operator^(llong)
505
 
    LLAssert((llong(0x55555555, 0x55555555) ^ llong(0xaaaaffff, 0xffffaaaa)) == llong(0xffffaaaa, 0xaaaaffff));
506
 
 
507
 
    // operator&(uint32)
508
 
    LLAssert((llong(0x55555555, 0x55555555) & (uint32_t)0xffffaaaa) == llong(0, 0x55550000));
509
 
 
510
 
    // operator|(uint32)
511
 
    LLAssert((llong(0x55555555, 0x55555555) | (uint32_t)0xffffaaaa) == llong(0x55555555, 0xffffffff));
512
 
 
513
 
    // operator^(uint32)
514
 
    LLAssert((llong(0x55555555, 0x55555555) ^ (uint32_t)0xffffaaaa) == llong(0x55555555, 0xaaaaffff));
515
 
 
516
 
    // operator~
517
 
    LLAssert(~llong(0x55555555, 0x55555555) == llong(0xaaaaaaaa, 0xaaaaaaaa));
518
 
 
519
 
    // operator&=(llong)
520
 
    LLAssert((llong(0x55555555, 0x55555555) &= llong(0xaaaaffff, 0xffffaaaa)) == llong(0x00005555, 0x55550000));
521
 
 
522
 
    // operator|=(llong)
523
 
    LLAssert((llong(0x55555555, 0x55555555) |= llong(0xaaaaffff, 0xffffaaaa)) == llong(0xffffffff, 0xffffffff));
524
 
 
525
 
    // operator^=(llong)
526
 
    LLAssert((llong(0x55555555, 0x55555555) ^= llong(0xaaaaffff, 0xffffaaaa)) == llong(0xffffaaaa, 0xaaaaffff));
527
 
 
528
 
    // operator&=(uint32)
529
 
    LLAssert((llong(0x55555555, 0x55555555) &= (uint32_t)0xffffaaaa) == llong(0, 0x55550000));
530
 
 
531
 
    // operator|=(uint32)
532
 
    LLAssert((llong(0x55555555, 0x55555555) |= (uint32_t)0xffffaaaa) == llong(0x55555555, 0xffffffff));
533
 
 
534
 
    // operator^=(uint32)
535
 
    LLAssert((llong(0x55555555, 0x55555555) ^= (uint32_t)0xffffaaaa) == llong(0x55555555, 0xaaaaffff));
536
 
 
537
 
    // prefix inc
538
 
    LLAssert(llong(1, 0) == ++llong(0,0xffffffff));
539
 
 
540
 
    // prefix dec
541
 
    LLAssert(llong(0,0xffffffff) == --llong(1, 0));
542
 
 
543
 
    // postfix inc
544
 
    {
545
 
        llong n(0, 0xffffffff);
546
 
        LLAssert(llong(0, 0xffffffff) == n++);
547
 
        LLAssert(llong(1, 0) == n);
548
 
    }
549
 
 
550
 
    // postfix dec
551
 
    {
552
 
        llong n(1, 0);
553
 
        LLAssert(llong(1, 0) == n--);
554
 
        LLAssert(llong(0, 0xffffffff) == n);
555
 
    }
556
 
 
557
 
    // unary minus
558
 
    LLAssert(llong(0, 0) == -llong(0, 0));
559
 
    LLAssert(llong(0xffffffff, 0xffffffff) == -llong(0, 1));
560
 
    LLAssert(llong(0, 1) == -llong(0xffffffff, 0xffffffff));
561
 
    LLAssert(llong(0x7fffffff, 0xffffffff) == -llong(0x80000000, 1));
562
 
    LLAssert(llong(0x80000000, 0) == -llong(0x80000000, 0)); // !!! we don't handle overflow
563
 
 
564
 
    // operator-=
565
 
    { 
566
 
        llong n;
567
 
        LLAssert((n -= llong(0, 1)) == llong(0xffffffff, 0xffffffff));
568
 
        LLAssert(n == llong(0xffffffff, 0xffffffff));
569
 
 
570
 
        n = llong(1, 0);
571
 
        LLAssert((n -= llong(0, 1)) == llong(0, 0xffffffff));
572
 
        LLAssert(n == llong(0, 0xffffffff));
573
 
    }
574
 
 
575
 
    // operator-
576
 
    {
577
 
        llong n;
578
 
        LLAssert((n - llong(0, 1)) == llong(0xffffffff, 0xffffffff));
579
 
        LLAssert(n == llong(0, 0));
580
 
 
581
 
        n = llong(1, 0);
582
 
        LLAssert((n - llong(0, 1)) == llong(0, 0xffffffff));
583
 
        LLAssert(n == llong(1, 0));
584
 
    }
585
 
 
586
 
    // operator+=
587
 
    {
588
 
        llong n(0xffffffff, 0xffffffff);
589
 
        LLAssert((n += llong(0, 1)) == llong(0, 0));
590
 
        LLAssert(n == llong(0, 0));
591
 
 
592
 
        n = llong(0, 0xffffffff);
593
 
        LLAssert((n += llong(0, 1)) == llong(1, 0));
594
 
        LLAssert(n == llong(1, 0));
595
 
    }
596
 
 
597
 
    // operator+
598
 
    {
599
 
        llong n(0xffffffff, 0xffffffff);
600
 
        LLAssert((n + llong(0, 1)) == llong(0, 0));
601
 
        LLAssert(n == llong(0xffffffff, 0xffffffff));
602
 
 
603
 
        n = llong(0, 0xffffffff);
604
 
        LLAssert((n + llong(0, 1)) == llong(1, 0));
605
 
        LLAssert(n == llong(0, 0xffffffff));
606
 
    }
607
 
 
608
 
}
609
 
 
610
 
void IntlTestRBNF::TestLLong()
611
 
{
612
 
    logln("Starting TestLLong");
613
 
 
614
 
    TestLLongConstructors();
615
 
 
616
 
    TestLLongSimpleOperators();
617
 
 
618
 
    logln("Testing operator*=, operator*");
619
 
 
620
 
    // operator*=, operator*
621
 
    // small and large values, positive, &NEGative, zero
622
 
    // also test commutivity
623
 
    {
624
 
        const llong ZERO;
625
 
        const llong ONE(0, 1);
626
 
        const llong NEG_ONE((int32_t)-1);
627
 
        const llong THREE(0, 3);
628
 
        const llong NEG_THREE((int32_t)-3);
629
 
        const llong TWO_TO_16(0, 0x10000);
630
 
        const llong NEG_TWO_TO_16 = -TWO_TO_16;
631
 
        const llong TWO_TO_32(1, 0);
632
 
        const llong NEG_TWO_TO_32 = -TWO_TO_32;
633
 
 
634
 
        const llong NINE(0, 9);
635
 
        const llong NEG_NINE = -NINE;
636
 
 
637
 
        const llong TWO_TO_16X3(0, 0x00030000);
638
 
        const llong NEG_TWO_TO_16X3 = -TWO_TO_16X3;
639
 
 
640
 
        const llong TWO_TO_32X3(3, 0);
641
 
        const llong NEG_TWO_TO_32X3 = -TWO_TO_32X3;
642
 
 
643
 
        const llong TWO_TO_48(0x10000, 0);
644
 
        const llong NEG_TWO_TO_48 = -TWO_TO_48;
645
 
 
646
 
        const int32_t VALUE_WIDTH = 9;
647
 
        const llong* values[VALUE_WIDTH] = {
648
 
            &ZERO, &ONE, &NEG_ONE, &THREE, &NEG_THREE, &TWO_TO_16, &NEG_TWO_TO_16, &TWO_TO_32, &NEG_TWO_TO_32
649
 
        };
650
 
 
651
 
        const llong* answers[VALUE_WIDTH*VALUE_WIDTH] = {
652
 
            &ZERO, &ZERO, &ZERO, &ZERO, &ZERO, &ZERO, &ZERO, &ZERO, &ZERO,
653
 
            &ZERO, &ONE,  &NEG_ONE, &THREE, &NEG_THREE,  &TWO_TO_16, &NEG_TWO_TO_16, &TWO_TO_32, &NEG_TWO_TO_32,
654
 
            &ZERO, &NEG_ONE, &ONE, &NEG_THREE, &THREE, &NEG_TWO_TO_16, &TWO_TO_16, &NEG_TWO_TO_32, &TWO_TO_32,
655
 
            &ZERO, &THREE, &NEG_THREE, &NINE, &NEG_NINE, &TWO_TO_16X3, &NEG_TWO_TO_16X3, &TWO_TO_32X3, &NEG_TWO_TO_32X3,
656
 
            &ZERO, &NEG_THREE, &THREE, &NEG_NINE, &NINE, &NEG_TWO_TO_16X3, &TWO_TO_16X3, &NEG_TWO_TO_32X3, &TWO_TO_32X3,
657
 
            &ZERO, &TWO_TO_16, &NEG_TWO_TO_16, &TWO_TO_16X3, &NEG_TWO_TO_16X3, &TWO_TO_32, &NEG_TWO_TO_32, &TWO_TO_48, &NEG_TWO_TO_48,
658
 
            &ZERO, &NEG_TWO_TO_16, &TWO_TO_16, &NEG_TWO_TO_16X3, &TWO_TO_16X3, &NEG_TWO_TO_32, &TWO_TO_32, &NEG_TWO_TO_48, &TWO_TO_48,
659
 
            &ZERO, &TWO_TO_32, &NEG_TWO_TO_32, &TWO_TO_32X3, &NEG_TWO_TO_32X3, &TWO_TO_48, &NEG_TWO_TO_48, &ZERO, &ZERO, 
660
 
            &ZERO, &NEG_TWO_TO_32, &TWO_TO_32, &NEG_TWO_TO_32X3, &TWO_TO_32X3, &NEG_TWO_TO_48, &TWO_TO_48, &ZERO, &ZERO
661
 
        };
662
 
 
663
 
        for (int i = 0; i < VALUE_WIDTH; ++i) {
664
 
            for (int j = 0; j < VALUE_WIDTH; ++j) {
665
 
                llong lhs = *values[i];
666
 
                llong rhs = *values[j];
667
 
                llong ans = *answers[i*VALUE_WIDTH + j];
668
 
 
669
 
                llong n = lhs;
670
 
 
671
 
                LLAssert((n *= rhs) == ans);
672
 
                LLAssert(n == ans);
673
 
 
674
 
                n = lhs;
675
 
                LLAssert((n * rhs) == ans);
676
 
                LLAssert(n == lhs);
677
 
            }
678
 
        }
679
 
    }
680
 
 
681
 
    logln("Testing operator/=, operator/");
682
 
    // operator/=, operator/
683
 
    // test num = 0, div = 0, pos/neg, > 2^32, div > num
684
 
    {
685
 
        const llong ZERO;
686
 
        const llong ONE(0, 1);
687
 
        const llong NEG_ONE = -ONE;
688
 
        const llong MAX(0x7fffffff, 0xffffffff);
689
 
        const llong MIN(0x80000000, 0);
690
 
        const llong TWO(0, 2);
691
 
        const llong NEG_TWO = -TWO;
692
 
        const llong FIVE(0, 5);
693
 
        const llong NEG_FIVE = -FIVE;
694
 
        const llong TWO_TO_32(1, 0);
695
 
        const llong NEG_TWO_TO_32 = -TWO_TO_32;
696
 
        const llong TWO_TO_32d5 = llong(TWO_TO_32.asDouble()/5.0);
697
 
        const llong NEG_TWO_TO_32d5 = -TWO_TO_32d5;
698
 
        const llong TWO_TO_32X5 = TWO_TO_32 * FIVE;
699
 
        const llong NEG_TWO_TO_32X5 = -TWO_TO_32X5;
700
 
 
701
 
        const llong* tuples[] = { // lhs, rhs, ans
702
 
            &ZERO, &ZERO, &ZERO,
703
 
            &ONE, &ZERO,&MAX,
704
 
            &NEG_ONE, &ZERO, &MIN,
705
 
            &ONE, &ONE, &ONE,
706
 
            &ONE, &NEG_ONE, &NEG_ONE,
707
 
            &NEG_ONE, &ONE, &NEG_ONE,
708
 
            &NEG_ONE, &NEG_ONE, &ONE,
709
 
            &FIVE, &TWO, &TWO,
710
 
            &FIVE, &NEG_TWO, &NEG_TWO,
711
 
            &NEG_FIVE, &TWO, &NEG_TWO,
712
 
            &NEG_FIVE, &NEG_TWO, &TWO,
713
 
            &TWO, &FIVE, &ZERO,
714
 
            &TWO, &NEG_FIVE, &ZERO,
715
 
            &NEG_TWO, &FIVE, &ZERO,
716
 
            &NEG_TWO, &NEG_FIVE, &ZERO,
717
 
            &TWO_TO_32, &TWO_TO_32, &ONE,
718
 
            &TWO_TO_32, &NEG_TWO_TO_32, &NEG_ONE,
719
 
            &NEG_TWO_TO_32, &TWO_TO_32, &NEG_ONE,
720
 
            &NEG_TWO_TO_32, &NEG_TWO_TO_32, &ONE,
721
 
            &TWO_TO_32, &FIVE, &TWO_TO_32d5,
722
 
            &TWO_TO_32, &NEG_FIVE, &NEG_TWO_TO_32d5,
723
 
            &NEG_TWO_TO_32, &FIVE, &NEG_TWO_TO_32d5,
724
 
            &NEG_TWO_TO_32, &NEG_FIVE, &TWO_TO_32d5,
725
 
            &TWO_TO_32X5, &FIVE, &TWO_TO_32,
726
 
            &TWO_TO_32X5, &NEG_FIVE, &NEG_TWO_TO_32,
727
 
            &NEG_TWO_TO_32X5, &FIVE, &NEG_TWO_TO_32,
728
 
            &NEG_TWO_TO_32X5, &NEG_FIVE, &TWO_TO_32,
729
 
            &TWO_TO_32X5, &TWO_TO_32, &FIVE,
730
 
            &TWO_TO_32X5, &NEG_TWO_TO_32, &NEG_FIVE,
731
 
            &NEG_TWO_TO_32X5, &NEG_TWO_TO_32, &FIVE,
732
 
            &NEG_TWO_TO_32X5, &TWO_TO_32, &NEG_FIVE
733
 
        };
734
 
        const int TUPLE_WIDTH = 3;
735
 
        const int TUPLE_COUNT = (int)(sizeof(tuples)/sizeof(tuples[0]))/TUPLE_WIDTH;
736
 
        for (int i = 0; i < TUPLE_COUNT; ++i) {
737
 
            const llong lhs = *tuples[i*TUPLE_WIDTH+0];
738
 
            const llong rhs = *tuples[i*TUPLE_WIDTH+1];
739
 
            const llong ans = *tuples[i*TUPLE_WIDTH+2];
740
 
 
741
 
            llong n = lhs;
742
 
            if (!((n /= rhs) == ans)) {
743
 
                errln("fail: (n /= rhs) == ans");
744
 
            }
745
 
            LLAssert(n == ans);
746
 
 
747
 
            n = lhs;
748
 
            LLAssert((n / rhs) == ans);
749
 
            LLAssert(n == lhs);
750
 
        }
751
 
    }
752
 
 
753
 
    logln("Testing operator%%=, operator%%");
754
 
    //operator%=, operator%
755
 
    {
756
 
        const llong ZERO;
757
 
        const llong ONE(0, 1);
758
 
        const llong TWO(0, 2);
759
 
        const llong THREE(0,3);
760
 
        const llong FOUR(0, 4);
761
 
        const llong FIVE(0, 5);
762
 
        const llong SIX(0, 6);
763
 
 
764
 
        const llong NEG_ONE = -ONE;
765
 
        const llong NEG_TWO = -TWO;
766
 
        const llong NEG_THREE = -THREE;
767
 
        const llong NEG_FOUR = -FOUR;
768
 
        const llong NEG_FIVE = -FIVE;
769
 
        const llong NEG_SIX = -SIX;
770
 
 
771
 
        const llong NINETY_NINE(0, 99);
772
 
        const llong HUNDRED(0, 100);
773
 
        const llong HUNDRED_ONE(0, 101);
774
 
 
775
 
        const llong BIG(0x12345678, 0x9abcdef0);
776
 
        const llong BIG_FIVE(BIG * FIVE);
777
 
        const llong BIG_FIVEm1 = BIG_FIVE - ONE;
778
 
        const llong BIG_FIVEp1 = BIG_FIVE + ONE;
779
 
 
780
 
        const llong* tuples[] = {
781
 
            &ZERO, &FIVE, &ZERO,
782
 
            &ONE, &FIVE, &ONE,
783
 
            &TWO, &FIVE, &TWO,
784
 
            &THREE, &FIVE, &THREE,
785
 
            &FOUR, &FIVE, &FOUR,
786
 
            &FIVE, &FIVE, &ZERO,
787
 
            &SIX, &FIVE, &ONE,
788
 
            &ZERO, &NEG_FIVE, &ZERO,
789
 
            &ONE, &NEG_FIVE, &ONE,
790
 
            &TWO, &NEG_FIVE, &TWO,
791
 
            &THREE, &NEG_FIVE, &THREE,
792
 
            &FOUR, &NEG_FIVE, &FOUR,
793
 
            &FIVE, &NEG_FIVE, &ZERO,
794
 
            &SIX, &NEG_FIVE, &ONE,
795
 
            &NEG_ONE, &FIVE, &NEG_ONE,
796
 
            &NEG_TWO, &FIVE, &NEG_TWO,
797
 
            &NEG_THREE, &FIVE, &NEG_THREE,
798
 
            &NEG_FOUR, &FIVE, &NEG_FOUR,
799
 
            &NEG_FIVE, &FIVE, &ZERO,
800
 
            &NEG_SIX, &FIVE, &NEG_ONE,
801
 
            &NEG_ONE, &NEG_FIVE, &NEG_ONE,
802
 
            &NEG_TWO, &NEG_FIVE, &NEG_TWO,
803
 
            &NEG_THREE, &NEG_FIVE, &NEG_THREE,
804
 
            &NEG_FOUR, &NEG_FIVE, &NEG_FOUR,
805
 
            &NEG_FIVE, &NEG_FIVE, &ZERO,
806
 
            &NEG_SIX, &NEG_FIVE, &NEG_ONE,
807
 
            &NINETY_NINE, &FIVE, &FOUR,
808
 
            &HUNDRED, &FIVE, &ZERO,
809
 
            &HUNDRED_ONE, &FIVE, &ONE,
810
 
            &BIG_FIVEm1, &FIVE, &FOUR,
811
 
            &BIG_FIVE, &FIVE, &ZERO,
812
 
            &BIG_FIVEp1, &FIVE, &ONE
813
 
        };
814
 
        const int TUPLE_WIDTH = 3;
815
 
        const int TUPLE_COUNT = (int)(sizeof(tuples)/sizeof(tuples[0]))/TUPLE_WIDTH;
816
 
        for (int i = 0; i < TUPLE_COUNT; ++i) {
817
 
            const llong lhs = *tuples[i*TUPLE_WIDTH+0];
818
 
            const llong rhs = *tuples[i*TUPLE_WIDTH+1];
819
 
            const llong ans = *tuples[i*TUPLE_WIDTH+2];
820
 
 
821
 
            llong n = lhs;
822
 
            if (!((n %= rhs) == ans)) {
823
 
                errln("fail: (n %= rhs) == ans");
824
 
            }
825
 
            LLAssert(n == ans);
826
 
 
827
 
            n = lhs;
828
 
            LLAssert((n % rhs) == ans);
829
 
            LLAssert(n == lhs);
830
 
        }
831
 
    }
832
 
 
833
 
    logln("Testing pow");
834
 
    // pow
835
 
    LLAssert(llong(0, 0).pow(0) == llong(0, 0));
836
 
    LLAssert(llong(0, 0).pow(2) == llong(0, 0));
837
 
    LLAssert(llong(0, 2).pow(0) == llong(0, 1));
838
 
    LLAssert(llong(0, 2).pow(2) == llong(0, 4));
839
 
    LLAssert(llong(0, 2).pow(32) == llong(1, 0));
840
 
    LLAssert(llong(0, 5).pow(10) == llong((double)5.0 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
841
 
 
842
 
    // absolute value
843
 
    {
844
 
        const llong n(0xffffffff,0xffffffff);
845
 
        LLAssert(n.abs() == llong(0, 1));
846
 
    }
847
 
 
848
 
#ifdef RBNF_DEBUG
849
 
    logln("Testing atoll");
850
 
    // atoll
851
 
    const char empty[] = "";
852
 
    const char zero[] = "0";
853
 
    const char neg_one[] = "-1";
854
 
    const char neg_12345[] = "-12345";
855
 
    const char big1[] = "123456789abcdef0";
856
 
    const char big2[] = "fFfFfFfFfFfFfFfF";
857
 
    LLAssert(llong::atoll(empty) == llong(0, 0));
858
 
    LLAssert(llong::atoll(zero) == llong(0, 0));
859
 
    LLAssert(llong::atoll(neg_one) == llong(0xffffffff, 0xffffffff));
860
 
    LLAssert(llong::atoll(neg_12345) == -llong(0, 12345));
861
 
    LLAssert(llong::atoll(big1, 16) == llong(0x12345678, 0x9abcdef0));
862
 
    LLAssert(llong::atoll(big2, 16) == llong(0xffffffff, 0xffffffff));
863
 
#endif
864
 
 
865
 
    // u_atoll
866
 
    const UChar uempty[] = { 0 };
867
 
    const UChar uzero[] = { 0x30, 0 };
868
 
    const UChar uneg_one[] = { 0x2d, 0x31, 0 };
869
 
    const UChar uneg_12345[] = { 0x2d, 0x31, 0x32, 0x33, 0x34, 0x35, 0 };
870
 
    const UChar ubig1[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x30, 0 };
871
 
    const UChar ubig2[] = { 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0x66, 0x46, 0 };
872
 
    LLAssert(llong::utoll(uempty) == llong(0, 0));
873
 
    LLAssert(llong::utoll(uzero) == llong(0, 0));
874
 
    LLAssert(llong::utoll(uneg_one) == llong(0xffffffff, 0xffffffff));
875
 
    LLAssert(llong::utoll(uneg_12345) == -llong(0, 12345));
876
 
    LLAssert(llong::utoll(ubig1, 16) == llong(0x12345678, 0x9abcdef0));
877
 
    LLAssert(llong::utoll(ubig2, 16) == llong(0xffffffff, 0xffffffff));
878
 
 
879
 
#ifdef RBNF_DEBUG
880
 
    logln("Testing lltoa");
881
 
    // lltoa
882
 
    {
883
 
        char buf[64]; // ascii
884
 
        LLAssert((llong(0, 0).lltoa(buf, (uint32_t)sizeof(buf)) == 1) && (strcmp(buf, zero) == 0));
885
 
        LLAssert((llong(0xffffffff, 0xffffffff).lltoa(buf, (uint32_t)sizeof(buf)) == 2) && (strcmp(buf, neg_one) == 0));
886
 
        LLAssert(((-llong(0, 12345)).lltoa(buf, (uint32_t)sizeof(buf)) == 6) && (strcmp(buf, neg_12345) == 0));
887
 
        LLAssert((llong(0x12345678, 0x9abcdef0).lltoa(buf, (uint32_t)sizeof(buf), 16) == 16) && (strcmp(buf, big1) == 0));
888
 
    }
889
 
#endif
890
 
 
891
 
    logln("Testing u_lltoa");
892
 
    // u_lltoa
893
 
    {
894
 
        UChar buf[64];
895
 
        LLAssert((llong(0, 0).lltou(buf, (uint32_t)sizeof(buf)) == 1) && (u_strcmp(buf, uzero) == 0));
896
 
        LLAssert((llong(0xffffffff, 0xffffffff).lltou(buf, (uint32_t)sizeof(buf)) == 2) && (u_strcmp(buf, uneg_one) == 0));
897
 
        LLAssert(((-llong(0, 12345)).lltou(buf, (uint32_t)sizeof(buf)) == 6) && (u_strcmp(buf, uneg_12345) == 0));
898
 
        LLAssert((llong(0x12345678, 0x9abcdef0).lltou(buf, (uint32_t)sizeof(buf), 16) == 16) && (u_strcmp(buf, ubig1) == 0));
899
 
    }
900
 
}
901
 
 
902
 
/* if 0 */
903
 
#endif
904
 
 
905
 
void 
906
 
IntlTestRBNF::TestEnglishSpellout() 
907
 
{
908
 
    UErrorCode status = U_ZERO_ERROR;
909
 
    RuleBasedNumberFormat* formatter
910
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getUS(), status);
911
 
 
912
 
    if (U_FAILURE(status)) {
913
 
        errln("FAIL: could not construct formatter");
914
 
    } else {
915
 
        static const char* testData[][2] = {
916
 
            { "1", "one" },
917
 
            { "2", "two" },
918
 
            { "15", "fifteen" },
919
 
            { "20", "twenty" },
920
 
            { "23", "twenty-three" },
921
 
            { "73", "seventy-three" },
922
 
            { "88", "eighty-eight" },
923
 
            { "100", "one hundred" },
924
 
            { "106", "one hundred and six" },
925
 
            { "127", "one hundred and twenty-seven" },
926
 
            { "200", "two hundred" },
927
 
            { "579", "five hundred and seventy-nine" },
928
 
            { "1,000", "one thousand" },
929
 
            { "2,000", "two thousand" },
930
 
            { "3,004", "three thousand and four" },
931
 
            { "4,567", "four thousand five hundred and sixty-seven" },
932
 
            { "15,943", "fifteen thousand nine hundred and forty-three" },
933
 
            { "2,345,678", "two million, three hundred and forty-five thousand, six hundred and seventy-eight" },
934
 
            { "-36", "minus thirty-six" },
935
 
            { "234.567", "two hundred and thirty-four point five six seven" },
936
 
            { NULL, NULL}
937
 
        };
938
 
 
939
 
        doTest(formatter, testData, TRUE);
940
 
 
941
 
        formatter->setLenient(TRUE);
942
 
        static const char* lpTestData[][2] = {
943
 
            { "fifty-7", "57" },
944
 
            { " fifty-7", "57" },
945
 
            { "  fifty-7", "57" },
946
 
            { "2 thousand six    HUNDRED fifty-7", "2,657" },
947
 
            { "fifteen hundred and zero", "1,500" },
948
 
            { "FOurhundred     thiRTY six", "436" },
949
 
            { NULL, NULL}
950
 
        };
951
 
        doLenientParseTest(formatter, lpTestData);
952
 
    }
953
 
    delete formatter;
954
 
}
955
 
 
956
 
void 
957
 
IntlTestRBNF::TestOrdinalAbbreviations() 
958
 
{
959
 
    UErrorCode status = U_ZERO_ERROR;
960
 
    RuleBasedNumberFormat* formatter
961
 
        = new RuleBasedNumberFormat(URBNF_ORDINAL, Locale::getUS(), status);
962
 
    
963
 
    if (U_FAILURE(status)) {
964
 
        errln("FAIL: could not construct formatter");
965
 
    } else {
966
 
        static const char* testData[][2] = {
967
 
            { "1", "1st" },
968
 
            { "2", "2nd" },
969
 
            { "3", "3rd" },
970
 
            { "4", "4th" },
971
 
            { "7", "7th" },
972
 
            { "10", "10th" },
973
 
            { "11", "11th" },
974
 
            { "13", "13th" },
975
 
            { "20", "20th" },
976
 
            { "21", "21st" },
977
 
            { "22", "22nd" },
978
 
            { "23", "23rd" },
979
 
            { "24", "24th" },
980
 
            { "33", "33rd" },
981
 
            { "102", "102nd" },
982
 
            { "312", "312th" },
983
 
            { "12,345", "12,345th" },
984
 
            { NULL, NULL}
985
 
        };
986
 
        
987
 
        doTest(formatter, testData, FALSE);
988
 
    }
989
 
    delete formatter;
990
 
}
991
 
 
992
 
void 
993
 
IntlTestRBNF::TestDurations() 
994
 
{
995
 
    UErrorCode status = U_ZERO_ERROR;
996
 
    RuleBasedNumberFormat* formatter
997
 
        = new RuleBasedNumberFormat(URBNF_DURATION, Locale::getUS(), status);
998
 
    
999
 
    if (U_FAILURE(status)) {
1000
 
        errln("FAIL: could not construct formatter");
1001
 
    } else {
1002
 
        static const char* testData[][2] = {
1003
 
            { "3,600", "1:00:00" },     //move me and I fail
1004
 
            { "0", "0 sec." },
1005
 
            { "1", "1 sec." },
1006
 
            { "24", "24 sec." },
1007
 
            { "60", "1:00" },
1008
 
            { "73", "1:13" },
1009
 
            { "145", "2:25" },
1010
 
            { "666", "11:06" },
1011
 
            //            { "3,600", "1:00:00" },
1012
 
            { "3,740", "1:02:20" },
1013
 
            { "10,293", "2:51:33" },
1014
 
            { NULL, NULL}
1015
 
        };
1016
 
        
1017
 
        doTest(formatter, testData, TRUE);
1018
 
        
1019
 
        formatter->setLenient(TRUE);
1020
 
        static const char* lpTestData[][2] = {
1021
 
            { "2-51-33", "10,293" },
1022
 
            { NULL, NULL}
1023
 
        };
1024
 
        doLenientParseTest(formatter, lpTestData);
1025
 
    }
1026
 
    delete formatter;
1027
 
}
1028
 
 
1029
 
void 
1030
 
IntlTestRBNF::TestSpanishSpellout() 
1031
 
{
1032
 
    UErrorCode status = U_ZERO_ERROR;
1033
 
    RuleBasedNumberFormat* formatter
1034
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("es", "ES", ""), status);
1035
 
    
1036
 
    if (U_FAILURE(status)) {
1037
 
        errln("FAIL: could not construct formatter");
1038
 
    } else {
1039
 
        static const char* testData[][2] = {
1040
 
            { "1", "uno" },
1041
 
            { "6", "seis" },
1042
 
            { "16", "diecis\\u00e9is" },
1043
 
            { "20", "veinte" },
1044
 
            { "24", "veinticuatro" },
1045
 
            { "26", "veintis\\u00e9is" },
1046
 
            { "73", "setenta y tres" },
1047
 
            { "88", "ochenta y ocho" },
1048
 
            { "100", "cien" },
1049
 
            { "106", "ciento seis" },
1050
 
            { "127", "ciento veintisiete" },
1051
 
            { "200", "doscientos" },
1052
 
            { "579", "quinientos setenta y nueve" },
1053
 
            { "1,000", "mil" },
1054
 
            { "2,000", "dos mil" },
1055
 
            { "3,004", "tres mil cuatro" },
1056
 
            { "4,567", "cuatro mil quinientos sesenta y siete" },
1057
 
            { "15,943", "quince mil novecientos cuarenta y tres" },
1058
 
            { "2,345,678", "dos mill\\u00f3n trescientos cuarenta y cinco mil seiscientos setenta y ocho"},
1059
 
            { "-36", "menos treinta y seis" },
1060
 
            { "234.567", "doscientos treinta y cuatro punto cinco seis siete" },
1061
 
            { NULL, NULL}
1062
 
        };
1063
 
        
1064
 
        doTest(formatter, testData, TRUE);
1065
 
    }
1066
 
    delete formatter;
1067
 
}
1068
 
 
1069
 
void 
1070
 
IntlTestRBNF::TestFrenchSpellout() 
1071
 
{
1072
 
    UErrorCode status = U_ZERO_ERROR;
1073
 
    RuleBasedNumberFormat* formatter
1074
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getFrance(), status);
1075
 
    
1076
 
    if (U_FAILURE(status)) {
1077
 
        errln("FAIL: could not construct formatter");
1078
 
    } else {
1079
 
        static const char* testData[][2] = {
1080
 
            { "1", "un" },
1081
 
            { "15", "quinze" },
1082
 
            { "20", "vingt" },
1083
 
            { "21", "vingt-et-un" },
1084
 
            { "23", "vingt-trois" },
1085
 
            { "62", "soixante-deux" },
1086
 
            { "70", "soixante-dix" },
1087
 
            { "71", "soixante et onze" },
1088
 
            { "73", "soixante-treize" },
1089
 
            { "80", "quatre-vingts" },
1090
 
            { "88", "quatre-vingt-huit" },
1091
 
            { "100", "cent" },
1092
 
            { "106", "cent six" },
1093
 
            { "127", "cent vingt-sept" },
1094
 
            { "200", "deux cents" },
1095
 
            { "579", "cinq cents soixante-dix-neuf" },
1096
 
            { "1,000", "mille" },
1097
 
            { "1,123", "onze cents vingt-trois" },
1098
 
            { "1,594", "mille cinq cents quatre-vingt-quatorze" },
1099
 
            { "2,000", "deux mille" },
1100
 
            { "3,004", "trois mille quatre" },
1101
 
            { "4,567", "quatre mille cinq cents soixante-sept" },
1102
 
            { "15,943", "quinze mille neuf cents quarante-trois" },
1103
 
            { "2,345,678", "deux million trois cents quarante-cinq mille six cents soixante-dix-huit" },
1104
 
            { "-36", "moins trente-six" },
1105
 
            { "234.567", "deux cents trente-quatre virgule cinq six sept" },
1106
 
            { NULL, NULL}
1107
 
        };
1108
 
        
1109
 
        doTest(formatter, testData, TRUE);
1110
 
        
1111
 
        formatter->setLenient(TRUE);
1112
 
        static const char* lpTestData[][2] = {
1113
 
            { "trente-un", "31" },
1114
 
            { "un cents quatre vingt dix huit", "198" },
1115
 
            { NULL, NULL}
1116
 
        };
1117
 
        doLenientParseTest(formatter, lpTestData);
1118
 
    }
1119
 
    delete formatter;
1120
 
}
1121
 
 
1122
 
void 
1123
 
IntlTestRBNF::TestSwissFrenchSpellout() 
1124
 
{
1125
 
    UErrorCode status = U_ZERO_ERROR;
1126
 
    RuleBasedNumberFormat* formatter
1127
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("fr", "CH", ""), status);
1128
 
    
1129
 
    if (U_FAILURE(status)) {
1130
 
        errln("FAIL: could not construct formatter");
1131
 
    } else {
1132
 
        static const char* testData[][2] = {
1133
 
            { "1", "un" },
1134
 
            { "15", "quinze" },
1135
 
            { "20", "vingt" },
1136
 
            { "21", "vingt-et-un" },
1137
 
            { "23", "vingt-trois" },
1138
 
            { "62", "soixante-deux" },
1139
 
            { "70", "septante" },
1140
 
            { "71", "septante-et-un" },
1141
 
            { "73", "septante-trois" },
1142
 
            { "80", "octante" },
1143
 
            { "88", "octante-huit" },
1144
 
            { "100", "cent" },
1145
 
            { "106", "cent six" },
1146
 
            { "127", "cent vingt-sept" },
1147
 
            { "200", "deux cents" },
1148
 
            { "579", "cinq cents septante-neuf" },
1149
 
            { "1,000", "mille" },
1150
 
            { "1,123", "onze cents vingt-trois" },
1151
 
            { "1,594", "mille cinq cents nonante-quatre" },
1152
 
            { "2,000", "deux mille" },
1153
 
            { "3,004", "trois mille quatre" },
1154
 
            { "4,567", "quatre mille cinq cents soixante-sept" },
1155
 
            { "15,943", "quinze mille neuf cents quarante-trois" },
1156
 
            { "2,345,678", "deux million trois cents quarante-cinq mille six cents septante-huit" },
1157
 
            { "-36", "moins trente-six" },
1158
 
            { "234.567", "deux cents trente-quatre virgule cinq six sept" },
1159
 
            { NULL, NULL}
1160
 
        };
1161
 
        
1162
 
        doTest(formatter, testData, TRUE);
1163
 
    }
1164
 
    delete formatter;
1165
 
}
1166
 
 
1167
 
void 
1168
 
IntlTestRBNF::TestItalianSpellout() 
1169
 
{
1170
 
    UErrorCode status = U_ZERO_ERROR;
1171
 
    RuleBasedNumberFormat* formatter
1172
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getItalian(), status);
1173
 
 
1174
 
    if (U_FAILURE(status)) {
1175
 
        errln("FAIL: could not construct formatter");
1176
 
    } else {
1177
 
        static const char* testData[][2] = {
1178
 
            { "1", "uno" },
1179
 
            { "15", "quindici" },
1180
 
            { "20", "venti" },
1181
 
            { "23", "ventitre" },
1182
 
            { "73", "settantatre" },
1183
 
            { "88", "ottantotto" },
1184
 
            { "100", "cento" },
1185
 
            { "106", "centosei" },
1186
 
            { "108", "centotto" },
1187
 
            { "127", "centoventisette" },
1188
 
            { "181", "centottantuno" },
1189
 
            { "200", "duecento" },
1190
 
            { "579", "cinquecentosettantanove" },
1191
 
            { "1,000", "mille" },
1192
 
            { "2,000", "duemila" },
1193
 
            { "3,004", "tremilaquattro" },
1194
 
            { "4,567", "quattromilacinquecentosessantasette" },
1195
 
            { "15,943", "quindicimilanovecentoquarantatre" },
1196
 
            { "-36", "meno trentisei" },
1197
 
            { "234.567", "duecentotrentiquattro virgola cinque sei sette" },
1198
 
            { NULL, NULL}
1199
 
        };
1200
 
        
1201
 
        doTest(formatter, testData, TRUE);
1202
 
    }
1203
 
    delete formatter;
1204
 
}
1205
 
 
1206
 
void 
1207
 
IntlTestRBNF::TestGermanSpellout() 
1208
 
{
1209
 
    UErrorCode status = U_ZERO_ERROR;
1210
 
    RuleBasedNumberFormat* formatter
1211
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getGermany(), status);
1212
 
    
1213
 
    if (U_FAILURE(status)) {
1214
 
        errln("FAIL: could not construct formatter");
1215
 
    } else {
1216
 
        static const char* testData[][2] = {
1217
 
            { "1", "eins" },
1218
 
            { "15", "f\\u00fcnfzehn" },
1219
 
            { "20", "zwanzig" },
1220
 
            { "23", "dreiundzwanzig" },
1221
 
            { "73", "dreiundsiebzig" },
1222
 
            { "88", "achtundachtzig" },
1223
 
            { "100", "hundert" },
1224
 
            { "106", "hundertsechs" },
1225
 
            { "127", "hundertsiebenundzwanzig" },
1226
 
            { "200", "zweihundert" },
1227
 
            { "579", "f\\u00fcnfhundertneunundsiebzig" },
1228
 
            { "1,000", "tausend" },
1229
 
            { "2,000", "zweitausend" },
1230
 
            { "3,004", "dreitausendvier" },
1231
 
            { "4,567", "viertausendf\\u00fcnfhundertsiebenundsechzig" },
1232
 
            { "15,943", "f\\u00fcnfzehntausendneunhundertdreiundvierzig" },
1233
 
            { "2,345,678", "zwei Millionen dreihundertf\\u00fcnfundvierzigtausendsechshundertachtundsiebzig" },
1234
 
            { NULL, NULL}
1235
 
        };
1236
 
        
1237
 
        doTest(formatter, testData, TRUE);
1238
 
        
1239
 
        formatter->setLenient(TRUE);
1240
 
        static const char* lpTestData[][2] = {
1241
 
            { "ein Tausend sechs Hundert fuenfunddreissig", "1,635" },
1242
 
            { NULL, NULL}
1243
 
        };
1244
 
        doLenientParseTest(formatter, lpTestData);
1245
 
    }
1246
 
    delete formatter;
1247
 
}
1248
 
 
1249
 
void 
1250
 
IntlTestRBNF::TestThaiSpellout() 
1251
 
{
1252
 
    UErrorCode status = U_ZERO_ERROR;
1253
 
    RuleBasedNumberFormat* formatter
1254
 
        = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("th"), status);
1255
 
    
1256
 
    if (U_FAILURE(status)) {
1257
 
        errln("FAIL: could not construct formatter");
1258
 
    } else {
1259
 
        static const char* testData[][2] = {
1260
 
            { "0", "\\u0e28\\u0e39\\u0e19\\u0e22\\u0e4c" },
1261
 
            { "1", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07" },
1262
 
            { "10", "\\u0e2a\\u0e34\\u0e1a" },
1263
 
            { "11", "\\u0e2a\\u0e34\\u0e1a\\u0e40\\u0e2d\\u0e47\\u0e14" },
1264
 
            { "21", "\\u0e22\\u0e35\\u0e48\\u0e2a\\u0e34\\u0e1a\\u0e40\\u0e2d\\u0e47\\u0e14" },
1265
 
            { "101", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u0e23\\u0e49\\u0e2d\\u0e22\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07" },
1266
 
            { "1.234", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u0e08\\u0e38\\u0e14\\u0e2a\\u0e2d\\u0e07\\u0e2a\\u0e32\\u0e21\\u0e2a\\u0e35\\u0e48" },
1267
 
            { NULL, NULL}
1268
 
        };
1269
 
        
1270
 
        doTest(formatter, testData, TRUE);
1271
 
    }
1272
 
    delete formatter;
1273
 
}
1274
 
 
1275
 
void 
1276
 
IntlTestRBNF::doTest(RuleBasedNumberFormat* formatter, const char* testData[][2], UBool testParsing) 
1277
 
{
1278
 
  // man, error reporting would be easier with printf-style syntax for unicode string and formattable
1279
 
 
1280
 
    UErrorCode status = U_ZERO_ERROR;
1281
 
    NumberFormat* decFmt = NumberFormat::createInstance(Locale::getUS(), status);
1282
 
    if (U_FAILURE(status)) {
1283
 
        errln("FAIL: could not create NumberFormat");
1284
 
    } else {
1285
 
        for (int i = 0; testData[i][0]; ++i) {
1286
 
            const char* numString = testData[i][0];
1287
 
            const char* expectedWords = testData[i][1];
1288
 
 
1289
 
            Formattable expectedNumber;
1290
 
            decFmt->parse(numString, expectedNumber, status);
1291
 
            if (U_FAILURE(status)) {
1292
 
                errln("FAIL: decFmt could not parse %s", numString);
1293
 
                break;
1294
 
            } else {
1295
 
                UnicodeString actualString;
1296
 
                FieldPosition pos;
1297
 
                formatter->format(expectedNumber, actualString/* , pos*/, status);
1298
 
                if (U_FAILURE(status)) {
1299
 
                    UnicodeString msg = "Fail: formatter could not format ";
1300
 
                    decFmt->format(expectedNumber, msg, status);
1301
 
                    errln(msg);
1302
 
                    break;
1303
 
                } else {
1304
 
                    UnicodeString expectedString = UnicodeString(expectedWords).unescape();
1305
 
                    if (actualString != expectedString) {
1306
 
                        UnicodeString msg = "FAIL: check failed for ";
1307
 
                        decFmt->format(expectedNumber, msg, status);
1308
 
                        msg.append(", expected ");
1309
 
                        msg.append(expectedString);
1310
 
                        msg.append(" but got ");
1311
 
                        msg.append(actualString);
1312
 
                        errln(msg);
1313
 
                        break;
1314
 
                    } else if (testParsing) {
1315
 
                        Formattable parsedNumber;
1316
 
                        formatter->parse(actualString, parsedNumber, status);
1317
 
                        if (U_FAILURE(status)) {
1318
 
                            UnicodeString msg = "FAIL: formatter could not parse ";
1319
 
                            msg.append(actualString);
1320
 
                            msg.append(" status code: " );
1321
 
                            char buffer[32];
1322
 
                            sprintf(buffer, "0x%x", status);
1323
 
                            msg.append(buffer);
1324
 
                            errln(msg);
1325
 
                            break;
1326
 
                        } else {
1327
 
                            if (parsedNumber != expectedNumber) {
1328
 
                                UnicodeString msg = "FAIL: parse failed for ";
1329
 
                                msg.append(actualString);
1330
 
                                msg.append(", expected ");
1331
 
                                decFmt->format(expectedNumber, msg, status);
1332
 
                                msg.append(", but got ");
1333
 
                                decFmt->format(parsedNumber, msg, status);
1334
 
                                errln(msg);
1335
 
                                break;
1336
 
                            }
1337
 
                        }
1338
 
                    }
1339
 
                }
1340
 
            }
1341
 
        }
1342
 
        delete decFmt;
1343
 
    }
1344
 
}
1345
 
 
1346
 
void 
1347
 
IntlTestRBNF::doLenientParseTest(RuleBasedNumberFormat* formatter, const char* testData[][2]) 
1348
 
{
1349
 
    UErrorCode status = U_ZERO_ERROR;
1350
 
    NumberFormat* decFmt = NumberFormat::createInstance(Locale::getUS(), status);
1351
 
    if (U_FAILURE(status)) {
1352
 
        errln("FAIL: could not create NumberFormat");
1353
 
    } else {
1354
 
        for (int i = 0; testData[i][0]; ++i) {
1355
 
            const char* spelledNumber = testData[i][0]; // spelled-out number
1356
 
            const char* asciiUSNumber = testData[i][1]; // number as ascii digits formatted for US locale
1357
 
            
1358
 
            UnicodeString spelledNumberString = UnicodeString(spelledNumber).unescape();
1359
 
            Formattable actualNumber;
1360
 
            formatter->parse(spelledNumberString, actualNumber, status);
1361
 
            if (U_FAILURE(status)) {
1362
 
                UnicodeString msg = "FAIL: formatter could not parse ";
1363
 
                msg.append(spelledNumberString);
1364
 
                errln(msg);
1365
 
                break;
1366
 
            } else {
1367
 
                // I changed the logic of this test somewhat from Java-- instead of comparing the
1368
 
                // strings, I compare the Formattables.  Hmmm, but the Formattables don't compare,
1369
 
                // so change it back.
1370
 
 
1371
 
                UnicodeString asciiUSNumberString = asciiUSNumber;
1372
 
                Formattable expectedNumber;
1373
 
                decFmt->parse(asciiUSNumberString, expectedNumber, status);
1374
 
                if (U_FAILURE(status)) {
1375
 
                    UnicodeString msg = "FAIL: decFmt could not parse ";
1376
 
                    msg.append(asciiUSNumberString);
1377
 
                    errln(msg);
1378
 
                    break;
1379
 
                } else {
1380
 
                    UnicodeString actualNumberString;
1381
 
                    UnicodeString expectedNumberString;
1382
 
                    decFmt->format(actualNumber, actualNumberString, status);
1383
 
                    decFmt->format(expectedNumber, expectedNumberString, status);
1384
 
                    if (actualNumberString != expectedNumberString) {
1385
 
                        UnicodeString msg = "FAIL: parsing";
1386
 
                        msg.append(asciiUSNumberString);
1387
 
                        msg.append("\n");
1388
 
                        msg.append("  lenient parse failed for ");
1389
 
                        msg.append(spelledNumberString);
1390
 
                        msg.append(", expected ");
1391
 
                        msg.append(expectedNumberString);
1392
 
                        msg.append(", but got ");
1393
 
                        msg.append(actualNumberString);
1394
 
                        errln(msg);
1395
 
                        break;
1396
 
                    }
1397
 
                }
1398
 
            }
1399
 
        }
1400
 
        delete decFmt;
1401
 
    }
1402
 
}
1403
 
 
1404
 
/* U_HAVE_RBNF */
1405
 
#else
1406
 
 
1407
 
void
1408
 
IntlTestRBNF::TestRBNFDisabled() {
1409
 
    errln("*** RBNF currently disabled on this platform ***\n");
1410
 
}
1411
 
 
1412
 
/* U_HAVE_RBNF */
1413
 
#endif