static void TestDateIntervalFormat() { const DateIntervalFormatTestItem * testItemPtr; UErrorCode status = U_ZERO_ERROR; ctest_setTimeZone(NULL, &status); log_verbose("\nTesting udtitvfmt_open() and udtitvfmt_format() with various parameters\n"); for ( testItemPtr = testItems; testItemPtr->locale != NULL; ++testItemPtr ) { UDateIntervalFormat* udtitvfmt; int32_t tzidLen; UChar skelBuf[kSkelBufLen]; UChar tzidBuf[kTZIDBufLen]; const char * tzidForLog = (testItemPtr->tzid)? testItemPtr->tzid: "NULL"; status = U_ZERO_ERROR; u_unescape(testItemPtr->skeleton, skelBuf, kSkelBufLen); if ( testItemPtr->tzid ) { u_unescape(testItemPtr->tzid, tzidBuf, kTZIDBufLen); tzidLen = -1; } else { tzidLen = 0; } udtitvfmt = udtitvfmt_open(testItemPtr->locale, skelBuf, -1, tzidBuf, tzidLen, &status); if ( U_SUCCESS(status) ) { UChar result[kFormatBufLen]; UChar resultExpected[kFormatBufLen]; int32_t fmtLen = udtitvfmt_format(udtitvfmt, testItemPtr->from, testItemPtr->to, result, kFormatBufLen, NULL, &status); if (fmtLen >= kFormatBufLen) { result[kFormatBufLen-1] = 0; } if ( U_SUCCESS(status) ) { u_unescape(testItemPtr->resultExpected, resultExpected, kFormatBufLen); if ( u_strcmp(result, resultExpected) != 0 ) { char bcharBuf[kFormatBufLen]; log_err("ERROR: udtitvfmt_format for locale %s, skeleton %s, tzid %s, from %.1f, to %.1f: expect %s, get %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, testItemPtr->from, testItemPtr->to, testItemPtr->resultExpected, u_austrcpy(bcharBuf,result) ); } } else { log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, tzid %s, from %.1f, to %.1f: %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, testItemPtr->from, testItemPtr->to, myErrorName(status) ); } udtitvfmt_close(udtitvfmt); } else { log_data_err("FAIL: udtitvfmt_open for locale %s, skeleton %s, tzid %s - %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, myErrorName(status) ); } } ctest_resetTimeZone(); }
static void TestFPos_SkelWithSeconds() { const LocaleAndSkeletonItem * locSkelItemPtr; for (locSkelItemPtr = locSkelItems; locSkelItemPtr->locale != NULL; locSkelItemPtr++) { UDateIntervalFormat* udifmt; UChar ubuf[kSizeUBuf]; int32_t ulen, uelen; UErrorCode status = U_ZERO_ERROR; u_strFromUTF8(ubuf, kSizeUBuf, &ulen, locSkelItemPtr->skeleton, -1, &status); udifmt = udtitvfmt_open(locSkelItemPtr->locale, ubuf, ulen, zoneGMT, -1, &status); if ( U_FAILURE(status) ) { log_data_err("FAIL: udtitvfmt_open for locale %s, skeleton %s: %s\n", locSkelItemPtr->locale, locSkelItemPtr->skeleton, u_errorName(status)); } else { const double * deltasPtr = deltas; const ExpectPosAndFormat * expectedPtr = locSkelItemPtr->expected; for (; *deltasPtr >= 0.0; deltasPtr++, expectedPtr++) { UFieldPosition fpos = { locSkelItemPtr->fieldToCheck, 0, 0 }; UChar uebuf[kSizeUBuf]; char bbuf[kSizeBBuf]; char bebuf[kSizeBBuf]; status = U_ZERO_ERROR; uelen = u_unescape(expectedPtr->format, uebuf, kSizeUBuf); ulen = udtitvfmt_format(udifmt, startTime, startTime + *deltasPtr, ubuf, kSizeUBuf, &fpos, &status); if ( U_FAILURE(status) ) { log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, delta %.1f: %s\n", locSkelItemPtr->locale, locSkelItemPtr->skeleton, *deltasPtr, u_errorName(status)); } else if ( ulen != uelen || u_strncmp(ubuf,uebuf,uelen) != 0 || fpos.beginIndex != expectedPtr->posBegin || fpos.endIndex != expectedPtr->posEnd ) { u_strToUTF8(bbuf, kSizeBBuf, NULL, ubuf, ulen, &status); u_strToUTF8(bebuf, kSizeBBuf, NULL, uebuf, uelen, &status); // convert back to get unescaped string log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, delta %12.1f, expect %d-%d \"%s\", get %d-%d \"%s\"\n", locSkelItemPtr->locale, locSkelItemPtr->skeleton, *deltasPtr, expectedPtr->posBegin, expectedPtr->posEnd, bebuf, fpos.beginIndex, fpos.endIndex, bbuf); } } udtitvfmt_close(udifmt); } } }