16f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/********************************************************************
26f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * COPYRIGHT:
36f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Copyright (c) 1997-2013, International Business Machines Corporation and
46f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * others. All Rights Reserved.
56f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org ********************************************************************/
66f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Modification History:
76f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   Date        Name        Description
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   07/15/99    helena      Ported to HPUX 10/11 CC.
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/utypes.h"
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "numfmtst.h"
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/dcfmtsym.h"
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/decimfmt.h"
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/localpointer.h"
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucurr.h"
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ustring.h"
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/measfmt.h"
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/curramt.h"
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "digitlst.h"
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "textfile.h"
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "tokiter.h"
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "charstr.h"
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "putilimp.h"
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "winnmtst.h"
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <float.h>
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <string.h>
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdlib.h>
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cstring.h"
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/numsys.h"
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "fmtableimp.h"
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//#define NUMFMTST_CACHE_DEBUG 1
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "stdio.h" /* for sprintf */
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// #include "iostream"   // for cout
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//#define NUMFMTST_DEBUG 1
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0]))
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const UChar EUR[] = {69,85,82,0}; // "EUR"
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const UChar JPY[] = {0x4A, 0x50, 0x59, 0};
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const UChar CNY[] = {0x43, 0x4E, 0x59, 0};
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD"
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// *****************************************************************************
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// class NumberFormatTest
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// *****************************************************************************
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO_BEGIN;
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencySign);
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrency);
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestParse);
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestRounding487);
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestQuotes);
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestExponential);
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestPatterns);
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  // Upgrade to alphaWorks - liu 5/99
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestExponent);
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestScientific);
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestPad);
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestPatterns2);
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestSecondaryGrouping);
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestSurrogateSupport);
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestAPI);
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyObject);
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyPatterns);
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  //TESTCASE_AUTO(TestDigitList);
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestWhiteSpaceParsing);
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestComplexCurrency);  // This test removed because CLDR no longer uses choice formats in currency symbols.
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestRegCurrency);
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestSymbolsWithBadLocale);
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestAdoptDecimalFormatSymbols);
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestScientific2);
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestScientificGrouping);
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestInt64);
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestPerMill);
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestIllegalPatterns);
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCases);
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyNames);
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyAmount);
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyUnit);
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCoverage);
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestJB3832);
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestHost);
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestHostClone);
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyFormat);
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestRounding);
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestNonpositiveMultiplier);
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestNumberingSystems);
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestSpaceParsing);
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestMultiCurrencySign);
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyFormatForMixParsing);
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestDecimalFormatCurrencyParse);
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyIsoPluralFormat);
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyParsing);
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestParseCurrencyInUCurr);
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestFormatAttributes);
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestFieldPositionIterator);
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestDecimal);
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCurrencyFractionDigits);
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestExponentParse);
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestExplicitParents);
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestLenientParse);
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestAvailableNumberingSystems);
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestRoundingPattern);
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(Test9087);
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestFormatFastpaths);
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestFormattableSize);
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestUFormattable);
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestSignificantDigits);
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestShowZero);
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCompatibleCurrencies);
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestBug9936);
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestParseNegativeWithFaLocale);
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign);
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestCustomCurrencySignAndSeparator);
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO(TestParseSignsAndMarks);
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TESTCASE_AUTO_END;
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Test API (increase code coverage)
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestAPI(void)
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  logln("Test API");
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  UErrorCode status = U_ZERO_ERROR;
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  NumberFormat *test = NumberFormat::createInstance("root", status);
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  if(U_FAILURE(status)) {
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dataerrln("unable to create format object - %s", u_errorName(status));
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  }
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  if(test != NULL) {
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->setMinimumIntegerDigits(10);
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->setMaximumIntegerDigits(2);
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->setMinimumFractionDigits(10);
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->setMaximumFractionDigits(2);
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString result;
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    FieldPosition pos;
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Formattable bla("Paja Patak"); // Donald Duck for non Serbian speakers
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->format(bla, result, pos, status);
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_SUCCESS(status)) {
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      errln("Yuck... Formatted a duck... As a number!");
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      status = U_ZERO_ERROR;
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result.remove();
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int64_t ll = 12;
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test->format(ll, result);
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (result != "12.00"){
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("format int64_t error");
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ParsePosition ppos;
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    LocalPointer<CurrencyAmount> currAmt(test->parseCurrency("",ppos));
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // old test for (U_FAILURE(status)) was bogus here, method does not set status!
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (ppos.getIndex()) {
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Parsed empty string as currency");
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete test;
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  }
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgclass StubNumberFormat :public NumberFormat{
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgpublic:
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    StubNumberFormat(){};
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UnicodeString& format(double ,UnicodeString& appendTo,FieldPosition& ) const {
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return appendTo;
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UnicodeString& format(int32_t ,UnicodeString& appendTo,FieldPosition& ) const {
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return appendTo.append((UChar)0x0033);
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UnicodeString& format(int64_t number,UnicodeString& appendTo,FieldPosition& pos) const {
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return NumberFormat::format(number, appendTo, pos);
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UnicodeString& format(const Formattable& , UnicodeString& appendTo, FieldPosition& , UErrorCode& ) const {
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return appendTo;
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual void parse(const UnicodeString& ,
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    Formattable& ,
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    ParsePosition& ) const {}
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual void parse( const UnicodeString& ,
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        Formattable& ,
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        UErrorCode& ) const {}
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UClassID getDynamicClassID(void) const {
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static char classID = 0;
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return (UClassID)&classID;
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual Format* clone() const {return NULL;}
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestCoverage(void){
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    StubNumberFormat stub;
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString agent("agent");
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    FieldPosition pos;
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int64_t num = 4;
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (stub.format(num, agent, pos) != UnicodeString("agent3")){
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Test various patterns
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestPatterns(void)
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols sym(Locale::getUS(), status);
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errcheckln(status, "FAIL: Could not construct DecimalFormatSymbols - %s", u_errorName(status)); return; }
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* pat[]    = { "#.#", "#.", ".#", "#" };
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* newpat[] = { "#0.#", "#0.", "#.0", "#" };
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* num[]    = { "0",   "0.", ".0", "0" };
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<pat_length; ++i)
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormat fmt(pat[i], sym, status);
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(status)) { errln((UnicodeString)"FAIL: DecimalFormat constructor failed for " + pat[i]); continue; }
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString newp; fmt.toPattern(newp);
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!(newp == newpat[i]))
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should transmute to " + newpat[i] +
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  "; " + newp + " seen instead");
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString s; (*(NumberFormat*)&fmt).format((int32_t)0, s);
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!(s == num[i]))
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should format zero as " + num[i] +
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  "; " + s + " seen instead");
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"Min integer digits = " + fmt.getMinimumIntegerDigits());
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgicu_2_4::DigitList::operator== 0 0 2 icuuc24d.dll digitlst.cpp Doug
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgicu_2_4::DigitList::append 0 0 4 icuin24d.dll digitlst.h Doug
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgicu_2_4::DigitList::operator!= 0 0 1 icuuc24d.dll digitlst.h Doug
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestDigitList(void)
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  // API coverage for DigitList
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  DigitList list1;
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  list1.append('1');
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  list1.fDecimalAt = 1;
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  DigitList list2;
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  list2.set((int32_t)1);
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  if (list1 != list2) {
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errln("digitlist append, operator!= or set failed ");
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  }
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  if (!(list1 == list2)) {
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errln("digitlist append, operator== or set failed ");
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  }
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Test exponential pattern
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestExponential(void)
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols sym(Locale::getUS(), status);
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errcheckln(status, "FAIL: Bad status returned by DecimalFormatSymbols ct - %s", u_errorName(status)); return; }
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* pat[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]"  };
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// The following #if statements allow this test to be built and run on
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// platforms that do not have standard IEEE numerics.  For example,
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// S/390 doubles have an exponent range of -78 to +75.  For the
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// following #if statements to work, float.h must define
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// DBL_MAX_10_EXP to be a compile-time constant.
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// This section may be expanded as needed.
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if DBL_MAX_10_EXP > 300
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double val[] = { 0.01234, 123456789, 1.23e300, -3.141592653e-271 };
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t val_length = (int32_t)(sizeof(val) / sizeof(val[0]));
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* valFormat[] =
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.####E0
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 00.000E00
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // ##0.######E000
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.###E0;[0.###E0]
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double valParse[] =
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123460000, 1.23E300, -3.1416E-271,
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123460000, 1.23E300, -3.1416E-271,
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123456800, 1.23E300, -3.141593E-271,
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123500000, 1.23E300, -3.142E-271,
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#elif DBL_MAX_10_EXP > 70
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double val[] = { 0.01234, 123456789, 1.23e70, -3.141592653e-71 };
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t val_length = sizeof(val) / sizeof(val[0]);
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char* valFormat[] =
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.####E0
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1.234E-2", "1.2346E8", "1.23E70", "-3.1416E-71",
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 00.000E00
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "12.340E-03", "12.346E07", "12.300E69", "-31.416E-72",
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // ##0.######E000
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "12.34E-003", "123.4568E006", "12.3E069", "-31.41593E-072",
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.###E0;[0.###E0]
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1.234E-2", "1.235E8", "1.23E70", "[3.142E-71]"
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double valParse[] =
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123460000, 1.23E70, -3.1416E-71,
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123460000, 1.23E70, -3.1416E-71,
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123456800, 1.23E70, -3.141593E-71,
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0.01234, 123500000, 1.23E70, -3.142E-71,
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Don't test double conversion
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double* val = 0;
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t val_length = 0;
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char** valFormat = 0;
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    double* valParse = 0;
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Warning: Skipping double conversion tests");
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t lval[] = { 0, -1, 1, 123456789 };
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t lval_length = (int32_t)(sizeof(lval) / sizeof(lval[0]));
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* lvalFormat[] =
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.####E0
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "0E0", "-1E0", "1E0", "1.2346E8",
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 00.000E00
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // ##0.######E000
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "0E000", "-1E000", "1E000", "123.4568E006",
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // 0.###E0;[0.###E0]
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "0E0", "[1E0]", "1E0", "1.235E8"
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t lvalParse[] =
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, -1, 1, 123460000,
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, -1, 1, 123460000,
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, -1, 1, 123456800,
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, -1, 1, 123500000,
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t ival = 0, ilval = 0;
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t p=0; p<pat_length; ++p)
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormat fmt(pat[p], sym, status);
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(status)) { errln("FAIL: Bad status returned by DecimalFormat ct"); continue; }
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pattern;
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Pattern \"" + pat[p] + "\" -toPattern-> \"" +
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          fmt.toPattern(pattern) + "\"");
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t v;
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (v=0; v<val_length; ++v)
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString s; (*(NumberFormat*)&fmt).format(val[v], s);
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)" " + val[v] + " -format-> " + s);
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (s != valFormat[v+ival])
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: Expected " + valFormat[v+ival]);
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ParsePosition pos(0);
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Formattable af;
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            fmt.parse(s, af, pos);
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            double a;
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UBool useEpsilon = FALSE;
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (af.getType() == Formattable::kLong)
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                a = af.getLong();
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else if (af.getType() == Formattable::kDouble) {
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                a = af.getDouble();
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // S/390 will show a failure like this:
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                //| -3.141592652999999e-271 -format-> -3.1416E-271
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                //|                          -parse-> -3.1416e-271
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                //| FAIL: Expected -3.141599999999999e-271
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // To compensate, we use an epsilon-based equality
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // test on S/390 only.  We don't want to do this in
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // general because it's less exacting.
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                useEpsilon = TRUE;
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else {
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: Non-numeric Formattable returned");
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (pos.getIndex() == s.length())
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                logln((UnicodeString)"  -parse-> " + a);
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // Use epsilon comparison as necessary
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if ((useEpsilon &&
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    (uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    (!useEpsilon && a != valParse[v+ival]))
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                {
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else {
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"  should be (" + s.length() + " chars) -> " + valParse[v+ival]);
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (v=0; v<lval_length; ++v)
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString s;
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            (*(NumberFormat*)&fmt).format(lval[v], s);
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)" " + lval[v] + "L -format-> " + s);
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (s != lvalFormat[v+ilval])
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"ERROR: Expected " + lvalFormat[v+ilval] + " Got: " + s);
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ParsePosition pos(0);
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Formattable af;
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            fmt.parse(s, af, pos);
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (af.getType() == Formattable::kLong ||
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                af.getType() == Formattable::kInt64) {
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UErrorCode status = U_ZERO_ERROR;
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                int32_t a = af.getLong(status);
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (pos.getIndex() == s.length())
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                {
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    logln((UnicodeString)"  -parse-> " + a);
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (a != lvalParse[v+ilval])
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        errln((UnicodeString)"FAIL: Expected " + lvalParse[v+ilval]);
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                else
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: Non-long Formattable returned for " + s
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    + " Double: " + af.getDouble()
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    + ", Long: " + af.getLong());
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ival += val_length;
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ilval += lval_length;
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestScientific2() {
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // jb 2552
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat* fmt = (DecimalFormat*)NumberFormat::createCurrencyInstance("en_US", status);
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_SUCCESS(status)) {
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        double num = 12.34;
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(*fmt, num, "$12.34");
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        fmt->setScientificNotation(TRUE);
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(*fmt, num, "$1.23E1");
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        fmt->setScientificNotation(FALSE);
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(*fmt, num, "$12.34");
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestScientificGrouping() {
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // jb 2552
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt("##0.00E0",status);
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_SUCCESS(status)) {
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, .01234, "12.3E-3");
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, .1234, "123E-3");
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, 1.234, "1.23E0");
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, 12.34, "12.3E0");
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, 123.4, "123E0");
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, 1234., "1.23E3");
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*static void setFromString(DigitList& dl, const char* str) {
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char c;
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool decimalSet = FALSE;
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dl.clear();
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while ((c = *str++)) {
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (c == '-') {
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dl.fIsPositive = FALSE;
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if (c == '+') {
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dl.fIsPositive = TRUE;
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if (c == '.') {
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dl.fDecimalAt = dl.fCount;
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            decimalSet = TRUE;
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dl.append(c);
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!decimalSet) {
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dl.fDecimalAt = dl.fCount;
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}*/
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestInt64() {
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt("#.#E0",status);
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setMaximumFractionDigits(20);
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_SUCCESS(status)) {
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)0, "0E0");
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)-1, "-1E0");
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)1, "1E0");
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)2147483647, "2.147483647E9");
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)((int64_t)-2147483647-1), "-2.147483648E9");
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)U_INT64_MAX, "9.223372036854775807E18");
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expect(fmt, (Formattable)(int64_t)U_INT64_MIN, "-9.223372036854775808E18");
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // also test digitlist
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*    int64_t int64max = U_INT64_MAX;
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int64_t int64min = U_INT64_MIN;
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* int64maxstr = "9223372036854775807";
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* int64minstr = "-9223372036854775808";
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString fail("fail: ");
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test max int64 value
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DigitList dl;
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setFromString(dl, int64maxstr);
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!dl.fitsIntoInt64(FALSE)) {
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + int64maxstr + " didn't fit");
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64_t int64Value = dl.getInt64();
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != int64max) {
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + int64maxstr);
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dl.set(int64Value);
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64Value = dl.getInt64();
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != int64max) {
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + int64maxstr);
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test negative of max int64 value (1 shy of min int64 value)
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dl.fIsPositive = FALSE;
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!dl.fitsIntoInt64(FALSE)) {
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + "-" + int64maxstr + " didn't fit");
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64_t int64Value = dl.getInt64();
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != -int64max) {
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + "-" + int64maxstr);
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dl.set(int64Value);
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64Value = dl.getInt64();
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != -int64max) {
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + "-" + int64maxstr);
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test min int64 value
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setFromString(dl, int64minstr);
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!dl.fitsIntoInt64(FALSE)) {
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + "-" + int64minstr + " didn't fit");
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64_t int64Value = dl.getInt64();
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != int64min) {
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + int64minstr);
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dl.set(int64Value);
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int64Value = dl.getInt64();
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (int64Value != int64min) {
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + int64minstr);
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test negative of min int 64 value (1 more than max int64 value)
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dl.fIsPositive = TRUE; // won't fit
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (dl.fitsIntoInt64(FALSE)) {
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(fail + "-(" + int64minstr + ") didn't fit");
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }*/
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Test the handling of quotes
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestQuotes(void)
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString *pat;
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), status);
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete sym;
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat = new UnicodeString("a'fo''o'b#");
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat *fmt = new DecimalFormat(*pat, *sym, status);
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString s;
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ((NumberFormat*)fmt)->format((int32_t)123, s);
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Pattern \"" + *pat + "\"");
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format 123 -> " + escape(s));
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(s=="afo'ob123"))
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Expected afo'ob123");
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete pat;
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat = new UnicodeString("a''b#");
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt = new DecimalFormat(*pat, *sym, status);
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ((NumberFormat*)fmt)->format((int32_t)123, s);
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Pattern \"" + *pat + "\"");
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format 123 -> " + escape(s));
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(s=="a'b123"))
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Expected a'b123");
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete pat;
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete sym;
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the handling of the currency symbol in patterns.
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestCurrencySign(void)
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols* sym = new DecimalFormatSymbols(Locale::getUS(), status);
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar currency = 0x00A4;
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete sym;
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // "\xA4#,##0.00;-\xA4#,##0.00"
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat.append(currency).append("#,##0.00;-").
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        append(currency).append("#,##0.00");
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat *fmt = new DecimalFormat(pat, *sym, status);
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString s; ((NumberFormat*)fmt)->format(1234.56, s);
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat.truncate(0);
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (s != "$1,234.56") dataerrln((UnicodeString)"FAIL: Expected $1,234.56");
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ((NumberFormat*)fmt)->format(- 1234.56, s);
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (s != "-$1,234.56") dataerrln((UnicodeString)"FAIL: Expected -$1,234.56");
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat.truncate(0);
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // "\xA4\xA4 #,##0.00;\xA4\xA4 -#,##0.00"
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat.append(currency).append(currency).
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        append(" #,##0.00;").
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        append(currency).append(currency).
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        append(" -#,##0.00");
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt = new DecimalFormat(pat, *sym, status);
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ((NumberFormat*)fmt)->format(1234.56, s);
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (s != "USD 1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD 1,234.56");
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ((NumberFormat*)fmt)->format(-1234.56, s);
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (s != "USD -1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD -1,234.56");
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete sym;
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + u_errorName(status));
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeString&
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::escape(UnicodeString& s)
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString buf;
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<s.length(); ++i)
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar c = s[(int32_t)i];
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (c <= (UChar)0x7F) buf += c;
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += (UChar)0x5c; buf += (UChar)0x55;
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0xF000) >> 12);
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0x0F00) >> 8);
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0x00F0) >> 4);
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString(c & 0x000F);
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return (s = buf);
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char* testCases[][2]= {
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     /* locale ID */  /* expected */
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" },
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"de_LU_PREEURO", "1,150\\u00A0F" },
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" },
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"en_BE_PREEURO", "1.150,50\\u00A0BEF" },
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"es_ES_PREEURO", "1\\u00A0150\\u00A0\\u20A7" },
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" },
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" },
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"it_IT_PREEURO", "ITL\\u00A01.150" },
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"pt_PT_PREEURO", "1,150$50\\u00A0Esc."},
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"en_US@currency=JPY", "\\u00A51,150"},
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"en_US@currency=jpy", "\\u00A51,150"},
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {"en-US-u-cu-jpy", "\\u00A51,150"}
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test localized currency patterns.
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestCurrency(void)
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status);
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Error calling NumberFormat::createCurrencyInstance()");
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString s; currencyFmt->format(1.50, s);
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Un pauvre ici a..........." + s);
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(s==CharsToUnicodeString("1,50\\u00A0$")))
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>$");
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete currencyFmt;
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char loc[256]={0};
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int len = uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    (void)len;  // Suppress unused variable warning.
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc),status);
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    currencyFmt->format(1.50, s);
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Un pauvre en Allemagne a.." + s);
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(s==CharsToUnicodeString("1,50\\u00A0DEM")))
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>DEM");
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete currencyFmt;
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.truncate(0);
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    currencyFmt->format(1.50, s);
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"Un pauvre en France a....." + s);
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(s==CharsToUnicodeString("1,50\\u00A0F")))
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>F");
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete currencyFmt;
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Status " + (int32_t)status);
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(int i=0; i < (int)(sizeof(testCases)/sizeof(testCases[i])); i++){
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID = testCases[i][0];
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString expected(testCases[i][1], -1, US_INV);
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expected = expected.unescape();
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        s.truncate(0);
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char loc[256]={0};
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_canonicalize(localeID, loc, 256, &status);
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Could not create currency formatter for locale %s",localeID);
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        currencyFmt->format(1150.50, s);
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(s!=expected){
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(UnicodeString("FAIL: Expected: ")+expected
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    + UnicodeString(" Got: ") + s
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(status)){
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: Status " + (int32_t)status);
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete currencyFmt;
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the Currency object handling, new as of ICU 2.2.
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCurrencyObject() {
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat* fmt =
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NumberFormat::createCurrencyInstance(Locale::getUS(), ec);
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: getCurrencyInstance(US) - %s", u_errorName(ec));
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete fmt;
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale null("", "", "");
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, null, 1234.56, "$1,234.56");
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getFrance(),
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, CharsToUnicodeString("\\u20AC1,234.56")); // Euro
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getJapan(),
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, CharsToUnicodeString("\\u00A51,235")); // Yen
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale("fr", "CH", ""),
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, "CHF1,234.56"); // no more 0.05 rounding here, see cldrbug 5548
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getUS(),
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, "$1,234.56");
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt = NumberFormat::createCurrencyInstance(Locale::getFrance(), ec);
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getCurrencyInstance(FRANCE)");
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete fmt;
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, null, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC"));
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getJapan(),
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, CharsToUnicodeString("1 235 \\u00A5JP")); // Yen
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale("fr", "CH", ""),
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see cldrbug 5548
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getUS(),
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, "1 234,56 $US");
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectCurrency(*fmt, Locale::getFrance(),
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete fmt;
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Do rudimentary testing of parsing.
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestParse(void)
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString arg("0");
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat* format = new DecimalFormat("00", status);
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //try {
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Formattable n; format->parse(arg, n, status);
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"parse(" + arg + ") = " + n.getLong());
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (n.getType() != Formattable::kLong ||
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            n.getLong() != 0) errln((UnicodeString)"FAIL: Expected 0");
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete format;
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) errcheckln(status, (UnicodeString)"FAIL: Status " + u_errorName(status));
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //}
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //catch(Exception e) {
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //    errln((UnicodeString)"Exception caught: " + e);
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //}
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientAffixTestCases[] = {
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "(1)",
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "( 1)",
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "(1 )",
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "( 1 )"
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientMinusTestCases[] = {
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    "-5",
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    "\\u22125",
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    "\\u20105"
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientCurrencyTestCases[] = {
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$1,000",
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$ 1,000",
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$1000",
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$ 1000",
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$1 000.00",
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$ 1 000.00",
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "$ 1\\u00A0000.00",
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1000.00"
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// changed from () to - per cldrbug 5674
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientNegativeCurrencyTestCases[] = {
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$1,000",
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$ 1,000",
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$1000",
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$ 1000",
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$1 000.00",
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$ 1 000.00",
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "- $ 1,000.00 ",
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-$ 1\\u00A0000.00",
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-1000.00"
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientPercentTestCases[] = {
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "25%",
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        " 25%",
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        " 25 %",
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    	"25 %",
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"25\\u00A0%",
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"25"
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *lenientNegativePercentTestCases[] = {
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"-25%",
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		" -25%",
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		" - 25%",
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"- 25 %",
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		" - 25 %",
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"-25 %",
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"-25\\u00A0%",
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"-25",
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"- 25"
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *strictFailureTestCases[] = {
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		" 1000",
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"10,00",
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"1,000,.0"
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define ARRAY_SIZE(array) ((int32_t) (sizeof (array) / sizeof(array[0])))
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test lenient parsing.
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestLenientParse(void)
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat *format = new DecimalFormat("(#,##0)", status);
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Formattable n;
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (format == NULL || U_FAILURE(status)) {
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Unable to create DecimalFormat (#,##0) - %s", u_errorName(status));
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        format->setLenient(TRUE);
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE (lenientAffixTestCases); t += 1) {
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	UnicodeString testCase = ctou(lenientAffixTestCases[t]);
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            format->parse(testCase, n, status);
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) || n.getType() != Formattable::kLong ||
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	n.getLong() != 1) {
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientAffixTestCases[t] + (UnicodeString) "\"");
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	status = U_ZERO_ERROR;
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       }
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       delete format;
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale en_US("en_US");
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale sv_SE("sv_SE");
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat *mFormat = NumberFormat::createInstance(sv_SE, UNUM_DECIMAL, status);
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (mFormat == NULL || U_FAILURE(status)) {
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Unable to create NumberFormat (sv_SE, UNUM_DECIMAL) - %s", u_errorName(status));
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        mFormat->setLenient(TRUE);
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString testCase = ctou(lenientMinusTestCases[t]);
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            mFormat->parse(testCase, n, status);
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                status = U_ZERO_ERROR;
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete mFormat;
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    mFormat = NumberFormat::createInstance(en_US, UNUM_DECIMAL, status);
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (mFormat == NULL || U_FAILURE(status)) {
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Unable to create NumberFormat (en_US, UNUM_DECIMAL) - %s", u_errorName(status));
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        mFormat->setLenient(TRUE);
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString testCase = ctou(lenientMinusTestCases[t]);
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            mFormat->parse(testCase, n, status);
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                status = U_ZERO_ERROR;
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete mFormat;
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat *cFormat = NumberFormat::createInstance(en_US, UNUM_CURRENCY, status);
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (cFormat == NULL || U_FAILURE(status)) {
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Unable to create NumberFormat (en_US, UNUM_CURRENCY) - %s", u_errorName(status));
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cFormat->setLenient(TRUE);
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE (lenientCurrencyTestCases); t += 1) {
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	UnicodeString testCase = ctou(lenientCurrencyTestCases[t]);
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            cFormat->parse(testCase, n, status);
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	n.getLong() != 1000) {
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientCurrencyTestCases[t] + (UnicodeString) "\"");
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	status = U_ZERO_ERROR;
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativeCurrencyTestCases); t += 1) {
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	UnicodeString testCase = ctou(lenientNegativeCurrencyTestCases[t]);
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            cFormat->parse(testCase, n, status);
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	n.getLong() != -1000) {
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativeCurrencyTestCases[t] + (UnicodeString) "\"");
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	status = U_ZERO_ERROR;
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete cFormat;
10406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat *pFormat = NumberFormat::createPercentInstance(en_US, status);
10436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (pFormat == NULL || U_FAILURE(status)) {
10456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Unable to create NumberFormat::createPercentInstance (en_US) - %s", u_errorName(status));
10466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
10476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        pFormat->setLenient(TRUE);
10486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE (lenientPercentTestCases); t += 1) {
10496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	UnicodeString testCase = ctou(lenientPercentTestCases[t]);
10506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	pFormat->parse(testCase, n, status);
10526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
10536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
10556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	n.getDouble() != 0.25) {
10566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientPercentTestCases[t] + (UnicodeString) "\"");
10576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	status = U_ZERO_ERROR;
10586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativePercentTestCases); t += 1) {
10626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	UnicodeString testCase = ctou(lenientNegativePercentTestCases[t]);
10636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        	pFormat->parse(testCase, n, status);
10656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
10666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
10686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	n.getDouble() != -0.25) {
10696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativePercentTestCases[t] + (UnicodeString) "\"");
10706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            	status = U_ZERO_ERROR;
10716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete pFormat;
10756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   // Test cases that should fail with a strict parse and pass with a
10786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   // lenient parse.
10796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   NumberFormat *nFormat = NumberFormat::createInstance(en_US, status);
10806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   if (nFormat == NULL || U_FAILURE(status)) {
10826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       dataerrln("Unable to create NumberFormat (en_US) - %s", u_errorName(status));
10836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   } else {
10846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       // first, make sure that they fail with a strict parse
10856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
10866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       UnicodeString testCase = ctou(strictFailureTestCases[t]);
10876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       nFormat->parse(testCase, n, status);
10896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
10906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       if (! U_FAILURE(status)) {
10926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		       errln((UnicodeString)"Strict Parse succeeded for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
10936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       }
10946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       status = U_ZERO_ERROR;
10966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       }
10976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       // then, make sure that they pass with a lenient parse
10996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       nFormat->setLenient(TRUE);
11006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
11016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       UnicodeString testCase = ctou(strictFailureTestCases[t]);
11026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       nFormat->parse(testCase, n, status);
11046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
11056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
11076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	            	n.getLong() != 1000) {
11086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		       errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
11096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		       status = U_ZERO_ERROR;
11106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	       }
11116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       }
11126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       delete nFormat;
11146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   }
11156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
11186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test proper rounding by the format method.
11216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
11236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::TestRounding487(void)
11246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
11256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
11266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat *nf = NumberFormat::createInstance(status);
11276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
11286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Error calling NumberFormat::createInstance()");
11296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
11306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    roundingTest(*nf, 0.00159999, 4, "0.0016");
11336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    roundingTest(*nf, 0.00995, 4, "0.01");
11346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    roundingTest(*nf, 12.3995, 3, "12.4");
11366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    roundingTest(*nf, 12.4999, 0, "12");
11386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    roundingTest(*nf, - 19.5, 0, "-20");
11396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete nf;
11406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + (int32_t)status);
11416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the functioning of the secondary grouping value.
11456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestSecondaryGrouping(void) {
11476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
11486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), status);
11496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols ct");
11506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat f("#,##,###", US, status);
11526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormat ct");
11536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(f, (int32_t)123456789L, "12,34,56,789");
11556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(f, "#,##,###");
11566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    f.applyPattern("#,###", status);
11576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "applyPattern");
11586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    f.setSecondaryGroupingSize(4);
11606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(f, (int32_t)123456789L, "12,3456,789");
11616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(f, "#,####,###");
11626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat *g = NumberFormat::createInstance(Locale("hi", "IN"), status);
11636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK_DATA(status, "createInstance(hi_IN)");
11646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString out;
11666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t l = (int32_t)1876543210L;
11676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    g->format(l, out);
11686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete g;
11696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // expect "1,87,65,43,210", but with Hindi digits
11706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //         01234567890123
11716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool ok = TRUE;
11726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (out.length() != 14) {
11736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ok = FALSE;
11746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
11756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t i=0; i<out.length(); ++i) {
11766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UBool expectGroup = FALSE;
11776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            switch (i) {
11786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 1:
11796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 4:
11806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 7:
11816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 10:
11826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                expectGroup = TRUE;
11836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
11846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
11856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // Later -- fix this to get the actual grouping
11866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // character from the resource bundle.
11876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UBool isGroup = (out.charAt(i) == 0x002C);
11886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (isGroup != expectGroup) {
11896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ok = FALSE;
11906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
11916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
11926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!ok) {
11956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL  Expected " + l +
11966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              " x hi_IN -> \"1,87,65,43,210\" (with Hindi digits), got \"" +
11976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              escape(out) + "\"");
11986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
11996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Ok    " + l +
12006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              " x hi_IN -> \"" +
12016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              escape(out) + "\"");
12026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestWhiteSpaceParsing(void) {
12066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
12076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), ec);
12086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt("a  b#0c  ", US, ec);
12096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
12106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(ec, "FAIL: Constructor - %s", u_errorName(ec));
12116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
12126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t n = 1234;
12146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(fmt, "a b1234c ", n);
12156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(fmt, "a   b1234c   ", n);
12166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test currencies whose display name is a ChoiceFormat.
12206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestComplexCurrency() {
12226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    UErrorCode ec = U_ZERO_ERROR;
12246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    Locale loc("kn", "IN", "");
12256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    NumberFormat* fmt = NumberFormat::createCurrencyInstance(loc, ec);
12266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    if (U_SUCCESS(ec)) {
12276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect2(*fmt, 1.0, CharsToUnicodeString("Re.\\u00A01.00"));
12286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        Use .00392625 because that's 2^-8.  Any value less than 0.005 is fine.
12296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect(*fmt, 1.00390625, CharsToUnicodeString("Re.\\u00A01.00")); // tricky
12306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect2(*fmt, 12345678.0, CharsToUnicodeString("Rs.\\u00A01,23,45,678.00"));
12316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect2(*fmt, 0.5, CharsToUnicodeString("Rs.\\u00A00.50"));
12326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect2(*fmt, -1.0, CharsToUnicodeString("-Re.\\u00A01.00"));
12336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        expect2(*fmt, -10.0, CharsToUnicodeString("-Rs.\\u00A010.00"));
12346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    } else {
12356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//        errln("FAIL: getCurrencyInstance(kn_IN)");
12366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    }
12376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//    delete fmt;
12386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// -------------------------------------
12426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
12446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgNumberFormatTest::roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected)
12456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
12466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    nf.setMaximumFractionDigits(maxFractionDigits);
12476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString out; nf.format(x, out);
12486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"" + x + " formats with " + maxFractionDigits + " fractional digits to " + out);
12496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(out==expected)) errln((UnicodeString)"FAIL: Expected " + expected);
12506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Upgrade to alphaWorks
12546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestExponent(void) {
12566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
12576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), status);
12586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols constructor");
12596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt1(UnicodeString("0.###E0"), US, status);
12606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormat(0.###E0)");
12616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt2(UnicodeString("0.###E+0"), US, status);
12626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormat(0.###E+0)");
12636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t n = 1234;
12646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(fmt1, n, "1.234E3");
12656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(fmt2, n, "1.234E+3");
12666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(fmt1, "1.234E+3", n); // Either format should parse "E+3"
12676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Upgrade to alphaWorks
12716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestScientific(void) {
12736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
12746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), status);
12756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols constructor");
12766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test pattern round-trip
12786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* PAT[] = { "#E0", "0.####E0", "00.000E00", "##0.####E000",
12796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "0.###E0;[0.###E0]" };
12806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t PAT_length = (int32_t)(sizeof(PAT) / sizeof(PAT[0]));
12816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t DIGITS[] = {
12826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // min int, max int, min frac, max frac
12836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, 1, 0, 0, // "#E0"
12846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 1, 0, 4, // "0.####E0"
12856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 2, 3, 3, // "00.000E00"
12866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 3, 0, 4, // "##0.####E000"
12876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 1, 0, 3, // "0.###E0;[0.###E0]"
12886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
12896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<PAT_length; ++i) {
12906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pat(PAT[i]);
12916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormat df(pat, US, status);
12926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CHECK(status, "DecimalFormat constructor");
12936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pat2;
12946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        df.toPattern(pat2);
12956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (pat == pat2) {
12966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln(UnicodeString("Ok   Pattern rt \"") +
12976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat + "\" -> \"" +
12986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat2 + "\"");
12996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
13006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(UnicodeString("FAIL Pattern rt \"") +
13016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat + "\" -> \"" +
13026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat2 + "\"");
13036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Make sure digit counts match what we expect
13056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (df.getMinimumIntegerDigits() != DIGITS[4*i] ||
13066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            df.getMaximumIntegerDigits() != DIGITS[4*i+1] ||
13076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            df.getMinimumFractionDigits() != DIGITS[4*i+2] ||
13086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            df.getMaximumFractionDigits() != DIGITS[4*i+3]) {
13096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(UnicodeString("FAIL \"" + pat +
13106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                "\" min/max int; min/max frac = ") +
13116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  df.getMinimumIntegerDigits() + "/" +
13126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  df.getMaximumIntegerDigits() + ";" +
13136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  df.getMinimumFractionDigits() + "/" +
13146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  df.getMaximumFractionDigits() + ", expect " +
13156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  DIGITS[4*i] + "/" +
13166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  DIGITS[4*i+1] + ";" +
13176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  DIGITS[4*i+2] + "/" +
13186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  DIGITS[4*i+3]);
13196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test the constructor for default locale. We have to
13246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // manually set the default locale, as there is no
13256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // guarantee that the default locale has the same
13266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // scientific format.
13276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale def = Locale::getDefault();
13286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(Locale::getUS(), status);
13296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(NumberFormat::createScientificInstance(status),
13306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.678901,
13316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "1.2345678901E4", status);
13326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(def, status);
13336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("#E0", US, status),
13356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.0,
13366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "1.2345E4", status);
13376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("0E0", US, status),
13386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.0,
13396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "1E4", status);
13406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(NumberFormat::createScientificInstance(Locale::getUS(), status),
13416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.678901,
13426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "1.2345678901E4", status);
13436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.###E0", US, status),
13446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.0,
13456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "12.34E3", status);
13466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.###E0", US, status),
13476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.00001,
13486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "12.35E3", status);
13496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.####E0", US, status),
13506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 12345,
13516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "12.345E3", status);
13526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(NumberFormat::createScientificInstance(Locale::getFrance(), status),
13536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12345.678901,
13546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "1,2345678901E4", status);
13556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.####E0", US, status),
13566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           789.12345e-9,
13576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "789.12E-9", status);
13586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.####E0", US, status),
13596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           780.e-9,
13606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           "780E-9", status);
13616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat(".###E0", US, status),
13626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           45678.0,
13636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           ".457E5", status);
13646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(".###E0", US, status),
13656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 0,
13666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           ".0E0", status);
13676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
13686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat[] { new DecimalFormat("#E0", US),
13696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 new DecimalFormat("##E0", US),
13706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 new DecimalFormat("####E0", US),
13716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 new DecimalFormat("0E0", US),
13726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 new DecimalFormat("00E0", US),
13736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 new DecimalFormat("000E0", US),
13746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               },
13756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           new Long(45678000),
13766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           new String[] { "4.5678E7",
13776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "45.678E6",
13786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "4567.8E4",
13796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "5E7",
13806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "46E6",
13816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          "457E5",
13826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
13836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           );
13846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
13856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ! Unroll this test into individual tests below...
13866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
13876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
13886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("#E0", US, status),
13896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "4.5678E7", status);
13906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##E0", US, status),
13916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "45.678E6", status);
13926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("####E0", US, status),
13936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "4567.8E4", status);
13946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("0E0", US, status),
13956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "5E7", status);
13966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("00E0", US, status),
13976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "46E6", status);
13986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("000E0", US, status),
13996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 45678000, "457E5", status);
14006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
14016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("###E0", US, status),
14026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           new Object[] { new Double(0.0000123), "12.3E-6",
14036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(0.000123), "123E-6",
14046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(0.00123), "1.23E-3",
14056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(0.0123), "12.3E-3",
14066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(0.123), "123E-3",
14076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(1.23), "1.23E0",
14086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(12.3), "12.3E0",
14096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(123), "123E0",
14106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Double(1230), "1.23E3",
14116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                         });
14126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
14136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ! Unroll this test into individual tests below...
14146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
14156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
14166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.0000123, "12.3E-6", status);
14186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.000123, "123E-6", status);
14206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.00123, "1.23E-3", status);
14226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.0123, "12.3E-3", status);
14246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.123, "123E-3", status);
14266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.23, "1.23E0", status);
14286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           12.3, "12.3E0", status);
14306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           123.0, "123E0", status);
14326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("###E0", US, status),
14336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1230.0, "1.23E3", status);
14346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
14356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("0.#E+00", US, status),
14366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           new Object[] { new Double(0.00012), "1.2E-04",
14376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          new Long(12000),     "1.2E+04",
14386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                         });
14396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
14406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ! Unroll this test into individual tests below...
14416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    !
14426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
14436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("0.#E+00", US, status),
14446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           0.00012, "1.2E-04", status);
14456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("0.#E+00", US, status),
14466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           (int32_t) 12000, "1.2E+04", status);
14476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
14506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Upgrade to alphaWorks
14516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
14526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestPad(void) {
14536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
14546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), status);
14556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols constructor");
14566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("*^##.##", US, status),
14586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "^^^^0", status);
14596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("*^##.##", US, status),
14606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1.3, "^-1.3", status);
14616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
14626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "0.0E0______ g-m/s^2", status);
14636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
14646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.0/3, "333.333E-3_ g-m/s^2", status);
14656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
14666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "0.0______ g-m/s^2", status);
14676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
14686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.0/3, "0.33333__ g-m/s^2", status);
14696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test padding before a sign
14716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *formatStr = "*x#,###,###,##0.0#;*x(###,###,##0.0#)";
14726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-10),  "xxxxxxxxxx(10.0)", status);
14746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-1000),"xxxxxxx(1,000.0)", status);
14766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-1000000),"xxx(1,000,000.0)", status);
14786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -100.37,       "xxxxxxxx(100.37)", status);
14806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -10456.37,     "xxxxx(10,456.37)", status);
14826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1120456.37,   "xx(1,120,456.37)", status);
14846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -112045600.37, "(112,045,600.37)", status);
14866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1252045600.37,"(1,252,045,600.37)", status);
14886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(10),  "xxxxxxxxxxxx10.0", status);
14916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(1000),"xxxxxxxxx1,000.0", status);
14936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(1000000),"xxxxx1,000,000.0", status);
14956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           100.37,       "xxxxxxxxxx100.37", status);
14976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
14986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           10456.37,     "xxxxxxx10,456.37", status);
14996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
15006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1120456.37,   "xxxx1,120,456.37", status);
15016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
15026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           112045600.37, "xx112,045,600.37", status);
15036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr, US, status),
15046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           10252045600.37,"10,252,045,600.37", status);
15056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test padding between a sign and a number
15086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *formatStr2 = "#,###,###,##0.0#*x;(###,###,##0.0#*x)";
15096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-10),  "(10.0xxxxxxxxxx)", status);
15116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-1000),"(1,000.0xxxxxxx)", status);
15136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-1000000),"(1,000,000.0xxx)", status);
15156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -100.37,       "(100.37xxxxxxxx)", status);
15176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -10456.37,     "(10,456.37xxxxx)", status);
15196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1120456.37,   "(1,120,456.37xx)", status);
15216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -112045600.37, "(112,045,600.37)", status);
15236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1252045600.37,"(1,252,045,600.37)", status);
15256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(10),  "10.0xxxxxxxxxxxx", status);
15286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(1000),"1,000.0xxxxxxxxx", status);
15306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(1000000),"1,000,000.0xxxxx", status);
15326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           100.37,       "100.37xxxxxxxxxx", status);
15346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           10456.37,     "10,456.37xxxxxxx", status);
15366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1120456.37,   "1,120,456.37xxxx", status);
15386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           112045600.37, "112,045,600.37xx", status);
15406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(formatStr2, US, status),
15416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           10252045600.37,"10,252,045,600.37", status);
15426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //testing the setPadCharacter(UnicodeString) and getPadCharacterString()
15446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt("#", US, status);
15456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormat constructor");
15466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString padString("P");
15476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadCharacter(padString);
15486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "*P##.##", DecimalFormat::kPadBeforePrefix, 5, padString);
15496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadCharacter((UnicodeString)"^");
15506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, (UnicodeString)"^");
15516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //commented untill implementation is complete
15526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /*  fmt.setPadCharacter((UnicodeString)"^^^");
15536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "*^^^#", DecimalFormat::kPadBeforePrefix, 3, (UnicodeString)"^^^");
15546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    padString.remove();
15556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    padString.append((UChar)0x0061);
15566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    padString.append((UChar)0x0302);
15576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadCharacter(padString);
15586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar patternChars[]={0x002a, 0x0061, 0x0302, 0x0061, 0x0302, 0x0023, 0x0000};
15596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pattern(patternChars);
15606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, pattern , DecimalFormat::kPadBeforePrefix, 4, padString);
15616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
15626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
15666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Upgrade to alphaWorks
15676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
15686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestPatterns2(void) {
15696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
15706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols US(Locale::getUS(), status);
15716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols constructor");
15726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt("#", US, status);
15746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormat constructor");
15756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar hat = 0x005E; /*^*/
15776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, hat);
15796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "$*^#", DecimalFormat::kPadAfterPrefix, 2, hat);
15806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "#*^", DecimalFormat::kPadBeforeSuffix, 1, hat);
15816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "#$*^", DecimalFormat::kPadAfterSuffix, 2, hat);
15826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "$*^$#", ILLEGAL);
15836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "#$*^$", ILLEGAL);
15846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "'pre'#,##0*x'post'", DecimalFormat::kPadBeforeSuffix,
15856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              12, (UChar)0x0078 /*x*/);
15866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "''#0*x", DecimalFormat::kPadBeforeSuffix,
15876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              3, (UChar)0x0078 /*x*/);
15886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPad(fmt, "'I''ll'*a###.##", DecimalFormat::kPadAfterPrefix,
15896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              10, (UChar)0x0061 /*a*/);
15906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.applyPattern("AA#,##0.00ZZ", status);
15926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "applyPattern");
15936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadCharacter(hat);
15946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(10);
15966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadPosition(DecimalFormat::kPadBeforePrefix);
15986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "*^AA#,##0.00ZZ");
15996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadPosition(DecimalFormat::kPadBeforeSuffix);
16016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA#,##0.00*^ZZ");
16026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadPosition(DecimalFormat::kPadAfterSuffix);
16046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA#,##0.00ZZ*^");
16056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //            12  3456789012
16076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString exp("AA*^#,##0.00ZZ", "");
16086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(12);
16096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setPadPosition(DecimalFormat::kPadAfterPrefix);
16106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, exp);
16116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(13);
16136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //              12  34567890123
16146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA*^##,##0.00ZZ");
16156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(14);
16176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //              12  345678901234
16186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA*^###,##0.00ZZ");
16196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(15);
16216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //              12  3456789012345
16226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA*^####,##0.00ZZ"); // This is the interesting case
16236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.setFormatWidth(16);
16256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //              12  34567890123456
16266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPat(fmt, "AA*^#,###,##0.00ZZ");
16276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
16286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestSurrogateSupport(void) {
16306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
16316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols custom(Locale::getUS(), status);
16326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CHECK(status, "DecimalFormatSymbols constructor");
16336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, "decimal");
16356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kPlusSignSymbol, "plus");
16366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, " minus ");
16376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kExponentialSymbol, "exponent");
16386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString patternStr("*\\U00010000##.##", "");
16406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    patternStr = patternStr.unescape();
16416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
16426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expStr = expStr.unescape();
16436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(patternStr, custom, status),
16446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), expStr, status);
16456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("*^##.##", custom, status),
16486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "^^^^0", status);
16496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##.##", custom, status),
16516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           -1.3, " minus 1decimal3", status);
16526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
16546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "0decimal0exponent0 g-m/s^2", status);
16556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
16576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.0/3, "333decimal333exponent minus 3 g-m/s^2", status);
16586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
16606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(0), "0decimal0 g-m/s^2", status);
16616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
16636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.0/3, "0decimal33333 g-m/s^2", status);
16646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString zero((UChar32)0x10000);
16666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString one((UChar32)0x10001);
16676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString two((UChar32)0x10002);
16686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString five((UChar32)0x10005);
16696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
16706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kOneDigitSymbol, one);
16716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kTwoDigitSymbol, two);
16726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kFiveDigitSymbol, five);
16736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expStr = UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
16746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expStr = expStr.unescape();
16756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat("##0.000", custom, status),
16776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           1.25, expStr, status);
16786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, (UChar)0x30);
16806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "units of money");
16816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, "money separator");
16826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    patternStr = UNICODE_STRING_SIMPLE("0.00 \\u00A4' in your bank account'");
16836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    patternStr = patternStr.unescape();
16846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expStr = UnicodeString(" minus 20money separator00 units of money in your bank account", "");
16856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(patternStr, custom, status),
16876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-20), expStr, status);
16886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    custom.setSymbol(DecimalFormatSymbols::kPercentSymbol, "percent");
16906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    patternStr = "'You''ve lost ' -0.00 %' of your money today'";
16916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    patternStr = patternStr.unescape();
16926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expStr = UnicodeString(" minus You've lost   minus 2000decimal00 percent of your money today", "");
16936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
16946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect2(new DecimalFormat(patternStr, custom, status),
16956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           int32_t(-20), expStr, status);
16966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
16976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCurrencyPatterns(void) {
16996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i, locCount;
17006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const Locale* locs = NumberFormat::getAvailableLocales(locCount);
17016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<locCount; ++i) {
17026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec = U_ZERO_ERROR;
17036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NumberFormat* nf = NumberFormat::createCurrencyInstance(locs[i], ec);
17046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
17056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Can't create NumberFormat(%s) - %s", locs[i].getName(), u_errorName(ec));
17066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
17076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // Make sure currency formats do not have a variable number
17086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // of fraction digits
17096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t min = nf->getMinimumFractionDigits();
17106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t max = nf->getMaximumFractionDigits();
17116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (min != max) {
17126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UnicodeString a, b;
17136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                nf->format(1.0, a);
17146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                nf->format(1.125, b);
17156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: " + locs[i].getName() +
17166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      " min fraction digits != max fraction digits; "
17176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      "x 1.0 => " + escape(a) +
17186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      "; x 1.125 => " + escape(b));
17196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // Make sure EURO currency formats have exactly 2 fraction digits
17226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
17236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (df != NULL) {
17246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (u_strcmp(EUR, df->getCurrency()) == 0) {
17256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (min != 2 || max != 2) {
17266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        UnicodeString a;
17276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        nf->format(1.0, a);
17286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        errln((UnicodeString)"FAIL: " + locs[i].getName() +
17296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              " is a EURO format but it does not have 2 fraction digits; "
17306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              "x 1.0 => " +
17316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              escape(a));
17326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
17336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
17346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete nf;
17376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestRegCurrency(void) {
17416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_SERVICE
17426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
17436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar USD[4];
17446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US", USD, 4, &status);
17456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar YEN[4];
17466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("ja_JP", YEN, 4, &status);
17476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar TMP[4];
17486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar QQQ[] = {0x51, 0x51, 0x51, 0};
17496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status)) {
17506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Unable to get currency for locale, error %s", u_errorName(status));
17516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
17526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UCurrRegistryKey enkey = ucurr_register(YEN, "en_US", &status);
17556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UCurrRegistryKey enUSEUROkey = ucurr_register(QQQ, "en_US_EURO", &status);
17566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US", TMP, 4, &status);
17586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(YEN, TMP) != 0) {
17596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: didn't return YEN registered for en_US");
17606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
17636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(QQQ, TMP) != 0) {
17646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: didn't return QQQ for en_US_EURO");
17656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t fallbackLen = ucurr_forLocale("en_XX_BAR", TMP, 4, &status);
17686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (fallbackLen) {
17696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: tried to fallback en_XX_BAR");
17706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR; // reset
17726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!ucurr_unregister(enkey, &status)) {
17746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: couldn't unregister enkey");
17756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US", TMP, 4, &status);
17786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(USD, TMP) != 0) {
17796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: didn't return USD for en_US after unregister of en_US");
17806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR; // reset
17826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
17846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(QQQ, TMP) != 0) {
17856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: didn't return QQQ for en_US_EURO after unregister of en_US");
17866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_BLAH", TMP, 4, &status);
17896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(USD, TMP) != 0) {
17906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: could not find USD for en_US_BLAH after unregister of en");
17916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR; // reset
17936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!ucurr_unregister(enUSEUROkey, &status)) {
17956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: couldn't unregister enUSEUROkey");
17966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
17996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(EUR, TMP) != 0) {
18006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: didn't return EUR for en_US_EURO after unregister of en_US_EURO");
18016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR; // reset
18036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
18046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCurrencyNames(void) {
18076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Do a basic check of getName()
18086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // USD { "US$", "US Dollar"            } // 04/04/1792-
18096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
18106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar USD[] = {0x55, 0x53, 0x44, 0}; /*USD*/
18116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar USX[] = {0x55, 0x53, 0x58, 0}; /*USX*/
18126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar CAD[] = {0x43, 0x41, 0x44, 0}; /*CAD*/
18136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar ITL[] = {0x49, 0x54, 0x4C, 0}; /*ITL*/
18146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool isChoiceFormat;
18156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t len;
18166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UBool possibleDataError = TRUE;
18176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Warning: HARD-CODED LOCALE DATA in this test.  If it fails, CHECK
18186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // THE LOCALE DATA before diving into the code.
18196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("USD.getName(SYMBOL_NAME)",
18206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("$"),
18216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(USD, "en",
18226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_SYMBOL_NAME,
18236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("USD.getName(LONG_NAME)",
18266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("US Dollar"),
18276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(USD, "en",
18286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_LONG_NAME,
18296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("CAD.getName(SYMBOL_NAME)",
18326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("CA$"),
18336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(CAD, "en",
18346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_SYMBOL_NAME,
18356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("CAD.getName(SYMBOL_NAME)",
18386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("$"),
18396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(CAD, "en_CA",
18406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_SYMBOL_NAME,
18416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("USD.getName(SYMBOL_NAME) in en_AU",
18446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("US$"),
18456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(USD, "en_AU",
18466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_SYMBOL_NAME,
18476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("CAD.getName(SYMBOL_NAME)",
18506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("CA$"),
18516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(CAD, "en_AU",
18526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_SYMBOL_NAME,
18536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("USX.getName(LONG_NAME)",
18566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString("USX"),
18576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 UnicodeString(ucurr_getName(USX, "en_US",
18586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             UCURR_LONG_NAME,
18596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             &isChoiceFormat, &len, &ec)),
18606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                             possibleDataError);
18616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertSuccess("ucurr_getName", ec);
18626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ec = U_ZERO_ERROR;
18646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test that a default or fallback warning is being returned. JB 4239.
18666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_getName(CAD, "es_ES", UCURR_LONG_NAME, &isChoiceFormat,
18676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            &len, &ec);
18686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertTrue("ucurr_getName (es_ES fallback)",
18696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
18706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_getName(CAD, "zh_TW", UCURR_LONG_NAME, &isChoiceFormat,
18726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            &len, &ec);
18736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertTrue("ucurr_getName (zh_TW fallback)",
18746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
18756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_getName(CAD, "en_US", UCURR_LONG_NAME, &isChoiceFormat,
18776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            &len, &ec);
18786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertTrue("ucurr_getName (en_US default)",
18796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    U_USING_DEFAULT_WARNING == ec || U_USING_FALLBACK_WARNING == ec, TRUE);
18806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_getName(CAD, "ti", UCURR_LONG_NAME, &isChoiceFormat,
18826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            &len, &ec);
18836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertTrue("ucurr_getName (ti default)",
18846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    U_USING_DEFAULT_WARNING == ec, TRUE);
18856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test that a default warning is being returned when falling back to root. JB 4536.
18876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_getName(ITL, "cy", UCURR_LONG_NAME, &isChoiceFormat,
18886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            &len, &ec);
18896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertTrue("ucurr_getName (cy default to root)",
18906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    U_USING_DEFAULT_WARNING == ec, TRUE);
18916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // TODO add more tests later
18936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCurrencyUnit(void){
18966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
18976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
18986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyUnit cu(USD, ec);
18996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertSuccess("CurrencyUnit", ec);
19006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar * r = cu.getISOCurrency(); // who is the buffer owner ?
19026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("getISOCurrency()", USD, r);
19036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyUnit cu2(cu);
19056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(cu2 == cu)){
19066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("CurrencyUnit copy constructed object should be same");
19076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone();
19106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(*cu3 == cu)){
19116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("CurrencyUnit cloned object should be same");
19126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete cu3;
19146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCurrencyAmount(void){
19176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
19186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
19196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyAmount ca(9, USD, ec);
19206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertSuccess("CurrencyAmount", ec);
19216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyAmount ca2(ca);
19236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(ca2 == ca)){
19246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("CurrencyAmount copy constructed object should be same");
19256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ca2=ca;
19286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(ca2 == ca)){
19296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("CurrencyAmount assigned object should be same");
19306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CurrencyAmount *ca3 = (CurrencyAmount *)ca.clone();
19336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!(*ca3 == ca)){
19346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("CurrencyAmount cloned object should be same");
19356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete ca3;
19376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestSymbolsWithBadLocale(void) {
19406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale locDefault;
19416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char *badLocales[] = {
19426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // length < ULOC_FULLNAME_CAPACITY
19436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME",
19446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // length > ULOC_FULLNAME_CAPACITY
19466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME"
19476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }; // expect U_USING_DEFAULT_WARNING for both
19486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    unsigned int i;
19506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < sizeof(badLocales) / sizeof(char*); i++) {
19516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeName = badLocales[i];
19526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale locBad(localeName);
19536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
19546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString intlCurrencySymbol((UChar)0xa4);
19556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        intlCurrencySymbol.append((UChar)0xa4);
19576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Current locale is %s", Locale::getDefault().getName());
19596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale::setDefault(locBad, status);
19606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Current locale is %s", Locale::getDefault().getName());
19616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormatSymbols mySymbols(status);
19626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (status != U_USING_DEFAULT_WARNING) {
19636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("DecimalFormatSymbols should return U_USING_DEFAULT_WARNING.");
19646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(mySymbols.getLocale().getName(), locBad.getName()) != 0) {
19666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("DecimalFormatSymbols does not have the right locale.", locBad.getName());
19676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int symbolEnum = (int)DecimalFormatSymbols::kDecimalSeparatorSymbol;
19696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (; symbolEnum < (int)DecimalFormatSymbols::kFormatSymbolCount; symbolEnum++) {
19706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString symbolString = mySymbols.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbolEnum);
19716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln(UnicodeString("DecimalFormatSymbols[") + symbolEnum + UnicodeString("] = ") + prettify(symbolString));
19726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (symbolString.length() == 0
19736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                && symbolEnum != (int)DecimalFormatSymbols::kGroupingSeparatorSymbol
19746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                && symbolEnum != (int)DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol)
19756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
19766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum);
19776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
19816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale::setDefault(locDefault, status);
19826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Current locale is %s", Locale::getDefault().getName());
19836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
19876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Check that adoptDecimalFormatSymbols and setDecimalFormatSymbols
19886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * behave the same, except for memory ownership semantics. (No
19896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * version of this test on Java, since Java has only one method.)
19906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
19916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestAdoptDecimalFormatSymbols(void) {
19926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
19936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), ec);
19946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
19956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(ec, "Fail: DecimalFormatSymbols constructor - %s", u_errorName(ec));
19966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete sym;
19976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat(" #,##0.00");
20006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    pat.insert(0, (UChar)0x00A4);
20016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt(pat, sym, ec);
20026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: DecimalFormat constructor");
20046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString str;
20086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.format(2350.75, str);
20096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (str == "$ 2,350.75") {
20106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(str);
20116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Fail: " + str + ", expected $ 2,350.75");
20136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sym = new DecimalFormatSymbols(Locale::getUS(), ec);
20166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: DecimalFormatSymbols constructor");
20186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete sym;
20196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sym->setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
20226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.adoptDecimalFormatSymbols(sym);
20236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    str.truncate(0);
20256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.format(2350.75, str);
20266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (str == "Q 2,350.75") {
20276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(str);
20286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Fail: adoptDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
20306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sym = new DecimalFormatSymbols(Locale::getUS(), ec);
20336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: DecimalFormatSymbols constructor");
20356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete sym;
20366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt2(pat, sym, ec);
20396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: DecimalFormat constructor");
20416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols sym2(Locale::getUS(), ec);
20456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: DecimalFormatSymbols constructor");
20476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sym2.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
20506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt2.setDecimalFormatSymbols(sym2);
20516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    str.truncate(0);
20536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt2.format(2350.75, str);
20546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (str == "Q 2,350.75") {
20556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(str);
20566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Fail: setDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
20586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestPerMill() {
20626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
20636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString str;
20646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt(ctou("###.###\\u2030"), ec);
20656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!assertSuccess("DecimalFormat ct", ec)) return;
20666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("0.4857 x ###.###\\u2030",
20676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 ctou("485.7\\u2030"), fmt.format(0.4857, str));
20686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols sym(Locale::getUS(), ec);
20706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, ctou("m"));
20716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat fmt2("", sym, ec);
20726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt2.applyLocalizedPattern("###.###m", ec);
20736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!assertSuccess("setup", ec)) return;
20746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    str.truncate(0);
20756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    assertEquals("0.4857 x ###.###m",
20766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 "485.7m", fmt2.format(0.4857, str));
20776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
20806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Generic test for patterns that should be legal/illegal.
20816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
20826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestIllegalPatterns() {
20836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test cases:
20846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Prefix with "-:" for illegal patterns
20856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Prefix with "+:" for legal patterns
20866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* DATA[] = {
20876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Unquoted special characters in the suffix are illegal
20886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-:000.000|###",
20896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "+:000.000'|###'",
20906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0
20916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; DATA[i]; ++i) {
20936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* pat=DATA[i];
20946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool valid = (*pat) == '+';
20956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        pat += 2;
20966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec = U_ZERO_ERROR;
20976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormat fmt(pat, ec); // locale doesn't matter here
20986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_SUCCESS(ec) == valid) {
20996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("Ok: pattern \"%s\": %s",
21006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat, u_errorName(ec));
21016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
21026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errcheckln(ec, "FAIL: pattern \"%s\" should have %s; got %s",
21036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  pat, (valid?"succeeded":"failed"),
21046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  u_errorName(ec));
21056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//----------------------------------------------------------------------
21106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char* KEYWORDS[] = {
21126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*0*/ "ref=", // <reference pattern to parse numbers>
21136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*1*/ "loc=", // <locale for formats>
21146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*2*/ "f:",   // <pattern or '-'> <number> <exp. string>
21156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*3*/ "fp:",  // <pattern or '-'> <number> <exp. string> <exp. number>
21166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*4*/ "rt:",  // <pattern or '-'> <(exp.) number> <(exp.) string>
21176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*5*/ "p:",   // <pattern or '-'> <string> <exp. number>
21186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*6*/ "perr:", // <pattern or '-'> <invalid string>
21196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*7*/ "pat:", // <pattern or '-'> <exp. toPattern or '-' or 'err'>
21206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*8*/ "fpc:", // <pattern or '-'> <curr.amt> <exp. string> <exp. curr.amt>
21216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    0
21226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
21236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
21256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Return an integer representing the next token from this
21266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * iterator.  The integer will be an index into the given list, or
21276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * -1 if there are no more tokens, or -2 if the token is not on
21286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * the list.
21296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
21306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t keywordIndex(const UnicodeString& tok) {
21316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; KEYWORDS[i]!=0; ++i) {
21326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (tok==KEYWORDS[i]) {
21336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return i;
21346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return -1;
21376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
21406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Parse a CurrencyAmount using the given NumberFormat, with
21416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * the 'delim' character separating the number and the currency.
21426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
21436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void parseCurrencyAmount(const UnicodeString& str,
21446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                const NumberFormat& fmt,
21456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                UChar delim,
21466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                Formattable& result,
21476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                UErrorCode& ec) {
21486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString num, cur;
21496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = str.indexOf(delim);
21506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    str.extractBetween(0, i, num);
21516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    str.extractBetween(i+1, INT32_MAX, cur);
21526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Formattable n;
21536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fmt.parse(num, n, ec);
21546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result.adoptObject(new CurrencyAmount(n, cur.getTerminatedBuffer(), ec));
21556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid NumberFormatTest::TestCases() {
21586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
21596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TextFile reader("NumberFormatTestCases.txt", "UTF8", ec);
21606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
21616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Couldn't open NumberFormatTestCases.txt");
21626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
21636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TokenIterator tokens(&reader);
21656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc("en", "US", "");
21676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat *ref = 0, *fmt = 0;
21686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    MeasureFormat *mfmt = 0;
21696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat, tok, mloc, str, out, where, currAmt;
21706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Formattable n;
21716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (;;) {
21736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ec = U_ZERO_ERROR;
21746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!tokens.next(tok, ec)) {
21756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
21766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        where = UnicodeString("(") + tokens.getLineNumber() + ") ";
21786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t cmd = keywordIndex(tok);
21796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        switch (cmd) {
21806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 0:
21816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // ref= <reference pattern>
21826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (!tokens.next(tok, ec)) goto error;
21836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            delete ref;
21846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ref = new DecimalFormat(tok,
21856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      new DecimalFormatSymbols(Locale::getUS(), ec), ec);
21866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
21876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                dataerrln("Error constructing DecimalFormat");
21886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                goto error;
21896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
21916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 1:
21926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // loc= <locale>
21936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (!tokens.next(tok, ec)) goto error;
21946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            loc = Locale::createFromName(CharString().appendInvariantChars(tok, ec).data());
21956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
21966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 2: // f:
21976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 3: // fp:
21986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 4: // rt:
21996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        case 5: // p:
22006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (!tokens.next(tok, ec)) goto error;
22016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (tok != "-") {
22026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                pat = tok;
22036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                delete fmt;
22046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                fmt = new DecimalFormat(pat, new DecimalFormatSymbols(loc, ec), ec);
22056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (U_FAILURE(ec)) {
22066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    errln("FAIL: " + where + "Pattern \"" + pat + "\": " + u_errorName(ec));
22076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    ec = U_ZERO_ERROR;
22086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (!tokens.next(tok, ec)) goto error;
22096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (!tokens.next(tok, ec)) goto error;
22106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (cmd == 3) {
22116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if (!tokens.next(tok, ec)) goto error;
22126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
22136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    continue;
22146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
22156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
22166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (cmd == 2 || cmd == 3 || cmd == 4) {
22176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // f: <pattern or '-'> <number> <exp. string>
22186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // fp: <pattern or '-'> <number> <exp. string> <exp. number>
22196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // rt: <pattern or '-'> <number> <string>
22206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UnicodeString num;
22216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!tokens.next(num, ec)) goto error;
22226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!tokens.next(str, ec)) goto error;
22236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ref->parse(num, n, ec);
22246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                assertSuccess("parse", ec);
22256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                assertEquals(where + "\"" + pat + "\".format(" + num + ")",
22266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             str, fmt->format(n, out.remove(), ec));
22276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                assertSuccess("format", ec);
22286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (cmd == 3) { // fp:
22296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if (!tokens.next(num, ec)) goto error;
22306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    ref->parse(num, n, ec);
22316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    assertSuccess("parse", ec);
22326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
22336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (cmd != 2) { // != f:
22346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    Formattable m;
22356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    fmt->parse(str, m, ec);
22366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    assertSuccess("parse", ec);
22376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    assertEquals(where + "\"" + pat + "\".parse(\"" + str + "\")",
22386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 n, m);
22396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
22406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
22416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // p: <pattern or '-'> <string to parse> <exp. number>
22426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else {
22436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UnicodeString expstr;
22446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!tokens.next(str, ec)) goto error;
22456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!tokens.next(expstr, ec)) goto error;
22466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                Formattable exp, n;
22476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ref->parse(expstr,