void CalendarRegressionTest::TestJ438(void) {
    UErrorCode ec = U_ZERO_ERROR;
    int32_t DATA[] = {
        2000, UCAL_JANUARY, 20,   2010, UCAL_JUNE, 15,
        2010, UCAL_JUNE, 15,      2000, UCAL_JANUARY, 20,
        1964, UCAL_SEPTEMBER, 7,  1999, UCAL_JUNE, 4,
        1999, UCAL_JUNE, 4,       1964, UCAL_SEPTEMBER, 7,
    };
    int32_t DATA_length = UPRV_LENGTHOF(DATA);
    Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec);
    if(U_FAILURE(ec)) {
      dataerrln("Error creating calendar %s", u_errorName(ec));
      delete pcal;
      return;
    }
    Calendar& cal = *pcal;
    int32_t i;
    SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec);
    fmt.setCalendar(cal);
    UnicodeString s, t, u;
    if (U_SUCCESS(ec)) {
        for (i=0; i<DATA_length; i+=6) {
            int32_t y1 = DATA[i];
            int32_t m1 = DATA[i+1];
            int32_t d1 = DATA[i+2];
            int32_t y2 = DATA[i+3];
            int32_t m2 = DATA[i+4];
            int32_t d2 = DATA[i+5];

            cal.clear();
            cal.set(y1, m1, d1);
            UDate date1 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;
            cal.set(y2, m2, d2);
            UDate date2 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;

            cal.setTime(date1, ec);
            if (failure(ec, "setTime"))
                break;
            int32_t dy = cal.fieldDifference(date2, UCAL_YEAR, ec);
            int32_t dm = cal.fieldDifference(date2, UCAL_MONTH, ec);
            int32_t dd = cal.fieldDifference(date2, UCAL_DATE, ec);
            if (failure(ec, "fieldDifference"))
                break;

            {
                Calendar *cal2 = cal.clone();
                UErrorCode ec2 = U_ZERO_ERROR;

                cal2->setTime(date1, ec2);

                int32_t dy2 = cal2->fieldDifference(date2, Calendar::YEAR, ec2);
                int32_t dm2 = cal2->fieldDifference(date2, Calendar::MONTH, ec2);
                int32_t dd2 = cal2->fieldDifference(date2, Calendar::DATE, ec2);
                if (failure(ec2, "fieldDifference(date, Calendar::DATE, ec)"))
                    break;
                if( (dd2 != dd) ||
                    (dm2 != dm) ||
                    (dy2 != dy)){
                    errln("fieldDifference(UCAL_...) and fieldDifference(Calendar::...) give different results!\n");
                }
                delete cal2;
            }


            logln(UnicodeString("") +
                  fmt.format(date2, s.remove()) + " - " +
                  fmt.format(date1, t.remove()) + " = " +
                  dy + "y " + dm + "m " + dd + "d");

            cal.setTime(date1, ec);
            if (failure(ec, "setTime"))
                break;
            cal.add(UCAL_YEAR, dy, ec);
            cal.add(UCAL_MONTH, dm, ec);
            cal.add(UCAL_DATE, dd, ec);
            if (failure(ec, "add"))
                break;
            UDate date22 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;
            if (date2 != date22) {
                errln(UnicodeString("FAIL: ") +
                      fmt.format(date1, s.remove()) + " + " +
                      dy + "y " + dm + "m " + dd + "d = " +
                      fmt.format(date22, t.remove()) + ", exp " +
                      fmt.format(date2, u.remove()));
            } else {
                logln(UnicodeString("Ok: ") +
                      fmt.format(date1, s.remove()) + " + " +
                      dy + "y " + dm + "m " + dd + "d = " +
                      fmt.format(date22, t.remove()));
            }
        }
    } else {
        dataerrln("Error creating SimpleDateFormat - %s", u_errorName(ec));
    }
    delete pcal;
}
void CalendarRegressionTest::TestJ438(void) {
    UErrorCode ec = U_ZERO_ERROR;
    int32_t DATA[] = {
        2000, UCAL_JANUARY, 20,   2010, UCAL_JUNE, 15,
        2010, UCAL_JUNE, 15,      2000, UCAL_JANUARY, 20,
        1964, UCAL_SEPTEMBER, 7,  1999, UCAL_JUNE, 4,
        1999, UCAL_JUNE, 4,       1964, UCAL_SEPTEMBER, 7,
    };
    int32_t DATA_length = UPRV_LENGTHOF(DATA);
    Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec);
    if(U_FAILURE(ec)) {
      dataerrln("Error creating calendar %s", u_errorName(ec));
      delete pcal;
      return;
    }
    Calendar& cal = *pcal;
    int32_t i;
    SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec);
    fmt.setCalendar(cal);
    UnicodeString s, t, u;
    if (U_SUCCESS(ec)) {
        for (i=0; i<DATA_length; i+=6) {
            int32_t y1 = DATA[i];
            int32_t m1 = DATA[i+1];
            int32_t d1 = DATA[i+2];
            int32_t y2 = DATA[i+3];
            int32_t m2 = DATA[i+4];
            int32_t d2 = DATA[i+5];

            cal.clear();
            cal.set(y1, m1, d1);
            UDate date1 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;
            cal.set(y2, m2, d2);
            UDate date2 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;

            cal.setTime(date1, ec);
            if (failure(ec, "setTime"))
                break;
            int32_t dy = cal.fieldDifference(date2, UCAL_YEAR, ec);
            int32_t dm = cal.fieldDifference(date2, UCAL_MONTH, ec);
            int32_t dd = cal.fieldDifference(date2, UCAL_DATE, ec);
            if (failure(ec, "fieldDifference"))
                break;

            {
                Calendar *cal2 = cal.clone();
                UErrorCode ec2 = U_ZERO_ERROR;

                cal2->setTime(date1, ec2);

                int32_t dy2 = cal2->fieldDifference(date2, Calendar::YEAR, ec2);
                int32_t dm2 = cal2->fieldDifference(date2, Calendar::MONTH, ec2);
                int32_t dd2 = cal2->fieldDifference(date2, Calendar::DATE, ec2);
                if (failure(ec2, "fieldDifference(date, Calendar::DATE, ec)"))
                    break;
                if( (dd2 != dd) ||
                    (dm2 != dm) ||
                    (dy2 != dy)){
                    errln("fieldDifference(UCAL_...) and fieldDifference(Calendar::...) give different results!\n");
                }
                delete cal2;
            }


            logln(UnicodeString("") +
                  fmt.format(date2, s.remove()) + " - " +
                  fmt.format(date1, t.remove()) + " = " +
                  dy + "y " + dm + "m " + dd + "d");

            cal.setTime(date1, ec);
            if (failure(ec, "setTime"))
                break;
            cal.add(UCAL_YEAR, dy, ec);
            cal.add(UCAL_MONTH, dm, ec);
            cal.add(UCAL_DATE, dd, ec);
            if (failure(ec, "add"))
                break;
            UDate date22 = cal.getTime(ec);
            if (failure(ec, "getTime"))
                break;
            if (date2 != date22) {
                errln(UnicodeString("FAIL: ") +
                      fmt.format(date1, s.remove()) + " + " +
                      dy + "y " + dm + "m " + dd + "d = " +
                      fmt.format(date22, t.remove()) + ", exp " +
                      fmt.format(date2, u.remove()));
            } else {
                logln(UnicodeString("Ok: ") +
                      fmt.format(date1, s.remove()) + " + " +
                      dy + "y " + dm + "m " + dd + "d = " +
                      fmt.format(date22, t.remove()));
            }
        }
    } else {
        dataerrln("Error creating SimpleDateFormat - %s", u_errorName(ec));
    }
    delete pcal;
}