void Grego::dayToFields(double day, int32_t& year, int32_t& month, int32_t& dom, int32_t& dow, int32_t& doy) { // Convert from 1970 CE epoch to 1 CE epoch (Gregorian calendar) day += JULIAN_1970_CE - JULIAN_1_CE; // Convert from the day number to the multiple radix // representation. We use 400-year, 100-year, and 4-year cycles. // For example, the 4-year cycle has 4 years + 1 leap day; giving // 1461 == 365*4 + 1 days. int32_t n400 = ClockMath::floorDivide(day, 146097, doy); // 400-year cycle length int32_t n100 = ClockMath::floorDivide(doy, 36524, doy); // 100-year cycle length int32_t n4 = ClockMath::floorDivide(doy, 1461, doy); // 4-year cycle length int32_t n1 = ClockMath::floorDivide(doy, 365, doy); year = 400*n400 + 100*n100 + 4*n4 + n1; if (n100 == 4 || n1 == 4) { doy = 365; // Dec 31 at end of 4- or 400-year cycle } else { ++year; } UBool isLeap = isLeapYear(year); // Gregorian day zero is a Monday. dow = (int32_t) uprv_fmod(day + 1, 7); dow += (dow < 0) ? (UCAL_SUNDAY + 7) : UCAL_SUNDAY; // Common Julian/Gregorian calculation int32_t correction = 0; int32_t march1 = isLeap ? 60 : 59; // zero-based DOY for March 1 if (doy >= march1) { correction = isLeap ? 1 : 2; } month = (12 * (doy + correction) + 6) / 367; // zero-based month dom = doy - DAYS_BEFORE[month + (isLeap ? 12 : 0)] + 1; // one-based DOM doy++; // one-based doy }
static void TestPUtilAPI(void){ double n1=0.0, y1=0.0, expn1, expy1; double value1 = 0.021; char *str=0; UBool isTrue=FALSE; log_verbose("Testing the API uprv_modf()\n"); y1 = uprv_modf(value1, &n1); expn1=0; expy1=0.021; if(y1 != expy1 || n1 != expn1){ log_err("Error in uprv_modf. Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n", expn1, n1, expy1, y1); } if(getTestOption(VERBOSITY_OPTION)){ log_verbose("[float] x = %f n = %f y = %f\n", value1, n1, y1); } log_verbose("Testing the API uprv_fmod()\n"); expn1=uprv_fmod(30.50, 15.00); doAssert(expn1, 0.5, "uprv_fmod(30.50, 15.00) failed."); log_verbose("Testing the API uprv_ceil()\n"); expn1=uprv_ceil(value1); doAssert(expn1, 1, "uprv_ceil(0.021) failed."); log_verbose("Testing the API uprv_floor()\n"); expn1=uprv_floor(value1); doAssert(expn1, 0, "uprv_floor(0.021) failed."); log_verbose("Testing the API uprv_fabs()\n"); expn1=uprv_fabs((2.02-1.345)); doAssert(expn1, 0.675, "uprv_fabs(2.02-1.345) failed."); log_verbose("Testing the API uprv_fmax()\n"); doAssert(uprv_fmax(2.4, 1.2), 2.4, "uprv_fmax(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmax() with x value= NaN\n"); expn1=uprv_fmax(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmax(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_fmin()\n"); doAssert(uprv_fmin(2.4, 1.2), 1.2, "uprv_fmin(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmin() with x value= NaN\n"); expn1=uprv_fmin(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmin(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_max()\n"); doAssert(uprv_max(4, 2), 4, "uprv_max(4, 2) failed."); log_verbose("Testing the API uprv_min()\n"); doAssert(uprv_min(-4, 2), -4, "uprv_min(-4, 2) failed."); log_verbose("Testing the API uprv_trunc()\n"); doAssert(uprv_trunc(12.3456), 12, "uprv_trunc(12.3456) failed."); doAssert(uprv_trunc(12.234E2), 1223, "uprv_trunc(12.234E2) failed."); doAssert(uprv_trunc(uprv_getNaN()), uprv_getNaN(), "uprv_trunc(uprv_getNaN()) failed. with parameter=NaN"); doAssert(uprv_trunc(uprv_getInfinity()), uprv_getInfinity(), "uprv_trunc(uprv_getInfinity()) failed. with parameter=Infinity"); log_verbose("Testing the API uprv_pow10()\n"); doAssert(uprv_pow10(4), 10000, "uprv_pow10(4) failed."); log_verbose("Testing the API uprv_isNegativeInfinity()\n"); isTrue=uprv_isNegativeInfinity(uprv_getInfinity() * -1); if(isTrue != TRUE){ log_err("ERROR: uprv_isNegativeInfinity failed.\n"); } log_verbose("Testing the API uprv_isPositiveInfinity()\n"); isTrue=uprv_isPositiveInfinity(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isPositiveInfinity failed.\n"); } log_verbose("Testing the API uprv_isInfinite()\n"); isTrue=uprv_isInfinite(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isInfinite failed.\n"); } #if 0 log_verbose("Testing the API uprv_digitsAfterDecimal()....\n"); doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E-2), 6, "uprv_digitsAfterDecimal(1.2345E-2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(-1.2345E-20), 24, "uprv_digitsAfterDecimal(1.2345E-20) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E20), 0, "uprv_digitsAfterDecimal(1.2345E20) failed."); doAssert(uprv_digitsAfterDecimal(-0.021), 3, "uprv_digitsAfterDecimal(-0.021) failed."); doAssert(uprv_digitsAfterDecimal(23.0), 0, "uprv_digitsAfterDecimal(23.0) failed."); doAssert(uprv_digitsAfterDecimal(0.022223333321), 9, "uprv_digitsAfterDecimal(0.022223333321) failed."); #endif log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)0); if(strcmp(str, "U_ZERO_ERROR") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_ZERO_ERROR Got=%s\n", str); } log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)-127); if(strcmp(str, "U_USING_DEFAULT_WARNING") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_USING_DEFAULT_WARNING Got=%s\n", str); } log_verbose("Testing the API u_errorName().. with BOGUS ERRORCODE...\n"); str=(char*)u_errorName((UErrorCode)200); if(strcmp(str, "[BOGUS UErrorCode]") != 0){ log_err("ERROR: u_getVersion() failed. Expected: [BOGUS UErrorCode] Got=%s\n", str); } { const char* dataDirectory; int32_t dataDirectoryLen; UChar *udataDir=0; UChar temp[100]; char *charvalue=0; log_verbose("Testing chars to UChars\n"); /* This cannot really work on a japanese system. u_uastrcpy will have different results than */ /* u_charsToUChars when there is a backslash in the string! */ /*dataDirectory=u_getDataDirectory();*/ dataDirectory="directory1"; /*no backslashes*/ dataDirectoryLen=(int32_t)strlen(dataDirectory); udataDir=(UChar*)malloc(sizeof(UChar) * (dataDirectoryLen + 1)); u_charsToUChars(dataDirectory, udataDir, (dataDirectoryLen + 1)); u_uastrcpy(temp, dataDirectory); if(u_strcmp(temp, udataDir) != 0){ log_err("ERROR: u_charsToUChars failed. Expected %s, Got %s\n", austrdup(temp), austrdup(udataDir)); } log_verbose("Testing UChars to chars\n"); charvalue=(char*)malloc(sizeof(char) * (u_strlen(udataDir) + 1)); u_UCharsToChars(udataDir, charvalue, (u_strlen(udataDir)+1)); if(strcmp(charvalue, dataDirectory) != 0){ log_err("ERROR: u_UCharsToChars failed. Expected %s, Got %s\n", charvalue, dataDirectory); } free(charvalue); free(udataDir); } log_verbose("Testing uprv_timezone()....\n"); { int32_t tzoffset = uprv_timezone(); log_verbose("Value returned from uprv_timezone = %d\n", tzoffset); if (tzoffset != 28800) { log_verbose("***** WARNING: If testing in the PST timezone, t_timezone should return 28800! *****"); } if ((tzoffset % 1800 != 0)) { log_info("Note: t_timezone offset of %ld (for %s : %s) is not a multiple of 30min.", tzoffset, uprv_tzname(0), uprv_tzname(1)); } /*tzoffset=uprv_getUTCtime();*/ } }
void GregorianCalendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) { if((amount == 0) || U_FAILURE(status)) { return; } // J81 processing. (gregorian cutover) UBool inCutoverMonth = FALSE; int32_t cMonthLen=0; // 'c' for cutover; in days int32_t cDayOfMonth=0; // no discontinuity: [0, cMonthLen) double cMonthStart=0.0; // in ms // Common code - see if we're in the cutover month of the cutover year if(get(UCAL_EXTENDED_YEAR, status) == fGregorianCutoverYear) { switch (field) { case UCAL_DAY_OF_MONTH: case UCAL_WEEK_OF_MONTH: { int32_t max = monthLength(internalGet(UCAL_MONTH)); UDate t = internalGetTime(); // We subtract 1 from the DAY_OF_MONTH to make it zero-based, and an // additional 10 if we are after the cutover. Thus the monthStart // value will be correct iff we actually are in the cutover month. cDayOfMonth = internalGet(UCAL_DAY_OF_MONTH) - ((t >= fGregorianCutover) ? 10 : 0); cMonthStart = t - ((cDayOfMonth - 1) * kOneDay); // A month containing the cutover is 10 days shorter. if ((cMonthStart < fGregorianCutover) && (cMonthStart + (cMonthLen=(max-10))*kOneDay >= fGregorianCutover)) { inCutoverMonth = TRUE; } } default: ; } } switch (field) { case UCAL_WEEK_OF_YEAR: { // Unlike WEEK_OF_MONTH, WEEK_OF_YEAR never shifts the day of the // week. Also, rolling the week of the year can have seemingly // strange effects simply because the year of the week of year // may be different from the calendar year. For example, the // date Dec 28, 1997 is the first day of week 1 of 1998 (if // weeks start on Sunday and the minimal days in first week is // <= 3). int32_t woy = get(UCAL_WEEK_OF_YEAR, status); // Get the ISO year, which matches the week of year. This // may be one year before or after the calendar year. int32_t isoYear = get(UCAL_YEAR_WOY, status); int32_t isoDoy = internalGet(UCAL_DAY_OF_YEAR); if (internalGet(UCAL_MONTH) == UCAL_JANUARY) { if (woy >= 52) { isoDoy += handleGetYearLength(isoYear); } } else { if (woy == 1) { isoDoy -= handleGetYearLength(isoYear - 1); } } woy += amount; // Do fast checks to avoid unnecessary computation: if (woy < 1 || woy > 52) { // Determine the last week of the ISO year. // We do this using the standard formula we use // everywhere in this file. If we can see that the // days at the end of the year are going to fall into // week 1 of the next year, we drop the last week by // subtracting 7 from the last day of the year. int32_t lastDoy = handleGetYearLength(isoYear); int32_t lastRelDow = (lastDoy - isoDoy + internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek()) % 7; if (lastRelDow < 0) lastRelDow += 7; if ((6 - lastRelDow) >= getMinimalDaysInFirstWeek()) lastDoy -= 7; int32_t lastWoy = weekNumber(lastDoy, lastRelDow + 1); woy = ((woy + lastWoy - 1) % lastWoy) + 1; } set(UCAL_WEEK_OF_YEAR, woy); set(UCAL_YEAR_WOY,isoYear); return; } case UCAL_DAY_OF_MONTH: if( !inCutoverMonth ) { Calendar::roll(field, amount, status); return; } else { // [j81] 1582 special case for DOM // The default computation works except when the current month // contains the Gregorian cutover. We handle this special case // here. [j81 - aliu] double monthLen = cMonthLen * kOneDay; double msIntoMonth = uprv_fmod(internalGetTime() - cMonthStart + amount * kOneDay, monthLen); if (msIntoMonth < 0) { msIntoMonth += monthLen; } #if defined (U_DEBUG_CAL) fprintf(stderr, "%s:%d: roll DOM %d -> %.0lf ms \n", __FILE__, __LINE__,amount, cMonthLen, cMonthStart+msIntoMonth); #endif setTimeInMillis(cMonthStart + msIntoMonth, status); return; } case UCAL_WEEK_OF_MONTH: if( !inCutoverMonth ) { Calendar::roll(field, amount, status); return; } else { #if defined (U_DEBUG_CAL) fprintf(stderr, "%s:%d: roll WOM %d ??????????????????? \n", __FILE__, __LINE__,amount); #endif // NOTE: following copied from the old // GregorianCalendar::roll( WEEK_OF_MONTH ) code // This is tricky, because during the roll we may have to shift // to a different day of the week. For example: // s m t w r f s // 1 2 3 4 5 // 6 7 8 9 10 11 12 // When rolling from the 6th or 7th back one week, we go to the // 1st (assuming that the first partial week counts). The same // thing happens at the end of the month. // The other tricky thing is that we have to figure out whether // the first partial week actually counts or not, based on the // minimal first days in the week. And we have to use the // correct first day of the week to delineate the week // boundaries. // Here's our algorithm. First, we find the real boundaries of // the month. Then we discard the first partial week if it // doesn't count in this locale. Then we fill in the ends with // phantom days, so that the first partial week and the last // partial week are full weeks. We then have a nice square // block of weeks. We do the usual rolling within this block, // as is done elsewhere in this method. If we wind up on one of // the phantom days that we added, we recognize this and pin to // the first or the last day of the month. Easy, eh? // Another wrinkle: To fix jitterbug 81, we have to make all this // work in the oddball month containing the Gregorian cutover. // This month is 10 days shorter than usual, and also contains // a discontinuity in the days; e.g., the default cutover month // is Oct 1582, and goes from day of month 4 to day of month 15. // Normalize the DAY_OF_WEEK so that 0 is the first day of the week // in this locale. We have dow in 0..6. int32_t dow = internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek(); if (dow < 0) dow += 7; // Find the day of month, compensating for cutover discontinuity. int32_t dom = cDayOfMonth; // Find the day of the week (normalized for locale) for the first // of the month. int32_t fdm = (dow - dom + 1) % 7; if (fdm < 0) fdm += 7; // Get the first day of the first full week of the month, // including phantom days, if any. Figure out if the first week // counts or not; if it counts, then fill in phantom days. If // not, advance to the first real full week (skip the partial week). int32_t start; if ((7 - fdm) < getMinimalDaysInFirstWeek()) start = 8 - fdm; // Skip the first partial week else start = 1 - fdm; // This may be zero or negative // Get the day of the week (normalized for locale) for the last // day of the month. int32_t monthLen = cMonthLen; int32_t ldm = (monthLen - dom + dow) % 7; // We know monthLen >= DAY_OF_MONTH so we skip the += 7 step here. // Get the limit day for the blocked-off rectangular month; that // is, the day which is one past the last day of the month, // after the month has already been filled in with phantom days // to fill out the last week. This day has a normalized DOW of 0. int32_t limit = monthLen + 7 - ldm; // Now roll between start and (limit - 1). int32_t gap = limit - start; int32_t newDom = (dom + amount*7 - start) % gap; if (newDom < 0) newDom += gap; newDom += start; // Finally, pin to the real start and end of the month. if (newDom < 1) newDom = 1; if (newDom > monthLen) newDom = monthLen; // Set the DAY_OF_MONTH. We rely on the fact that this field // takes precedence over everything else (since all other fields // are also set at this point). If this fact changes (if the // disambiguation algorithm changes) then we will have to unset // the appropriate fields here so that DAY_OF_MONTH is attended // to. // If we are in the cutover month, manipulate ms directly. Don't do // this in general because it doesn't work across DST boundaries // (details, details). This takes care of the discontinuity. setTimeInMillis(cMonthStart + (newDom-1)*kOneDay, status); return; } default: Calendar::roll(field, amount, status); return; } }
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return oldRuleValue - uprv_fmod(oldRuleValue, divisor) + newRuleValue; }
virtual double transformNumber(double number) const { return uprv_fmod(number, divisor); }
static void TestPUtilAPI(void){ double n1=0.0, y1=0.0, expn1, expy1; double value1 = 0.021; UVersionInfo versionArray = {0x01, 0x00, 0x02, 0x02}; char versionString[17]; /* xxx.xxx.xxx.xxx\0 */ char *str=0; UBool isTrue=FALSE; log_verbose("Testing the API uprv_modf()\n"); y1 = uprv_modf(value1, &n1); expn1=0; expy1=0.021; if(y1 != expy1 || n1 != expn1){ log_err("Error in uprv_modf. Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n", expn1, n1, expy1, y1); } if(VERBOSITY){ log_verbose("[float] x = %f n = %f y = %f\n", value1, n1, y1); } log_verbose("Testing the API uprv_fmod()\n"); expn1=uprv_fmod(30.50, 15.00); doAssert(expn1, 0.5, "uprv_fmod(30.50, 15.00) failed."); log_verbose("Testing the API uprv_ceil()\n"); expn1=uprv_ceil(value1); doAssert(expn1, 1, "uprv_ceil(0.021) failed."); log_verbose("Testing the API uprv_floor()\n"); expn1=uprv_floor(value1); doAssert(expn1, 0, "uprv_floor(0.021) failed."); log_verbose("Testing the API uprv_fabs()\n"); expn1=uprv_fabs((2.02-1.345)); doAssert(expn1, 0.675, "uprv_fabs(2.02-1.345) failed."); log_verbose("Testing the API uprv_fmax()\n"); doAssert(uprv_fmax(2.4, 1.2), 2.4, "uprv_fmax(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmax() with x value= NaN\n"); expn1=uprv_fmax(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmax(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_fmin()\n"); doAssert(uprv_fmin(2.4, 1.2), 1.2, "uprv_fmin(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmin() with x value= NaN\n"); expn1=uprv_fmin(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmin(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_max()\n"); doAssert(uprv_max(4, 2), 4, "uprv_max(4, 2) failed."); log_verbose("Testing the API uprv_min()\n"); doAssert(uprv_min(-4, 2), -4, "uprv_min(-4, 2) failed."); log_verbose("Testing the API uprv_trunc()\n"); doAssert(uprv_trunc(12.3456), 12, "uprv_trunc(12.3456) failed."); doAssert(uprv_trunc(12.234E2), 1223, "uprv_trunc(12.234E2) failed."); doAssert(uprv_trunc(uprv_getNaN()), uprv_getNaN(), "uprv_trunc(uprv_getNaN()) failed. with parameter=NaN"); doAssert(uprv_trunc(uprv_getInfinity()), uprv_getInfinity(), "uprv_trunc(uprv_getInfinity()) failed. with parameter=Infinity"); log_verbose("Testing the API uprv_pow10()\n"); doAssert(uprv_pow10(4), 10000, "uprv_pow10(4) failed."); log_verbose("Testing the API uprv_log10()\n"); doAssert(uprv_log10(3456), 3, "uprv_log10(3456) failed."); #ifdef OS390 doAssert(uprv_log10(1.0e55), 55, "uprv_log10(1.0e55) failed."); #else doAssert(uprv_log10(1.0e300), 300, "uprv_log10(1.0e300) failed."); #endif log_verbose("Testing the API uprv_isNegativeInfinity()\n"); isTrue=uprv_isNegativeInfinity(uprv_getInfinity() * -1); if(isTrue != TRUE){ log_err("ERROR: uprv_isNegativeInfinity failed.\n"); } log_verbose("Testing the API uprv_isPositiveInfinity()\n"); isTrue=uprv_isPositiveInfinity(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isPositiveInfinity failed.\n"); } log_verbose("Testing the API uprv_isInfinite()\n"); isTrue=uprv_isInfinite(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isInfinite failed.\n"); } #if 0 log_verbose("Testing the API uprv_digitsAfterDecimal()....\n"); doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E-2), 6, "uprv_digitsAfterDecimal(1.2345E-2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(-1.2345E-20), 24, "uprv_digitsAfterDecimal(1.2345E-20) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E20), 0, "uprv_digitsAfterDecimal(1.2345E20) failed."); doAssert(uprv_digitsAfterDecimal(-0.021), 3, "uprv_digitsAfterDecimal(-0.021) failed."); doAssert(uprv_digitsAfterDecimal(23.0), 0, "uprv_digitsAfterDecimal(23.0) failed."); doAssert(uprv_digitsAfterDecimal(0.022223333321), 9, "uprv_digitsAfterDecimal(0.022223333321) failed."); #endif log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 1.0.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL. It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed . It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionString=NULL\n"); u_versionToString(versionArray, NULL); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL It should just return\n"); } versionArray[0] = 0x0a; log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "10.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 10.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; versionArray[1] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.160.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } versionArray[0] = 0x01; versionArray[1] = 0x0a; u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.10.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() ....\n"); u_versionFromString(versionArray, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() where versionArray=NULL....\n"); u_versionFromString(NULL, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_getVersion().....\n"); u_getVersion(versionArray); u_versionToString(versionArray, versionString); if(strcmp(versionString, U_ICU_VERSION) != 0){ log_err("ERROR: u_getVersion() failed. Got=%s, expected %s\n", versionString, U_ICU_VERSION); } log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)0); if(strcmp(str, "U_ZERO_ERROR") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_ZERO_ERROR Got=%s\n", str); } log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)-127); if(strcmp(str, "U_USING_DEFAULT_WARNING") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_USING_DEFAULT_WARNING Got=%s\n", str); } log_verbose("Testing the API u_errorName().. with BOGUS ERRORCODE...\n"); str=(char*)u_errorName((UErrorCode)200); if(strcmp(str, "[BOGUS UErrorCode]") != 0){ log_err("ERROR: u_getVersion() failed. Expected: [BOGUS UErrorCode] Got=%s\n", str); } { const char* dataDirectory; UChar *udataDir=0; UChar temp[100]; char *charvalue=0; log_verbose("Testing chars to UChars\n"); /* This cannot really work on a japanese system. u_uastrcpy will have different results than */ /* u_charsToUChars when there is a backslash in the string! */ /*dataDirectory=u_getDataDirectory();*/ dataDirectory="directory1"; /*no backslashes*/ udataDir=(UChar*)malloc(sizeof(UChar) * (strlen(dataDirectory) + 1)); u_charsToUChars(dataDirectory, udataDir, (strlen(dataDirectory)+1)); u_uastrcpy(temp, dataDirectory); if(u_strcmp(temp, udataDir) != 0){ log_err("ERROR: u_charsToUChars failed. Expected %s, Got %s\n", austrdup(temp), austrdup(udataDir)); } log_verbose("Testing UChars to chars\n"); charvalue=(char*)malloc(sizeof(char) * (u_strlen(udataDir) + 1)); u_UCharsToChars(udataDir, charvalue, (u_strlen(udataDir)+1)); if(strcmp(charvalue, dataDirectory) != 0){ log_err("ERROR: u_UCharsToChars failed. Expected %s, Got %s\n", charvalue, dataDirectory); } free(charvalue); free(udataDir); } log_verbose("Testing uprv_timezone()....\n"); { int32_t tzoffset = uprv_timezone(); log_verbose("Value returned from uprv_timezone = %d\n", tzoffset); if (tzoffset != 28800) { log_verbose("***** WARNING: If testing in the PST timezone, t_timezone should return 28800! *****"); } if ((tzoffset % 1800 != 0)) { log_err("FAIL: t_timezone may be incorrect. It is not a multiple of 30min."); } tzoffset=uprv_getUTCtime(); } }