X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..e4f10fab0c078f399c9deef476d9c9b73b47dff8:/icuSources/test/intltest/dcfmtest.cpp diff --git a/icuSources/test/intltest/dcfmtest.cpp b/icuSources/test/intltest/dcfmtest.cpp index 00b1b6fe..89788b5c 100644 --- a/icuSources/test/intltest/dcfmtest.cpp +++ b/icuSources/test/intltest/dcfmtest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2010, International Business Machines Corporation and + * Copyright (c) 2002-2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -112,7 +112,7 @@ InvariantStringPiece::InvariantStringPiece(const UnicodeString &s) { } // Buffer size is len+1 so that s.extract() will nul-terminate the string. s.extract(0, len, buf.getAlias(), len+1, US_INV); - this->set(buf, len); + this->set(buf.getAlias(), len); } @@ -138,7 +138,7 @@ UnicodeStringPiece::UnicodeStringPiece(const UnicodeString &s) { capacity = requiredCapacity; s.extract(0, len, buf.getAlias(), capacity); } - this->set(buf, requiredCapacity - 1); + this->set(buf.getAlias(), requiredCapacity - 1); } @@ -213,9 +213,9 @@ void DecimalFormatTest::DataDrivenTests() { RegexMatcher formatLineMat(UnicodeString( "(?i)\\s*format\\s+" "(\\S+)\\s+" // Capture group 1: pattern - "(ceiling|floor|down|up|halfeven|halfdown|halfup|default)\\s+" // Capture group 2: Rounding Mode + "(ceiling|floor|down|up|halfeven|halfdown|halfup|default|unnecessary)\\s+" // Capture group 2: Rounding Mode "\"([^\"]*)\"\\s+" // Capture group 3: input - "\"([^\"]*)\"" // Capture group 4: expected output + "\"([^\"]*)\"" // Capture group 4: expected output "\\s*(?:#.*)?"), // Trailing comment 0, status); @@ -234,7 +234,7 @@ void DecimalFormatTest::DataDrivenTests() { while (lineMat.find()) { lineNum++; if (U_FAILURE(status)) { - errln("File dcfmtest.txt, line %d: ICU Error \"%s\"", lineNum, u_errorName(status)); + dataerrln("File dcfmtest.txt, line %d: ICU Error \"%s\"", lineNum, u_errorName(status)); } status = U_ZERO_ERROR; @@ -280,6 +280,15 @@ void DecimalFormatTest::DataDrivenTests() { formatLineMat.group(2, status), // rounding mode formatLineMat.group(3, status), // input decimal number formatLineMat.group(4, status), // expected formatted result + kFormattable, + status); + + execFormatTest(lineNum, + formatLineMat.group(1, status), // Pattern + formatLineMat.group(2, status), // rounding mode + formatLineMat.group(3, status), // input decimal number + formatLineMat.group(4, status), // expected formatted result + kStringPiece, status); continue; } @@ -312,7 +321,7 @@ void DecimalFormatTest::execParseTest(int32_t lineNum, DecimalFormat format(pattern, symbols, status); Formattable result; if (U_FAILURE(status)) { - errln("file dcfmtest.txt, line %d: %s error creating the formatter.", + dataerrln("file dcfmtest.txt, line %d: %s error creating the formatter.", lineNum, u_errorName(status)); return; } @@ -368,6 +377,7 @@ void DecimalFormatTest::execFormatTest(int32_t lineNum, const UnicodeString &round, // rounding mode const UnicodeString &input, // input decimal number const UnicodeString &expected, // expected formatted result + EFormatInputType inType, // input number type UErrorCode &status) { if (U_FAILURE(status)) { return; @@ -377,7 +387,7 @@ void DecimalFormatTest::execFormatTest(int32_t lineNum, // printf("Pattern = %s\n", UnicodeStringPiece(pattern).data()); DecimalFormat fmtr(pattern, symbols, status); if (U_FAILURE(status)) { - errln("file dcfmtest.txt, line %d: %s error creating the formatter.", + dataerrln("file dcfmtest.txt, line %d: %s error creating the formatter.", lineNum, u_errorName(status)); return; } @@ -397,30 +407,49 @@ void DecimalFormatTest::execFormatTest(int32_t lineNum, fmtr.setRoundingMode(DecimalFormat::kRoundHalfUp); } else if (round=="default") { // don't set any value. + } else if (round=="unnecessary") { + fmtr.setRoundingMode(DecimalFormat::kRoundUnnecessary); } else { fmtr.setRoundingMode(DecimalFormat::kRoundFloor); errln("file dcfmtest.txt, line %d: Bad rounding mode \"%s\"", lineNum, UnicodeStringPiece(round).data()); } - + + const char *typeStr; UnicodeString result; UnicodeStringPiece spInput(input); - //fmtr.format(spInput, result, NULL, status); - Formattable fmtbl; - fmtbl.setDecimalNumber(spInput, status); - //NumberFormat &nfmtr = fmtr; - fmtr.format(fmtbl, result, NULL, status); + switch (inType) { + case kFormattable: + { + typeStr = "Formattable"; + Formattable fmtbl; + fmtbl.setDecimalNumber(spInput, status); + fmtr.format(fmtbl, result, NULL, status); + } + break; + case kStringPiece: + typeStr = "StringPiece"; + fmtr.format(spInput, result, NULL, status); + break; + } + + if ((status == U_FORMAT_INEXACT_ERROR) && (result == "") && (expected == "Inexact")) { + // Test succeeded. + status = U_ZERO_ERROR; + return; + } if (U_FAILURE(status)) { - errln("file dcfmtest.txt, line %d: format() returned %s.", - lineNum, u_errorName(status)); + errln("[%s] file dcfmtest.txt, line %d: format() returned %s.", + typeStr, lineNum, u_errorName(status)); + status = U_ZERO_ERROR; return; } if (result != expected) { - errln("file dcfmtest.txt, line %d: expected \"%s\", got \"%s\"", - lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data()); + errln("[%s] file dcfmtest.txt, line %d: expected \"%s\", got \"%s\"", + typeStr, lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data()); } }