U_CAPI int32_t U_EXPORT2 ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen) { UErrorCode status = U_ZERO_ERROR; int32_t len = 0; int32_t UCAlen = 0; const UChar* ucaRules = 0; const UChar *rules = ucol_getRules(coll, &len); if(delta == UCOL_FULL_RULES) { /* take the UCA rules and append real rules at the end */ /* UCA rules will be probably coming from the root RB */ ucaRules = ures_getStringByKey(coll->rb,"UCARules",&UCAlen,&status); /* UResourceBundle* cresb = ures_getByKeyWithFallback(coll->rb, "collations", NULL, &status); UResourceBundle* uca = ures_getByKeyWithFallback(cresb, "UCA", NULL, &status); ucaRules = ures_getStringByKey(uca,"Sequence",&UCAlen,&status); ures_close(uca); ures_close(cresb); */ } if(U_FAILURE(status)) { return 0; } if(buffer!=0 && bufferLen>0){ *buffer=0; if(UCAlen > 0) { u_memcpy(buffer, ucaRules, uprv_min(UCAlen, bufferLen)); } if(len > 0 && bufferLen > UCAlen) { u_memcpy(buffer+UCAlen, rules, uprv_min(len, bufferLen-UCAlen)); } } return u_terminateUChars(buffer, bufferLen, len+UCAlen, &status); }
static int32_t _getStringOrCopyKey(const char *path, const char *locale, const char *tableKey, const char* subTableKey, const char *itemKey, const char *substitute, UChar *dest, int32_t destCapacity, UErrorCode *pErrorCode) { const UChar *s = NULL; int32_t length = 0; if(itemKey==NULL) { /* top-level item: normal resource bundle access */ UResourceBundle *rb; rb=ures_open(path, locale, pErrorCode); if(U_SUCCESS(*pErrorCode)) { s=ures_getStringByKey(rb, tableKey, &length, pErrorCode); /* see comment about closing rb near "return item;" in _res_getTableStringWithFallback() */ ures_close(rb); } } else { /* Language code should not be a number. If it is, set the error code. */ if (!uprv_strncmp(tableKey, "Languages", 9) && uprv_strtol(itemKey, NULL, 10)) { *pErrorCode = U_MISSING_RESOURCE_ERROR; } else { /* second-level item, use special fallback */ s=uloc_getTableStringWithFallback(path, locale, tableKey, subTableKey, itemKey, &length, pErrorCode); } } if(U_SUCCESS(*pErrorCode)) { int32_t copyLength=uprv_min(length, destCapacity); if(copyLength>0 && s != NULL) { u_memcpy(dest, s, copyLength); } } else { /* no string from a resource bundle: convert the substitute */ length=(int32_t)uprv_strlen(substitute); u_charsToUChars(substitute, dest, uprv_min(length, destCapacity)); *pErrorCode=U_USING_DEFAULT_WARNING; } return u_terminateUChars(dest, destCapacity, length, pErrorCode); }
void NumberFormat::setMinimumFractionDigits(int32_t newValue) { fMinFractionDigits = uprv_max(0, uprv_min(newValue, fgMinIntegerDigits)); if (fMaxFractionDigits < fMinFractionDigits) fMaxFractionDigits = fMinFractionDigits; }
void NumberFormat::setMaximumIntegerDigits(int32_t newValue) { fMaxIntegerDigits = uprv_max(0, uprv_min(newValue, fgMaxIntegerDigits)); if(fMinIntegerDigits > fMaxIntegerDigits) fMinIntegerDigits = fMaxIntegerDigits; }
UCollationResult RuleBasedCollator::compare( const UnicodeString& source, const UnicodeString& target, int32_t length, UErrorCode &status) const { return compare(source.getBuffer(), uprv_min(length,source.length()), target.getBuffer(), uprv_min(length,target.length()), status); }
Collator::EComparisonResult RuleBasedCollator::compare( const UnicodeString& source, const UnicodeString& target, int32_t length) const { UErrorCode status = U_ZERO_ERROR; return getEComparisonResult(compare(source.getBuffer(), uprv_min(length,source.length()), target.getBuffer(), uprv_min(length,target.length()), status)); }
U_CAPI int32_t U_EXPORT2 ucnv_getDisplayName(const UConverter *cnv, const char *displayLocale, UChar *displayName, int32_t displayNameCapacity, UErrorCode *pErrorCode) { UResourceBundle *rb; const UChar *name; int32_t length; UErrorCode localStatus = U_ZERO_ERROR; /* check arguments */ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; } if(cnv==NULL || displayNameCapacity<0 || (displayNameCapacity>0 && displayName==NULL)) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } /* open the resource bundle and get the display name string */ rb=ures_open(NULL, displayLocale, pErrorCode); if(U_FAILURE(*pErrorCode)) { return 0; } /* use the internal name as the key */ name=ures_getStringByKey(rb, cnv->sharedData->staticData->name, &length, &localStatus); ures_close(rb); if(U_SUCCESS(localStatus)) { /* copy the string */ if (*pErrorCode == U_ZERO_ERROR) { *pErrorCode = localStatus; } u_memcpy(displayName, name, uprv_min(length, displayNameCapacity)*U_SIZEOF_UCHAR); } else { /* convert the internal name into a Unicode string */ length=(int32_t)uprv_strlen(cnv->sharedData->staticData->name); u_charsToUChars(cnv->sharedData->staticData->name, displayName, uprv_min(length, displayNameCapacity)); } return u_terminateUChars(displayName, displayNameCapacity, length, pErrorCode); }
// Fill the precontext and postcontext with the patterns of the rules // that are masking one another. static void maskingError(const U_NAMESPACE_QUALIFIER TransliterationRule& rule1, const U_NAMESPACE_QUALIFIER TransliterationRule& rule2, UParseError& parseError) { U_NAMESPACE_QUALIFIER UnicodeString r; int32_t len; parseError.line = parseError.offset = -1; // for pre-context rule1.toRule(r, FALSE); len = uprv_min(r.length(), U_PARSE_CONTEXT_LEN-1); r.extract(0, len, parseError.preContext); parseError.preContext[len] = 0; //for post-context r.truncate(0); rule2.toRule(r, FALSE); len = uprv_min(r.length(), U_PARSE_CONTEXT_LEN-1); r.extract(0, len, parseError.postContext); parseError.postContext[len] = 0; }
void UVector32::_init(int32_t initialCapacity, UErrorCode &status) { // Fix bogus initialCapacity values; avoid malloc(0) if (initialCapacity < 1) { initialCapacity = DEFAULT_CAPACITY; } if (maxCapacity>0 && maxCapacity<initialCapacity) { initialCapacity = maxCapacity; } if (initialCapacity > (int32_t)(INT32_MAX / sizeof(int32_t))) { initialCapacity = uprv_min(DEFAULT_CAPACITY, maxCapacity); } elements = (int32_t *)uprv_malloc(sizeof(int32_t)*initialCapacity); if (elements == 0) { status = U_MEMORY_ALLOCATION_ERROR; } else { capacity = initialCapacity; } }
/** * Implements {@link Transliterator#handleTransliterate}. */ void AnyTransliterator::handleTransliterate(Replaceable& text, UTransPosition& pos, UBool isIncremental) const { int32_t allStart = pos.start; int32_t allLimit = pos.limit; ScriptRunIterator it(text, pos.contextStart, pos.contextLimit); while (it.next()) { // Ignore runs in the ante context if (it.limit <= allStart) continue; // Try to instantiate transliterator from it.scriptCode to // our target or target/variant Transliterator* t = getTransliterator(it.scriptCode); if (t == NULL) { // We have no transliterator. Do nothing, but keep // pos.start up to date. pos.start = it.limit; continue; } // If the run end is before the transliteration limit, do // a non-incremental transliteration. Otherwise do an // incremental one. UBool incremental = isIncremental && (it.limit >= allLimit); pos.start = uprv_max(allStart, it.start); pos.limit = uprv_min(allLimit, it.limit); int32_t limit = pos.limit; t->filteredTransliterate(text, pos, incremental); int32_t delta = pos.limit - limit; allLimit += delta; it.adjustLimit(delta); // We're done if we enter the post context if (it.limit >= allLimit) break; } // Restore limit. pos.start is fine where the last transliterator // left it, or at the end of the last run. pos.limit = allLimit; }
static const char* getCodepageFromPOSIXID(const char *localeName, char * buffer, int32_t buffCapacity) { char localeBuf[100]; const char *name = NULL; char *variant = NULL; if (localeName != NULL && (name = (uprv_strchr(localeName, '.'))) != NULL) { size_t localeCapacity = uprv_min(sizeof(localeBuf), (name-localeName)+1); uprv_strncpy(localeBuf, localeName, localeCapacity); localeBuf[localeCapacity-1] = 0; /* ensure NULL termination */ name = uprv_strncpy(buffer, name+1, buffCapacity); buffer[buffCapacity-1] = 0; /* ensure NULL termination */ if ((variant = (uprv_strchr(name, '@'))) != NULL) { *variant = 0; } name = remapPlatformDependentCodepage(localeBuf, name); } return name; }
/** * Attempt a match and replacement at the given position. Return * the degree of match between this rule and the given text. The * degree of match may be mismatch, a partial match, or a full * match. A mismatch means at least one character of the text * does not match the context or key. A partial match means some * context and key characters match, but the text is not long * enough to match all of them. A full match means all context * and key characters match. * * If a full match is obtained, perform a replacement, update pos, * and return U_MATCH. Otherwise both text and pos are unchanged. * * @param text the text * @param pos the position indices * @param incremental if TRUE, test for partial matches that may * be completed by additional text inserted at pos.limit. * @return one of <code>U_MISMATCH</code>, * <code>U_PARTIAL_MATCH</code>, or <code>U_MATCH</code>. If * incremental is FALSE then U_PARTIAL_MATCH will not be returned. */ UMatchDegree TransliterationRule::matchAndReplace(Replaceable& text, UTransPosition& pos, UBool incremental) const { // Matching and replacing are done in one method because the // replacement operation needs information obtained during the // match. Another way to do this is to have the match method // create a match result struct with relevant offsets, and to pass // this into the replace method. // ============================ MATCH =========================== // Reset segment match data if (segments != NULL) { for (int32_t i=0; i<segmentsCount; ++i) { ((StringMatcher*) segments[i])->resetMatch(); } } // int32_t lenDelta, keyLimit; int32_t keyLimit; // ------------------------ Ante Context ------------------------ // A mismatch in the ante context, or with the start anchor, // is an outright U_MISMATCH regardless of whether we are // incremental or not. int32_t oText; // offset into 'text' // int32_t newStart = 0; int32_t minOText; // Note (1): We process text in 16-bit code units, rather than // 32-bit code points. This works because stand-ins are // always in the BMP and because we are doing a literal match // operation, which can be done 16-bits at a time. int32_t anteLimit = posBefore(text, pos.contextStart); UMatchDegree match; // Start reverse match at char before pos.start oText = posBefore(text, pos.start); if (anteContext != NULL) { match = anteContext->matches(text, oText, anteLimit, FALSE); if (match != U_MATCH) { return U_MISMATCH; } } minOText = posAfter(text, oText); // ------------------------ Start Anchor ------------------------ if (((flags & ANCHOR_START) != 0) && oText != anteLimit) { return U_MISMATCH; } // -------------------- Key and Post Context -------------------- oText = pos.start; if (key != NULL) { match = key->matches(text, oText, pos.limit, incremental); if (match != U_MATCH) { return match; } } keyLimit = oText; if (postContext != NULL) { if (incremental && keyLimit == pos.limit) { // The key matches just before pos.limit, and there is // a postContext. Since we are in incremental mode, // we must assume more characters may be inserted at // pos.limit -- this is a partial match. return U_PARTIAL_MATCH; } match = postContext->matches(text, oText, pos.contextLimit, incremental); if (match != U_MATCH) { return match; } } // ------------------------- Stop Anchor ------------------------ if (((flags & ANCHOR_END)) != 0) { if (oText != pos.contextLimit) { return U_MISMATCH; } if (incremental) { return U_PARTIAL_MATCH; } } // =========================== REPLACE ========================== // We have a full match. The key is between pos.start and // keyLimit. int32_t newStart; int32_t newLength = output->toReplacer()->replace(text, pos.start, keyLimit, newStart); int32_t lenDelta = newLength - (keyLimit - pos.start); oText += lenDelta; pos.limit += lenDelta; pos.contextLimit += lenDelta; // Restrict new value of start to [minOText, min(oText, pos.limit)]. pos.start = uprv_max(minOText, uprv_min(uprv_min(oText, pos.limit), newStart)); return U_MATCH; }
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();*/ } }
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(); } }