+// Test bug9042
+void TimeUnitTest::testGreekWithSanitization() {
+
+ UErrorCode status = U_ZERO_ERROR;
+ Locale elLoc("el");
+ NumberFormat* numberFmt = NumberFormat::createInstance(Locale("el"), status);
+ if (!assertSuccess("NumberFormat::createInstance for el locale", status, TRUE)) return;
+ numberFmt->setMaximumFractionDigits(1);
+
+ TimeUnitFormat* timeUnitFormat = new TimeUnitFormat(elLoc, status);
+ if (!assertSuccess("TimeUnitFormat::TimeUnitFormat for el locale", status)) return;
+
+ timeUnitFormat->setNumberFormat(*numberFmt, status);
+
+ delete numberFmt;
+ delete timeUnitFormat;
+}
+
+void TimeUnitTest::test10219Plurals() {
+ Locale usLocale("en_US");
+ double values[2] = {1.588, 1.011};
+ UnicodeString expected[2][3] = {
+ {"1 minute", "1.5 minutes", "1.58 minutes"},
+ {"1 minute", "1.0 minutes", "1.01 minutes"}
+ };
+ UErrorCode status = U_ZERO_ERROR;
+ TimeUnitFormat tuf(usLocale, status);
+ if (U_FAILURE(status)) {
+ dataerrln("generating TimeUnitFormat Object failed: %s", u_errorName(status));
+ return;
+ }
+ LocalPointer<DecimalFormat> nf((DecimalFormat *) NumberFormat::createInstance(usLocale, status));
+ if (U_FAILURE(status)) {
+ dataerrln("generating NumberFormat Object failed: %s", u_errorName(status));
+ return;
+ }
+ for (int32_t j = 0; j < LENGTHOF(values); ++j) {
+ for (int32_t i = 0; i < LENGTHOF(expected[j]); ++i) {
+ nf->setMinimumFractionDigits(i);
+ nf->setMaximumFractionDigits(i);
+ nf->setRoundingMode(DecimalFormat::kRoundDown);
+ tuf.setNumberFormat(*nf, status);
+ if (U_FAILURE(status)) {
+ dataerrln("setting NumberFormat failed: %s", u_errorName(status));
+ return;
+ }
+ UnicodeString actual;
+ Formattable fmt;
+ LocalPointer<TimeUnitAmount> tamt(new TimeUnitAmount(values[j], TimeUnit::UTIMEUNIT_MINUTE, status));
+ if (U_FAILURE(status)) {
+ dataerrln("generating TimeUnitAmount Object failed: %s", u_errorName(status));
+ return;
+ }
+ fmt.adoptObject(tamt.orphan());
+ tuf.format(fmt, actual, status);
+ if (U_FAILURE(status)) {
+ dataerrln("Actual formatting failed: %s", u_errorName(status));
+ return;
+ }
+ if (expected[j][i] != actual) {
+ errln("Expected " + expected[j][i] + ", got " + actual);
+ }
+ }
+ }
+
+ // test parsing
+ Formattable result;
+ ParsePosition pos;
+ UnicodeString formattedString = "1 minutes";
+ tuf.parseObject(formattedString, result, pos);
+ if (formattedString.length() != pos.getIndex()) {
+ errln("Expect parsing to go all the way to the end of the string.");
+ }
+}
+