+ {
+ // We make sure that setDateIntervalInfo does not corrupt the cache. See ticket 9919.
+ status = U_ZERO_ERROR;
+ logln("Testing DateIntervalFormat setDateIntervalInfo");
+ const Locale &enLocale = Locale::getEnglish();
+ LocalPointer<DateIntervalFormat> dif(DateIntervalFormat::createInstance("yMd", enLocale, status));
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ UnicodeString expected;
+ LocalPointer<Calendar> fromTime(Calendar::createInstance(enLocale, status));
+ LocalPointer<Calendar> toTime(Calendar::createInstance(enLocale, status));
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ FieldPosition pos = 0;
+ fromTime->set(2013, 3, 26);
+ toTime->set(2013, 3, 28);
+ dif->format(*fromTime, *toTime, expected, pos, status);
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ LocalPointer<DateIntervalInfo> dii(new DateIntervalInfo(Locale::getEnglish(), status));
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ dii->setIntervalPattern(ctou("yMd"), UCAL_DATE, ctou("M/d/y \\u2013 d"), status);
+ dif->setDateIntervalInfo(*dii, status);
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ dif.adoptInstead(DateIntervalFormat::createInstance("yMd", enLocale, status));
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ UnicodeString actual;
+ pos = 0;
+ dif->format(*fromTime, *toTime, actual, pos, status);
+ if (U_FAILURE(status)) {
+ errln("Failure encountered: %s", u_errorName(status));
+ return;
+ }
+ if (expected != actual) {
+ errln("DateIntervalFormat.setIntervalInfo should have no side effects.");
+ }
+ }
+