From: Travis Keep Date: Mon, 15 Sep 2014 18:59:23 +0000 (+0000) Subject: ICU-10999 Mark Davis' review comments applied to C++ X-Git-Tag: milestone-59-0-1~1515 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ede5c1dc6c5855c8769935fc0e491e002d0f023;p=icu ICU-10999 Mark Davis' review comments applied to C++ X-SVN-Rev: 36507 --- diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp index 221d6416634..2a229736df8 100644 --- a/icu4c/source/test/intltest/measfmttest.cpp +++ b/icu4c/source/test/intltest/measfmttest.cpp @@ -48,6 +48,8 @@ private: void TestFormatSingleArg(); void TestFormatMeasuresZeroArg(); void TestMultiplesWithPer(); + void TestSimplePer(); + void TestNumeratorPlurals(); void TestMultiples(); void TestGram(); void TestCurrencies(); @@ -76,6 +78,13 @@ private: const MeasureFormat &fmt, const ExpectedResult *expectedResults, int32_t count); + void helperTestSimplePer( + const Locale &locale, + UMeasureFormatWidth width, + double value, + const MeasureUnit &unit, + const MeasureUnit &perUnit, + const char *expected); void helperTestMultiplesWithPer( const Locale &locale, UMeasureFormatWidth width, @@ -123,6 +132,8 @@ void MeasureFormatTest::runIndexedTest( TESTCASE_AUTO(TestFormatSingleArg); TESTCASE_AUTO(TestFormatMeasuresZeroArg); TESTCASE_AUTO(TestMultiplesWithPer); + TESTCASE_AUTO(TestSimplePer); + TESTCASE_AUTO(TestNumeratorPlurals); TESTCASE_AUTO(TestMultiples); TESTCASE_AUTO(TestGram); TESTCASE_AUTO(TestCurrencies); @@ -886,6 +897,81 @@ void MeasureFormatTest::TestMultiplesWithPer() { en, UMEASFMT_WIDTH_NARROW, *minute, "2mi 1\\u2032 2.3\\u2033/m"); } +void MeasureFormatTest::TestSimplePer() { + Locale en("en"); + UErrorCode status = U_ZERO_ERROR; + LocalPointer second(MeasureUnit::createSecond(status)); + LocalPointer minute(MeasureUnit::createMinute(status)); + LocalPointer pound(MeasureUnit::createPound(status)); + if (!assertSuccess("", status)) { + return; + } + + helperTestSimplePer( + en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *second, "1 lbps"); + helperTestSimplePer( + en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *second, "2 lbps"); + helperTestSimplePer( + en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *minute, "1 lb/min"); + helperTestSimplePer( + en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *minute, "2 lb/min"); +} + +void MeasureFormatTest::TestNumeratorPlurals() { + Locale pl("pl"); + UErrorCode status = U_ZERO_ERROR; + LocalPointer second(MeasureUnit::createSecond(status)); + LocalPointer foot(MeasureUnit::createFoot(status)); + if (!assertSuccess("", status)) { + return; + } + + helperTestSimplePer( + pl, UMEASFMT_WIDTH_WIDE, 1.0, *foot, *second, "1 stopa na sekund\\u0119"); + helperTestSimplePer( + pl, UMEASFMT_WIDTH_WIDE, 2.0, *foot, *second, "2 stopy na sekund\\u0119"); + helperTestSimplePer( + pl, UMEASFMT_WIDTH_WIDE, 5.0, *foot, *second, "5 st\u00f3p na sekund\\u0119"); + helperTestSimplePer( + pl, UMEASFMT_WIDTH_WIDE, 1.5, *foot, *second, "1,5 stopy na sekund\\u0119"); +} + + + +void MeasureFormatTest::helperTestSimplePer( + const Locale &locale, + UMeasureFormatWidth width, + double value, + const MeasureUnit &unit, + const MeasureUnit &perUnit, + const char *expected) { + UErrorCode status = U_ZERO_ERROR; + FieldPosition pos(0); + MeasureFormat fmt(locale, width, status); + if (!assertSuccess("Error creating format object", status)) { + return; + } + Measure measure(value, (MeasureUnit *) unit.clone(), status); + if (!assertSuccess("Error creating measure object", status)) { + return; + } + UnicodeString buffer; + fmt.formatMeasuresPer( + &measure, + 1, + perUnit, + buffer, + pos, + status); + if (!assertSuccess("Error formatting measures with per", status)) { + return; + } + assertEquals( + "TestSimplePer", + UnicodeString(expected).unescape(), + buffer); +} + void MeasureFormatTest::helperTestMultiplesWithPer( const Locale &locale, UMeasureFormatWidth width,