mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-13807 ICU 62 No Data Testing fixes. Mostly to test code.
X-SVN-Rev: 41500
This commit is contained in:
parent
4e55f07e42
commit
c0f9d2eeef
20 changed files with 350 additions and 268 deletions
|
@ -93,6 +93,7 @@ void NumberFormatterImpl::apply(DecimalQuantity& inValue, NumberStringBuilder& o
|
|||
UErrorCode& status) const {
|
||||
if (U_FAILURE(status)) { return; }
|
||||
MicroProps micros;
|
||||
if (!fMicroPropsGenerator) { return; }
|
||||
fMicroPropsGenerator->processQuantity(inValue, micros, status);
|
||||
if (U_FAILURE(status)) { return; }
|
||||
microsToString(micros, inValue, outString, status);
|
||||
|
|
|
@ -375,13 +375,13 @@ static void TestSampleMessageFormat(void)
|
|||
static void TestNewFormatAndParseAPI(void)
|
||||
{
|
||||
|
||||
UChar *result, tzID[4], str[25];
|
||||
UChar *result = NULL, tzID[4], str[25];
|
||||
UChar pattern[100];
|
||||
UChar expected[100];
|
||||
int32_t resultLengthOut, resultlength;
|
||||
UCalendar *cal;
|
||||
UDate d1,d;
|
||||
UDateFormat *def1;
|
||||
UDateFormat *def1 = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t value = 0;
|
||||
UChar ret[30];
|
||||
|
@ -398,13 +398,12 @@ static void TestNewFormatAndParseAPI(void)
|
|||
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
|
||||
return;
|
||||
goto cleanup;
|
||||
}
|
||||
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
|
||||
d1=ucal_getMillis(cal, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Error: failure in get millis: %s\n", myErrorName(status) );
|
||||
return;
|
||||
log_err("Error: failure in get millis: %s\n", myErrorName(status) );
|
||||
}
|
||||
|
||||
log_verbose("\nTesting with pattern test#4");
|
||||
|
@ -414,7 +413,7 @@ static void TestNewFormatAndParseAPI(void)
|
|||
fmt = umsg_open(pattern,u_strlen(pattern),"en_US",&parseError,&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("error in umsg_open : %s (Are you missing data?)\n", u_errorName(status) );
|
||||
return;
|
||||
goto cleanup;
|
||||
}
|
||||
result=(UChar*)malloc(sizeof(UChar) * resultlength);
|
||||
|
||||
|
@ -463,6 +462,7 @@ static void TestNewFormatAndParseAPI(void)
|
|||
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
umsg_close(fmt);
|
||||
udat_close(def1);
|
||||
ucal_close(cal);
|
||||
|
@ -483,7 +483,7 @@ static void TestSampleFormatAndParseWithError(void)
|
|||
int32_t resultLengthOut, resultlength;
|
||||
UCalendar *cal;
|
||||
UDate d1,d;
|
||||
UDateFormat *def1;
|
||||
UDateFormat *def1 = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t value = 0;
|
||||
UChar ret[30];
|
||||
|
@ -523,6 +523,7 @@ static void TestSampleFormatAndParseWithError(void)
|
|||
}
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
|
||||
goto cleanup;
|
||||
}
|
||||
else if(u_strcmp(result, expected)==0)
|
||||
log_verbose("PASS: MessagFormat successful on test#4\n");
|
||||
|
@ -557,6 +558,7 @@ static void TestSampleFormatAndParseWithError(void)
|
|||
austrdup(myDateFormat(def1,d)), austrdup(myDateFormat(def1,d1)) );
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
udat_close(def1);
|
||||
ucal_close(cal);
|
||||
|
||||
|
@ -593,11 +595,12 @@ static void TestSampleFormatAndParse(void)
|
|||
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status) );
|
||||
return;
|
||||
}
|
||||
ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
|
||||
d1=ucal_getMillis(cal, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
|
||||
log_data_err("Error: failure in get millis: %s - (Are you missing data?)\n", myErrorName(status) );
|
||||
}
|
||||
|
||||
log_verbose("\nTesting with pattern test#4");
|
||||
|
@ -616,6 +619,7 @@ static void TestSampleFormatAndParse(void)
|
|||
}
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("ERROR: failure in message format test#4: %s (Are you missing data?)\n", myErrorName(status));
|
||||
return;
|
||||
}
|
||||
else if(u_strcmp(result, expected)==0)
|
||||
log_verbose("PASS: MessagFormat successful on test#4\n");
|
||||
|
|
|
@ -1409,6 +1409,10 @@ TestQuickCheckPerCP() {
|
|||
}
|
||||
|
||||
length=unorm_normalize(s, length, UNORM_NFD, 0, nfd, UPRV_LENGTHOF(nfd), &errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
log_data_err("%s:%d errorCode=%s\n", __FILE__, __LINE__, u_errorName(errorCode));
|
||||
break;
|
||||
}
|
||||
/* length-length == 0 is used to get around a compiler warning. */
|
||||
U16_GET(nfd, 0, length-length, length, lead);
|
||||
U16_GET(nfd, 0, length-1, length, trail);
|
||||
|
|
|
@ -3070,6 +3070,7 @@ static void Test12052_NullPointer() {
|
|||
static const UChar input[] = u"199a";
|
||||
UChar currency[200] = {0};
|
||||
UNumberFormat *theFormatter = unum_open(UNUM_CURRENCY, NULL, 0, "en_US", NULL, &status);
|
||||
if (!assertSuccessCheck("unum_open() failed", &status, TRUE)) { return; }
|
||||
status = U_ZERO_ERROR;
|
||||
unum_setAttribute(theFormatter, UNUM_LENIENT_PARSE, 1);
|
||||
int32_t pos = 1;
|
||||
|
|
|
@ -35,34 +35,37 @@ void addUNumberFormatterTest(TestNode** root) {
|
|||
static void TestSkeletonFormatToString() {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UChar buffer[CAPACITY];
|
||||
UFormattedNumber* result = NULL;
|
||||
|
||||
// setup:
|
||||
UNumberFormatter* f = unumf_openForSkeletonAndLocale(
|
||||
u"precision-integer currency/USD sign-accounting", -1, "en", &ec);
|
||||
assertSuccess("Should create without error", &ec);
|
||||
UFormattedNumber* result = unumf_openResult(&ec);
|
||||
u"precision-integer currency/USD sign-accounting", -1, "en", &ec);
|
||||
assertSuccessCheck("Should create without error", &ec, TRUE);
|
||||
result = unumf_openResult(&ec);
|
||||
assertSuccess("Should create result without error", &ec);
|
||||
|
||||
// int64 test:
|
||||
unumf_formatInt(f, -444444, result, &ec);
|
||||
assertSuccess("Should format integer without error", &ec);
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"($444,444)", buffer);
|
||||
// Missing data will give a U_MISSING_RESOURCE_ERROR here.
|
||||
if (assertSuccessCheck("Should format integer without error", &ec, TRUE)) {
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"($444,444)", buffer);
|
||||
|
||||
// double test:
|
||||
unumf_formatDouble(f, -5142.3, result, &ec);
|
||||
assertSuccess("Should format double without error", &ec);
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"($5,142)", buffer);
|
||||
// double test:
|
||||
unumf_formatDouble(f, -5142.3, result, &ec);
|
||||
assertSuccess("Should format double without error", &ec);
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"($5,142)", buffer);
|
||||
|
||||
// decnumber test:
|
||||
unumf_formatDecimal(f, "9.876E2", -1, result, &ec);
|
||||
assertSuccess("Should format decimal without error", &ec);
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"$988", buffer);
|
||||
// decnumber test:
|
||||
unumf_formatDecimal(f, "9.876E2", -1, result, &ec);
|
||||
assertSuccess("Should format decimal without error", &ec);
|
||||
unumf_resultToString(result, buffer, CAPACITY, &ec);
|
||||
assertSuccess("Should print string to buffer without error", &ec);
|
||||
assertUEquals("Should produce expected string result", u"$988", buffer);
|
||||
}
|
||||
|
||||
// cleanup:
|
||||
unumf_closeResult(result);
|
||||
|
@ -72,74 +75,79 @@ static void TestSkeletonFormatToString() {
|
|||
|
||||
static void TestSkeletonFormatToFields() {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UFieldPositionIterator* ufpositer = NULL;
|
||||
|
||||
// setup:
|
||||
UNumberFormatter* uformatter = unumf_openForSkeletonAndLocale(
|
||||
u".00 measure-unit/length-meter sign-always", -1, "en", &ec);
|
||||
assertSuccessCheck("Should create without error", &ec, TRUE);
|
||||
if (U_FAILURE(ec)) { return; }
|
||||
UFormattedNumber* uresult = unumf_openResult(&ec);
|
||||
assertSuccess("Should create result without error", &ec);
|
||||
unumf_formatInt(uformatter, 9876543210L, uresult, &ec); // "+9,876,543,210.00 m"
|
||||
if (assertSuccessCheck("unumf_formatInt() failed", &ec, TRUE)) {
|
||||
|
||||
// field position test:
|
||||
UFieldPosition ufpos = {UNUM_DECIMAL_SEPARATOR_FIELD};
|
||||
unumf_resultNextFieldPosition(uresult, &ufpos, &ec);
|
||||
assertIntEquals("Field position should be correct", 14, ufpos.beginIndex);
|
||||
assertIntEquals("Field position should be correct", 15, ufpos.endIndex);
|
||||
// field position test:
|
||||
UFieldPosition ufpos = {UNUM_DECIMAL_SEPARATOR_FIELD};
|
||||
unumf_resultNextFieldPosition(uresult, &ufpos, &ec);
|
||||
assertIntEquals("Field position should be correct", 14, ufpos.beginIndex);
|
||||
assertIntEquals("Field position should be correct", 15, ufpos.endIndex);
|
||||
|
||||
// field position iterator test:
|
||||
UFieldPositionIterator* ufpositer = ufieldpositer_open(&ec);
|
||||
assertSuccess("Should create iterator without error", &ec);
|
||||
unumf_resultGetAllFieldPositions(uresult, ufpositer, &ec);
|
||||
static const UFieldPosition expectedFields[] = {
|
||||
// Field, begin index, end index
|
||||
{UNUM_SIGN_FIELD, 0, 1},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 2, 3},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 6, 7},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 10, 11},
|
||||
{UNUM_INTEGER_FIELD, 1, 14},
|
||||
{UNUM_DECIMAL_SEPARATOR_FIELD, 14, 15},
|
||||
{UNUM_FRACTION_FIELD, 15, 17}};
|
||||
UFieldPosition actual;
|
||||
for (int32_t i = 0; i < sizeof(expectedFields) / sizeof(*expectedFields); i++) {
|
||||
// Iterate using the UFieldPosition to hold state...
|
||||
UFieldPosition expected = expectedFields[i];
|
||||
actual.field = ufieldpositer_next(ufpositer, &actual.beginIndex, &actual.endIndex);
|
||||
assertTrue("Should not return a negative index yet", actual.field >= 0);
|
||||
if (expected.field != actual.field) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected field %d; got %d\n", i, expected.field, actual.field);
|
||||
}
|
||||
if (expected.beginIndex != actual.beginIndex) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected beginIndex %d; got %d\n",
|
||||
i,
|
||||
expected.beginIndex,
|
||||
actual.beginIndex);
|
||||
}
|
||||
if (expected.endIndex != actual.endIndex) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected endIndex %d; got %d\n",
|
||||
i,
|
||||
expected.endIndex,
|
||||
actual.endIndex);
|
||||
// field position iterator test:
|
||||
ufpositer = ufieldpositer_open(&ec);
|
||||
if (assertSuccessCheck("Should create iterator without error", &ec, TRUE)) {
|
||||
|
||||
unumf_resultGetAllFieldPositions(uresult, ufpositer, &ec);
|
||||
static const UFieldPosition expectedFields[] = {
|
||||
// Field, begin index, end index
|
||||
{UNUM_SIGN_FIELD, 0, 1},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 2, 3},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 6, 7},
|
||||
{UNUM_GROUPING_SEPARATOR_FIELD, 10, 11},
|
||||
{UNUM_INTEGER_FIELD, 1, 14},
|
||||
{UNUM_DECIMAL_SEPARATOR_FIELD, 14, 15},
|
||||
{UNUM_FRACTION_FIELD, 15, 17}
|
||||
};
|
||||
UFieldPosition actual;
|
||||
for (int32_t i = 0; i < sizeof(expectedFields) / sizeof(*expectedFields); i++) {
|
||||
// Iterate using the UFieldPosition to hold state...
|
||||
UFieldPosition expected = expectedFields[i];
|
||||
actual.field = ufieldpositer_next(ufpositer, &actual.beginIndex, &actual.endIndex);
|
||||
assertTrue("Should not return a negative index yet", actual.field >= 0);
|
||||
if (expected.field != actual.field) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected field %d; got %d\n", i, expected.field, actual.field);
|
||||
}
|
||||
if (expected.beginIndex != actual.beginIndex) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected beginIndex %d; got %d\n",
|
||||
i,
|
||||
expected.beginIndex,
|
||||
actual.beginIndex);
|
||||
}
|
||||
if (expected.endIndex != actual.endIndex) {
|
||||
log_err(
|
||||
"FAIL: iteration %d; expected endIndex %d; got %d\n",
|
||||
i,
|
||||
expected.endIndex,
|
||||
actual.endIndex);
|
||||
}
|
||||
}
|
||||
actual.field = ufieldpositer_next(ufpositer, &actual.beginIndex, &actual.endIndex);
|
||||
assertTrue("No more fields; should return a negative index", actual.field < 0);
|
||||
|
||||
// next field iteration:
|
||||
actual.field = UNUM_GROUPING_SEPARATOR_FIELD;
|
||||
actual.beginIndex = 0;
|
||||
actual.endIndex = 0;
|
||||
int32_t i = 1;
|
||||
while (unumf_resultNextFieldPosition(uresult, &actual, &ec)) {
|
||||
UFieldPosition expected = expectedFields[i++];
|
||||
assertIntEquals("Grouping separator begin index", expected.beginIndex, actual.beginIndex);
|
||||
assertIntEquals("Grouping separator end index", expected.endIndex, actual.endIndex);
|
||||
}
|
||||
assertIntEquals("Should have seen all grouping separators", 4, i);
|
||||
}
|
||||
}
|
||||
actual.field = ufieldpositer_next(ufpositer, &actual.beginIndex, &actual.endIndex);
|
||||
assertTrue("No more fields; should return a negative index", actual.field < 0);
|
||||
|
||||
// next field iteration:
|
||||
actual.field = UNUM_GROUPING_SEPARATOR_FIELD;
|
||||
actual.beginIndex = 0;
|
||||
actual.endIndex = 0;
|
||||
int32_t i = 1;
|
||||
while (unumf_resultNextFieldPosition(uresult, &actual, &ec)) {
|
||||
UFieldPosition expected = expectedFields[i++];
|
||||
assertIntEquals("Grouping separator begin index", expected.beginIndex, actual.beginIndex);
|
||||
assertIntEquals("Grouping separator end index", expected.endIndex, actual.endIndex);
|
||||
}
|
||||
assertIntEquals("Should have seen all grouping separators", 4, i);
|
||||
|
||||
// cleanup:
|
||||
unumf_closeResult(uresult);
|
||||
|
@ -155,21 +163,22 @@ static void TestExampleCode() {
|
|||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UNumberFormatter* uformatter = unumf_openForSkeletonAndLocale(u"precision-integer", -1, "en", &ec);
|
||||
UFormattedNumber* uresult = unumf_openResult(&ec);
|
||||
UChar* buffer = NULL;
|
||||
assertSuccessCheck("There should not be a failure in the example code", &ec, TRUE);
|
||||
if (U_FAILURE(ec)) { return; }
|
||||
|
||||
// Format a double:
|
||||
unumf_formatDouble(uformatter, 5142.3, uresult, &ec);
|
||||
assertSuccess("There should not be a failure in the example code", &ec);
|
||||
if (assertSuccessCheck("There should not be a failure in the example code", &ec, TRUE)) {
|
||||
|
||||
// Export the string to a malloc'd buffer:
|
||||
int32_t len = unumf_resultToString(uresult, NULL, 0, &ec);
|
||||
assertTrue("No buffer yet", ec == U_BUFFER_OVERFLOW_ERROR);
|
||||
ec = U_ZERO_ERROR;
|
||||
UChar* buffer = (UChar*) uprv_malloc((len+1)*sizeof(UChar));
|
||||
unumf_resultToString(uresult, buffer, len+1, &ec);
|
||||
assertSuccess("There should not be a failure in the example code", &ec);
|
||||
assertUEquals("Should produce expected string result", u"5,142", buffer);
|
||||
// Export the string to a malloc'd buffer:
|
||||
int32_t len = unumf_resultToString(uresult, NULL, 0, &ec);
|
||||
assertTrue("No buffer yet", ec == U_BUFFER_OVERFLOW_ERROR);
|
||||
ec = U_ZERO_ERROR;
|
||||
buffer = (UChar*) uprv_malloc((len+1)*sizeof(UChar));
|
||||
unumf_resultToString(uresult, buffer, len+1, &ec);
|
||||
assertSuccess("There should not be a failure in the example code", &ec);
|
||||
assertUEquals("Should produce expected string result", u"5,142", buffer);
|
||||
}
|
||||
|
||||
// Cleanup:
|
||||
unumf_close(uformatter);
|
||||
|
|
|
@ -485,17 +485,18 @@ void CompactDecimalFormatTest::TestBug12975() {
|
|||
IcuTestErrorCode status(*this, "TestBug12975");
|
||||
Locale locale("it");
|
||||
LocalPointer<CompactDecimalFormat> cdf(CompactDecimalFormat::createInstance(locale, UNUM_SHORT, status));
|
||||
UnicodeString resultCdf;
|
||||
cdf->format(120000, resultCdf);
|
||||
LocalPointer<DecimalFormat> df((DecimalFormat*) DecimalFormat::createInstance(locale, status));
|
||||
UnicodeString resultDefault;
|
||||
df->format(120000, resultDefault);
|
||||
assertEquals("CompactDecimalFormat should use default pattern when compact pattern is unavailable",
|
||||
resultDefault, resultCdf);
|
||||
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
UnicodeString resultCdf;
|
||||
cdf->format(120000, resultCdf);
|
||||
LocalPointer<DecimalFormat> df((DecimalFormat*) DecimalFormat::createInstance(locale, status));
|
||||
UnicodeString resultDefault;
|
||||
df->format(120000, resultDefault);
|
||||
assertEquals("CompactDecimalFormat should use default pattern when compact pattern is unavailable",
|
||||
resultDefault, resultCdf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// End test cases. Helpers:
|
||||
|
||||
void CompactDecimalFormatTest::CheckLocale(const Locale& locale, UNumberCompactStyle style, const ExpectedResult* expectedResults, int32_t expectedResultLength) {
|
||||
|
|
|
@ -5543,6 +5543,10 @@ void DateFormatTest::TestDayPeriodParsing() {
|
|||
void DateFormatTest::TestParseRegression13744() {
|
||||
LocalPointer<DateFormat> dfmt(DateFormat::createDateTimeInstance(
|
||||
DateFormat::SHORT, DateFormat::SHORT, Locale("en", "US")));
|
||||
if (dfmt.isNull()) {
|
||||
dataerrln("DateFormat::createDateTimeInstance() failed");
|
||||
return;
|
||||
}
|
||||
ParsePosition pos(0);
|
||||
UnicodeString inDate("4/27/18");
|
||||
dfmt->parse(inDate, pos);
|
||||
|
|
|
@ -2291,12 +2291,14 @@ void IntlTestRBNF::TestParseFailure() {
|
|||
static const UChar* testData[] = {
|
||||
u"・・・・・・・・・・・・・・・・・・・・・・・・"
|
||||
};
|
||||
for (int i = 0; i < UPRV_LENGTHOF(testData); ++i) {
|
||||
UnicodeString spelledNumberString(testData[i]);
|
||||
Formattable actualNumber;
|
||||
rbnf.parse(spelledNumberString, actualNumber, status);
|
||||
if (status != U_INVALID_FORMAT_ERROR) { // I would have expected U_PARSE_ERROR, but NumberFormat::parse gives U_INVALID_FORMAT_ERROR
|
||||
errln("FAIL: string should be unparseable index=%d %s", i, u_errorName(status));
|
||||
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
for (int i = 0; i < UPRV_LENGTHOF(testData); ++i) {
|
||||
UnicodeString spelledNumberString(testData[i]);
|
||||
Formattable actualNumber;
|
||||
rbnf.parse(spelledNumberString, actualNumber, status);
|
||||
if (status != U_INVALID_FORMAT_ERROR) { // I would have expected U_PARSE_ERROR, but NumberFormat::parse gives U_INVALID_FORMAT_ERROR
|
||||
errln("FAIL: string should be unparseable index=%d %s", i, u_errorName(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2307,13 +2309,15 @@ void IntlTestRBNF::TestMinMaxIntegerDigitsIgnored() {
|
|||
// NOTE: SimpleDateFormat has an optimization that depends on the fact that min/max integer digits
|
||||
// do not affect RBNF (see SimpleDateFormat#zeroPaddingNumber).
|
||||
RuleBasedNumberFormat rbnf(URBNF_SPELLOUT, "en", status);
|
||||
rbnf.setMinimumIntegerDigits(2);
|
||||
rbnf.setMaximumIntegerDigits(3);
|
||||
UnicodeString result;
|
||||
rbnf.format(3, result.remove(), status);
|
||||
assertEquals("Min integer digits are ignored", u"three", result);
|
||||
rbnf.format(1012, result.remove(), status);
|
||||
assertEquals("Max integer digits are ignored", u"one thousand twelve", result);
|
||||
if (status.isSuccess()) {
|
||||
rbnf.setMinimumIntegerDigits(2);
|
||||
rbnf.setMaximumIntegerDigits(3);
|
||||
UnicodeString result;
|
||||
rbnf.format(3, result.remove(), status);
|
||||
assertEquals("Min integer digits are ignored", u"three", result);
|
||||
rbnf.format(1012, result.remove(), status);
|
||||
assertEquals("Max integer digits are ignored", u"one thousand twelve", result);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -648,7 +648,7 @@ void IntlTestSpoof::testMixedNumbers() {
|
|||
void IntlTestSpoof::testBug12153() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalUSpoofCheckerPointer sc(uspoof_open(&status));
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
int32_t checks = uspoof_getChecks(sc.getAlias(), &status);
|
||||
TEST_ASSERT((checks & USPOOF_RESTRICTION_LEVEL) != 0);
|
||||
checks &= ~USPOOF_RESTRICTION_LEVEL;
|
||||
|
@ -688,7 +688,7 @@ void IntlTestSpoof::testBug12815() {
|
|||
void IntlTestSpoof::testBug13314_MixedNumbers() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalUSpoofCheckerPointer sc(uspoof_open(&status));
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
uspoof_setChecks(sc.getAlias(), USPOOF_ALL_CHECKS, &status);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
int32_t failedChecks = uspoof_areConfusableUnicodeString(sc.getAlias(), u"列", u"列", &status);
|
||||
|
@ -702,7 +702,7 @@ void IntlTestSpoof::testBug13314_MixedNumbers() {
|
|||
void IntlTestSpoof::testBug13328_MixedCombiningMarks() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalUSpoofCheckerPointer sc(uspoof_open(&status));
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
int32_t failedChecks = uspoof_check2UnicodeString(sc.getAlias(), u"\u0061\u0F84", nullptr, &status);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
assertEquals(
|
||||
|
@ -714,7 +714,7 @@ void IntlTestSpoof::testBug13328_MixedCombiningMarks() {
|
|||
void IntlTestSpoof::testCombiningDot() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalUSpoofCheckerPointer sc(uspoof_open(&status));
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
uspoof_setChecks(sc.getAlias(), USPOOF_HIDDEN_OVERLAY, &status);
|
||||
TEST_ASSERT_SUCCESS(status);
|
||||
|
||||
|
|
|
@ -2338,7 +2338,8 @@ void NumberFormatterApiTest::copyMove() {
|
|||
|
||||
// Default constructors
|
||||
LocalizedNumberFormatter l1;
|
||||
assertEquals("Initial behavior", u"10", l1.formatInt(10, status).toString());
|
||||
assertEquals("Initial behavior", u"10", l1.formatInt(10, status).toString(), true);
|
||||
if (status.errDataIfFailureAndReset()) { return; }
|
||||
assertEquals("Initial call count", 1, l1.getCallCount());
|
||||
assertTrue("Initial compiled", l1.getCompiled() == nullptr);
|
||||
|
||||
|
@ -2414,12 +2415,11 @@ void NumberFormatterApiTest::localPointerCAPI() {
|
|||
// Setup:
|
||||
LocalUNumberFormatterPointer uformatter(unumf_openForSkeletonAndLocale(u"percent", -1, "en", &ec));
|
||||
LocalUFormattedNumberPointer uresult(unumf_openResult(&ec));
|
||||
assertSuccess("", ec, TRUE);
|
||||
if (U_FAILURE(ec)) { return; }
|
||||
if (!assertSuccess("", ec, true, __FILE__, __LINE__)) { return; }
|
||||
|
||||
// Format a decimal number:
|
||||
unumf_formatDecimal(uformatter.getAlias(), "9.87E-3", -1, uresult.getAlias(), &ec);
|
||||
assertSuccess("", ec);
|
||||
if (!assertSuccess("", ec, true, __FILE__, __LINE__)) { return; }
|
||||
|
||||
// Get the location of the percent sign:
|
||||
UFieldPosition ufpos = {UNUM_PERCENT_FIELD, 0, 0};
|
||||
|
|
|
@ -101,7 +101,9 @@ void ModifiersTest::testSimpleModifier() {
|
|||
void ModifiersTest::testCurrencySpacingEnabledModifier() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols symbols(Locale("en"), status);
|
||||
assertSuccess("Spot 1", status);
|
||||
if (!assertSuccess("Spot 1", status, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NumberStringBuilder prefix;
|
||||
NumberStringBuilder suffix;
|
||||
|
|
|
@ -128,6 +128,9 @@ void NumberParserTest::testBasic() {
|
|||
LocalPointer<const NumberParserImpl> parser(
|
||||
NumberParserImpl::createSimpleParser(
|
||||
Locale("en"), patternString, parseFlags, status));
|
||||
if (status.errDataIfFailureAndReset("createSimpleParser() failed")) {
|
||||
continue;
|
||||
}
|
||||
UnicodeString message =
|
||||
UnicodeString("Input <") + inputString + UnicodeString("> Parser ") + parser->toString();
|
||||
|
||||
|
@ -180,7 +183,9 @@ void NumberParserTest::testSeriesMatcher() {
|
|||
IcuTestErrorCode status(*this, "testSeriesMatcher");
|
||||
|
||||
DecimalFormatSymbols symbols("en", status);
|
||||
|
||||
if (status.errDataIfFailureAndReset("Failure in DecimalFormtSymbols constructor")) {
|
||||
return;
|
||||
}
|
||||
PlusSignMatcher m0(symbols, false);
|
||||
MinusSignMatcher m1(symbols, false);
|
||||
IgnorablesMatcher m2(unisets::DEFAULT_IGNORABLES);
|
||||
|
@ -237,6 +242,9 @@ void NumberParserTest::testCombinedCurrencyMatcher() {
|
|||
Locale locale = Locale::getEnglish();
|
||||
|
||||
DecimalFormatSymbols dfs(locale, status);
|
||||
if (status.errDataIfFailureAndReset("Failure in DecimalFormtSymbols constructor")) {
|
||||
return;
|
||||
}
|
||||
dfs.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"IU$", status);
|
||||
dfs.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, u"ICU", status);
|
||||
CurrencySymbols currencySymbols({u"ICU", status}, locale, dfs, status);
|
||||
|
@ -328,16 +336,17 @@ void NumberParserTest::testAffixPatternMatcher() {
|
|||
bool success;
|
||||
AffixPatternMatcher matcher = AffixPatternMatcher::fromAffixPattern(
|
||||
affixPattern, warehouse, parseFlags, &success, status);
|
||||
assertTrue("Creation should be successful", success);
|
||||
if (!status.errDataIfFailureAndReset("Creation should be successful")) {
|
||||
|
||||
// Check that the matcher has the expected number of children
|
||||
assertEquals(affixPattern + " " + cas.exactMatch, cas.expectedMatcherLength, matcher.length());
|
||||
// Check that the matcher has the expected number of children
|
||||
assertEquals(affixPattern + " " + cas.exactMatch, cas.expectedMatcherLength, matcher.length());
|
||||
|
||||
// Check that the matcher works on a sample string
|
||||
StringSegment segment(sampleParseableString, false);
|
||||
ParsedNumber result;
|
||||
matcher.match(segment, result, status);
|
||||
assertEquals(affixPattern + " " + cas.exactMatch, sampleParseableString.length(), result.charEnd);
|
||||
// Check that the matcher works on a sample string
|
||||
StringSegment segment(sampleParseableString, false);
|
||||
ParsedNumber result;
|
||||
matcher.match(segment, result, status);
|
||||
assertEquals(affixPattern + " " + cas.exactMatch, sampleParseableString.length(), result.charEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,9 @@ void PatternModifierTest::testBasic() {
|
|||
mod.setPatternAttributes(UNUM_SIGN_AUTO, false);
|
||||
DecimalFormatSymbols symbols(Locale::getEnglish(), status);
|
||||
CurrencySymbols currencySymbols({u"USD", status}, "en", status);
|
||||
assertSuccess("Spot 2", status);
|
||||
if (!assertSuccess("Spot 2", status, true)) {
|
||||
return;
|
||||
}
|
||||
mod.setSymbols(&symbols, ¤cySymbols, UNUM_UNIT_WIDTH_SHORT, nullptr);
|
||||
|
||||
mod.setNumberProperties(1, StandardPlural::Form::COUNT);
|
||||
|
@ -90,7 +92,9 @@ void PatternModifierTest::testPatternWithNoPlaceholder() {
|
|||
mod.setPatternAttributes(UNUM_SIGN_AUTO, false);
|
||||
DecimalFormatSymbols symbols(Locale::getEnglish(), status);
|
||||
CurrencySymbols currencySymbols({u"USD", status}, "en", status);
|
||||
assertSuccess("Spot 2", status);
|
||||
if (!assertSuccess("Spot 2", status, true)) {
|
||||
return;
|
||||
}
|
||||
mod.setSymbols(&symbols, ¤cySymbols, UNUM_UNIT_WIDTH_SHORT, nullptr);
|
||||
mod.setNumberProperties(1, StandardPlural::Form::COUNT);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ void PatternStringTest::runIndexedTest(int32_t index, UBool exec, const char*& n
|
|||
void PatternStringTest::testLocalized() {
|
||||
IcuTestErrorCode status(*this, "testLocalized");
|
||||
DecimalFormatSymbols symbols(Locale::getEnglish(), status);
|
||||
if (status.isFailure()) { return; }
|
||||
symbols.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, u"a", status);
|
||||
symbols.setSymbol(DecimalFormatSymbols::kPercentSymbol, u"b", status);
|
||||
symbols.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, u".", status);
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "putilimp.h"
|
||||
#include "unicode/dcfmtsym.h"
|
||||
|
||||
#include "cstr.h"
|
||||
#include "numbertest.h"
|
||||
#include "number_utils.h"
|
||||
#include "number_skeletons.h"
|
||||
#include "putilimp.h"
|
||||
|
||||
using namespace icu::number::impl;
|
||||
|
||||
|
@ -109,7 +111,7 @@ void NumberSkeletonTest::validTokens() {
|
|||
UnicodeString skeletonString(cas);
|
||||
status.setScope(skeletonString);
|
||||
NumberFormatter::forSkeleton(skeletonString, status);
|
||||
assertSuccess(skeletonString, status);
|
||||
assertSuccess(CStr(skeletonString)(), status, true);
|
||||
status.errIfFailureAndReset();
|
||||
}
|
||||
}
|
||||
|
@ -247,9 +249,11 @@ void NumberSkeletonTest::flexibleSeparators() {
|
|||
UnicodeString expected(cas.expected);
|
||||
status.setScope(skeletonString);
|
||||
UnicodeString actual = NumberFormatter::forSkeleton(skeletonString, status).locale("en")
|
||||
.formatDouble(5142.3, status)
|
||||
.toString();
|
||||
assertEquals(skeletonString, expected, actual);
|
||||
.formatDouble(5142.3, status)
|
||||
.toString();
|
||||
if (!status.errDataIfFailureAndReset()) {
|
||||
assertEquals(skeletonString, expected, actual);
|
||||
}
|
||||
status.errIfFailureAndReset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -620,7 +620,7 @@ NumberFormatTest::TestScientificGrouping() {
|
|||
// jb 2552
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormat fmt("##0.00E0",status);
|
||||
if (U_SUCCESS(status)) {
|
||||
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
expect(fmt, .01234, "12.3E-3");
|
||||
expect(fmt, .1234, "123E-3");
|
||||
expect(fmt, 1.234, "1.23E0");
|
||||
|
@ -1099,7 +1099,7 @@ NumberFormatTest::TestLenientParse(void)
|
|||
|
||||
if (U_FAILURE(status) || n.getType() != Formattable::kLong ||
|
||||
n.getLong() != 1) {
|
||||
errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientAffixTestCases[t]
|
||||
dataerrln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientAffixTestCases[t]
|
||||
+ (UnicodeString) "\"; error code = " + u_errorName(status));
|
||||
status = U_ZERO_ERROR;
|
||||
}
|
||||
|
@ -2306,11 +2306,17 @@ void NumberFormatTest::TestPerMill() {
|
|||
DecimalFormat fmt(ctou("###.###\\u2030"), ec);
|
||||
if (!assertSuccess("DecimalFormat ct", ec)) return;
|
||||
assertEquals("0.4857 x ###.###\\u2030",
|
||||
ctou("485.7\\u2030"), fmt.format(0.4857, str));
|
||||
ctou("485.7\\u2030"), fmt.format(0.4857, str), true);
|
||||
|
||||
DecimalFormatSymbols sym(Locale::getUS(), ec);
|
||||
if (!assertSuccess("", ec, true, __FILE__, __LINE__)) {
|
||||
return;
|
||||
}
|
||||
sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, ctou("m"));
|
||||
DecimalFormat fmt2("", sym, ec);
|
||||
if (!assertSuccess("", ec, true, __FILE__, __LINE__)) {
|
||||
return;
|
||||
}
|
||||
fmt2.applyLocalizedPattern("###.###m", ec);
|
||||
if (!assertSuccess("setup", ec)) return;
|
||||
str.truncate(0);
|
||||
|
@ -3548,6 +3554,7 @@ void NumberFormatTest::TestMismatchedCurrencyFormatFail() {
|
|||
IcuTestErrorCode status(*this, "TestMismatchedCurrencyFormatFail");
|
||||
LocalPointer<DecimalFormat> df(
|
||||
dynamic_cast<DecimalFormat*>(DecimalFormat::createCurrencyInstance("en", status)), status);
|
||||
if (!assertSuccess("createCurrencyInstance() failed.", status, true, __FILE__, __LINE__)) {return;}
|
||||
UnicodeString pattern;
|
||||
assertEquals("Test assumes that currency sign is at the beginning",
|
||||
u"\u00A4#,##0.00",
|
||||
|
@ -6393,28 +6400,24 @@ NumberFormatTest::TestParseCurrencyInUCurr() {
|
|||
|
||||
Locale locale("en_US");
|
||||
for (uint32_t i=0; i<UPRV_LENGTHOF(DATA); ++i) {
|
||||
UnicodeString formatted = ctou(DATA[i]);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
NumberFormat* numFmt = NumberFormat::createInstance(locale, UNUM_CURRENCY, status);
|
||||
// NOTE: ICU 62 requires that the currency format match the pattern in strict mode.
|
||||
numFmt->setLenient(TRUE);
|
||||
if (numFmt != NULL && U_SUCCESS(status)) {
|
||||
ParsePosition parsePos;
|
||||
LocalPointer<CurrencyAmount> currAmt(numFmt->parseCurrency(formatted, parsePos));
|
||||
if (parsePos.getIndex() > 0) {
|
||||
double doubleVal = currAmt->getNumber().getDouble(status);
|
||||
if ( doubleVal != 1.0 ) {
|
||||
errln("Parsed as currency value other than 1.0: " + formatted + " -> " + doubleVal);
|
||||
}
|
||||
} else {
|
||||
errln("Failed to parse as currency: " + formatted);
|
||||
}
|
||||
} else {
|
||||
dataerrln("Unable to create NumberFormat. - %s", u_errorName(status));
|
||||
delete numFmt;
|
||||
break;
|
||||
}
|
||||
delete numFmt;
|
||||
UnicodeString formatted = ctou(DATA[i]);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<NumberFormat> numFmt(NumberFormat::createInstance(locale, UNUM_CURRENCY, status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
return;
|
||||
}
|
||||
// NOTE: ICU 62 requires that the currency format match the pattern in strict mode.
|
||||
numFmt->setLenient(TRUE);
|
||||
ParsePosition parsePos;
|
||||
LocalPointer<CurrencyAmount> currAmt(numFmt->parseCurrency(formatted, parsePos));
|
||||
if (parsePos.getIndex() > 0) {
|
||||
double doubleVal = currAmt->getNumber().getDouble(status);
|
||||
if ( doubleVal != 1.0 ) {
|
||||
errln("Parsed as currency value other than 1.0: " + formatted + " -> " + doubleVal);
|
||||
}
|
||||
} else {
|
||||
errln("Failed to parse as currency: " + formatted);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i=0; i<UPRV_LENGTHOF(WRONG_DATA); ++i) {
|
||||
|
@ -6815,7 +6818,7 @@ void NumberFormatTest::TestExponentParse() {
|
|||
|
||||
// set the exponent symbol
|
||||
status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getDefault(), status);
|
||||
DecimalFormatSymbols symbols(Locale::getDefault(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
dataerrln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (Default)");
|
||||
return;
|
||||
|
@ -6823,7 +6826,7 @@ void NumberFormatTest::TestExponentParse() {
|
|||
|
||||
// create format instance
|
||||
status = U_ZERO_ERROR;
|
||||
DecimalFormat fmt("#####", symbols, status);
|
||||
DecimalFormat fmt(u"#####", symbols, status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols*)");
|
||||
}
|
||||
|
@ -6961,7 +6964,7 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
// get some additional case
|
||||
{
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
DecimalFormat df(UnicodeString("0000",""),status);
|
||||
DecimalFormat df(UnicodeString(u"0000"),status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
|
||||
} else {
|
||||
|
@ -6971,15 +6974,16 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
FieldPosition pos;
|
||||
df.format(long_number, result, pos);
|
||||
if(U_FAILURE(status)||expect!=result) {
|
||||
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
|
||||
} else {
|
||||
dataerrln("%s:%d FAIL: expected '%s' got '%s' status %s",
|
||||
__FILE__, __LINE__, CStr(expect)(), CStr(result)(), u_errorName(status));
|
||||
} else {
|
||||
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),""));
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
|
||||
DecimalFormat df(UnicodeString(u"0000000000000000000"),status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
|
||||
} else {
|
||||
|
@ -6994,7 +6998,8 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
FieldPosition pos;
|
||||
df.format(long_number, result, pos);
|
||||
if(U_FAILURE(status)||expect!=result) {
|
||||
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
|
||||
dataerrln("%s:%d FAIL: expected '%s' got '%s' status %s on -9223372036854775808",
|
||||
__FILE__, __LINE__, CStr(expect)(), CStr(result)(), u_errorName(status));
|
||||
} else {
|
||||
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
|
||||
}
|
||||
|
@ -7002,7 +7007,7 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
}
|
||||
{
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
|
||||
DecimalFormat df(UnicodeString(u"0000000000000000000"),status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
|
||||
} else {
|
||||
|
@ -7017,7 +7022,8 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
FieldPosition pos;
|
||||
df.format(long_number, result, pos);
|
||||
if(U_FAILURE(status)||expect!=result) {
|
||||
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
|
||||
dataerrln("%s:%d FAIL: expected '%s' got '%s' status %s on U_INT64_MAX",
|
||||
__FILE__, __LINE__, CStr(expect)(), CStr(result)(), u_errorName(status));
|
||||
} else {
|
||||
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
|
||||
}
|
||||
|
@ -7040,7 +7046,8 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
FieldPosition pos;
|
||||
df.format(long_number, result, pos);
|
||||
if(U_FAILURE(status)||expect!=result) {
|
||||
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
|
||||
dataerrln("%s:%d FAIL: expected '%s' got '%s' status %s on 0",
|
||||
__FILE__, __LINE__, CStr(expect)(), CStr(result)(), u_errorName(status));
|
||||
} else {
|
||||
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
|
||||
}
|
||||
|
@ -7058,7 +7065,8 @@ void NumberFormatTest::TestFormatFastpaths() {
|
|||
FieldPosition pos;
|
||||
df.format(long_number, result, pos);
|
||||
if(U_FAILURE(status)||expect!=result) {
|
||||
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
|
||||
dataerrln("%s:%d FAIL: expected '%s' got '%s' status %s on -9223372036854775807",
|
||||
__FILE__, __LINE__, CStr(expect)(), CStr(result)(), u_errorName(status));
|
||||
} else {
|
||||
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
|
||||
}
|
||||
|
@ -7803,12 +7811,12 @@ void NumberFormatTest::TestRoundingScientific10542() {
|
|||
void NumberFormatTest::TestZeroScientific10547() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormat fmt("0.00E0", status);
|
||||
if (!assertSuccess("Formt creation", status)) {
|
||||
if (!assertSuccess("Format creation", status)) {
|
||||
return;
|
||||
}
|
||||
UnicodeString out;
|
||||
fmt.format(-0.0, out);
|
||||
assertEquals("format", "-0.00E0", out);
|
||||
assertEquals("format", "-0.00E0", out, true);
|
||||
}
|
||||
|
||||
void NumberFormatTest::verifyRounding(
|
||||
|
@ -7827,13 +7835,8 @@ void NumberFormatTest::verifyRounding(
|
|||
UnicodeString actual;
|
||||
format.format(values[j], actual);
|
||||
if (currentExpected != actual) {
|
||||
char buffer[256];
|
||||
sprintf(
|
||||
buffer,
|
||||
"For %s value %f, expected ",
|
||||
descriptions[i],
|
||||
values[j]);
|
||||
errln(UnicodeString(buffer) + currentExpected + ", got " + actual);
|
||||
dataerrln("For %s value %f, expected '%s', got '%s'",
|
||||
descriptions[i], values[j], CStr(currentExpected)(), CStr(actual)());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7862,26 +7865,24 @@ void NumberFormatTest::TestAccountingCurrency() {
|
|||
// for #5186
|
||||
void NumberFormatTest::TestEquality() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols* symbols = new DecimalFormatSymbols(Locale("root"), status);
|
||||
DecimalFormatSymbols symbols(Locale("root"), status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Fail: can't create DecimalFormatSymbols for root");
|
||||
return;
|
||||
}
|
||||
UnicodeString pattern("#,##0.###");
|
||||
DecimalFormat* fmtBase = new DecimalFormat(pattern, symbols, status);
|
||||
DecimalFormat fmtBase(pattern, symbols, status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Fail: can't create DecimalFormat using root symbols");
|
||||
return;
|
||||
}
|
||||
|
||||
DecimalFormat* fmtClone = (DecimalFormat*)fmtBase->clone();
|
||||
fmtClone->setFormatWidth(fmtBase->getFormatWidth() + 32);
|
||||
if (*fmtClone == *fmtBase) {
|
||||
DecimalFormat* fmtClone = (DecimalFormat*)fmtBase.clone();
|
||||
fmtClone->setFormatWidth(fmtBase.getFormatWidth() + 32);
|
||||
if (*fmtClone == fmtBase) {
|
||||
errln("Error: DecimalFormat == does not distinguish objects that differ only in FormatWidth");
|
||||
}
|
||||
delete fmtClone;
|
||||
|
||||
delete fmtBase;
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestCurrencyUsage() {
|
||||
|
@ -8288,21 +8289,25 @@ void NumberFormatTest::Test11739_ParseLongCurrency() {
|
|||
void NumberFormatTest::Test13035_MultiCodePointPaddingInPattern() {
|
||||
IcuTestErrorCode status(*this, "Test13035_MultiCodePointPaddingInPattern");
|
||||
DecimalFormat df(u"a*'நி'###0b", status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
UnicodeString result;
|
||||
df.format(12, result.remove());
|
||||
// TODO(13034): Re-enable this test when support is added in ICU4C.
|
||||
//assertEquals("Multi-codepoint padding should not be split", u"aநிநி12b", result);
|
||||
df = DecimalFormat(u"a*\U0001F601###0b", status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
result = df.format(12, result.remove());
|
||||
assertEquals("Single-codepoint padding should not be split", u"a\U0001F601\U0001F60112b", result);
|
||||
assertEquals("Single-codepoint padding should not be split", u"a\U0001F601\U0001F60112b", result, true);
|
||||
df = DecimalFormat(u"a*''###0b", status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
result = df.format(12, result.remove());
|
||||
assertEquals("Quote should be escapable in padding syntax", "a''12b", result);
|
||||
assertEquals("Quote should be escapable in padding syntax", "a''12b", result, true);
|
||||
}
|
||||
|
||||
void NumberFormatTest::Test13737_ParseScientificStrict() {
|
||||
IcuTestErrorCode status(*this, "Test13737_ParseScientificStrict");
|
||||
LocalPointer<NumberFormat> df(NumberFormat::createScientificInstance("en", status));
|
||||
LocalPointer<NumberFormat> df(NumberFormat::createScientificInstance("en", status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) {return;}
|
||||
df->setLenient(FALSE);
|
||||
// Parse Test
|
||||
expect(*df, u"1.2", 1.2);
|
||||
|
@ -8533,24 +8538,16 @@ void NumberFormatTest::verifyFieldPositionIterator(
|
|||
}
|
||||
|
||||
void NumberFormatTest::Test11735_ExceptionIssue() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
IcuTestErrorCode status(*this, "Test11735_ExceptionIssue");
|
||||
Locale enLocale("en");
|
||||
DecimalFormatSymbols symbols(enLocale, status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
errln((UnicodeString)
|
||||
"Fail: Construct DecimalFormatSymbols");
|
||||
if (status.isSuccess()) {
|
||||
DecimalFormat fmt("0", symbols, status);
|
||||
assertSuccess("Fail: Construct DecimalFormat formatter", status, true, __FILE__, __LINE__);
|
||||
ParsePosition ppos(0);
|
||||
fmt.parseCurrency("53.45", ppos); // NPE thrown here in ICU4J.
|
||||
assertEquals("Issue11735 ppos", 0, ppos.getIndex());
|
||||
}
|
||||
|
||||
DecimalFormat fmt("0", symbols, status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln((UnicodeString)
|
||||
"Fail: Construct DecimalFormat formatter");
|
||||
}
|
||||
|
||||
ParsePosition ppos(0);
|
||||
fmt.parseCurrency("53.45", ppos); // NPE thrown here in ICU4J.
|
||||
assertEquals("Issue11735 ppos", 0, ppos.getIndex());
|
||||
}
|
||||
|
||||
void NumberFormatTest::Test11035_FormatCurrencyAmount() {
|
||||
|
@ -8600,8 +8597,9 @@ void NumberFormatTest::Test11318_DoubleConversion() {
|
|||
|
||||
void NumberFormatTest::TestParsePercentRegression() {
|
||||
IcuTestErrorCode status(*this, "TestParsePercentRegression");
|
||||
LocalPointer<DecimalFormat> df1((DecimalFormat*) NumberFormat::createInstance("en", status));
|
||||
LocalPointer<DecimalFormat> df2((DecimalFormat*) NumberFormat::createPercentInstance("en", status));
|
||||
LocalPointer<DecimalFormat> df1((DecimalFormat*) NumberFormat::createInstance("en", status), status);
|
||||
LocalPointer<DecimalFormat> df2((DecimalFormat*) NumberFormat::createPercentInstance("en", status), status);
|
||||
if (status.isFailure()) {return; }
|
||||
df1->setLenient(TRUE);
|
||||
df2->setLenient(TRUE);
|
||||
|
||||
|
@ -8634,9 +8632,11 @@ void NumberFormatTest::TestMultiplierWithScale() {
|
|||
|
||||
// Test magnitude combined with multiplier, as shown in API docs
|
||||
DecimalFormat df("0", {"en", status}, status);
|
||||
df.setMultiplier(5);
|
||||
df.setMultiplierScale(-1);
|
||||
expect2(df, 100, u"50"); // round-trip test
|
||||
if (status.isSuccess()) {
|
||||
df.setMultiplier(5);
|
||||
df.setMultiplierScale(-1);
|
||||
expect2(df, 100, u"50"); // round-trip test
|
||||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestFastFormatInt32() {
|
||||
|
@ -8645,7 +8645,8 @@ void NumberFormatTest::TestFastFormatInt32() {
|
|||
// The two simplest formatters, old API and new API.
|
||||
// Old API should use the fastpath for ints.
|
||||
LocalizedNumberFormatter lnf = NumberFormatter::withLocale("en");
|
||||
LocalPointer<NumberFormat> df(NumberFormat::createInstance("en", status));
|
||||
LocalPointer<NumberFormat> df(NumberFormat::createInstance("en", status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) {return;}
|
||||
|
||||
double nums[] = {
|
||||
0.0,
|
||||
|
@ -8727,6 +8728,7 @@ void NumberFormatTest::TestParseNaN() {
|
|||
IcuTestErrorCode status(*this, "TestParseNaN");
|
||||
|
||||
DecimalFormat df("0", { "en", status }, status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
Formattable parseResult;
|
||||
df.parse(u"NaN", parseResult, status);
|
||||
assertEquals("NaN should parse successfully", NAN, parseResult.getDouble());
|
||||
|
@ -8754,6 +8756,7 @@ void NumberFormatTest::Test11897_LocalizedPatternSeparator() {
|
|||
DecimalFormatSymbols dfs("en", status);
|
||||
dfs.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, u"!", FALSE);
|
||||
DecimalFormat df(u"0", dfs, status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
df.applyPattern("a0;b0", status); // should not throw
|
||||
UnicodeString result;
|
||||
assertEquals("should apply the normal pattern",
|
||||
|
@ -8783,7 +8786,8 @@ void NumberFormatTest::Test13055_PercentageRounding() {
|
|||
void NumberFormatTest::Test11839() {
|
||||
IcuTestErrorCode errorCode(*this, "Test11839");
|
||||
// Ticket #11839: DecimalFormat does not respect custom plus sign
|
||||
LocalPointer<DecimalFormatSymbols> dfs(new DecimalFormatSymbols(Locale::getEnglish(), errorCode));
|
||||
LocalPointer<DecimalFormatSymbols> dfs(new DecimalFormatSymbols(Locale::getEnglish(), errorCode), errorCode);
|
||||
if (!assertSuccess("", errorCode, true, __FILE__, __LINE__)) { return; }
|
||||
dfs->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, u"a∸");
|
||||
dfs->setSymbol(DecimalFormatSymbols::kPlusSignSymbol, u"b∔"); // ∔ U+2214 DOT PLUS
|
||||
DecimalFormat df(u"0.00+;0.00-", dfs.orphan(), errorCode);
|
||||
|
@ -8818,7 +8822,8 @@ void NumberFormatTest::Test10354() {
|
|||
void NumberFormatTest::Test11645_ApplyPatternEquality() {
|
||||
IcuTestErrorCode status(*this, "Test11645_ApplyPatternEquality");
|
||||
const char16_t* pattern = u"#,##0.0#";
|
||||
LocalPointer<DecimalFormat> fmt((DecimalFormat*) NumberFormat::createInstance(status));
|
||||
LocalPointer<DecimalFormat> fmt((DecimalFormat*) NumberFormat::createInstance(status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
fmt->applyPattern(pattern, status);
|
||||
LocalPointer<DecimalFormat> fmtCopy;
|
||||
|
||||
|
@ -8866,6 +8871,7 @@ void NumberFormatTest::Test12567() {
|
|||
NumberFormat::createInstance(Locale::getUS(), UNUM_CURRENCY, errorCode));
|
||||
LocalPointer<DecimalFormat> df2((DecimalFormat *)
|
||||
NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, errorCode));
|
||||
if (!assertSuccess("", errorCode, true, __FILE__, __LINE__)) { return; }
|
||||
// NOTE: CurrencyPluralInfo equality not tested in C++ because its operator== is not defined.
|
||||
df1->applyPattern(u"0.00", errorCode);
|
||||
df2->applyPattern(u"0.00", errorCode);
|
||||
|
@ -8882,8 +8888,9 @@ void NumberFormatTest::Test11626_CustomizeCurrencyPluralInfo() {
|
|||
// change formatting spelled out currencies
|
||||
// Use locale sr because it has interesting plural rules.
|
||||
Locale locale("sr");
|
||||
LocalPointer<DecimalFormatSymbols> symbols(new DecimalFormatSymbols(locale, errorCode));
|
||||
LocalPointer<DecimalFormatSymbols> symbols(new DecimalFormatSymbols(locale, errorCode), errorCode);
|
||||
CurrencyPluralInfo info(locale, errorCode);
|
||||
if (!assertSuccess("", errorCode, true, __FILE__, __LINE__)) { return; }
|
||||
info.setCurrencyPluralPattern(u"one", u"0 qwerty", errorCode);
|
||||
info.setCurrencyPluralPattern(u"few", u"0 dvorak", errorCode);
|
||||
DecimalFormat df(u"#", symbols.orphan(), UNUM_CURRENCY_PLURAL, errorCode);
|
||||
|
@ -8934,6 +8941,7 @@ void NumberFormatTest::Test11648_ExpDecFormatMalPattern() {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
DecimalFormat fmt("0.00", {"en", status}, status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
fmt.setScientificNotation(TRUE);
|
||||
UnicodeString pattern;
|
||||
|
||||
|
@ -8950,6 +8958,7 @@ void NumberFormatTest::Test11649_DecFmtCurrencies() {
|
|||
UnicodeString pattern("\\u00a4\\u00a4\\u00a4 0.00");
|
||||
pattern = pattern.unescape();
|
||||
DecimalFormat fmt(pattern, status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
static const UChar USD[] = u"USD";
|
||||
fmt.setCurrency(USD);
|
||||
UnicodeString appendTo;
|
||||
|
@ -8968,7 +8977,8 @@ void NumberFormatTest::Test11649_DecFmtCurrencies() {
|
|||
void NumberFormatTest::Test13148_ParseGroupingSeparators() {
|
||||
IcuTestErrorCode status(*this, "Test13148");
|
||||
LocalPointer<DecimalFormat> fmt(
|
||||
(DecimalFormat*)NumberFormat::createInstance("en-ZA", status));
|
||||
(DecimalFormat*)NumberFormat::createInstance("en-ZA", status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
|
||||
DecimalFormatSymbols symbols = *fmt->getDecimalFormatSymbols();
|
||||
|
||||
|
@ -9018,6 +9028,7 @@ void NumberFormatTest::Test11020_RoundingInScientificNotation() {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols sym(Locale::getFrance(), status);
|
||||
DecimalFormat fmt(u"0.05E0", sym, status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
assertSuccess("", status);
|
||||
UnicodeString result;
|
||||
fmt.format(12301.2, result);
|
||||
|
@ -9044,7 +9055,8 @@ void NumberFormatTest::Test13763_FieldPositionIteratorOffset() {
|
|||
IcuTestErrorCode status(*this, "Test13763_FieldPositionIteratorOffset");
|
||||
FieldPositionIterator fpi;
|
||||
UnicodeString result(u"foo\U0001F4FBbar"); // 8 code units
|
||||
LocalPointer<NumberFormat> nf(NumberFormat::createInstance("en", status));
|
||||
LocalPointer<NumberFormat> nf(NumberFormat::createInstance("en", status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
nf->format(5142.3, result, &fpi, status);
|
||||
|
||||
int32_t expected[] = {
|
||||
|
@ -9061,7 +9073,8 @@ void NumberFormatTest::Test13777_ParseLongNameNonCurrencyMode() {
|
|||
IcuTestErrorCode status(*this, "Test13777_ParseLongNameNonCurrencyMode");
|
||||
|
||||
LocalPointer<NumberFormat> df(
|
||||
NumberFormat::createInstance("en-us", UNumberFormatStyle::UNUM_CURRENCY_PLURAL, status));
|
||||
NumberFormat::createInstance("en-us", UNumberFormatStyle::UNUM_CURRENCY_PLURAL, status), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
expect2(*df, 1.5, u"1.50 US dollars");
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "unicode/datefmt.h"
|
||||
#include "unicode/ucurr.h"
|
||||
#include "cmemory.h"
|
||||
#include "cstr.h"
|
||||
#include "putilimp.h"
|
||||
#include "uassert.h"
|
||||
|
||||
|
@ -1177,30 +1178,28 @@ void NumberFormatRegressionTest::Test4071859 (void)
|
|||
void NumberFormatRegressionTest::Test4093610(void)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormat *df = new DecimalFormat("#0.#", status);
|
||||
DecimalFormat df("#0.#", status);
|
||||
if (!failure(status, "new DecimalFormat")) {
|
||||
UnicodeString s("12.4");
|
||||
roundingTest(df, 12.35, s);
|
||||
roundingTest(df, 12.45, s);
|
||||
roundingTest(&df, 12.35, s);
|
||||
roundingTest(&df, 12.45, s);
|
||||
s = "12.5";
|
||||
roundingTest(df, 12.452,s);
|
||||
roundingTest(&df, 12.452,s);
|
||||
s = "12.6";
|
||||
roundingTest(df, 12.55, s);
|
||||
roundingTest(df, 12.65, s);
|
||||
roundingTest(&df, 12.55, s);
|
||||
roundingTest(&df, 12.65, s);
|
||||
s = "12.7";
|
||||
roundingTest(df, 12.652,s);
|
||||
roundingTest(&df, 12.652,s);
|
||||
s = "12.8";
|
||||
roundingTest(df, 12.75, s);
|
||||
roundingTest(df, 12.752,s);
|
||||
roundingTest(df, 12.85, s);
|
||||
roundingTest(&df, 12.75, s);
|
||||
roundingTest(&df, 12.752,s);
|
||||
roundingTest(&df, 12.85, s);
|
||||
s = "12.9";
|
||||
roundingTest(df, 12.852,s);
|
||||
roundingTest(&df, 12.852,s);
|
||||
s = "13";
|
||||
roundingTest(df, 12.95, s);
|
||||
roundingTest(df, 12.952,s);
|
||||
roundingTest(&df, 12.95, s);
|
||||
roundingTest(&df, 12.952,s);
|
||||
}
|
||||
|
||||
delete df;
|
||||
}
|
||||
|
||||
void NumberFormatRegressionTest::roundingTest(DecimalFormat *df, double x, UnicodeString& expected)
|
||||
|
@ -1209,8 +1208,9 @@ void NumberFormatRegressionTest::roundingTest(DecimalFormat *df, double x, Unico
|
|||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
out = df->format(x, out, pos);
|
||||
logln(UnicodeString("") + x + " formats with 1 fractional digits to " + out);
|
||||
if (out != expected)
|
||||
errln("FAIL: Expected " + expected);
|
||||
if (out != expected) {
|
||||
dataerrln("FAIL: Expected '%s'; got '%s'", CStr(expected)(), CStr(out)());
|
||||
}
|
||||
}
|
||||
/* @bug 4098741
|
||||
* Tests the setMaximumFractionDigits limit.
|
||||
|
@ -1892,9 +1892,11 @@ void NumberFormatRegressionTest::Test4134300(void) {
|
|||
void NumberFormatRegressionTest::Test4140009(void)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status);
|
||||
failure(status, "new DecimalFormatSymbols");
|
||||
DecimalFormat *f = new DecimalFormat(UnicodeString(""), syms, status);
|
||||
LocalPointer<DecimalFormatSymbols> syms(new DecimalFormatSymbols(Locale::getEnglish(), status), status);
|
||||
if (failure(status, "new DecimalFormatSymbols")) {
|
||||
return;
|
||||
}
|
||||
DecimalFormat *f = new DecimalFormat(UnicodeString(u""), syms.orphan(), status);
|
||||
if (!failure(status, "new DecimalFormat")) {
|
||||
UnicodeString s;
|
||||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
|
@ -2216,6 +2218,9 @@ void NumberFormatRegressionTest::Test4170798(void) {
|
|||
IcuTestErrorCode status(*this, "Test4170798");
|
||||
LocalPointer<DecimalFormat> df(dynamic_cast<DecimalFormat*>(
|
||||
NumberFormat::createInstance(Locale::getUS(), status)), status);
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
return;
|
||||
}
|
||||
{
|
||||
Formattable n;
|
||||
ParsePosition pos(0);
|
||||
|
|
|
@ -931,9 +931,9 @@ void RBBIMonkeyTest::testMonkey() {
|
|||
int32_t i;
|
||||
for (i=0; tests[i] != NULL; ++i) {
|
||||
logln("beginning testing of %s", tests[i]);
|
||||
RBBIMonkeyImpl *test = new RBBIMonkeyImpl(status);
|
||||
LocalPointer<RBBIMonkeyImpl> test(new RBBIMonkeyImpl(status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln("%s:%d: error %s while starting test %s.", __FILE__, __LINE__, u_errorName(status), tests[i]);
|
||||
dataerrln("%s:%d: error %s while starting test %s.", __FILE__, __LINE__, u_errorName(status), tests[i]);
|
||||
break;
|
||||
}
|
||||
test->fDumpExpansions = dumpExpansions;
|
||||
|
@ -942,11 +942,11 @@ void RBBIMonkeyTest::testMonkey() {
|
|||
test->fLoopCount = loopCount;
|
||||
test->setup(tests[i], status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("%s:%d: error %s while starting test %s.", __FILE__, __LINE__, u_errorName(status), tests[i]);
|
||||
dataerrln("%s:%d: error %s while starting test %s.", __FILE__, __LINE__, u_errorName(status), tests[i]);
|
||||
break;
|
||||
}
|
||||
test->startTest();
|
||||
startedTests.addElement(test, status);
|
||||
startedTests.addElement(test.orphan(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("%s:%d: error %s while starting test %s.", __FILE__, __LINE__, u_errorName(status), tests[i]);
|
||||
break;
|
||||
|
|
|
@ -1059,7 +1059,7 @@ void RBBITest::TestExtended() {
|
|||
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ICU Error %s while parsing test file at line %d.",
|
||||
dataerrln("ICU Error %s while parsing test file at line %d.",
|
||||
u_errorName(status), lineNum);
|
||||
status = U_ZERO_ERROR;
|
||||
goto end_test; // Stop the test
|
||||
|
@ -4472,21 +4472,23 @@ void RBBITest::TestReverse() {
|
|||
|
||||
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
|
||||
BreakIterator::createCharacterInstance(Locale::getEnglish(), status)));
|
||||
assertSuccess(WHERE, status);
|
||||
assertSuccess(WHERE, status, true);
|
||||
status = U_ZERO_ERROR;
|
||||
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
|
||||
BreakIterator::createWordInstance(Locale::getEnglish(), status)));
|
||||
assertSuccess(WHERE, status);
|
||||
assertSuccess(WHERE, status, true);
|
||||
status = U_ZERO_ERROR;
|
||||
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
|
||||
BreakIterator::createLineInstance(Locale::getEnglish(), status)));
|
||||
assertSuccess(WHERE, status);
|
||||
assertSuccess(WHERE, status, true);
|
||||
status = U_ZERO_ERROR;
|
||||
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
|
||||
BreakIterator::createSentenceInstance(Locale::getEnglish(), status)));
|
||||
assertSuccess(WHERE, status);
|
||||
assertSuccess(WHERE, status, true);
|
||||
}
|
||||
|
||||
void RBBITest::TestReverse(std::unique_ptr<RuleBasedBreakIterator>bi) {
|
||||
if (!bi) {
|
||||
errln(WHERE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4546,6 +4548,9 @@ void RBBITest::TestBug13692() {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<RuleBasedBreakIterator> bi ((RuleBasedBreakIterator *)
|
||||
BreakIterator::createWordInstance(Locale::getEnglish(), status), status);
|
||||
if (!assertSuccess(WHERE, status, true)) {
|
||||
return;
|
||||
}
|
||||
constexpr int32_t LENGTH = 1000000;
|
||||
UnicodeString longNumber(LENGTH, (UChar32)u'3', LENGTH);
|
||||
for (int i=0; i<20; i+=2) {
|
||||
|
@ -4565,6 +4570,9 @@ void RBBITest::TestDebug(void) {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<RuleBasedBreakIterator> bi ((RuleBasedBreakIterator *)
|
||||
BreakIterator::createCharacterInstance(Locale::getEnglish(), status), status);
|
||||
if (!assertSuccess(WHERE, status, true)) {
|
||||
return;
|
||||
}
|
||||
const UnicodeString &rules = bi->getRules();
|
||||
UParseError pe;
|
||||
LocalPointer<RuleBasedBreakIterator> newbi(new RuleBasedBreakIterator(rules, pe, status));
|
||||
|
|
|
@ -473,6 +473,10 @@ void TestIDNA::testAPI(const UChar* src, const UChar* expected, const char* test
|
|||
|
||||
// test null-terminated source and return value of number of UChars required
|
||||
destLen = func(src,-1,NULL,0,options, &parseError , &status);
|
||||
if (status == U_FILE_ACCESS_ERROR) {
|
||||
dataerrln("U_FILE_ACCESS_ERROR. Skipping the remainder of this test.");
|
||||
return;
|
||||
}
|
||||
if(status == U_BUFFER_OVERFLOW_ERROR){
|
||||
status = U_ZERO_ERROR; // reset error code
|
||||
if(destLen+1 < MAX_DEST_SIZE){
|
||||
|
@ -1297,17 +1301,25 @@ void TestIDNA::TestIDNToUnicode(){
|
|||
testIDNToUnicode("uidna_IDNToUnicode", uidna_IDNToUnicode);
|
||||
}
|
||||
void TestIDNA::TestCompare(){
|
||||
testCompare("uidna_compare",uidna_compare);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
uidna_close(uidna_openUTS46(0, &status)); // Fail quickly if no data.
|
||||
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
testCompare("uidna_compare",uidna_compare);
|
||||
}
|
||||
}
|
||||
void TestIDNA::TestErrorCases(){
|
||||
testErrorCases( "uidna_IDNToASCII",uidna_IDNToASCII,
|
||||
"uidna_IDNToUnicode",uidna_IDNToUnicode);
|
||||
}
|
||||
void TestIDNA::TestRootLabelSeparator(){
|
||||
testRootLabelSeparator( "uidna_compare",uidna_compare,
|
||||
"uidna_IDNToASCII", uidna_IDNToASCII,
|
||||
"uidna_IDNToUnicode",uidna_IDNToUnicode
|
||||
);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
uidna_close(uidna_openUTS46(0, &status)); // Fail quickly if no data.
|
||||
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
|
||||
testRootLabelSeparator( "uidna_compare",uidna_compare,
|
||||
"uidna_IDNToASCII", uidna_IDNToASCII,
|
||||
"uidna_IDNToUnicode",uidna_IDNToUnicode
|
||||
);
|
||||
}
|
||||
}
|
||||
void TestIDNA::TestChaining(){
|
||||
testChaining("uidna_toASCII",uidna_toASCII, "uidna_toUnicode", uidna_toUnicode);
|
||||
|
@ -1529,14 +1541,14 @@ void TestIDNA::TestCompareReferenceImpl(){
|
|||
int32_t srcLen = 0;
|
||||
|
||||
// data even OK?
|
||||
{
|
||||
UErrorCode dataStatus = U_ZERO_ERROR;
|
||||
loadTestData(dataStatus);
|
||||
if(U_FAILURE(dataStatus)) {
|
||||
UErrorCode dataStatus = U_ZERO_ERROR;
|
||||
loadTestData(dataStatus);
|
||||
if(U_FAILURE(dataStatus)) {
|
||||
dataerrln("Couldn't load test data: %s\n", u_errorName(dataStatus)); // save us from thousands and thousands of errors
|
||||
return;
|
||||
}
|
||||
}
|
||||
uidna_close(uidna_openUTS46(0, &dataStatus)); // Fail quickly if no data.
|
||||
if (!assertSuccess("", dataStatus, true, __FILE__, __LINE__)) { return; }
|
||||
|
||||
for (int32_t i = 0; i <= 0x10FFFF; i++){
|
||||
if (quick == TRUE && i > 0x0FFF){
|
||||
|
@ -1561,13 +1573,9 @@ void TestIDNA::TestCompareReferenceImpl(){
|
|||
|
||||
void TestIDNA::TestRefIDNA(){
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
getInstance(status); // Init prep
|
||||
if (U_FAILURE(status)) {
|
||||
if (status == U_FILE_ACCESS_ERROR) {
|
||||
dataerrln("Test could not initialize. Got %s", u_errorName(status));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
getInstance(status); // Init prep. Abort test early if no data.
|
||||
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
|
||||
|
||||
testToASCII("idnaref_toASCII", idnaref_toASCII);
|
||||
testToUnicode("idnaref_toUnicode", idnaref_toUnicode);
|
||||
|
|
Loading…
Add table
Reference in a new issue