From 3402a7cc547c0c50902b9ab3c19cab9d1bd00ca6 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 12 Jun 2003 18:02:40 +0000 Subject: [PATCH] ICU-2039 format code coverage improvements X-SVN-Rev: 12492 --- icu4c/source/test/intltest/dcfmapts.cpp | 32 ++++++++++++++++++++++++- icu4c/source/test/intltest/incaltst.cpp | 2 +- icu4c/source/test/intltest/itrbnf.cpp | 20 ++++++++++++++++ icu4c/source/test/intltest/pptest.cpp | 7 ++++++ icu4c/source/test/intltest/tchcfmt.cpp | 22 +++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp index 9470ac83862..3fc9de4bc1d 100644 --- a/icu4c/source/test/intltest/dcfmapts.cpp +++ b/icu4c/source/test/intltest/dcfmapts.cpp @@ -12,6 +12,7 @@ #include "unicode/decimfmt.h" #include "unicode/dcfmtsym.h" +#include "unicode/parseerr.h" // This is an API test, not a unit test. It doesn't test very many cases, and doesn't // try to test the full functionality. It just calls each function in the class and @@ -297,7 +298,15 @@ void IntlTestDecimalFormatAPI::testAPI(/*char *par*/) errln((UnicodeString)"ERROR: toPattern() result did not match pattern applied"); } - UnicodeString p2("#,##0.0# FF;(#,##0.0# FF)"); + if(pat.getSecondaryGroupingSize() != 0) { + errln("FAIL: Secondary Grouping Size should be 0, not %d\n", pat.getSecondaryGroupingSize()); + } + + if(pat.getGroupingSize() != 3) { + errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize()); + } + + UnicodeString p2("#,##,##0.0# FF;(#,##,##0.0# FF)"); logln((UnicodeString)"Applying pattern " + p2); status = U_ZERO_ERROR; pat.applyLocalizedPattern(p2, status); @@ -311,6 +320,27 @@ void IntlTestDecimalFormatAPI::testAPI(/*char *par*/) errln((UnicodeString)"ERROR: toLocalizedPattern() result did not match pattern applied"); } + status = U_ZERO_ERROR; + UParseError pe; + pat.applyLocalizedPattern(p2, pe, status); + if(U_FAILURE(status)) { + errln((UnicodeString)"ERROR: applyPattern((with ParseError)) failed with " + (int32_t) status); + } + UnicodeString s4; + s4 = pat.toLocalizedPattern(s3); + logln((UnicodeString)"Extracted pattern is " + s4); + if(s4 != p2) { + errln((UnicodeString)"ERROR: toLocalizedPattern(with ParseErr) result did not match pattern applied"); + } + + if(pat.getSecondaryGroupingSize() != 2) { + errln("FAIL: Secondary Grouping Size should be 2, not %d\n", pat.getSecondaryGroupingSize()); + } + + if(pat.getGroupingSize() != 3) { + errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize()); + } + // ======= Test getStaticClassID() logln((UnicodeString)"Testing getStaticClassID()"); diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp index 90dff4993fa..44cb39b7ff4 100644 --- a/icu4c/source/test/intltest/incaltst.cpp +++ b/icu4c/source/test/intltest/incaltst.cpp @@ -60,7 +60,7 @@ static UnicodeString calToStr(const Calendar & cal) { UnicodeString out; - UErrorCode status; + UErrorCode status = U_ZERO_ERROR; int i; for(i = 0;iformat(4.5,result); + if(result != expected) { + errln("Formatted 4.5, expected " + expected + " got " + result); + } else { + logln("Formatted 4.5, expected " + expected + " got " + result); + } + result.remove(); + expected = "four"; + formatter->format((long)4,result); + if(result != expected) { + errln("Formatted 4, expected " + expected + " got " + result); + } else { + logln("Formatted 4, expected " + expected + " got " + result); + } + + // clean up logln("Cleaning up"); delete formatter; diff --git a/icu4c/source/test/intltest/pptest.cpp b/icu4c/source/test/intltest/pptest.cpp index 4a39fe0c991..954a1bd1d96 100644 --- a/icu4c/source/test/intltest/pptest.cpp +++ b/icu4c/source/test/intltest/pptest.cpp @@ -103,6 +103,13 @@ void ParsePositionTest::TestFieldPosition() errln("*** FP constructor(int) or getField"); } + FieldPosition fpc(fp); + if (fpc.getField() == 7) { + logln("FP Constructor(FP&) passed"); + } else { + errln("*** FP Constructor(FP&)"); + } + FieldPosition fph( 3 ); if ( fph.getField() != 3) errln("*** FP getField or heap constr."); diff --git a/icu4c/source/test/intltest/tchcfmt.cpp b/icu4c/source/test/intltest/tchcfmt.cpp index e96f4da4c8d..9a962a5bd2d 100644 --- a/icu4c/source/test/intltest/tchcfmt.cpp +++ b/icu4c/source/test/intltest/tchcfmt.cpp @@ -509,6 +509,28 @@ void TestChoiceFormat::TestClosures(void) { errln("FAIL: fmt1 != fmt2"); } + int32_t i; + int32_t count2 = 0; + const double *limits2 = fmt2.getLimits(count2); + const UBool *closures2 = fmt2.getClosures(count2); + + if(count2 != 6 || !limits2 || !closures2) { + errln("FAIL: couldn't get limits or closures"); + } else { + for(i=0;i */ ",1)",