1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/********************************************************************
250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * COPYRIGHT:
3fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius * Copyright (c) 1997-2014, International Business Machines Corporation and
4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * others. All Rights Reserved.
5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ********************************************************************/
6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* Modification History:
7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   Date        Name        Description
8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   07/15/99    helena      Ported to HPUX 10/11 CC.
9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h"
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "numfmtst.h"
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/dcfmtsym.h"
17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/decimfmt.h"
18b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#include "unicode/localpointer.h"
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ucurr.h"
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h"
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/measfmt.h"
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/curramt.h"
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "digitlst.h"
24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "textfile.h"
25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "tokiter.h"
26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "charstr.h"
27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "putilimp.h"
28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "winnmtst.h"
29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <float.h>
30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <string.h>
31b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#include <stdlib.h>
32b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#include "cstring.h"
3350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/numsys.h"
3454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "fmtableimp.h"
35b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
36b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//#define NUMFMTST_CACHE_DEBUG 1
3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "stdio.h" /* for sprintf */
3850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho// #include "iostream"   // for cout
39b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
40b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//#define NUMFMTST_DEBUG 1
41b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
42b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0]))
43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
44b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar EUR[] = {69,85,82,0}; // "EUR"
45b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD"
4650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
4759d709d503bab6e2b61931737e662dd293b40578ccornelius
48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// *****************************************************************************
49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// class NumberFormatTest
50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// *****************************************************************************
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
526d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru#define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
5327f654740f2a26ad62a5c155af9199af9e69b889claireho#define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
578393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO_BEGIN;
588393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencySign);
598393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrency);
608393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestParse);
618393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestRounding487);
628393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestQuotes);
638393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestExponential);
648393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestPatterns);
658393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
668393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  // Upgrade to alphaWorks - liu 5/99
678393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestExponent);
688393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestScientific);
698393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestPad);
708393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestPatterns2);
718393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestSecondaryGrouping);
728393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestSurrogateSupport);
738393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestAPI);
748393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
758393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyObject);
768393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyPatterns);
778393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  //TESTCASE_AUTO(TestDigitList);
788393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestWhiteSpaceParsing);
798393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestComplexCurrency);  // This test removed because CLDR no longer uses choice formats in currency symbols.
808393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestRegCurrency);
818393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestSymbolsWithBadLocale);
828393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestAdoptDecimalFormatSymbols);
838393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
848393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestScientific2);
858393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestScientificGrouping);
868393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestInt64);
878393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
888393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestPerMill);
898393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestIllegalPatterns);
908393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCases);
918393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
928393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyNames);
938393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyAmount);
948393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyUnit);
958393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCoverage);
968393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestJB3832);
978393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestHost);
988393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestHostClone);
998393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyFormat);
1008393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestRounding);
1018393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestNonpositiveMultiplier);
1028393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestNumberingSystems);
1038393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestSpaceParsing);
1048393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestMultiCurrencySign);
1058393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyFormatForMixParsing);
1068393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestDecimalFormatCurrencyParse);
1078393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyIsoPluralFormat);
1088393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyParsing);
1098393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestParseCurrencyInUCurr);
1108393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestFormatAttributes);
1118393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestFieldPositionIterator);
1128393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestDecimal);
1138393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestCurrencyFractionDigits);
1148393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestExponentParse);
1158393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestExplicitParents);
1168393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestLenientParse);
1178393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestAvailableNumberingSystems);
1188393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestRoundingPattern);
1198393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(Test9087);
1208393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestFormatFastpaths);
1218393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO(TestFormattableSize);
12259d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestUFormattable);
12359d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestSignificantDigits);
12459d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestShowZero);
12559d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestCompatibleCurrencies);
12659d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestBug9936);
12759d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestParseNegativeWithFaLocale);
12859d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign);
12959d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestCustomCurrencySignAndSeparator);
13059d709d503bab6e2b61931737e662dd293b40578ccornelius  TESTCASE_AUTO(TestParseSignsAndMarks);
131fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(Test10419RoundingWith0FractionDigits);
132fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(Test10468ApplyPattern);
133fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(TestRoundingScientific10542);
134fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(TestZeroScientific10547);
135fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(TestAccountingCurrency);
136fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius  TESTCASE_AUTO(TestEquality);
1378393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  TESTCASE_AUTO_END;
138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
13950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// Test API (increase code coverage)
143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestAPI(void)
145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  logln("Test API");
147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  NumberFormat *test = NumberFormat::createInstance("root", status);
149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  if(U_FAILURE(status)) {
1506d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    dataerrln("unable to create format object - %s", u_errorName(status));
151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  }
152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  if(test != NULL) {
153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->setMinimumIntegerDigits(10);
154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->setMaximumIntegerDigits(2);
155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->setMinimumFractionDigits(10);
157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->setMaximumFractionDigits(2);
158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString result;
160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    FieldPosition pos;
161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Formattable bla("Paja Patak"); // Donald Duck for non Serbian speakers
162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->format(bla, result, pos, status);
163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(U_SUCCESS(status)) {
164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      errln("Yuck... Formatted a duck... As a number!");
165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      status = U_ZERO_ERROR;
167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    result.remove();
170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int64_t ll = 12;
171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    test->format(ll, result);
172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (result != "12.00"){
173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("format int64_t error");
174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
17650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    ParsePosition ppos;
177103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    LocalPointer<CurrencyAmount> currAmt(test->parseCurrency("",ppos));
178103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    // old test for (U_FAILURE(status)) was bogus here, method does not set status!
179103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    if (ppos.getIndex()) {
180103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        errln("Parsed empty string as currency");
18150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    }
18250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
18350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    delete test;
184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  }
185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
18759d709d503bab6e2b61931737e662dd293b40578ccorneliusclass StubNumberFormat :public NumberFormat{
188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querupublic:
18959d709d503bab6e2b61931737e662dd293b40578ccornelius    StubNumberFormat(){};
190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual UnicodeString& format(double ,UnicodeString& appendTo,FieldPosition& ) const {
191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return appendTo;
192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual UnicodeString& format(int32_t ,UnicodeString& appendTo,FieldPosition& ) const {
194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return appendTo.append((UChar)0x0033);
195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual UnicodeString& format(int64_t number,UnicodeString& appendTo,FieldPosition& pos) const {
197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return NumberFormat::format(number, appendTo, pos);
198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual UnicodeString& format(const Formattable& , UnicodeString& appendTo, FieldPosition& , UErrorCode& ) const {
200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return appendTo;
201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual void parse(const UnicodeString& ,
203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    Formattable& ,
204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    ParsePosition& ) const {}
205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual void parse( const UnicodeString& ,
206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        Formattable& ,
207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        UErrorCode& ) const {}
208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual UClassID getDynamicClassID(void) const {
209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        static char classID = 0;
21050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        return (UClassID)&classID;
211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    virtual Format* clone() const {return NULL;}
213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
21550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehovoid
216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestCoverage(void){
21759d709d503bab6e2b61931737e662dd293b40578ccornelius    StubNumberFormat stub;
218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString agent("agent");
219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    FieldPosition pos;
220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int64_t num = 4;
221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (stub.format(num, agent, pos) != UnicodeString("agent3")){
222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// Test various patterns
227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestPatterns(void)
229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols sym(Locale::getUS(), status);
2326d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) { errcheckln(status, "FAIL: Could not construct DecimalFormatSymbols - %s", u_errorName(status)); return; }
233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* pat[]    = { "#.#", "#.", ".#", "#" };
235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* newpat[] = { "#0.#", "#0.", "#.0", "#" };
237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* num[]    = { "0",   "0.", ".0", "0" };
238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t i=0; i<pat_length; ++i)
239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        DecimalFormat fmt(pat[i], sym, status);
242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_FAILURE(status)) { errln((UnicodeString)"FAIL: DecimalFormat constructor failed for " + pat[i]); continue; }
243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UnicodeString newp; fmt.toPattern(newp);
244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!(newp == newpat[i]))
245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should transmute to " + newpat[i] +
246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  "; " + newp + " seen instead");
247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UnicodeString s; (*(NumberFormat*)&fmt).format((int32_t)0, s);
249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!(s == num[i]))
250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should format zero as " + num[i] +
252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  "; " + s + " seen instead");
253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            logln((UnicodeString)"Min integer digits = " + fmt.getMinimumIntegerDigits());
254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
25950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoicu_2_4::DigitList::operator== 0 0 2 icuuc24d.dll digitlst.cpp Doug
26050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoicu_2_4::DigitList::append 0 0 4 icuin24d.dll digitlst.h Doug
26150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoicu_2_4::DigitList::operator!= 0 0 1 icuuc24d.dll digitlst.h Doug
262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
26450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehovoid
265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestDigitList(void)
266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  // API coverage for DigitList
268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  DigitList list1;
269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  list1.append('1');
270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  list1.fDecimalAt = 1;
271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  DigitList list2;
272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  list2.set((int32_t)1);
273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  if (list1 != list2) {
274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    errln("digitlist append, operator!= or set failed ");
275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  }
276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  if (!(list1 == list2)) {
277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    errln("digitlist append, operator== or set failed ");
278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  }
279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// Test exponential pattern
285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestExponential(void)
287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols sym(Locale::getUS(), status);
2906d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) { errcheckln(status, "FAIL: Bad status returned by DecimalFormatSymbols ct - %s", u_errorName(status)); return; }
291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* pat[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]"  };
292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// The following #if statements allow this test to be built and run on
295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// platforms that do not have standard IEEE numerics.  For example,
296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// S/390 doubles have an exponent range of -78 to +75.  For the
297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// following #if statements to work, float.h must define
298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// DBL_MAX_10_EXP to be a compile-time constant.
299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// This section may be expanded as needed.
301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if DBL_MAX_10_EXP > 300
303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double val[] = { 0.01234, 123456789, 1.23e300, -3.141592653e-271 };
304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t val_length = (int32_t)(sizeof(val) / sizeof(val[0]));
305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* valFormat[] =
306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.####E0
308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 00.000E00
310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // ##0.######E000
312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.###E0;[0.###E0]
314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double valParse[] =
317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123460000, 1.23E300, -3.1416E-271,
319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123460000, 1.23E300, -3.1416E-271,
320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123456800, 1.23E300, -3.141593E-271,
321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123500000, 1.23E300, -3.142E-271,
322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#elif DBL_MAX_10_EXP > 70
324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double val[] = { 0.01234, 123456789, 1.23e70, -3.141592653e-71 };
325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t val_length = sizeof(val) / sizeof(val[0]);
326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char* valFormat[] =
327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.####E0
329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "1.234E-2", "1.2346E8", "1.23E70", "-3.1416E-71",
330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 00.000E00
331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "12.340E-03", "12.346E07", "12.300E69", "-31.416E-72",
332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // ##0.######E000
333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "12.34E-003", "123.4568E006", "12.3E069", "-31.41593E-072",
334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.###E0;[0.###E0]
335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "1.234E-2", "1.235E8", "1.23E70", "[3.142E-71]"
336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double valParse[] =
338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123460000, 1.23E70, -3.1416E-71,
340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123460000, 1.23E70, -3.1416E-71,
341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123456800, 1.23E70, -3.141593E-71,
342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0.01234, 123500000, 1.23E70, -3.142E-71,
343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#else
345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Don't test double conversion
346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double* val = 0;
347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t val_length = 0;
348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char** valFormat = 0;
349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    double* valParse = 0;
350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln("Warning: Skipping double conversion tests");
351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t lval[] = { 0, -1, 1, 123456789 };
354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t lval_length = (int32_t)(sizeof(lval) / sizeof(lval[0]));
355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* lvalFormat[] =
356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.####E0
358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "0E0", "-1E0", "1E0", "1.2346E8",
359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 00.000E00
360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // ##0.######E000
362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "0E000", "-1E000", "1E000", "123.4568E006",
363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // 0.###E0;[0.###E0]
364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "0E0", "[1E0]", "1E0", "1.235E8"
365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t lvalParse[] =
367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0, -1, 1, 123460000,
369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0, -1, 1, 123460000,
370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0, -1, 1, 123456800,
371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0, -1, 1, 123500000,
372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t ival = 0, ilval = 0;
374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t p=0; p<pat_length; ++p)
375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        DecimalFormat fmt(pat[p], sym, status);
377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_FAILURE(status)) { errln("FAIL: Bad status returned by DecimalFormat ct"); continue; }
378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UnicodeString pattern;
379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln((UnicodeString)"Pattern \"" + pat[p] + "\" -toPattern-> \"" +
380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          fmt.toPattern(pattern) + "\"");
381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t v;
382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (v=0; v<val_length; ++v)
383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            UnicodeString s; (*(NumberFormat*)&fmt).format(val[v], s);
385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            logln((UnicodeString)" " + val[v] + " -format-> " + s);
386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (s != valFormat[v+ival])
387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"FAIL: Expected " + valFormat[v+ival]);
388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ParsePosition pos(0);
390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            Formattable af;
391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            fmt.parse(s, af, pos);
392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            double a;
393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            UBool useEpsilon = FALSE;
394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (af.getType() == Formattable::kLong)
395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                a = af.getLong();
396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else if (af.getType() == Formattable::kDouble) {
397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                a = af.getDouble();
398103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // S/390 will show a failure like this:
400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                //| -3.141592652999999e-271 -format-> -3.1416E-271
401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                //|                          -parse-> -3.1416e-271
402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                //| FAIL: Expected -3.141599999999999e-271
403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // To compensate, we use an epsilon-based equality
404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // test on S/390 only.  We don't want to do this in
405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // general because it's less exacting.
406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                useEpsilon = TRUE;
407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else {
410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"FAIL: Non-numeric Formattable returned");
411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                continue;
412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (pos.getIndex() == s.length())
414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {
415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                logln((UnicodeString)"  -parse-> " + a);
416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // Use epsilon comparison as necessary
417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if ((useEpsilon &&
418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    (uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    (!useEpsilon && a != valParse[v+ival]))
420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                {
421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else {
425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"  should be (" + s.length() + " chars) -> " + valParse[v+ival]);
427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (v=0; v<lval_length; ++v)
430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            UnicodeString s;
432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            (*(NumberFormat*)&fmt).format(lval[v], s);
433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            logln((UnicodeString)" " + lval[v] + "L -format-> " + s);
434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (s != lvalFormat[v+ilval])
435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"ERROR: Expected " + lvalFormat[v+ilval] + " Got: " + s);
436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ParsePosition pos(0);
438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            Formattable af;
439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            fmt.parse(s, af, pos);
440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (af.getType() == Formattable::kLong ||
441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                af.getType() == Formattable::kInt64) {
442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                UErrorCode status = U_ZERO_ERROR;
443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                int32_t a = af.getLong(status);
444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (pos.getIndex() == s.length())
445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                {
446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    logln((UnicodeString)"  -parse-> " + a);
447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (a != lvalParse[v+ilval])
448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        errln((UnicodeString)"FAIL: Expected " + lvalParse[v+ilval]);
449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                else
451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else
454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"FAIL: Non-long Formattable returned for " + s
455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    + " Double: " + af.getDouble()
456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    + ", Long: " + af.getLong());
457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        ival += val_length;
459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        ilval += lval_length;
460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestScientific2() {
465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // jb 2552
466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat* fmt = (DecimalFormat*)NumberFormat::createCurrencyInstance("en_US", status);
468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_SUCCESS(status)) {
469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        double num = 12.34;
470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(*fmt, num, "$12.34");
471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        fmt->setScientificNotation(TRUE);
472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(*fmt, num, "$1.23E1");
473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        fmt->setScientificNotation(FALSE);
474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(*fmt, num, "$12.34");
475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
47950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehovoid
480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestScientificGrouping() {
481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // jb 2552
482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt("##0.00E0",status);
484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_SUCCESS(status)) {
485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, .01234, "12.3E-3");
486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, .1234, "123E-3");
487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, 1.234, "1.23E0");
488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, 12.34, "12.3E0");
489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, 123.4, "123E0");
490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, 1234., "1.23E3");
491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*static void setFromString(DigitList& dl, const char* str) {
495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char c;
496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UBool decimalSet = FALSE;
497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    dl.clear();
498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    while ((c = *str++)) {
499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (c == '-') {
500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            dl.fIsPositive = FALSE;
501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else if (c == '+') {
502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            dl.fIsPositive = TRUE;
503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else if (c == '.') {
504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            dl.fDecimalAt = dl.fCount;
505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            decimalSet = TRUE;
506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            dl.append(c);
508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!decimalSet) {
511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dl.fDecimalAt = dl.fCount;
512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}*/
514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestInt64() {
517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt("#.#E0",status);
519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setMaximumFractionDigits(20);
520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_SUCCESS(status)) {
521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)0, "0E0");
522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)-1, "-1E0");
523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)1, "1E0");
524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)2147483647, "2.147483647E9");
525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)((int64_t)-2147483647-1), "-2.147483648E9");
526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)U_INT64_MAX, "9.223372036854775807E18");
527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expect(fmt, (Formattable)(int64_t)U_INT64_MIN, "-9.223372036854775808E18");
528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // also test digitlist
531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*    int64_t int64max = U_INT64_MAX;
532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int64_t int64min = U_INT64_MIN;
533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* int64maxstr = "9223372036854775807";
534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* int64minstr = "-9223372036854775808";
535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString fail("fail: ");
536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // test max int64 value
538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DigitList dl;
539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    setFromString(dl, int64maxstr);
540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!dl.fitsIntoInt64(FALSE)) {
542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + int64maxstr + " didn't fit");
543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64_t int64Value = dl.getInt64();
545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != int64max) {
546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + int64maxstr);
547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dl.set(int64Value);
549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64Value = dl.getInt64();
550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != int64max) {
551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + int64maxstr);
552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // test negative of max int64 value (1 shy of min int64 value)
555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    dl.fIsPositive = FALSE;
556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!dl.fitsIntoInt64(FALSE)) {
558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + "-" + int64maxstr + " didn't fit");
559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64_t int64Value = dl.getInt64();
561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != -int64max) {
562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + "-" + int64maxstr);
563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dl.set(int64Value);
565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64Value = dl.getInt64();
566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != -int64max) {
567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + "-" + int64maxstr);
568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // test min int64 value
571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    setFromString(dl, int64minstr);
572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!dl.fitsIntoInt64(FALSE)) {
574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + "-" + int64minstr + " didn't fit");
575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64_t int64Value = dl.getInt64();
577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != int64min) {
578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + int64minstr);
579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dl.set(int64Value);
581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int64Value = dl.getInt64();
582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (int64Value != int64min) {
583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + int64minstr);
584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // test negative of min int 64 value (1 more than max int64 value)
587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    dl.fIsPositive = TRUE; // won't fit
588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (dl.fitsIntoInt64(FALSE)) {
590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(fail + "-(" + int64minstr + ") didn't fit");
591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }*/
593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// Test the handling of quotes
598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestQuotes(void)
600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString *pat;
603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), status);
6046d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) {
6056d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
6066d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        delete sym;
6076d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        return;
6086d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    }
609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat = new UnicodeString("a'fo''o'b#");
610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat *fmt = new DecimalFormat(*pat, *sym, status);
61150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    UnicodeString s;
612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ((NumberFormat*)fmt)->format((int32_t)123, s);
613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Pattern \"" + *pat + "\"");
614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format 123 -> " + escape(s));
61550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    if (!(s=="afo'ob123"))
616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln((UnicodeString)"FAIL: Expected afo'ob123");
61750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete pat;
621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat = new UnicodeString("a''b#");
623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt = new DecimalFormat(*pat, *sym, status);
624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ((NumberFormat*)fmt)->format((int32_t)123, s);
625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Pattern \"" + *pat + "\"");
626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format 123 -> " + escape(s));
62750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    if (!(s=="a'b123"))
628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln((UnicodeString)"FAIL: Expected a'b123");
629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete pat;
631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete sym;
632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the handling of the currency symbol in patterns.
636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestCurrencySign(void)
639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols* sym = new DecimalFormatSymbols(Locale::getUS(), status);
642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString pat;
643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar currency = 0x00A4;
6446d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) {
6456d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
6466d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        delete sym;
6476d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        return;
6486d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    }
649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // "\xA4#,##0.00;-\xA4#,##0.00"
650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat.append(currency).append("#,##0.00;-").
651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        append(currency).append("#,##0.00");
652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat *fmt = new DecimalFormat(pat, *sym, status);
653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString s; ((NumberFormat*)fmt)->format(1234.56, s);
654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat.truncate(0);
655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
65727f654740f2a26ad62a5c155af9199af9e69b889claireho    if (s != "$1,234.56") dataerrln((UnicodeString)"FAIL: Expected $1,234.56");
658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ((NumberFormat*)fmt)->format(- 1234.56, s);
660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
66127f654740f2a26ad62a5c155af9199af9e69b889claireho    if (s != "-$1,234.56") dataerrln((UnicodeString)"FAIL: Expected -$1,234.56");
662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat.truncate(0);
664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // "\xA4\xA4 #,##0.00;\xA4\xA4 -#,##0.00"
665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat.append(currency).append(currency).
666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        append(" #,##0.00;").
667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        append(currency).append(currency).
668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        append(" -#,##0.00");
669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt = new DecimalFormat(pat, *sym, status);
670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ((NumberFormat*)fmt)->format(1234.56, s);
672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
67427f654740f2a26ad62a5c155af9199af9e69b889claireho    if (s != "USD 1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD 1,234.56");
675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ((NumberFormat*)fmt)->format(-1234.56, s);
677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
67827f654740f2a26ad62a5c155af9199af9e69b889claireho    if (s != "USD -1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD -1,234.56");
679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete sym;
6816d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + u_errorName(status));
682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
68350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruUnicodeString&
689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::escape(UnicodeString& s)
690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString buf;
692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t i=0; i<s.length(); ++i)
693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar c = s[(int32_t)i];
695b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (c <= (UChar)0x7F) buf += c;
696b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else {
697b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            buf += (UChar)0x5c; buf += (UChar)0x55;
698b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            buf += toHexString((c & 0xF000) >> 12);
699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            buf += toHexString((c & 0x0F00) >> 8);
700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            buf += toHexString((c & 0x00F0) >> 4);
701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            buf += toHexString(c & 0x000F);
702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    return (s = buf);
705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
70750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const char* testCases[][2]= {
710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     /* locale ID */  /* expected */
71154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" },
712c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {"de_LU_PREEURO", "1,150\\u00A0F" },
713c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" },
714b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    {"en_BE_PREEURO", "1.150,50\\u00A0BEF" },
715fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    {"es_ES_PREEURO", "1.150\\u00A0\\u20A7" },
71654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" },
717c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" },
718b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    {"it_IT_PREEURO", "ITL\\u00A01.150" },
719c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {"pt_PT_PREEURO", "1,150$50\\u00A0Esc."},
72027f654740f2a26ad62a5c155af9199af9e69b889claireho    {"en_US@currency=JPY", "\\u00A51,150"},
72127f654740f2a26ad62a5c155af9199af9e69b889claireho    {"en_US@currency=jpy", "\\u00A51,150"},
72227f654740f2a26ad62a5c155af9199af9e69b889claireho    {"en-US-u-cu-jpy", "\\u00A51,150"}
723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test localized currency patterns.
726b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestCurrency(void)
729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
730b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
731b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status);
732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(status)) {
733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dataerrln("Error calling NumberFormat::createCurrencyInstance()");
734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
737b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString s; currencyFmt->format(1.50, s);
738b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Un pauvre ici a..........." + s);
739c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    if (!(s==CharsToUnicodeString("1,50\\u00A0$")))
740c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>$");
741b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete currencyFmt;
742b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
743b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char loc[256]={0};
744b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int len = uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
74559d709d503bab6e2b61931737e662dd293b40578ccornelius    (void)len;  // Suppress unused variable warning.
746b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc),status);
747b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    currencyFmt->format(1.50, s);
748b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Un pauvre en Allemagne a.." + s);
749b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (!(s==CharsToUnicodeString("1,50\\u00A0DEM")))
750b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>DEM");
751b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete currencyFmt;
752b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    s.truncate(0);
753b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
754b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
755b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    currencyFmt->format(1.50, s);
756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"Un pauvre en France a....." + s);
757c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    if (!(s==CharsToUnicodeString("1,50\\u00A0F")))
758c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        errln((UnicodeString)"FAIL: Expected 1,50<nbsp>F");
759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete currencyFmt;
760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(status))
761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln((UnicodeString)"FAIL: Status " + (int32_t)status);
76250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(int i=0; i < (int)(sizeof(testCases)/sizeof(testCases[i])); i++){
764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID = testCases[i][0];
766c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        UnicodeString expected(testCases[i][1], -1, US_INV);
767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expected = expected.unescape();
768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        s.truncate(0);
769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char loc[256]={0};
770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_canonicalize(localeID, loc, 256, &status);
771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln("Could not create currency formatter for locale %s",localeID);
774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            continue;
775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        currencyFmt->format(1150.50, s);
777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(s!=expected){
77850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho            errln(UnicodeString("FAIL: Expected: ")+expected
77950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                    + UnicodeString(" Got: ") + s
780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_FAILURE(status)){
783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln((UnicodeString)"FAIL: Status " + (int32_t)status);
784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete currencyFmt;
786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
78850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the Currency object handling, new as of ICU 2.2.
793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCurrencyObject() {
795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
79650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    NumberFormat* fmt =
797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        NumberFormat::createCurrencyInstance(Locale::getUS(), ec);
798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
8006d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        dataerrln("FAIL: getCurrencyInstance(US) - %s", u_errorName(ec));
801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete fmt;
802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale null("", "", "");
80650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, null, 1234.56, "$1,234.56");
808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getFrance(),
810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, CharsToUnicodeString("\\u20AC1,234.56")); // Euro
811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getJapan(),
813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, CharsToUnicodeString("\\u00A51,235")); // Yen
814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale("fr", "CH", ""),
8168393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius                   1234.56, "CHF1,234.56"); // no more 0.05 rounding here, see cldrbug 5548
817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getUS(),
819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, "$1,234.56");
820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt = NumberFormat::createCurrencyInstance(Locale::getFrance(), ec);
823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: getCurrencyInstance(FRANCE)");
826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete fmt;
827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
82950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, null, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC"));
831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getJapan(),
833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, CharsToUnicodeString("1 235 \\u00A5JP")); // Yen
834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale("fr", "CH", ""),
8368393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius                   1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see cldrbug 5548
837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getUS(),
839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, "1 234,56 $US");
840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectCurrency(*fmt, Locale::getFrance(),
842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                   1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro
843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete fmt;
845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
84650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Do rudimentary testing of parsing.
851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestParse(void)
854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString arg("0");
857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat* format = new DecimalFormat("00", status);
858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //try {
859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        Formattable n; format->parse(arg, n, status);
860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln((UnicodeString)"parse(" + arg + ") = " + n.getLong());
861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (n.getType() != Formattable::kLong ||
862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            n.getLong() != 0) errln((UnicodeString)"FAIL: Expected 0");
863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete format;
8646d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    if (U_FAILURE(status)) errcheckln(status, (UnicodeString)"FAIL: Status " + u_errorName(status));
865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //}
866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //catch(Exception e) {
867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //    errln((UnicodeString)"Exception caught: " + e);
868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //}
869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
87050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
873b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientAffixTestCases[] = {
874103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "(1)",
875103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "( 1)",
876103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "(1 )",
877103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "( 1 )"
878b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
879b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
880b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientMinusTestCases[] = {
881b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    "-5",
882b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    "\\u22125",
883b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    "\\u20105"
884b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
885b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
886b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientCurrencyTestCases[] = {
887103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$1,000",
888103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$ 1,000",
889103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$1000",
890103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$ 1000",
891103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$1 000.00",
892103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$ 1 000.00",
893103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "$ 1\\u00A0000.00",
894103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "1000.00"
895b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
896b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
89759d709d503bab6e2b61931737e662dd293b40578ccornelius// changed from () to - per cldrbug 5674
898b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientNegativeCurrencyTestCases[] = {
89959d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$1,000",
90059d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$ 1,000",
90159d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$1000",
90259d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$ 1000",
90359d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$1 000.00",
90459d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$ 1 000.00",
90559d709d503bab6e2b61931737e662dd293b40578ccornelius        "- $ 1,000.00 ",
90659d709d503bab6e2b61931737e662dd293b40578ccornelius        "-$ 1\\u00A0000.00",
90759d709d503bab6e2b61931737e662dd293b40578ccornelius        "-1000.00"
908b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
909b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
910b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientPercentTestCases[] = {
911103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "25%",
912103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        " 25%",
913103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        " 25 %",
914103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    	"25 %",
915b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"25\\u00A0%",
916b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"25"
917b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
918b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
919b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *lenientNegativePercentTestCases[] = {
920b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"-25%",
921b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		" -25%",
922b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		" - 25%",
923b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"- 25 %",
924b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		" - 25 %",
925b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"-25 %",
926b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"-25\\u00A0%",
927b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"-25",
928b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"- 25"
929b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
930b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
931b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic const char *strictFailureTestCases[] = {
932b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		" 1000",
933b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"10,00",
934b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		"1,000,.0"
935b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho};
936b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
937b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#define ARRAY_SIZE(array) ((int32_t) (sizeof (array) / sizeof(array[0])))
938b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
939b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho/**
940b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * Test lenient parsing.
941b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho */
942b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehovoid
943b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehoNumberFormatTest::TestLenientParse(void)
944b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{
945b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    UErrorCode status = U_ZERO_ERROR;
946b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    DecimalFormat *format = new DecimalFormat("(#,##0)", status);
947b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    Formattable n;
948b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
949b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (format == NULL || U_FAILURE(status)) {
950b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        dataerrln("Unable to create DecimalFormat (#,##0) - %s", u_errorName(status));
951b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } else {
952b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        format->setLenient(TRUE);
953b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE (lenientAffixTestCases); t += 1) {
954b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	UnicodeString testCase = ctou(lenientAffixTestCases[t]);
955b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
956b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            format->parse(testCase, n, status);
957b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
958b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
959b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) || n.getType() != Formattable::kLong ||
960b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	n.getLong() != 1) {
961b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientAffixTestCases[t] + (UnicodeString) "\"");
962b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	status = U_ZERO_ERROR;
963b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
964b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       }
965b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       delete format;
966b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
967b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
968b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    Locale en_US("en_US");
969b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    Locale sv_SE("sv_SE");
970b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
971b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    NumberFormat *mFormat = NumberFormat::createInstance(sv_SE, UNUM_DECIMAL, status);
972b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
973b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (mFormat == NULL || U_FAILURE(status)) {
974b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        dataerrln("Unable to create NumberFormat (sv_SE, UNUM_DECIMAL) - %s", u_errorName(status));
975b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } else {
976b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        mFormat->setLenient(TRUE);
977b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
978b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            UnicodeString testCase = ctou(lenientMinusTestCases[t]);
979b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
980b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            mFormat->parse(testCase, n, status);
981b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
982b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
983b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
984b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
985b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                status = U_ZERO_ERROR;
986b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
987b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
988b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        delete mFormat;
989b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
990b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
991b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    mFormat = NumberFormat::createInstance(en_US, UNUM_DECIMAL, status);
992b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
993b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (mFormat == NULL || U_FAILURE(status)) {
994b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        dataerrln("Unable to create NumberFormat (en_US, UNUM_DECIMAL) - %s", u_errorName(status));
995b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } else {
996b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        mFormat->setLenient(TRUE);
997b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
998b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            UnicodeString testCase = ctou(lenientMinusTestCases[t]);
999b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1000b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            mFormat->parse(testCase, n, status);
1001b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1002b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1003b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
1004b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
1005b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                status = U_ZERO_ERROR;
1006b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
1007b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
1008b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        delete mFormat;
1009b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
1010b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1011b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    NumberFormat *cFormat = NumberFormat::createInstance(en_US, UNUM_CURRENCY, status);
1012b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1013b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (cFormat == NULL || U_FAILURE(status)) {
1014b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        dataerrln("Unable to create NumberFormat (en_US, UNUM_CURRENCY) - %s", u_errorName(status));
1015b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } else {
1016b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        cFormat->setLenient(TRUE);
1017b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE (lenientCurrencyTestCases); t += 1) {
1018b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	UnicodeString testCase = ctou(lenientCurrencyTestCases[t]);
1019b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1020b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            cFormat->parse(testCase, n, status);
1021b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1022b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1023b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1024b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	n.getLong() != 1000) {
1025b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientCurrencyTestCases[t] + (UnicodeString) "\"");
1026b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	status = U_ZERO_ERROR;
1027b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
1028b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
1029b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1030b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativeCurrencyTestCases); t += 1) {
1031b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	UnicodeString testCase = ctou(lenientNegativeCurrencyTestCases[t]);
1032b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1033b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            cFormat->parse(testCase, n, status);
1034b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1035b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1036b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1037b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	n.getLong() != -1000) {
1038b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativeCurrencyTestCases[t] + (UnicodeString) "\"");
1039b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	status = U_ZERO_ERROR;
1040b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
1041b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
1042b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1043b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        delete cFormat;
1044b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
1045b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1046b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    NumberFormat *pFormat = NumberFormat::createPercentInstance(en_US, status);
1047b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1048b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if (pFormat == NULL || U_FAILURE(status)) {
1049b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        dataerrln("Unable to create NumberFormat::createPercentInstance (en_US) - %s", u_errorName(status));
1050b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } else {
1051b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        pFormat->setLenient(TRUE);
1052b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE (lenientPercentTestCases); t += 1) {
1053b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	UnicodeString testCase = ctou(lenientPercentTestCases[t]);
1054b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1055b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	pFormat->parse(testCase, n, status);
1056b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
1057b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1058b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
1059b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	n.getDouble() != 0.25) {
1060b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientPercentTestCases[t] + (UnicodeString) "\"");
1061b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	status = U_ZERO_ERROR;
1062b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
1063b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
1064b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1065b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativePercentTestCases); t += 1) {
1066b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	UnicodeString testCase = ctou(lenientNegativePercentTestCases[t]);
1067b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1068b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        	pFormat->parse(testCase, n, status);
1069b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
1070b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1071b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
1072b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	n.getDouble() != -0.25) {
1073b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativePercentTestCases[t] + (UnicodeString) "\"");
1074b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            	status = U_ZERO_ERROR;
1075b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
1076b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
1077b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1078b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        delete pFormat;
1079b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
1080b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1081b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   // Test cases that should fail with a strict parse and pass with a
1082b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   // lenient parse.
1083b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   NumberFormat *nFormat = NumberFormat::createInstance(en_US, status);
1084b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1085b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   if (nFormat == NULL || U_FAILURE(status)) {
1086b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       dataerrln("Unable to create NumberFormat (en_US) - %s", u_errorName(status));
1087b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   } else {
1088b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       // first, make sure that they fail with a strict parse
1089b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
1090b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       UnicodeString testCase = ctou(strictFailureTestCases[t]);
1091b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1092b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       nFormat->parse(testCase, n, status);
1093b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1094b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1095b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       if (! U_FAILURE(status)) {
1096b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		       errln((UnicodeString)"Strict Parse succeeded for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
1097b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       }
1098b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1099b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       status = U_ZERO_ERROR;
1100b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       }
1101b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1102b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       // then, make sure that they pass with a lenient parse
1103b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       nFormat->setLenient(TRUE);
1104b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
1105b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       UnicodeString testCase = ctou(strictFailureTestCases[t]);
1106b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1107b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       nFormat->parse(testCase, n, status);
1108b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1109b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1110b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1111b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	            	n.getLong() != 1000) {
1112b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		       errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
1113b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho		       status = U_ZERO_ERROR;
1114b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho	       }
1115b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       }
1116b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1117b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       delete nFormat;
1118b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   }
1119b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho}
1120b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1121b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho// -------------------------------------
1122b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
1123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test proper rounding by the format method.
1125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
1127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::TestRounding487(void)
1128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    NumberFormat *nf = NumberFormat::createInstance(status);
1131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(status)) {
1132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dataerrln("Error calling NumberFormat::createInstance()");
1133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    roundingTest(*nf, 0.00159999, 4, "0.0016");
1137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    roundingTest(*nf, 0.00995, 4, "0.01");
1138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    roundingTest(*nf, 12.3995, 3, "12.4");
1140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    roundingTest(*nf, 12.4999, 0, "12");
1142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    roundingTest(*nf, - 19.5, 0, "-20");
1143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete nf;
1144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + (int32_t)status);
1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the functioning of the secondary grouping value.
1149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestSecondaryGrouping(void) {
1151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), status);
1153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols ct");
1154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat f("#,##,###", US, status);
1156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormat ct");
1157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(f, (int32_t)123456789L, "12,34,56,789");
1159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(f, "#,##,###");
1160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    f.applyPattern("#,###", status);
1161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "applyPattern");
1162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    f.setSecondaryGroupingSize(4);
1164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(f, (int32_t)123456789L, "12,3456,789");
1165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(f, "#,####,###");
1166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    NumberFormat *g = NumberFormat::createInstance(Locale("hi", "IN"), status);
116727f654740f2a26ad62a5c155af9199af9e69b889claireho    CHECK_DATA(status, "createInstance(hi_IN)");
1168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString out;
1170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t l = (int32_t)1876543210L;
1171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    g->format(l, out);
1172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete g;
1173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // expect "1,87,65,43,210", but with Hindi digits
1174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //         01234567890123
1175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UBool ok = TRUE;
1176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (out.length() != 14) {
1177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        ok = FALSE;
1178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
1179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (int32_t i=0; i<out.length(); ++i) {
1180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            UBool expectGroup = FALSE;
1181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            switch (i) {
1182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case 1:
1183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case 4:
1184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case 7:
1185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case 10:
1186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                expectGroup = TRUE;
1187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // Later -- fix this to get the actual grouping
1190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // character from the resource bundle.
1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            UBool isGroup = (out.charAt(i) == 0x002C);
1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (isGroup != expectGroup) {
1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                ok = FALSE;
1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!ok) {
1199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln((UnicodeString)"FAIL  Expected " + l +
1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              " x hi_IN -> \"1,87,65,43,210\" (with Hindi digits), got \"" +
1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              escape(out) + "\"");
1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln((UnicodeString)"Ok    " + l +
1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              " x hi_IN -> \"" +
1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              escape(out) + "\"");
1206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestWhiteSpaceParsing(void) {
1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), ec);
1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt("a  b#0c  ", US, ec);
1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
12146d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        errcheckln(ec, "FAIL: Constructor - %s", u_errorName(ec));
1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t n = 1234;
1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(fmt, "a b1234c ", n);
1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(fmt, "a   b1234c   ", n);
1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test currencies whose display name is a ChoiceFormat.
1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestComplexCurrency() {
122650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1227b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    UErrorCode ec = U_ZERO_ERROR;
1228b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    Locale loc("kn", "IN", "");
1229b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    NumberFormat* fmt = NumberFormat::createCurrencyInstance(loc, ec);
1230b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    if (U_SUCCESS(ec)) {
1231b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect2(*fmt, 1.0, CharsToUnicodeString("Re.\\u00A01.00"));
1232b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        Use .00392625 because that's 2^-8.  Any value less than 0.005 is fine.
1233b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect(*fmt, 1.00390625, CharsToUnicodeString("Re.\\u00A01.00")); // tricky
1234b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect2(*fmt, 12345678.0, CharsToUnicodeString("Rs.\\u00A01,23,45,678.00"));
1235b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect2(*fmt, 0.5, CharsToUnicodeString("Rs.\\u00A00.50"));
1236b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect2(*fmt, -1.0, CharsToUnicodeString("-Re.\\u00A01.00"));
1237b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        expect2(*fmt, -10.0, CharsToUnicodeString("-Rs.\\u00A010.00"));
1238b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    } else {
1239b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//        errln("FAIL: getCurrencyInstance(kn_IN)");
1240b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    }
1241b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//    delete fmt;
1242b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
124450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// -------------------------------------
124650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid
1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNumberFormatTest::roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected)
1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    nf.setMaximumFractionDigits(maxFractionDigits);
1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString out; nf.format(x, out);
1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    logln((UnicodeString)"" + x + " formats with " + maxFractionDigits + " fractional digits to " + out);
1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(out==expected)) errln((UnicodeString)"FAIL: Expected " + expected);
1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Upgrade to alphaWorks
1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestExponent(void) {
1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), status);
1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols constructor");
1263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt1(UnicodeString("0.###E0"), US, status);
1264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormat(0.###E0)");
1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt2(UnicodeString("0.###E+0"), US, status);
1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormat(0.###E+0)");
1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t n = 1234;
1268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(fmt1, n, "1.234E3");
1269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(fmt2, n, "1.234E+3");
1270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(fmt1, "1.234E+3", n); // Either format should parse "E+3"
1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Upgrade to alphaWorks
1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestScientific(void) {
1277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), status);
1279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols constructor");
1280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test pattern round-trip
1282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* PAT[] = { "#E0", "0.####E0", "00.000E00", "##0.####E000",
1283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          "0.###E0;[0.###E0]" };
1284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t PAT_length = (int32_t)(sizeof(PAT) / sizeof(PAT[0]));
1285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t DIGITS[] = {
1286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // min int, max int, min frac, max frac
1287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0, 1, 0, 0, // "#E0"
1288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        1, 1, 0, 4, // "0.####E0"
1289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        2, 2, 3, 3, // "00.000E00"
1290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        1, 3, 0, 4, // "##0.####E000"
1291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        1, 1, 0, 3, // "0.###E0;[0.###E0]"
1292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
1293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t i=0; i<PAT_length; ++i) {
1294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UnicodeString pat(PAT[i]);
1295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        DecimalFormat df(pat, US, status);
1296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        CHECK(status, "DecimalFormat constructor");
1297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UnicodeString pat2;
1298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        df.toPattern(pat2);
1299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (pat == pat2) {
1300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            logln(UnicodeString("Ok   Pattern rt \"") +
1301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat + "\" -> \"" +
1302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat2 + "\"");
1303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
1304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(UnicodeString("FAIL Pattern rt \"") +
1305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat + "\" -> \"" +
1306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat2 + "\"");
1307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // Make sure digit counts match what we expect
1309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (df.getMinimumIntegerDigits() != DIGITS[4*i] ||
1310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            df.getMaximumIntegerDigits() != DIGITS[4*i+1] ||
1311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            df.getMinimumFractionDigits() != DIGITS[4*i+2] ||
1312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            df.getMaximumFractionDigits() != DIGITS[4*i+3]) {
1313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln(UnicodeString("FAIL \"" + pat +
1314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                "\" min/max int; min/max frac = ") +
1315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  df.getMinimumIntegerDigits() + "/" +
1316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  df.getMaximumIntegerDigits() + ";" +
1317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  df.getMinimumFractionDigits() + "/" +
1318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  df.getMaximumFractionDigits() + ", expect " +
1319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  DIGITS[4*i] + "/" +
1320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  DIGITS[4*i+1] + ";" +
1321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  DIGITS[4*i+2] + "/" +
1322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  DIGITS[4*i+3]);
1323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test the constructor for default locale. We have to
132850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    // manually set the default locale, as there is no
132950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    // guarantee that the default locale has the same
1330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // scientific format.
1331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale def = Locale::getDefault();
1332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale::setDefault(Locale::getUS(), status);
1333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(NumberFormat::createScientificInstance(status),
1334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.678901,
1335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "1.2345678901E4", status);
1336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale::setDefault(def, status);
1337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("#E0", US, status),
1339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.0,
1340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "1.2345E4", status);
1341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("0E0", US, status),
1342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.0,
1343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "1E4", status);
1344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(NumberFormat::createScientificInstance(Locale::getUS(), status),
1345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.678901,
1346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "1.2345678901E4", status);
1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.###E0", US, status),
1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.0,
1349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "12.34E3", status);
1350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.###E0", US, status),
1351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.00001,
1352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "12.35E3", status);
1353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.####E0", US, status),
1354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 12345,
1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "12.345E3", status);
1356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(NumberFormat::createScientificInstance(Locale::getFrance(), status),
1357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12345.678901,
1358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "1,2345678901E4", status);
1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.####E0", US, status),
1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           789.12345e-9,
1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "789.12E-9", status);
1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.####E0", US, status),
1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           780.e-9,
1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           "780E-9", status);
1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat(".###E0", US, status),
1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           45678.0,
1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           ".457E5", status);
1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(".###E0", US, status),
1369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 0,
1370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           ".0E0", status);
1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*
1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat[] { new DecimalFormat("#E0", US),
1373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                 new DecimalFormat("##E0", US),
1374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                 new DecimalFormat("####E0", US),
137550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                                 new DecimalFormat("0E0", US),
137650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                                 new DecimalFormat("00E0", US),
137750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                                 new DecimalFormat("000E0", US),
1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                               },
1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           new Long(45678000),
1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           new String[] { "4.5678E7",
1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          "45.678E6",
1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          "4567.8E4",
1383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          "5E7",
138450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                          "46E6",
1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          "457E5",
1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        }
1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           );
1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ! Unroll this test into individual tests below...
1390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    */
1392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("#E0", US, status),
1393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "4.5678E7", status);
1394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##E0", US, status),
1395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "45.678E6", status);
1396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("####E0", US, status),
1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "4567.8E4", status);
1398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("0E0", US, status),
1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "5E7", status);
1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("00E0", US, status),
1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "46E6", status);
1402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("000E0", US, status),
1403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 45678000, "457E5", status);
1404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*
1405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("###E0", US, status),
1406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           new Object[] { new Double(0.0000123), "12.3E-6",
1407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(0.000123), "123E-6",
1408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(0.00123), "1.23E-3",
1409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(0.0123), "12.3E-3",
1410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(0.123), "123E-3",
1411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(1.23), "1.23E0",
1412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(12.3), "12.3E0",
1413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(123), "123E0",
1414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Double(1230), "1.23E3",
1415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                         });
1416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ! Unroll this test into individual tests below...
1418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    */
1420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.0000123, "12.3E-6", status);
1422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.000123, "123E-6", status);
1424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.00123, "1.23E-3", status);
1426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.0123, "12.3E-3", status);
1428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.123, "123E-3", status);
1430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.23, "1.23E0", status);
1432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           12.3, "12.3E0", status);
1434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           123.0, "123E0", status);
1436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("###E0", US, status),
1437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1230.0, "1.23E3", status);
1438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*
1439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("0.#E+00", US, status),
1440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           new Object[] { new Double(0.00012), "1.2E-04",
1441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                          new Long(12000),     "1.2E+04",
1442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                         });
1443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ! Unroll this test into individual tests below...
1445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    !
1446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    */
1447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("0.#E+00", US, status),
1448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           0.00012, "1.2E-04", status);
1449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("0.#E+00", US, status),
1450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           (int32_t) 12000, "1.2E+04", status);
1451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Upgrade to alphaWorks
1455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestPad(void) {
1457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), status);
1459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols constructor");
1460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("*^##.##", US, status),
1462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "^^^^0", status);
1463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("*^##.##", US, status),
1464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1.3, "^-1.3", status);
1465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
1466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "0.0E0______ g-m/s^2", status);
1467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
1468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.0/3, "333.333E-3_ g-m/s^2", status);
1469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
1470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "0.0______ g-m/s^2", status);
1471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
1472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.0/3, "0.33333__ g-m/s^2", status);
1473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test padding before a sign
1475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *formatStr = "*x#,###,###,##0.0#;*x(###,###,##0.0#)";
1476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-10),  "xxxxxxxxxx(10.0)", status);
1478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-1000),"xxxxxxx(1,000.0)", status);
1480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-1000000),"xxx(1,000,000.0)", status);
1482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -100.37,       "xxxxxxxx(100.37)", status);
1484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -10456.37,     "xxxxx(10,456.37)", status);
1486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1120456.37,   "xx(1,120,456.37)", status);
1488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -112045600.37, "(112,045,600.37)", status);
1490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1252045600.37,"(1,252,045,600.37)", status);
1492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(10),  "xxxxxxxxxxxx10.0", status);
1495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(1000),"xxxxxxxxx1,000.0", status);
1497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(1000000),"xxxxx1,000,000.0", status);
1499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           100.37,       "xxxxxxxxxx100.37", status);
1501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           10456.37,     "xxxxxxx10,456.37", status);
1503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1120456.37,   "xxxx1,120,456.37", status);
1505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           112045600.37, "xx112,045,600.37", status);
1507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr, US, status),
1508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           10252045600.37,"10,252,045,600.37", status);
1509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test padding between a sign and a number
1512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *formatStr2 = "#,###,###,##0.0#*x;(###,###,##0.0#*x)";
1513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-10),  "(10.0xxxxxxxxxx)", status);
1515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-1000),"(1,000.0xxxxxxx)", status);
1517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-1000000),"(1,000,000.0xxx)", status);
1519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -100.37,       "(100.37xxxxxxxx)", status);
1521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -10456.37,     "(10,456.37xxxxx)", status);
1523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1120456.37,   "(1,120,456.37xx)", status);
1525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -112045600.37, "(112,045,600.37)", status);
1527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1252045600.37,"(1,252,045,600.37)", status);
1529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(10),  "10.0xxxxxxxxxxxx", status);
1532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(1000),"1,000.0xxxxxxxxx", status);
1534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(1000000),"1,000,000.0xxxxx", status);
1536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           100.37,       "100.37xxxxxxxxxx", status);
1538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           10456.37,     "10,456.37xxxxxxx", status);
1540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1120456.37,   "1,120,456.37xxxx", status);
1542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           112045600.37, "112,045,600.37xx", status);
1544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(formatStr2, US, status),
1545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           10252045600.37,"10,252,045,600.37", status);
1546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //testing the setPadCharacter(UnicodeString) and getPadCharacterString()
1548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt("#", US, status);
1549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormat constructor");
1550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString padString("P");
1551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadCharacter(padString);
1552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "*P##.##", DecimalFormat::kPadBeforePrefix, 5, padString);
1553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadCharacter((UnicodeString)"^");
1554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, (UnicodeString)"^");
1555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //commented untill implementation is complete
1556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /*  fmt.setPadCharacter((UnicodeString)"^^^");
1557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "*^^^#", DecimalFormat::kPadBeforePrefix, 3, (UnicodeString)"^^^");
1558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    padString.remove();
1559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    padString.append((UChar)0x0061);
1560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    padString.append((UChar)0x0302);
1561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadCharacter(padString);
1562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar patternChars[]={0x002a, 0x0061, 0x0302, 0x0061, 0x0302, 0x0023, 0x0000};
1563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString pattern(patternChars);
1564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, pattern , DecimalFormat::kPadBeforePrefix, 4, padString);
1565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Upgrade to alphaWorks
1571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestPatterns2(void) {
1573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols US(Locale::getUS(), status);
1575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols constructor");
1576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt("#", US, status);
1578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormat constructor");
157950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar hat = 0x005E; /*^*/
1581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, hat);
1583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "$*^#", DecimalFormat::kPadAfterPrefix, 2, hat);
1584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "#*^", DecimalFormat::kPadBeforeSuffix, 1, hat);
1585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "#$*^", DecimalFormat::kPadAfterSuffix, 2, hat);
1586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "$*^$#", ILLEGAL);
1587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "#$*^$", ILLEGAL);
1588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "'pre'#,##0*x'post'", DecimalFormat::kPadBeforeSuffix,
1589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              12, (UChar)0x0078 /*x*/);
1590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "''#0*x", DecimalFormat::kPadBeforeSuffix,
1591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              3, (UChar)0x0078 /*x*/);
1592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPad(fmt, "'I''ll'*a###.##", DecimalFormat::kPadAfterPrefix,
1593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              10, (UChar)0x0061 /*a*/);
1594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.applyPattern("AA#,##0.00ZZ", status);
1596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "applyPattern");
1597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadCharacter(hat);
1598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(10);
1600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadPosition(DecimalFormat::kPadBeforePrefix);
1602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "*^AA#,##0.00ZZ");
1603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1604b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadPosition(DecimalFormat::kPadBeforeSuffix);
1605b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA#,##0.00*^ZZ");
1606b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1607b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadPosition(DecimalFormat::kPadAfterSuffix);
1608b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA#,##0.00ZZ*^");
1609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //            12  3456789012
1611b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString exp("AA*^#,##0.00ZZ", "");
1612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(12);
1613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setPadPosition(DecimalFormat::kPadAfterPrefix);
1614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, exp);
1615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(13);
1617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //              12  34567890123
1618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA*^##,##0.00ZZ");
1619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(14);
1621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //              12  345678901234
1622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA*^###,##0.00ZZ");
1623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(15);
1625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //              12  3456789012345
1626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA*^####,##0.00ZZ"); // This is the interesting case
1627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.setFormatWidth(16);
1629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    //              12  34567890123456
1630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expectPat(fmt, "AA*^#,###,##0.00ZZ");
1631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestSurrogateSupport(void) {
1634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols custom(Locale::getUS(), status);
1636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CHECK(status, "DecimalFormatSymbols constructor");
1637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, "decimal");
1639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kPlusSignSymbol, "plus");
1640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, " minus ");
1641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kExponentialSymbol, "exponent");
1642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString patternStr("*\\U00010000##.##", "");
1644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    patternStr = patternStr.unescape();
1645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
1646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expStr = expStr.unescape();
1647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(patternStr, custom, status),
1648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), expStr, status);
1649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("*^##.##", custom, status),
1652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "^^^^0", status);
1653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##.##", custom, status),
1655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           -1.3, " minus 1decimal3", status);
1656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
1658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "0decimal0exponent0 g-m/s^2", status);
1659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
1661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.0/3, "333decimal333exponent minus 3 g-m/s^2", status);
1662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
1664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(0), "0decimal0 g-m/s^2", status);
1665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
1667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.0/3, "0decimal33333 g-m/s^2", status);
1668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString zero((UChar32)0x10000);
167027f654740f2a26ad62a5c155af9199af9e69b889claireho    UnicodeString one((UChar32)0x10001);
167127f654740f2a26ad62a5c155af9199af9e69b889claireho    UnicodeString two((UChar32)0x10002);
167227f654740f2a26ad62a5c155af9199af9e69b889claireho    UnicodeString five((UChar32)0x10005);
1673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
167427f654740f2a26ad62a5c155af9199af9e69b889claireho    custom.setSymbol(DecimalFormatSymbols::kOneDigitSymbol, one);
167527f654740f2a26ad62a5c155af9199af9e69b889claireho    custom.setSymbol(DecimalFormatSymbols::kTwoDigitSymbol, two);
167627f654740f2a26ad62a5c155af9199af9e69b889claireho    custom.setSymbol(DecimalFormatSymbols::kFiveDigitSymbol, five);
1677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expStr = UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
1678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expStr = expStr.unescape();
1679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat("##0.000", custom, status),
1681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           1.25, expStr, status);
1682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, (UChar)0x30);
1684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "units of money");
1685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, "money separator");
1686c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    patternStr = UNICODE_STRING_SIMPLE("0.00 \\u00A4' in your bank account'");
1687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    patternStr = patternStr.unescape();
1688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expStr = UnicodeString(" minus 20money separator00 units of money in your bank account", "");
1689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(patternStr, custom, status),
1691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-20), expStr, status);
1692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    custom.setSymbol(DecimalFormatSymbols::kPercentSymbol, "percent");
1694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    patternStr = "'You''ve lost ' -0.00 %' of your money today'";
1695b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    patternStr = patternStr.unescape();
1696b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expStr = UnicodeString(" minus You've lost   minus 2000decimal00 percent of your money today", "");
1697b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1698b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect2(new DecimalFormat(patternStr, custom, status),
1699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           int32_t(-20), expStr, status);
1700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCurrencyPatterns(void) {
1703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i, locCount;
1704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const Locale* locs = NumberFormat::getAvailableLocales(locCount);
1705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i=0; i<locCount; ++i) {
1706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode ec = U_ZERO_ERROR;
1707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        NumberFormat* nf = NumberFormat::createCurrencyInstance(locs[i], ec);
1708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_FAILURE(ec)) {
1709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errln("FAIL: Can't create NumberFormat(%s) - %s", locs[i].getName(), u_errorName(ec));
1710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
1711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // Make sure currency formats do not have a variable number
1712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // of fraction digits
1713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            int32_t min = nf->getMinimumFractionDigits();
1714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            int32_t max = nf->getMaximumFractionDigits();
1715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (min != max) {
1716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                UnicodeString a, b;
1717b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                nf->format(1.0, a);
1718b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                nf->format(1.125, b);
1719b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                errln((UnicodeString)"FAIL: " + locs[i].getName() +
1720b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      " min fraction digits != max fraction digits; "
1721b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      "x 1.0 => " + escape(a) +
1722b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      "; x 1.125 => " + escape(b));
1723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // Make sure EURO currency formats have exactly 2 fraction digits
172627f654740f2a26ad62a5c155af9199af9e69b889claireho            DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
172727f654740f2a26ad62a5c155af9199af9e69b889claireho            if (df != NULL) {
1728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (u_strcmp(EUR, df->getCurrency()) == 0) {
1729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (min != 2 || max != 2) {
1730b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        UnicodeString a;
1731b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        nf->format(1.0, a);
1732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        errln((UnicodeString)"FAIL: " + locs[i].getName() +
1733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                              " is a EURO format but it does not have 2 fraction digits; "
1734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                              "x 1.0 => " +
1735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                              escape(a));
1736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    }
1737b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
1738b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1739b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1740b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete nf;
1741b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1742b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1743b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1744b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestRegCurrency(void) {
1745b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if !UCONFIG_NO_SERVICE
1746b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1747b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar USD[4];
1748b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US", USD, 4, &status);
1749b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar YEN[4];
1750b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("ja_JP", YEN, 4, &status);
1751b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar TMP[4];
1752b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar QQQ[] = {0x51, 0x51, 0x51, 0};
1753b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(U_FAILURE(status)) {
17546d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        errcheckln(status, "Unable to get currency for locale, error %s", u_errorName(status));
1755b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
175750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1758b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UCurrRegistryKey enkey = ucurr_register(YEN, "en_US", &status);
1759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UCurrRegistryKey enUSEUROkey = ucurr_register(QQQ, "en_US_EURO", &status);
176050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US", TMP, 4, &status);
1762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(YEN, TMP) != 0) {
1763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: didn't return YEN registered for en_US");
1764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(QQQ, TMP) != 0) {
1768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: didn't return QQQ for en_US_EURO");
1769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
177050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t fallbackLen = ucurr_forLocale("en_XX_BAR", TMP, 4, &status);
1772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (fallbackLen) {
1773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: tried to fallback en_XX_BAR");
1774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR; // reset
177650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!ucurr_unregister(enkey, &status)) {
1778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: couldn't unregister enkey");
1779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
178150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    ucurr_forLocale("en_US", TMP, 4, &status);
1782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(USD, TMP) != 0) {
1783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: didn't return USD for en_US after unregister of en_US");
1784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR; // reset
178650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(QQQ, TMP) != 0) {
1789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: didn't return QQQ for en_US_EURO after unregister of en_US");
1790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
179150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US_BLAH", TMP, 4, &status);
1793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(USD, TMP) != 0) {
1794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: could not find USD for en_US_BLAH after unregister of en");
1795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR; // reset
179750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!ucurr_unregister(enUSEUROkey, &status)) {
1799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: couldn't unregister enUSEUROkey");
1800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
180150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (u_strcmp(EUR, TMP) != 0) {
1804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("FAIL: didn't return EUR for en_US_EURO after unregister of en_US_EURO");
1805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR; // reset
1807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCurrencyNames(void) {
1811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Do a basic check of getName()
1812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // USD { "US$", "US Dollar"            } // 04/04/1792-
1813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
1814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar USD[] = {0x55, 0x53, 0x44, 0}; /*USD*/
1815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar USX[] = {0x55, 0x53, 0x58, 0}; /*USX*/
1816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar CAD[] = {0x43, 0x41, 0x44, 0}; /*CAD*/
1817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar ITL[] = {0x49, 0x54, 0x4C, 0}; /*ITL*/
1818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UBool isChoiceFormat;
1819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t len;
18206d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru    const UBool possibleDataError = TRUE;
1821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Warning: HARD-CODED LOCALE DATA in this test.  If it fails, CHECK
182250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    // THE LOCALE DATA before diving into the code.
1823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("USD.getName(SYMBOL_NAME)",
1824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString("$"),
1825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(USD, "en",
1826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_SYMBOL_NAME,
18276d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18286d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("USD.getName(LONG_NAME)",
1830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString("US Dollar"),
1831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(USD, "en",
1832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_LONG_NAME,
18336d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18346d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("CAD.getName(SYMBOL_NAME)",
1836c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru                 UnicodeString("CA$"),
1837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(CAD, "en",
1838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_SYMBOL_NAME,
18396d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18406d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("CAD.getName(SYMBOL_NAME)",
1842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString("$"),
1843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(CAD, "en_CA",
1844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_SYMBOL_NAME,
18456d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18466d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1847103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    assertEquals("USD.getName(SYMBOL_NAME) in en_AU",
1848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString("US$"),
1849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(USD, "en_AU",
1850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_SYMBOL_NAME,
18516d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18526d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("CAD.getName(SYMBOL_NAME)",
1854c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru                 UnicodeString("CA$"),
1855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(CAD, "en_AU",
1856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_SYMBOL_NAME,
18576d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18586d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("USX.getName(LONG_NAME)",
1860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString("USX"),
1861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 UnicodeString(ucurr_getName(USX, "en_US",
1862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                             UCURR_LONG_NAME,
18636d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             &isChoiceFormat, &len, &ec)),
18646d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                                             possibleDataError);
1865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertSuccess("ucurr_getName", ec);
186650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ec = U_ZERO_ERROR;
1868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test that a default or fallback warning is being returned. JB 4239.
1870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_getName(CAD, "es_ES", UCURR_LONG_NAME, &isChoiceFormat,
1871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            &len, &ec);
187250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    assertTrue("ucurr_getName (es_ES fallback)",
18736d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                    U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
1874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1875b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_getName(CAD, "zh_TW", UCURR_LONG_NAME, &isChoiceFormat,
1876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            &len, &ec);
187750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    assertTrue("ucurr_getName (zh_TW fallback)",
18786d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                    U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
1879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_getName(CAD, "en_US", UCURR_LONG_NAME, &isChoiceFormat,
1881b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            &len, &ec);
188250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    assertTrue("ucurr_getName (en_US default)",
188350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                    U_USING_DEFAULT_WARNING == ec || U_USING_FALLBACK_WARNING == ec, TRUE);
188450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1885b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    ucurr_getName(CAD, "ti", UCURR_LONG_NAME, &isChoiceFormat,
1886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            &len, &ec);
1887b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    assertTrue("ucurr_getName (ti default)",
1888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    U_USING_DEFAULT_WARNING == ec, TRUE);
188950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test that a default warning is being returned when falling back to root. JB 4536.
1891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ucurr_getName(ITL, "cy", UCURR_LONG_NAME, &isChoiceFormat,
1892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            &len, &ec);
189350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    assertTrue("ucurr_getName (cy default to root)",
1894b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    U_USING_DEFAULT_WARNING == ec, TRUE);
189550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // TODO add more tests later
1897b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1899b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCurrencyUnit(void){
1900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
1901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
1902fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    static const UChar BAD[] = {63, 63, 63, 0}; /*???*/
1903fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    static const UChar BAD2[] = {63, 63, 65, 0}; /*???*/
1904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyUnit cu(USD, ec);
1905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertSuccess("CurrencyUnit", ec);
1906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1907b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const UChar * r = cu.getISOCurrency(); // who is the buffer owner ?
1908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("getISOCurrency()", USD, r);
1909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1910b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyUnit cu2(cu);
1911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(cu2 == cu)){
1912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("CurrencyUnit copy constructed object should be same");
1913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1914b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1915b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone();
1916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(*cu3 == cu)){
1917b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("CurrencyUnit cloned object should be same");
1918b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1919fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    CurrencyUnit bad(BAD, ec);
1920fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    assertSuccess("CurrencyUnit", ec);
1921fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    if (cu.getIndex() == bad.getIndex()) {
1922fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius        errln("Indexes of different currencies should differ.");
1923fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    }
1924fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    CurrencyUnit bad2(BAD2, ec);
1925fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    assertSuccess("CurrencyUnit", ec);
1926fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    if (bad2.getIndex() != bad.getIndex()) {
1927fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius        errln("Indexes of unrecognized currencies should be the same.");
1928fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    }
1929fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    if (bad == bad2) {
1930fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius        errln("Different unrecognized currencies should not be equal.");
1931fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    }
1932fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    bad = bad2;
1933fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    if (bad != bad2) {
1934fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius        errln("Currency unit assignment should be the same.");
1935fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    }
1936b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete cu3;
1937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCurrencyAmount(void){
1940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
1941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
1942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyAmount ca(9, USD, ec);
1943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertSuccess("CurrencyAmount", ec);
1944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyAmount ca2(ca);
1946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(ca2 == ca)){
1947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("CurrencyAmount copy constructed object should be same");
1948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ca2=ca;
1951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(ca2 == ca)){
1952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("CurrencyAmount assigned object should be same");
1953b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
195450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
1955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CurrencyAmount *ca3 = (CurrencyAmount *)ca.clone();
1956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!(*ca3 == ca)){
1957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("CurrencyAmount cloned object should be same");
1958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    delete ca3;
1960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestSymbolsWithBadLocale(void) {
1963b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale locDefault;
1964103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    static const char *badLocales[] = {
1965103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        // length < ULOC_FULLNAME_CAPACITY
1966103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME",
1967103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius
1968103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        // length > ULOC_FULLNAME_CAPACITY
1969103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        "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"
1970103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    }; // expect U_USING_DEFAULT_WARNING for both
1971103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius
1972103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    unsigned int i;
1973103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    for (i = 0; i < sizeof(badLocales) / sizeof(char*); i++) {
1974103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        const char *localeName = badLocales[i];
1975103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        Locale locBad(localeName);
1976103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        UErrorCode status = U_ZERO_ERROR;
1977103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        UnicodeString intlCurrencySymbol((UChar)0xa4);
1978b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1979103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        intlCurrencySymbol.append((UChar)0xa4);
1980b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1981103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        logln("Current locale is %s", Locale::getDefault().getName());
1982103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        Locale::setDefault(locBad, status);
1983103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        logln("Current locale is %s", Locale::getDefault().getName());
1984103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        DecimalFormatSymbols mySymbols(status);
1985103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        if (status != U_USING_DEFAULT_WARNING) {
1986103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            errln("DecimalFormatSymbols should return U_USING_DEFAULT_WARNING.");
1987103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        }
1988103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        if (strcmp(mySymbols.getLocale().getName(), locBad.getName()) != 0) {
1989103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            errln("DecimalFormatSymbols does not have the right locale.", locBad.getName());
1990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1991103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        int symbolEnum = (int)DecimalFormatSymbols::kDecimalSeparatorSymbol;
1992103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        for (; symbolEnum < (int)DecimalFormatSymbols::kFormatSymbolCount; symbolEnum++) {
1993103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            UnicodeString symbolString = mySymbols.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbolEnum);
1994103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            logln(UnicodeString("DecimalFormatSymbols[") + symbolEnum + UnicodeString("] = ") + prettify(symbolString));
1995103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            if (symbolString.length() == 0
1996103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                && symbolEnum != (int)DecimalFormatSymbols::kGroupingSeparatorSymbol
1997103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                && symbolEnum != (int)DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol)
1998103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            {
1999103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum);
2000103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            }
2001103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        }
2002103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius
2003103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        status = U_ZERO_ERROR;
2004103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        Locale::setDefault(locDefault, status);
2005103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        logln("Current locale is %s", Locale::getDefault().getName());
2006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2007b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2008b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
2010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Check that adoptDecimalFormatSymbols and setDecimalFormatSymbols
2011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * behave the same, except for memory ownership semantics. (No
2012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * version of this test on Java, since Java has only one method.)
2013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
2014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestAdoptDecimalFormatSymbols(void) {
2015b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
2016b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
20186d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        errcheckln(ec, "Fail: DecimalFormatSymbols constructor - %s", u_errorName(ec));
2019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete sym;
2020b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString pat(" #,##0.00");
2023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pat.insert(0, (UChar)0x00A4);
2024b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt(pat, sym, ec);
2025b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
2026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("Fail: DecimalFormat constructor");
2027b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2028b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2029b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2030b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString str;
2031b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.format(2350.75, str);
2032b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (str == "$ 2,350.75") {
2033b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln(str);
2034b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
203527f654740f2a26ad62a5c155af9199af9e69b889claireho        dataerrln("Fail: " + str + ", expected $ 2,350.75");
2036b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2037b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2038b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2039b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
2040b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("Fail: DecimalFormatSymbols constructor");
2041b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete sym;
2042b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2044b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    sym->setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
2045b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.adoptDecimalFormatSymbols(sym);
2046b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2047b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    str.truncate(0);
2048b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.format(2350.75, str);
2049b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (str == "Q 2,350.75") {
2050b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln(str);
2051b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
205227f654740f2a26ad62a5c155af9199af9e69b889claireho        dataerrln("Fail: adoptDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
2053b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2054b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2055b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2056b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
2057b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("Fail: DecimalFormatSymbols constructor");
2058b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        delete sym;
2059b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2060b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2061b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt2(pat, sym, ec);
2062b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
2063b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("Fail: DecimalFormat constructor");
2064b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2065b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
206650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
2067b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols sym2(Locale::getUS(), ec);
2068b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
2069b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        errln("Fail: DecimalFormatSymbols constructor");
2070b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2071b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2072b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    sym2.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
2073b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt2.setDecimalFormatSymbols(sym2);
2074b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2075b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    str.truncate(0);
2076b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt2.format(2350.75, str);
2077b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (str == "Q 2,350.75") {
2078b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        logln(str);
2079b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
208027f654740f2a26ad62a5c155af9199af9e69b889claireho        dataerrln("Fail: setDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
2081b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2082b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2083b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2084b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestPerMill() {
2085b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
2086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString str;
2087b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt(ctou("###.###\\u2030"), ec);
2088b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!assertSuccess("DecimalFormat ct", ec)) return;
2089b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("0.4857 x ###.###\\u2030",
2090b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 ctou("485.7\\u2030"), fmt.format(0.4857, str));
209150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
2092b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormatSymbols sym(Locale::getUS(), ec);
2093b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, ctou("m"));
2094b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat fmt2("", sym, ec);
2095b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt2.applyLocalizedPattern("###.###m", ec);
2096b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!assertSuccess("setup", ec)) return;
2097b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    str.truncate(0);
2098b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    assertEquals("0.4857 x ###.###m",
2099b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                 "485.7m", fmt2.format(0.4857, str));
2100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
2103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Generic test for patterns that should be legal/illegal.
2104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
2105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestIllegalPatterns() {
2106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Test cases:
2107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Prefix with "-:" for illegal patterns
2108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    // Prefix with "+:" for legal patterns
2109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* DATA[] = {
2110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        // Unquoted special characters in the suffix are illegal
2111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "-:000.000|###",
2112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "+:000.000'|###'",
2113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0
2114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
2115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t i=0; DATA[i]; ++i) {
2116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* pat=DATA[i];
2117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UBool valid = (*pat) == '+';
2118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        pat += 2;
2119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode ec = U_ZERO_ERROR;
2120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        DecimalFormat fmt(pat, ec); // locale doesn't matter here
2121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_SUCCESS(ec) == valid) {
2122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            logln("Ok: pattern \"%s\": %s",
2123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat, u_errorName(ec));
2124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
21256d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            errcheckln(ec, "FAIL: pattern \"%s\" should have %s; got %s",
2126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  pat, (valid?"succeeded":"failed"),
2127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  u_errorName(ec));
2128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru//----------------------------------------------------------------------
2133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const char* KEYWORDS[] = {
2135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*0*/ "ref=", // <reference pattern to parse numbers>
2136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*1*/ "loc=", // <locale for formats>
2137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*2*/ "f:",   // <pattern or '-'> <number> <exp. string>
2138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*3*/ "fp:",  // <pattern or '-'> <number> <exp. string> <exp. number>
2139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*4*/ "rt:",  // <pattern or '-'> <(exp.) number> <(exp.) string>
2140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*5*/ "p:",   // <pattern or '-'> <string> <exp. number>
2141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*6*/ "perr:", // <pattern or '-'> <invalid string>
2142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*7*/ "pat:", // <pattern or '-'> <exp. toPattern or '-' or 'err'>
2143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*8*/ "fpc:", // <pattern or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    0
2145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
2146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
2148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Return an integer representing the next token from this
2149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * iterator.  The integer will be an index into the given list, or
2150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * -1 if there are no more tokens, or -2 if the token is not on
2151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the list.
2152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
2153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t keywordIndex(const UnicodeString& tok) {
2154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (int32_t i=0; KEYWORDS[i]!=0; ++i) {
2155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (tok==KEYWORDS[i]) {
2156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return i;
2157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    return -1;
2160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
2163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Parse a CurrencyAmount using the given NumberFormat, with
2164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the 'delim' character separating the number and the currency.
2165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
2166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void parseCurrencyAmount(const UnicodeString& str,
2167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                const NumberFormat& fmt,
2168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                UChar delim,
2169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                Formattable& result,
2170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                UErrorCode& ec) {
2171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString num, cur;
2172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i = str.indexOf(delim);
2173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    str.extractBetween(0, i, num);
2174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    str.extractBetween(i+1, INT32_MAX, cur);
2175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Formattable n;
2176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    fmt.parse(num, n, ec);
2177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    result.adoptObject(new CurrencyAmount(n, cur.getTerminatedBuffer(), ec));
2178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid NumberFormatTest::TestCases() {
2181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode ec = U_ZERO_ERROR;
2182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TextFile reader("NumberFormatTestCases.txt", "UTF8", ec);
2183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(ec)) {
21846d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        dataerrln("Couldn't open NumberFormatTestCases.txt");
2185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
2186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TokenIterator tokens(&reader);
2188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Locale loc("en", "US", "");
2190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DecimalFormat *ref = 0, *fmt = 0;
2191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    MeasureFormat *mfmt = 0;
2192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UnicodeString pat, tok, mloc, str, out, where, currAmt;
2193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    Formattable n;
2194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (;;) {
2196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        ec = U_ZERO_ERROR;
2197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (!tokens.next(tok, ec)) {
2198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            break;
2199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        where = UnicodeString("(") + tokens.getLineNumber() + ") ";
2201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t cmd = keywordIndex(tok);
2202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        switch (cmd) {
2203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 0:
2204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // ref= <reference pattern>
2205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (!tokens.next(tok, ec)) goto error;
2206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            delete ref;
2207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ref = new DecimalFormat(tok,
2208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      new DecimalFormatSymbols(Locale::getUS(), ec), ec);
2209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (U_FAILURE(ec)) {
2210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                dataerrln("Error constructing DecimalFormat");
2211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                goto error;
2212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            break;
2214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 1:
2215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            // loc= <locale>
2216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (!tokens.next(tok, ec)) goto error;
221727f654740f2a26ad62a5c155af9199af9e69b889claireho            loc = Locale::createFromName(CharString().appendInvariantChars(tok, ec).data());
2218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            break;
2219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 2: // f:
2220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 3: // fp:
2221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 4: // rt:
2222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        case 5: // p:
2223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (!tokens.next(tok, ec)) goto error;
2224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (tok != "-") {
2225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                pat = tok;
2226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                delete fmt;
2227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                fmt = new DecimalFormat(pat, new DecimalFormatSymbols(loc, ec), ec);
2228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (U_FAILURE(ec)) {
2229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    errln("FAIL: " + where + "Pattern \"" + pat + "\": " + u_errorName(ec));
2230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    ec = U_ZERO_ERROR;
2231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (!tokens.next(tok, ec)) goto error;
2232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (!tokens.next(tok, ec)) goto error;
2233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (cmd == 3) {
2234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        if (!tokens.next(tok, ec)) goto error;
2235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    }
2236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    continue;
2237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
2238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (cmd == 2 || cmd == 3 || cmd == 4) {
2240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // f: <pattern or '-'> <number> <exp. string>
2241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // fp: <pattern or '-'> <number> <exp. string> <exp. number>
2242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                // rt: <pattern or '-'> <number> <string>
2243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                UnicodeString num;
2244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (!tokens.next(num, ec)) goto error;
2245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (!tokens.next(str, ec)) goto error;
2246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                ref->parse(num, n, ec);
2247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                assertSuccess("parse", ec);
2248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                assertEquals(where + "\"" + pat + "\".format(" + num + ")",
2249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                             str, fmt->format(n, out.remove(), ec));
2250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                assertSuccess("format", ec);
2251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (cmd == 3) { // fp:
2252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if (!tokens.next(num, ec)) goto error;
2253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    ref->parse(num, n, ec);
2254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    assertSuccess("parse", ec);
2255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
2256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (cmd != 2) { // != f:
2257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    Formattable m;
2258