+#if ADD_ALLOC_TEST
+#include <stdio.h>
+#include <unistd.h>
+static const UChar* tzName = u"US/Pacific";
+static const UDate udatToUse = 1290714600000.0; // Thurs, Nov. 25, 2010 11:50:00 AM PT
+static const UChar* dateStrEST = u"Thursday, November 25, 2010 at 11:50:00 AM EST";
+enum { kUCharsOutMax = 128, kBytesOutMax = 256, kRepeatCount = 100, SLEEPSECS = 6 };
+
+static void TestPerf(void) {
+ UDateFormat *udatfmt;
+ UErrorCode status = U_ZERO_ERROR;
+ printf("\n# TestPerf start; sleeping %d seconds to check heap.\n", SLEEPSECS); sleep(SLEEPSECS);
+ udatfmt = udat_open(UDAT_FULL, UDAT_FULL, "en_US", tzName, -1, NULL, 0, &status);
+ if ( U_SUCCESS(status) ) {
+ UChar outUChars[kUCharsOutMax];
+ int32_t count, datlen, datlen2, parsePos;
+ UDate dateParsed, dateParsed2;
+
+ datlen = udat_format(udatfmt, udatToUse, outUChars, kUCharsOutMax, NULL, &status);
+ printf("# TestPerf after first open & format, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS);
+
+ for (count = kRepeatCount; count-- > 0;) {
+ status = U_ZERO_ERROR;
+ datlen2 = udat_format(udatfmt, udatToUse, outUChars, kUCharsOutMax, NULL, &status);
+ if ( U_FAILURE(status) || datlen2 != datlen ) {
+ printf("# TestPerf udat_format unexpected result.\n");
+ break;
+ }
+ }
+ printf("# TestPerf after many more format, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS);
+
+ udat_setLenient(udatfmt, TRUE);
+ status = U_ZERO_ERROR;
+ parsePos = 0;
+ dateParsed = udat_parse(udatfmt, dateStrEST, -1, &parsePos, &status);
+ printf("# TestPerf after first parse lenient diff style/zone, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS);
+
+ for (count = kRepeatCount; count-- > 0;) {
+ status = U_ZERO_ERROR;
+ parsePos = 0;
+ dateParsed2 = udat_parse(udatfmt, dateStrEST, -1, &parsePos, &status);
+ if ( U_FAILURE(status) || dateParsed2 != dateParsed ) {
+ printf("# TestPerf udat_parse unexpected result.\n");
+ break;
+ }
+ }
+ printf("# TestPerf after many more parse, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS);
+
+ udat_close(udatfmt);
+ printf("# TestPerf after udat_close; sleeping %d seconds to check heap.\n", SLEEPSECS); sleep(SLEEPSECS);
+ }
+}
+#endif /* #if ADD_ALLOC_TEST */
+
+#if WRITE_HOUR_MISMATCH_ERRS
+// WriteHourMismatchErrs stuff 52980140
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static const char* langs[] = {
+ "ar", "ca", "cs", "da", "de", "el", "en", "es", "fi", "fr", "he",
+ "hi", "hr", "hu", "id", "it", "ja", "ko", "ms", "nb", "nl", "pl",
+ "pt", "ro", "ru", "sk", "sv", "th", "tr", "uk", "vi", "zh" }; // handle "yue" separately
+enum { kNlangs = sizeof(langs)/sizeof(langs[0]) };
+
+static const char* cals[] = {
+ "buddhist",
+ "chinese",
+ "coptic",
+ "ethiopic",
+ "gregorian",
+ "hebrew",
+ "indian",
+ "islamic-umalqura",
+ "islamic",
+ "japanese",
+ "persian",
+ NULL
+};
+
+enum { kLBufMax = 63 };
+
+static int compKeys(const void* keyval, const void* baseval) {
+ const char* keystr = (const char*)keyval;
+ const char* basestr = *(const char**)baseval;
+ return strcmp(keystr,basestr);
+}
+
+static UBool useLocale(const char* locale) {
+ if (strncmp(locale, "yue", 3) == 0) {
+ return TRUE;
+ }
+ if (locale[2]==0 || locale[2]=='_') {
+ char lang[3] = {0,0,0};
+ strncpy(lang,locale,2);
+ if (bsearch(&lang, langs, kNlangs, sizeof(char*), compKeys) != NULL) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static UBool patIsBad(const UChar* ubuf) {
+ return (u_strchr(ubuf,0x251C)!=NULL || u_strchr(ubuf,0x2524)!=NULL || u_strstr(ubuf,u": ")!=NULL);
+}
+
+
+static void WriteHourMismatchErrs(void) { /* Apple-specific */
+ int32_t iloc, nloc = uloc_countAvailable();
+ int32_t errcnt = 0;
+ printf("# uloc_countAvailable: %d\n", nloc);
+ for (iloc = 0; iloc < nloc; iloc++) {
+ const char* locale = uloc_getAvailable(iloc);
+ if (useLocale(locale)) {
+ const char** calsPtr = cals;
+ const char* cal;
+ while ((cal = *calsPtr++) != NULL) {
+ char fullLocale[kLBufMax+1];
+ UErrorCode status = U_ZERO_ERROR;
+ strncpy(fullLocale, locale, kLBufMax);
+ fullLocale[kLBufMax] = 0;
+ uloc_setKeywordValue("calendar", cal, fullLocale, kLBufMax, &status);
+ if ( U_SUCCESS(status) ) {
+ fullLocale[kLBufMax] = 0;
+ UDateFormat* udat = udat_open(UDAT_SHORT, UDAT_NONE, fullLocale, NULL, 0, NULL, 0, &status);
+ UDateTimePatternGenerator* udatpg = udatpg_open(fullLocale, &status);
+ if ( U_FAILURE(status) ) {
+ printf("# udat_open/udatpg_open for locale %s: %s\n", fullLocale, u_errorName(status));
+ } else {
+ UChar ubufs[kUBufMax];
+ UChar ubufp[kUBufMax];
+ char bbufs[kBBufMax];
+ char bbufpj[kBBufMax];
+ char bbufpH[kBBufMax];
+ char bbufph[kBBufMax];
+ int32_t ulen;
+ int8_t errors[4] = {0,0,0,0};
+
+ status = U_ZERO_ERROR;
+ ulen = udat_toPattern(udat, FALSE, ubufs, kUBufMax, &status);
+ u_strToUTF8(bbufs, kBBufMax, NULL, ubufs, ulen, &status);
+ if ( U_FAILURE(status) ) {
+ printf("# udat_toPattern for locale %s: %s\n", fullLocale, u_errorName(status));
+ strcpy(bbufs, "****");
+ errors[0] = 3;
+ } else if (patIsBad(ubufs)) {
+ errors[0] = 2;
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = udatpg_getBestPattern(udatpg, u"jmm", 3, ubufp, kUBufMax, &status);
+ u_strToUTF8(bbufpj, kBBufMax, NULL, ubufp, ulen, &status);
+ if ( U_FAILURE(status) ) {
+ printf("# udatpg_getBestPat jmm for locale %s: %s\n", fullLocale, u_errorName(status));
+ strcpy(bbufpj, "****");
+ errors[1] = 3;
+ } else if (patIsBad(ubufp)) {
+ errors[1] = 2;
+ } else if (errors[0] == 0 && u_strcmp(ubufp,ubufs) != 0) {
+ errors[0] = 1;
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = udatpg_getBestPattern(udatpg, u"Hmm", 3, ubufp, kUBufMax, &status);
+ u_strToUTF8(bbufpH, kBBufMax, NULL, ubufp, ulen, &status);
+ if ( U_FAILURE(status) ) {
+ printf("# udatpg_getBestPat Hmm for locale %s: %s\n", fullLocale, u_errorName(status));
+ strcpy(bbufpH, "****");
+ errors[2] = 3;
+ } else if (patIsBad(ubufp)) {
+ errors[2] = 2;
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = udatpg_getBestPattern(udatpg, u"hmm", 3, ubufp, kUBufMax, &status);
+ u_strToUTF8(bbufph, kBBufMax, NULL, ubufp, ulen, &status);
+ if ( U_FAILURE(status) ) {
+ printf("# udatpg_getBestPat hmm for locale %s: %s\n", fullLocale, u_errorName(status));
+ strcpy(bbufph, "****");
+ errors[3] = 3;
+ } else if (patIsBad(ubufp)) {
+ errors[3] = 2;
+ }
+
+ if ( errors[0] || errors[1] || errors[2] || errors[3]) {
+ printf("%-36s\tshr-%d %-8s\tjmm-%d %-18s\tHmm-%d %-18s\thmm-%d %-18s\n", fullLocale,
+ errors[0], bbufs, errors[1], bbufpj, errors[2], bbufpH, errors[3], bbufph);
+ errcnt++;
+ }
+
+ udatpg_close(udatpg);
+ udat_close(udat);
+ }
+ }
+ }
+ }
+ }
+ printf("# total err lines: %d\n", errcnt);
+}
+#endif /* #if WRITE_HOUR_MISMATCH_ERRS */
+