+void DateIntervalFormatTest::testTicket11583_2() {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<DateIntervalFormat> fmt(
+ DateIntervalFormat::createInstance("yMMM", "es-US", status));
+ if (!assertSuccess("Error create format object", status)) {
+ return;
+ }
+ DateInterval interval((UDate) 1232364615000.0, (UDate) 1328787015000.0);
+ UnicodeString appendTo;
+ FieldPosition fpos(FieldPosition::DONT_CARE);
+ UnicodeString expected("ene. 2009\\u2009\\u2013\\u2009feb. 2012");
+ assertEquals(
+ "",
+ expected.unescape(),
+ fmt->format(&interval, appendTo, fpos, status));
+ if (!assertSuccess("Error formatting", status)) {
+ return;
+ }
+}
+
+
+void DateIntervalFormatTest::testTicket11985() {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<DateIntervalFormat> fmt(
+ DateIntervalFormat::createInstance(UDAT_HOUR_MINUTE, Locale::getEnglish(), status));
+ if (!assertSuccess("createInstance", status)) {
+ return;
+ }
+ UnicodeString pattern;
+ static_cast<const SimpleDateFormat*>(fmt->getDateFormat())->toPattern(pattern);
+ assertEquals("Format pattern", "h:mm a", pattern);
+}
+
+// Ticket 11669 - thread safety of DateIntervalFormat::format(). This test failed before
+// the implementation was fixed.
+
+static const DateIntervalFormat *gIntervalFormatter = NULL; // The Formatter to be used concurrently by test threads.
+static const DateInterval *gInterval = NULL; // The date interval to be formatted concurrently.
+static const UnicodeString *gExpectedResult = NULL;
+
+void DateIntervalFormatTest::threadFunc11669(int32_t threadNum) {
+ (void)threadNum;
+ for (int loop=0; loop<1000; ++loop) {
+ UErrorCode status = U_ZERO_ERROR;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ UnicodeString result;
+ gIntervalFormatter->format(gInterval, result, pos, status);
+ if (U_FAILURE(status)) {
+ errln("%s:%d %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+ if (result != *gExpectedResult) {
+ errln("%s:%d Expected \"%s\", got \"%s\"", __FILE__, __LINE__, CStr(*gExpectedResult)(), CStr(result)());
+ return;
+ }
+ }
+}
+
+void DateIntervalFormatTest::testTicket11669() {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<DateIntervalFormat> formatter(DateIntervalFormat::createInstance(UDAT_YEAR_MONTH_DAY, Locale::getEnglish(), status), status);
+ LocalPointer<TimeZone> tz(TimeZone::createTimeZone("America/Los_Angleles"), status);
+ LocalPointer<Calendar> intervalStart(Calendar::createInstance(*tz, Locale::getEnglish(), status), status);
+ LocalPointer<Calendar> intervalEnd(Calendar::createInstance(*tz, Locale::getEnglish(), status), status);
+ if (U_FAILURE(status)) {
+ errcheckln(status, "%s:%d %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ intervalStart->set(2009, 6, 1, 14, 0);
+ intervalEnd->set(2009, 6, 2, 14, 0);
+ DateInterval interval(intervalStart->getTime(status), intervalEnd->getTime(status));
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ UnicodeString expectedResult;
+ formatter->format(&interval, expectedResult, pos, status);
+ if (U_FAILURE(status)) {
+ errln("%s:%d %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ gInterval = &interval;
+ gIntervalFormatter = formatter.getAlias();
+ gExpectedResult = &expectedResult;
+
+ ThreadPool<DateIntervalFormatTest> threads(this, 4, &DateIntervalFormatTest::threadFunc11669);
+ threads.start();
+ threads.join();
+
+ gInterval = NULL; // Don't leave dangling pointers lying around. Not strictly necessary.
+ gIntervalFormatter = NULL;
+ gExpectedResult = NULL;
+}
+
+
+// testTicket12065
+// Using a DateIntervalFormat to format shouldn't change its state in any way
+// that changes how the behavior of operator ==.
+void DateIntervalFormatTest::testTicket12065() {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<DateIntervalFormat> formatter(DateIntervalFormat::createInstance(UDAT_YEAR_MONTH_DAY, Locale::getEnglish(), status), status);
+ if (formatter.isNull()) {
+ dataerrln("FAIL: DateIntervalFormat::createInstance failed for Locale::getEnglish()");
+ return;
+ }
+ LocalPointer<DateIntervalFormat> clone(dynamic_cast<DateIntervalFormat *>(formatter->clone()));
+ if (*formatter != *clone) {
+ errln("%s:%d DateIntervalFormat and clone are not equal.", __FILE__, __LINE__);
+ return;
+ }
+ DateInterval interval((UDate) 1232364615000.0, (UDate) 1328787015000.0);
+ UnicodeString appendTo;
+ FieldPosition fpos(FieldPosition::DONT_CARE);
+ formatter->format(&interval, appendTo, fpos, status);
+ if (*formatter != *clone) {
+ errln("%s:%d DateIntervalFormat and clone are not equal after formatting.", __FILE__, __LINE__);
+ return;
+ }
+ if (U_FAILURE(status)) {
+ errln("%s:%d %s", __FILE__, __LINE__, u_errorName(status));
+ }
+}
+
+