+void TestGregorianChange() {
+ static const UChar utc[] = { 0x45, 0x74, 0x63, 0x2f, 0x47, 0x4d, 0x54, 0 }; /* "Etc/GMT" */
+ const int32_t dayMillis = 86400 * INT64_C(1000); /* 1 day = 86400 seconds */
+ UCalendar *cal;
+ UDate date;
+ UErrorCode errorCode = U_ZERO_ERROR;
+
+ /* Test ucal_setGregorianChange() on a Gregorian calendar. */
+ errorCode = U_ZERO_ERROR;
+ cal = ucal_open(utc, -1, "", UCAL_GREGORIAN, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("ucal_open(UTC) failed: %s\n", u_errorName(errorCode));
+ return;
+ }
+ ucal_setGregorianChange(cal, -365 * (dayMillis * (UDate)1), &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("ucal_setGregorianChange(1969) failed: %s\n", u_errorName(errorCode));
+ } else {
+ date = ucal_getGregorianChange(cal, &errorCode);
+ if(U_FAILURE(errorCode) || date != -365 * (dayMillis * (UDate)1)) {
+ log_err("ucal_getGregorianChange() failed: %s, date = %f\n", u_errorName(errorCode), date);
+ }
+ }
+ ucal_close(cal);
+
+ /* Test ucal_setGregorianChange() on a non-Gregorian calendar where it should fail. */
+ errorCode = U_ZERO_ERROR;
+ cal = ucal_open(utc, -1, "th@calendar=buddhist", UCAL_TRADITIONAL, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("ucal_open(UTC, non-Gregorian) failed: %s\n", u_errorName(errorCode));
+ return;
+ }
+ ucal_setGregorianChange(cal, -730 * (dayMillis * (UDate)1), &errorCode);
+ if(errorCode != U_UNSUPPORTED_ERROR) {
+ log_err("ucal_setGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
+ u_errorName(errorCode));
+ }
+ errorCode = U_ZERO_ERROR;
+ date = ucal_getGregorianChange(cal, &errorCode);
+ if(errorCode != U_UNSUPPORTED_ERROR) {
+ log_err("ucal_getGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
+ u_errorName(errorCode));
+ }
+ ucal_close(cal);
+}
+