2010-01-22 22:44:29 +00:00
|
|
|
/************************************************************************
|
2008-09-26 21:25:04 +00:00
|
|
|
* COPYRIGHT:
|
2013-04-02 22:01:33 +00:00
|
|
|
* Copyright (c) 1997-2013, International Business Machines Corporation
|
2010-01-22 22:44:29 +00:00
|
|
|
* and others. All Rights Reserved.
|
|
|
|
************************************************************************/
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#ifndef _NUMBERFORMATTEST_
|
|
|
|
#define _NUMBERFORMATTEST_
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
#include "unicode/numfmt.h"
|
2008-09-26 21:25:04 +00:00
|
|
|
#include "unicode/decimfmt.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "caltztst.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs various in-depth test on NumberFormat
|
|
|
|
**/
|
|
|
|
class NumberFormatTest: public CalendarTimeZoneTest {
|
2003-04-21 19:16:38 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// IntlTest override
|
2000-08-14 21:42:36 +00:00
|
|
|
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
|
2003-04-21 19:16:38 +00:00
|
|
|
public:
|
|
|
|
|
2001-11-28 22:28:16 +00:00
|
|
|
/**
|
|
|
|
* Test APIs (to increase code coverage)
|
2008-09-26 21:25:04 +00:00
|
|
|
*/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestAPI(void);
|
2005-07-14 23:24:38 +00:00
|
|
|
|
|
|
|
void TestCoverage(void);
|
|
|
|
|
2001-11-28 22:28:16 +00:00
|
|
|
/**
|
1999-08-16 21:50:52 +00:00
|
|
|
* Test the handling of quotes
|
|
|
|
**/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestQuotes(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test patterns with exponential representation
|
|
|
|
**/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestExponential(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test handling of patterns with currency symbols
|
|
|
|
**/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestCurrencySign(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test different format patterns
|
|
|
|
**/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestPatterns(void);
|
2002-11-22 18:17:42 +00:00
|
|
|
/**
|
|
|
|
* API coverage for DigitList
|
|
|
|
**/
|
2007-06-24 03:19:59 +00:00
|
|
|
//void TestDigitList(void);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test localized currency patterns.
|
|
|
|
*/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestCurrency(void);
|
2002-05-13 19:37:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the Currency object handling, new as of ICU 2.2.
|
|
|
|
*/
|
|
|
|
void TestCurrencyObject(void);
|
|
|
|
|
2002-07-31 19:17:34 +00:00
|
|
|
void TestCurrencyPatterns(void);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Do rudimentary testing of parsing.
|
|
|
|
*/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestParse(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test proper rounding by the format method.
|
|
|
|
*/
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestRounding487(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// New tests for alphaWorks upgrade
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestExponent(void);
|
|
|
|
|
|
|
|
void TestScientific(void);
|
2000-06-07 00:17:23 +00:00
|
|
|
|
2003-10-29 00:20:05 +00:00
|
|
|
void TestScientific2(void);
|
|
|
|
|
|
|
|
void TestScientificGrouping(void);
|
|
|
|
|
2003-10-31 22:47:25 +00:00
|
|
|
void TestInt64(void);
|
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestSurrogateSupport(void);
|
2001-09-20 21:34:19 +00:00
|
|
|
|
2000-06-07 00:17:23 +00:00
|
|
|
/**
|
|
|
|
* Test the functioning of the secondary grouping value.
|
|
|
|
*/
|
|
|
|
void TestSecondaryGrouping(void);
|
2003-04-04 20:55:10 +00:00
|
|
|
|
|
|
|
void TestWhiteSpaceParsing(void);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2003-04-21 22:48:41 +00:00
|
|
|
void TestComplexCurrency(void);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
void TestPad(void);
|
|
|
|
void TestPatterns2(void);
|
|
|
|
|
2003-04-25 18:02:09 +00:00
|
|
|
/**
|
|
|
|
* Test currency registration.
|
|
|
|
*/
|
|
|
|
void TestRegCurrency(void);
|
|
|
|
|
2004-06-04 22:33:20 +00:00
|
|
|
void TestCurrencyNames(void);
|
|
|
|
|
2005-06-30 22:45:24 +00:00
|
|
|
void TestCurrencyAmount(void);
|
|
|
|
|
|
|
|
void TestCurrencyUnit(void);
|
|
|
|
|
2003-05-08 23:17:49 +00:00
|
|
|
void TestSymbolsWithBadLocale(void);
|
|
|
|
|
2003-05-26 20:21:40 +00:00
|
|
|
void TestAdoptDecimalFormatSymbols(void);
|
|
|
|
|
2004-02-12 01:10:19 +00:00
|
|
|
void TestPerMill(void);
|
|
|
|
|
2004-02-20 19:40:31 +00:00
|
|
|
void TestIllegalPatterns(void);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
void TestCases(void);
|
|
|
|
|
2006-01-09 23:03:31 +00:00
|
|
|
void TestJB3832(void);
|
2006-01-23 23:25:00 +00:00
|
|
|
|
|
|
|
void TestHost(void);
|
2006-07-28 19:35:12 +00:00
|
|
|
|
2007-06-12 05:20:11 +00:00
|
|
|
void TestHostClone(void);
|
|
|
|
|
2006-07-28 19:35:12 +00:00
|
|
|
void TestCurrencyFormat(void);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2007-08-22 19:58:25 +00:00
|
|
|
/* Port of ICU4J rounding test. */
|
|
|
|
void TestRounding(void);
|
2008-01-14 20:10:54 +00:00
|
|
|
|
2012-02-13 19:23:47 +00:00
|
|
|
void TestRoundingPattern(void);
|
|
|
|
|
2008-01-14 20:10:54 +00:00
|
|
|
void TestNonpositiveMultiplier(void);
|
2009-01-22 04:46:35 +00:00
|
|
|
|
|
|
|
void TestNumberingSystems();
|
|
|
|
|
2009-02-12 22:55:29 +00:00
|
|
|
|
|
|
|
void TestSpaceParsing();
|
|
|
|
void TestMultiCurrencySign();
|
|
|
|
void TestCurrencyFormatForMixParsing();
|
|
|
|
void TestDecimalFormatCurrencyParse();
|
|
|
|
void TestCurrencyIsoPluralFormat();
|
2009-02-28 02:07:55 +00:00
|
|
|
void TestCurrencyParsing();
|
|
|
|
void TestParseCurrencyInUCurr();
|
2009-12-17 22:15:20 +00:00
|
|
|
void TestFormatAttributes();
|
2010-01-22 22:44:29 +00:00
|
|
|
void TestFieldPositionIterator();
|
2009-02-12 22:55:29 +00:00
|
|
|
|
2011-05-04 12:23:42 +00:00
|
|
|
void TestLenientParse();
|
|
|
|
|
2010-02-26 02:29:00 +00:00
|
|
|
void TestDecimal();
|
2010-05-28 16:45:11 +00:00
|
|
|
void TestCurrencyFractionDigits();
|
2010-02-26 02:29:00 +00:00
|
|
|
|
2010-07-06 16:35:34 +00:00
|
|
|
void TestExponentParse();
|
2011-02-16 13:46:19 +00:00
|
|
|
void TestExplicitParents();
|
2011-08-08 16:03:37 +00:00
|
|
|
void TestAvailableNumberingSystems();
|
2012-02-17 04:00:49 +00:00
|
|
|
void Test9087();
|
2012-05-30 00:41:57 +00:00
|
|
|
void TestFormatFastpaths();
|
2011-08-08 16:03:37 +00:00
|
|
|
|
2012-11-29 01:09:50 +00:00
|
|
|
void TestFormattableSize();
|
|
|
|
|
2013-06-26 06:31:09 +00:00
|
|
|
void TestUFormattable();
|
|
|
|
|
2012-10-12 19:52:43 +00:00
|
|
|
void TestEnumSet();
|
2010-07-06 16:35:34 +00:00
|
|
|
|
2013-04-02 22:01:33 +00:00
|
|
|
void TestSignificantDigits();
|
2013-05-24 22:45:48 +00:00
|
|
|
void TestShowZero();
|
2013-04-02 22:01:33 +00:00
|
|
|
|
2013-06-13 18:38:53 +00:00
|
|
|
void TestCompatibleCurrencies();
|
2013-06-17 18:49:28 +00:00
|
|
|
void TestBug9936();
|
2013-07-25 17:58:37 +00:00
|
|
|
void TestParseNegativeWithFaLocale();
|
|
|
|
void TestParseNegativeWithAlternateMinusSign();
|
2013-06-17 18:49:28 +00:00
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
private:
|
2013-06-26 06:31:09 +00:00
|
|
|
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
|
|
|
|
|
2013-06-20 22:09:42 +00:00
|
|
|
void expectParseCurrency(const NumberFormat &fmt, const UChar* currency, double amount, const char *text);
|
2003-04-21 19:16:38 +00:00
|
|
|
|
|
|
|
static UBool equalValue(const Formattable& a, const Formattable& b);
|
|
|
|
|
2009-12-17 22:15:20 +00:00
|
|
|
void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
|
|
|
|
const UnicodeString& str);
|
|
|
|
|
|
|
|
void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
|
|
|
|
const UnicodeString& str);
|
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
|
|
|
|
|
2009-01-22 20:56:32 +00:00
|
|
|
void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
|
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
void expect2(NumberFormat& fmt, const Formattable& n, const char* str) {
|
|
|
|
expect2(fmt, n, UnicodeString(str, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec);
|
|
|
|
|
|
|
|
void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) {
|
|
|
|
expect2(fmt, n, UnicodeString(str, ""), ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
|
|
|
|
|
|
|
|
void expect(NumberFormat& fmt, const char *str, const Formattable& n) {
|
2000-03-31 22:02:12 +00:00
|
|
|
expect(fmt, UnicodeString(str, ""), n);
|
|
|
|
}
|
2003-04-21 19:16:38 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void expect(NumberFormat& fmt, const Formattable& n,
|
2003-04-21 19:16:38 +00:00
|
|
|
const UnicodeString& exp, UBool rt=TRUE);
|
|
|
|
|
2000-03-31 22:02:12 +00:00
|
|
|
void expect(NumberFormat& fmt, const Formattable& n,
|
2003-04-21 19:16:38 +00:00
|
|
|
const char *exp, UBool rt=TRUE) {
|
|
|
|
expect(fmt, n, UnicodeString(exp, ""), rt);
|
2000-03-31 22:02:12 +00:00
|
|
|
}
|
2003-04-21 19:16:38 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void expect(NumberFormat* fmt, const Formattable& n,
|
|
|
|
const UnicodeString& exp, UErrorCode);
|
2003-04-21 19:16:38 +00:00
|
|
|
|
2000-03-31 22:02:12 +00:00
|
|
|
void expect(NumberFormat* fmt, const Formattable& n,
|
|
|
|
const char *exp, UErrorCode errorCode) {
|
|
|
|
expect(fmt, n, UnicodeString(exp, ""), errorCode);
|
|
|
|
}
|
2003-04-21 19:16:38 +00:00
|
|
|
|
|
|
|
void expectCurrency(NumberFormat& nf, const Locale& locale,
|
|
|
|
double value, const UnicodeString& string);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
|
|
|
|
int32_t pos, int32_t width, UChar pad);
|
2003-04-21 19:16:38 +00:00
|
|
|
|
2000-03-31 22:02:12 +00:00
|
|
|
void expectPad(DecimalFormat& fmt, const char *pat,
|
|
|
|
int32_t pos, int32_t width, UChar pad) {
|
|
|
|
expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
|
|
|
|
}
|
2003-04-21 19:16:38 +00:00
|
|
|
|
2000-06-01 18:46:31 +00:00
|
|
|
void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
|
2000-06-02 00:36:28 +00:00
|
|
|
int32_t pos, int32_t width, const UnicodeString& pad);
|
2003-04-21 19:16:38 +00:00
|
|
|
|
2000-06-01 18:46:31 +00:00
|
|
|
void expectPad(DecimalFormat& fmt, const char *pat,
|
2000-06-02 00:36:28 +00:00
|
|
|
int32_t pos, int32_t width, const UnicodeString& pad) {
|
2000-06-01 18:46:31 +00:00
|
|
|
expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
|
|
|
|
}
|
|
|
|
|
2005-01-02 19:30:11 +00:00
|
|
|
void expectPat(DecimalFormat& fmt, const UnicodeString& exp);
|
|
|
|
|
|
|
|
void expectPat(DecimalFormat& fmt, const char *exp) {
|
|
|
|
expectPat(fmt, UnicodeString(exp, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
|
|
|
|
int32_t pos);
|
|
|
|
|
|
|
|
void expectPad(DecimalFormat& fmt, const char *pat,
|
|
|
|
int32_t pos) {
|
|
|
|
expectPad(fmt, pat, pos, 0, (UChar)0);
|
|
|
|
}
|
|
|
|
|
2009-01-22 20:56:32 +00:00
|
|
|
void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
|
|
|
|
|
|
|
|
void expect_rbnf(NumberFormat& fmt, const Formattable& n,
|
|
|
|
const UnicodeString& exp, UBool rt=TRUE);
|
|
|
|
|
2003-04-21 19:16:38 +00:00
|
|
|
// internal utility routine
|
|
|
|
static UnicodeString& escape(UnicodeString& s);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
enum { ILLEGAL = -1 };
|
|
|
|
|
|
|
|
// internal subtest used by TestRounding487
|
2000-06-07 00:17:23 +00:00
|
|
|
void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2007-08-22 19:58:25 +00:00
|
|
|
// internal rounding checking for TestRounding
|
|
|
|
void checkRounding(DecimalFormat* df, double base, int iterations, double increment);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2007-08-22 19:58:25 +00:00
|
|
|
double checkRound(DecimalFormat* df, double iValue, double lastParsed);
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif // _NUMBERFORMATTEST_
|