CalendarRegressionTest::Test4166109()
{
    /* Test month:
     *
     *      March 1998
     * Su Mo Tu We Th Fr Sa
     *  1  2  3  4  5  6  7
     *  8  9 10 11 12 13 14
     * 15 16 17 18 19 20 21
     * 22 23 24 25 26 27 28
     * 29 30 31
     */
    UBool passed = TRUE;
    UErrorCode status = U_ZERO_ERROR;
    UCalendarDateFields field = UCAL_WEEK_OF_MONTH;

    GregorianCalendar *calendar = new GregorianCalendar(Locale::getUS(), status);
    if(U_FAILURE(status)) {
        dataerrln("Couldn't create calendar.: %s", u_errorName(status));
        return;
    }
    calendar->set(1998, UCAL_MARCH, 1);
    calendar->setMinimalDaysInFirstWeek(1);
    logln(UnicodeString("Date:  ") + calendar->getTime(status)); // 888817448000

    int32_t firstInMonth = calendar->get(UCAL_DATE, status);
    if(U_FAILURE(status))
        errln("get(D_O_M) failed");

    for(int32_t firstInWeek = UCAL_SUNDAY; firstInWeek <= UCAL_SATURDAY; firstInWeek++) {
        calendar->setFirstDayOfWeek((UCalendarDaysOfWeek)firstInWeek);
        int32_t returned = calendar->getActualMaximum(field, status);
        int32_t expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7;

        logln(UnicodeString("First day of week = ") + firstInWeek +
              "  getActualMaximum(WEEK_OF_MONTH, status) = " + returned +
              "  expected = " + expected +
              ((returned == expected) ? "  ok" : "  FAIL"));

        if (returned != expected) {
            passed = FALSE;
        }
    }
    if (!passed) {
        errln("Test failed");
    }

    delete calendar;
}
CalendarRegressionTest::Test4166109()
{
     
    UBool passed = TRUE;
    UErrorCode status = U_ZERO_ERROR;
    UCalendarDateFields field = UCAL_WEEK_OF_MONTH;

    GregorianCalendar *calendar = new GregorianCalendar(Locale::getUS(), status);
    if(U_FAILURE(status)) {
        dataerrln("Couldn't create calendar.: %s", u_errorName(status));
        return;
    }
    calendar->set(1998, UCAL_MARCH, 1);
    calendar->setMinimalDaysInFirstWeek(1);
    logln(UnicodeString("Date:  ") + calendar->getTime(status));  

    int32_t firstInMonth = calendar->get(UCAL_DATE, status);
    if(U_FAILURE(status))
        errln("get(D_O_M) failed");

    for(int32_t firstInWeek = UCAL_SUNDAY; firstInWeek <= UCAL_SATURDAY; firstInWeek++) {
        calendar->setFirstDayOfWeek((UCalendarDaysOfWeek)firstInWeek);
        int32_t returned = calendar->getActualMaximum(field, status);
        int32_t expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7;

        logln(UnicodeString("First day of week = ") + firstInWeek +
              "  getActualMaximum(WEEK_OF_MONTH, status) = " + returned +
              "  expected = " + expected +
              ((returned == expected) ? "  ok" : "  FAIL"));

        if (returned != expected) {
            passed = FALSE;
        }
    }
    if (!passed) {
        errln("Test failed");
    }

    delete calendar;
}