2010-01-22 22:44:29 +00:00
|
|
|
/************************************************************************
|
2008-09-26 21:25:04 +00:00
|
|
|
* COPYRIGHT:
|
2016-05-26 22:32:17 +00:00
|
|
|
* Copyright (C) 2016 and later: Unicode, Inc. and others.
|
|
|
|
* License & terms of use: http://www.unicode.org/copyright.html
|
2010-01-22 22:44:29 +00:00
|
|
|
************************************************************************/
|
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"
|
|
|
|
|
2015-08-27 18:03:18 +00:00
|
|
|
/**
|
|
|
|
* Expected field positions from field position iterator. Tests should
|
|
|
|
* stack allocate an array of these making sure that the last element is
|
|
|
|
* {0, -1, 0} (The sentinel element indicating end of iterator). Then test
|
|
|
|
* should call verifyFieldPositionIterator() passing both this array of
|
|
|
|
* expected results and the field position iterator from the format method.
|
|
|
|
*/
|
|
|
|
struct NumberFormatTest_Attributes {
|
|
|
|
int32_t id;
|
|
|
|
int32_t spos;
|
|
|
|
int32_t epos;
|
|
|
|
};
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2013-09-04 10:46:03 +00:00
|
|
|
void TestCustomCurrencySignAndSeparator();
|
|
|
|
|
|
|
|
void TestParseSignsAndMarks();
|
2013-10-10 21:49:53 +00:00
|
|
|
void Test10419RoundingWith0FractionDigits();
|
2013-10-17 18:44:44 +00:00
|
|
|
void Test10468ApplyPattern();
|
2013-11-14 18:57:06 +00:00
|
|
|
void TestRoundingScientific10542();
|
2014-02-21 20:41:39 +00:00
|
|
|
void TestZeroScientific10547();
|
2014-02-22 00:16:56 +00:00
|
|
|
void TestAccountingCurrency();
|
2014-03-04 05:54:16 +00:00
|
|
|
void TestEquality();
|
2013-08-20 20:51:31 +00:00
|
|
|
|
2014-06-12 21:40:34 +00:00
|
|
|
void TestCurrencyUsage();
|
2015-05-28 20:09:43 +00:00
|
|
|
void TestNumberFormatTestTuple();
|
|
|
|
void TestDataDriven();
|
|
|
|
|
2014-12-18 22:46:45 +00:00
|
|
|
void TestDoubleLimit11439();
|
2015-02-12 21:45:27 +00:00
|
|
|
void TestFastPathConsistent11524();
|
2015-08-25 23:31:01 +00:00
|
|
|
void TestGetAffixes();
|
|
|
|
void TestToPatternScientific11648();
|
|
|
|
void TestBenchmark();
|
|
|
|
void TestCtorApplyPatternDifference();
|
|
|
|
void TestFractionalDigitsForCurrency();
|
|
|
|
void TestFormatCurrencyPlural();
|
2015-08-27 18:03:18 +00:00
|
|
|
void Test11868();
|
2015-08-28 18:38:37 +00:00
|
|
|
void Test10727_RoundingZero();
|
|
|
|
void Test11376_getAndSetPositivePrefix();
|
|
|
|
void Test11475_signRecognition();
|
|
|
|
void Test11640_getAffixes();
|
|
|
|
void Test11649_toPatternWithMultiCurrency();
|
2014-06-12 21:40:34 +00:00
|
|
|
|
2016-02-26 23:59:20 +00:00
|
|
|
void checkExceptionIssue11735();
|
|
|
|
|
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,
|
2014-02-22 00:16:56 +00:00
|
|
|
const UnicodeString& exp, UBool rt, UErrorCode errorCode);
|
|
|
|
|
|
|
|
void expect(NumberFormat* fmt, const Formattable& n,
|
|
|
|
const char *exp, UBool rt, UErrorCode errorCode) {
|
|
|
|
expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect(NumberFormat* fmt, const Formattable& n,
|
|
|
|
const UnicodeString& exp, UErrorCode errorCode) {
|
|
|
|
expect(fmt, n, exp, TRUE, errorCode);
|
|
|
|
}
|
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) {
|
2014-02-22 00:16:56 +00:00
|
|
|
expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
|
2000-03-31 22:02:12 +00:00
|
|
|
}
|
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);
|
2013-11-14 18:57:06 +00:00
|
|
|
|
|
|
|
void verifyRounding(
|
|
|
|
DecimalFormat& format,
|
|
|
|
const double *values,
|
|
|
|
const char * const *expected,
|
|
|
|
const DecimalFormat::ERoundingMode *roundingModes,
|
|
|
|
const char * const *descriptions,
|
|
|
|
int32_t valueSize,
|
|
|
|
int32_t roundingModeSize);
|
|
|
|
|
2015-08-27 18:03:18 +00:00
|
|
|
void verifyFieldPositionIterator(
|
|
|
|
NumberFormatTest_Attributes *expected,
|
|
|
|
FieldPositionIterator &iter);
|
|
|
|
|
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_
|