void UTS46Test::TestSomeCases() { IcuTestErrorCode errorCode(*this, "TestSomeCases"); char buffer[400], buffer2[400]; int32_t i; for(i=0; i<UPRV_LENGTHOF(testCases); ++i) { const TestCase &testCase=testCases[i]; UnicodeString input(ctou(testCase.s)); UnicodeString expected(ctou(testCase.u)); // ToASCII/ToUnicode, transitional/nontransitional UnicodeString aT, uT, aN, uN; IDNAInfo aTInfo, uTInfo, aNInfo, uNInfo; trans->nameToASCII(input, aT, aTInfo, errorCode); trans->nameToUnicode(input, uT, uTInfo, errorCode); nontrans->nameToASCII(input, aN, aNInfo, errorCode); nontrans->nameToUnicode(input, uN, uNInfo, errorCode); if(errorCode.logIfFailureAndReset("first-level processing [%d/%s] %s", (int)i, testCase.o, testCase.s) ) { continue; } // ToUnicode does not set length-overflow errors. uint32_t uniErrors=testCase.errors&~ (UIDNA_ERROR_LABEL_TOO_LONG| UIDNA_ERROR_DOMAIN_NAME_TOO_LONG); char mode=testCase.o[0]; if(mode=='B' || mode=='N') { if(uNInfo.getErrors()!=uniErrors) { errln("N.nameToUnicode([%d] %s) unexpected errors %04lx", (int)i, testCase.s, (long)uNInfo.getErrors()); continue; } if(uN!=expected) { prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("N.nameToUnicode([%d] %s) unexpected string %s", (int)i, testCase.s, buffer); continue; } if(aNInfo.getErrors()!=testCase.errors) { errln("N.nameToASCII([%d] %s) unexpected errors %04lx", (int)i, testCase.s, (long)aNInfo.getErrors()); continue; } } if(mode=='B' || mode=='T') { if(uTInfo.getErrors()!=uniErrors) { errln("T.nameToUnicode([%d] %s) unexpected errors %04lx", (int)i, testCase.s, (long)uTInfo.getErrors()); continue; } if(uT!=expected) { prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("T.nameToUnicode([%d] %s) unexpected string %s", (int)i, testCase.s, buffer); continue; } if(aTInfo.getErrors()!=testCase.errors) { errln("T.nameToASCII([%d] %s) unexpected errors %04lx", (int)i, testCase.s, (long)aTInfo.getErrors()); continue; } } // ToASCII is all-ASCII if no severe errors if((aNInfo.getErrors()&severeErrors)==0 && !isASCII(aN)) { prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s", (int)i, testCase.s, aNInfo.getErrors(), buffer); continue; } if((aTInfo.getErrors()&severeErrors)==0 && !isASCII(aT)) { prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s", (int)i, testCase.s, aTInfo.getErrors(), buffer); continue; } if(verbose) { char m= mode=='B' ? mode : 'N'; prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s", m, (int)i, testCase.s, aNInfo.getErrors(), buffer); if(mode!='B') { prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s", (int)i, testCase.s, aTInfo.getErrors(), buffer); } } // second-level processing UnicodeString aTuN, uTaN, aNuN, uNaN; IDNAInfo aTuNInfo, uTaNInfo, aNuNInfo, uNaNInfo; nontrans->nameToUnicode(aT, aTuN, aTuNInfo, errorCode); nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode); nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode); nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode); if(errorCode.logIfFailureAndReset("second-level processing [%d/%s] %s", (int)i, testCase.o, testCase.s) ) { continue; } if(aN!=uNaN) { prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(uNaN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("N.nameToASCII([%d] %s)!=N.nameToUnicode().N.nameToASCII() " "(errors %04lx) %s vs. %s", (int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2); continue; } if(aT!=uTaN) { prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(uTaN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("T.nameToASCII([%d] %s)!=T.nameToUnicode().N.nameToASCII() " "(errors %04lx) %s vs. %s", (int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2); continue; } if(uN!=aNuN) { prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(aNuN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("N.nameToUnicode([%d] %s)!=N.nameToASCII().N.nameToUnicode() " "(errors %04lx) %s vs. %s", (int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2); continue; } if(uT!=aTuN) { prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(aTuN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("T.nameToUnicode([%d] %s)!=T.nameToASCII().N.nameToUnicode() " "(errors %04lx) %s vs. %s", (int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2); continue; } // labelToUnicode UnicodeString aTL, uTL, aNL, uNL; IDNAInfo aTLInfo, uTLInfo, aNLInfo, uNLInfo; trans->labelToASCII(input, aTL, aTLInfo, errorCode); trans->labelToUnicode(input, uTL, uTLInfo, errorCode); nontrans->labelToASCII(input, aNL, aNLInfo, errorCode); nontrans->labelToUnicode(input, uNL, uNLInfo, errorCode); if(errorCode.logIfFailureAndReset("labelToXYZ processing [%d/%s] %s", (int)i, testCase.o, testCase.s) ) { continue; } if(aN.indexOf((UChar)0x2e)<0) { if(aN!=aNL || aNInfo.getErrors()!=aNLInfo.getErrors()) { prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(aNL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("N.nameToASCII([%d] %s)!=N.labelToASCII() " "(errors %04lx vs %04lx) %s vs. %s", (int)i, testCase.s, aNInfo.getErrors(), aNLInfo.getErrors(), buffer, buffer2); continue; } } else { if((aNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) { errln("N.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT", (int)i, testCase.s, (long)aNLInfo.getErrors()); continue; } } if(aT.indexOf((UChar)0x2e)<0) { if(aT!=aTL || aTInfo.getErrors()!=aTLInfo.getErrors()) { prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(aTL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("T.nameToASCII([%d] %s)!=T.labelToASCII() " "(errors %04lx vs %04lx) %s vs. %s", (int)i, testCase.s, aTInfo.getErrors(), aTLInfo.getErrors(), buffer, buffer2); continue; } } else { if((aTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) { errln("T.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT", (int)i, testCase.s, (long)aTLInfo.getErrors()); continue; } } if(uN.indexOf((UChar)0x2e)<0) { if(uN!=uNL || uNInfo.getErrors()!=uNLInfo.getErrors()) { prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(uNL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("N.nameToUnicode([%d] %s)!=N.labelToUnicode() " "(errors %04lx vs %04lx) %s vs. %s", (int)i, testCase.s, uNInfo.getErrors(), uNLInfo.getErrors(), buffer, buffer2); continue; } } else { if((uNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) { errln("N.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT", (int)i, testCase.s, (long)uNLInfo.getErrors()); continue; } } if(uT.indexOf((UChar)0x2e)<0) { if(uT!=uTL || uTInfo.getErrors()!=uTLInfo.getErrors()) { prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); prettify(uTL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2)); errln("T.nameToUnicode([%d] %s)!=T.labelToUnicode() " "(errors %04lx vs %04lx) %s vs. %s", (int)i, testCase.s, uTInfo.getErrors(), uTLInfo.getErrors(), buffer, buffer2); continue; } } else { if((uTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) { errln("T.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT", (int)i, testCase.s, (long)uTLInfo.getErrors()); continue; } } // Differences between transitional and nontransitional processing if(mode=='B') { if( aNInfo.isTransitionalDifferent() || aTInfo.isTransitionalDifferent() || uNInfo.isTransitionalDifferent() || uTInfo.isTransitionalDifferent() || aNLInfo.isTransitionalDifferent() || aTLInfo.isTransitionalDifferent() || uNLInfo.isTransitionalDifferent() || uTLInfo.isTransitionalDifferent() ) { errln("B.process([%d] %s) isTransitionalDifferent()", (int)i, testCase.s); continue; } if( aN!=aT || uN!=uT || aNL!=aTL || uNL!=uTL || aNInfo.getErrors()!=aTInfo.getErrors() || uNInfo.getErrors()!=uTInfo.getErrors() || aNLInfo.getErrors()!=aTLInfo.getErrors() || uNLInfo.getErrors()!=uTLInfo.getErrors() ) { errln("N.process([%d] %s) vs. T.process() different errors or result strings", (int)i, testCase.s); continue; } } else { if( !aNInfo.isTransitionalDifferent() || !aTInfo.isTransitionalDifferent() || !uNInfo.isTransitionalDifferent() || !uTInfo.isTransitionalDifferent() || !aNLInfo.isTransitionalDifferent() || !aTLInfo.isTransitionalDifferent() || !uNLInfo.isTransitionalDifferent() || !uTLInfo.isTransitionalDifferent() ) { errln("%s.process([%d] %s) !isTransitionalDifferent()", testCase.o, (int)i, testCase.s); continue; } if(aN==aT || uN==uT || aNL==aTL || uNL==uTL) { errln("N.process([%d] %s) vs. T.process() same result strings", (int)i, testCase.s); continue; } } // UTF-8 std::string input8, aT8, uT8, aN8, uN8; StringByteSink<std::string> aT8Sink(&aT8), uT8Sink(&uT8), aN8Sink(&aN8), uN8Sink(&uN8); IDNAInfo aT8Info, uT8Info, aN8Info, uN8Info; input.toUTF8String(input8); trans->nameToASCII_UTF8(input8, aT8Sink, aT8Info, errorCode); trans->nameToUnicodeUTF8(input8, uT8Sink, uT8Info, errorCode); nontrans->nameToASCII_UTF8(input8, aN8Sink, aN8Info, errorCode); nontrans->nameToUnicodeUTF8(input8, uN8Sink, uN8Info, errorCode); if(errorCode.logIfFailureAndReset("UTF-8 processing [%d/%s] %s", (int)i, testCase.o, testCase.s) ) { continue; } UnicodeString aT16(UnicodeString::fromUTF8(aT8)); UnicodeString uT16(UnicodeString::fromUTF8(uT8)); UnicodeString aN16(UnicodeString::fromUTF8(aN8)); UnicodeString uN16(UnicodeString::fromUTF8(uN8)); if( aN8Info.getErrors()!=aNInfo.getErrors() || uN8Info.getErrors()!=uNInfo.getErrors() ) { errln("N.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx", (int)i, testCase.s, (long)aN8Info.getErrors(), (long)aNInfo.getErrors()); continue; } if( aT8Info.getErrors()!=aTInfo.getErrors() || uT8Info.getErrors()!=uTInfo.getErrors() ) { errln("T.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx", (int)i, testCase.s, (long)aT8Info.getErrors(), (long)aTInfo.getErrors()); continue; } if(aT16!=aT || uT16!=uT || aN16!=aN || uN16!=uN) { errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different string results", testCase.o, (int)i, testCase.s, (long)aTInfo.getErrors()); continue; } if( aT8Info.isTransitionalDifferent()!=aTInfo.isTransitionalDifferent() || uT8Info.isTransitionalDifferent()!=uTInfo.isTransitionalDifferent() || aN8Info.isTransitionalDifferent()!=aNInfo.isTransitionalDifferent() || uN8Info.isTransitionalDifferent()!=uNInfo.isTransitionalDifferent() ) { errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different isTransitionalDifferent()", testCase.o, (int)i, testCase.s); continue; } } }
//------------------------------------------------------------------------------ // // Parse RBBI rules. The state machine for rules parsing is here. // The state tables are hand-written in the file rbbirpt.txt, // and converted to the form used here by a perl // script rbbicst.pl // //------------------------------------------------------------------------------ void RBBIRuleScanner::parse() { uint16_t state; const RBBIRuleTableEl *tableEl; if (U_FAILURE(*fRB->fStatus)) { return; } state = 1; nextChar(fC); // // Main loop for the rule parsing state machine. // Runs once per state transition. // Each time through optionally performs, depending on the state table, // - an advance to the the next input char // - an action to be performed. // - pushing or popping a state to/from the local state return stack. // for (;;) { // Bail out if anything has gone wrong. // RBBI rule file parsing stops on the first error encountered. if (U_FAILURE(*fRB->fStatus)) { break; } // Quit if state == 0. This is the normal way to exit the state machine. // if (state == 0) { break; } // Find the state table element that matches the input char from the rule, or the // class of the input character. Start with the first table row for this // state, then linearly scan forward until we find a row that matches the // character. The last row for each state always matches all characters, so // the search will stop there, if not before. // tableEl = &gRuleParseStateTable[state]; #ifdef RBBI_DEBUG if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf("char, line, col = (\'%c\', %d, %d) state=%s ", fC.fChar, fLineNum, fCharNum, RBBIRuleStateNames[state]); } #endif for (;;) { #ifdef RBBI_DEBUG if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf("."); fflush(stdout);} #endif if (tableEl->fCharClass < 127 && fC.fEscaped == FALSE && tableEl->fCharClass == fC.fChar) { // Table row specified an individual character, not a set, and // the input character is not escaped, and // the input character matched it. break; } if (tableEl->fCharClass == 255) { // Table row specified default, match anything character class. break; } if (tableEl->fCharClass == 254 && fC.fEscaped) { // Table row specified "escaped" and the char was escaped. break; } if (tableEl->fCharClass == 253 && fC.fEscaped && (fC.fChar == 0x50 || fC.fChar == 0x70 )) { // Table row specified "escaped P" and the char is either 'p' or 'P'. break; } if (tableEl->fCharClass == 252 && fC.fChar == (UChar32)-1) { // Table row specified eof and we hit eof on the input. break; } if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class && fC.fEscaped == FALSE && // char is not escaped && fC.fChar != (UChar32)-1) { // char is not EOF U_ASSERT((tableEl->fCharClass-128) < UPRV_LENGTHOF(fRuleSets)); if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) { // Table row specified a character class, or set of characters, // and the current char matches it. break; } } // No match on this row, advance to the next row for this state, tableEl++; } if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPuts("");} // // We've found the row of the state table that matches the current input // character from the rules string. // Perform any action specified by this row in the state table. if (doParseActions((int32_t)tableEl->fAction) == FALSE) { // Break out of the state machine loop if the // the action signalled some kind of error, or // the action was to exit, occurs on normal end-of-rules-input. break; } if (tableEl->fPushState != 0) { fStackPtr++; if (fStackPtr >= kStackSize) { error(U_BRK_INTERNAL_ERROR); RBBIDebugPuts("RBBIRuleScanner::parse() - state stack overflow."); fStackPtr--; } fStack[fStackPtr] = tableEl->fPushState; } if (tableEl->fNextChar) { nextChar(fC); } // Get the next state from the table entry, or from the // state stack if the next state was specified as "pop". if (tableEl->fNextState != 255) { state = tableEl->fNextState; } else { state = fStack[fStackPtr]; fStackPtr--; if (fStackPtr < 0) { error(U_BRK_INTERNAL_ERROR); RBBIDebugPuts("RBBIRuleScanner::parse() - state stack underflow."); fStackPtr++; } } } if (U_FAILURE(*fRB->fStatus)) { return; } // If there are no forward rules set an error. // if (fRB->fForwardTree == NULL) { error(U_BRK_RULE_SYNTAX); return; } // // Parsing of the input RBBI rules is complete. // We now have a parse tree for the rule expressions // and a list of all UnicodeSets that are referenced. // #ifdef RBBI_DEBUG if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->rbbiSymtablePrint();} if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ptree")) { RBBIDebugPrintf("Completed Forward Rules Parse Tree...\n"); RBBINode::printTree(fRB->fForwardTree, TRUE); RBBIDebugPrintf("\nCompleted Reverse Rules Parse Tree...\n"); RBBINode::printTree(fRB->fReverseTree, TRUE); RBBIDebugPrintf("\nCompleted Safe Point Forward Rules Parse Tree...\n"); RBBINode::printTree(fRB->fSafeFwdTree, TRUE); RBBIDebugPrintf("\nCompleted Safe Point Reverse Rules Parse Tree...\n"); RBBINode::printTree(fRB->fSafeRevTree, TRUE); } #endif }
ScriptSet &ScriptSet::resetAll() { for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) { bits[i] = 0; } return *this; }
UnhandledEngine::UnhandledEngine(UErrorCode &/*status*/) { for (int32_t i = 0; i < UPRV_LENGTHOF(fHandled); ++i) { fHandled[i] = 0; } }
U_CAPI int32_t U_EXPORT2 udata_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, UErrorCode *pErrorCode) { char dataFormatChars[4]; const UDataInfo *pInfo; int32_t i, swappedLength; if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; } /* * Preflight the header first; checks for illegal arguments, too. * Do not swap the header right away because the format-specific swapper * will swap it, get the headerSize again, and also use the header * information. Otherwise we would have to pass some of the information * and not be able to use the UDataSwapFn signature. */ udata_swapDataHeader(ds, inData, -1, NULL, pErrorCode); /* * If we wanted udata_swap() to also handle non-loadable data like a UTrie, * then we could check here for further known magic values and structures. */ if(U_FAILURE(*pErrorCode)) { return 0; /* the data format was not recognized */ } pInfo=(const UDataInfo *)((const char *)inData+4); { /* convert the data format from ASCII to Unicode to the system charset */ UChar u[4]={ pInfo->dataFormat[0], pInfo->dataFormat[1], pInfo->dataFormat[2], pInfo->dataFormat[3] }; if(uprv_isInvariantUString(u, 4)) { u_UCharsToChars(u, dataFormatChars, 4); } else { dataFormatChars[0]=dataFormatChars[1]=dataFormatChars[2]=dataFormatChars[3]='?'; } } /* dispatch to the swap function for the dataFormat */ for(i=0; i<UPRV_LENGTHOF(swapFns); ++i) { if(0==memcmp(swapFns[i].dataFormat, pInfo->dataFormat, 4)) { swappedLength=swapFns[i].swapFn(ds, inData, length, outData, pErrorCode); if(U_FAILURE(*pErrorCode)) { udata_printError(ds, "udata_swap(): failure swapping data format %02x.%02x.%02x.%02x (\"%c%c%c%c\") - %s\n", pInfo->dataFormat[0], pInfo->dataFormat[1], pInfo->dataFormat[2], pInfo->dataFormat[3], dataFormatChars[0], dataFormatChars[1], dataFormatChars[2], dataFormatChars[3], u_errorName(*pErrorCode)); } else if(swappedLength<(length-15)) { /* swapped less than expected */ udata_printError(ds, "udata_swap() warning: swapped only %d out of %d bytes - data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n", swappedLength, length, pInfo->dataFormat[0], pInfo->dataFormat[1], pInfo->dataFormat[2], pInfo->dataFormat[3], dataFormatChars[0], dataFormatChars[1], dataFormatChars[2], dataFormatChars[3], u_errorName(*pErrorCode)); } return swappedLength; } } /* the dataFormat was not recognized */ udata_printError(ds, "udata_swap(): unknown data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n", pInfo->dataFormat[0], pInfo->dataFormat[1], pInfo->dataFormat[2], pInfo->dataFormat[3], dataFormatChars[0], dataFormatChars[1], dataFormatChars[2], dataFormatChars[3]); *pErrorCode=U_UNSUPPORTED_ERROR; return 0; }
static void TestSelector() { TestText text; USet* excluded_sets[3] = { NULL }; int32_t i, testCaseIdx; if (!getAvailableNames()) { return; } if (!text_open(&text)) { releaseAvailableNames();; } excluded_sets[0] = uset_openEmpty(); for(i = 1 ; i < 3 ; i++) { excluded_sets[i] = uset_open(i*30, i*30+500); } for(testCaseIdx = 0; testCaseIdx < UPRV_LENGTHOF(getEncodingsFns); testCaseIdx++) { int32_t excluded_set_id; int32_t num_encodings; const char **encodings = getEncodingsFns[testCaseIdx](&num_encodings); if (getTestOption(QUICK_OPTION) && num_encodings > 25) { uprv_free((void *)encodings); continue; } /* * for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++) * * This loop was replaced by the following statement because * the loop made the test run longer without adding to the code coverage. * The handling of the exclusion set is independent of the * set of encodings, so there is no need to test every combination. */ excluded_set_id = testCaseIdx % UPRV_LENGTHOF(excluded_sets); { UConverterSelector *sel_rt, *sel_fb; char *buffer_fb = NULL; UErrorCode status = U_ZERO_ERROR; sel_rt = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status); if (num_encodings == gCountAvailable) { /* test the special "all converters" parameter values */ sel_fb = ucnvsel_open(NULL, 0, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else if (uset_isEmpty(excluded_sets[excluded_set_id])) { /* test that a NULL set gives the same results as an empty set */ sel_fb = ucnvsel_open(encodings, num_encodings, NULL, UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else { sel_fb = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } if (U_FAILURE(status)) { log_err("ucnv_sel_open(encodings %ld) failed - %s\n", testCaseIdx, u_errorName(status)); ucnvsel_close(sel_rt); uprv_free((void *)encodings); continue; } text_reset(&text); for (;;) { UBool *manual_rt, *manual_fb; static UChar utf16[10000]; char *s; int32_t length8, length16; s = text_nextString(&text, &length8); if (s == NULL || (getTestOption(QUICK_OPTION) && text.number > 3)) { break; } manual_rt = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET); manual_fb = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET); /* UTF-8 with length */ status = U_ZERO_ERROR; verifyResult(ucnvsel_selectForUTF8(sel_rt, s, length8, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, length8, &status), manual_fb); /* UTF-8 NUL-terminated */ verifyResult(ucnvsel_selectForUTF8(sel_rt, s, -1, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, -1, &status), manual_fb); u_strFromUTF8(utf16, UPRV_LENGTHOF(utf16), &length16, s, length8, &status); if (U_FAILURE(status)) { log_err("error converting the test text (string %ld) to UTF-16 - %s\n", (long)text.number, u_errorName(status)); } else { if (text.number == 0) { sel_fb = serializeAndUnserialize(sel_fb, &buffer_fb, &status); } if (U_SUCCESS(status)) { /* UTF-16 with length */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, length16, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, length16, &status), manual_fb); /* UTF-16 NUL-terminated */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, -1, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, -1, &status), manual_fb); } } uprv_free(manual_rt); uprv_free(manual_fb); } ucnvsel_close(sel_rt); ucnvsel_close(sel_fb); uprv_free(buffer_fb); } uprv_free((void *)encodings); } releaseAvailableNames(); text_close(&text); for(i = 0 ; i < 3 ; i++) { uset_close(excluded_sets[i]); } }
void NewResourceBundleTest::TestIteration() { UErrorCode err = U_ZERO_ERROR; const char* testdatapath; const char* data[]={ "string_in_Root_te_te_IN", "1", "array_in_Root_te_te_IN", "5", "array_2d_in_Root_te_te_IN", "4", }; Locale *locale=new Locale("te_IN"); testdatapath=loadTestData(err); if(U_FAILURE(err)) { dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); return; } ResourceBundle test1(testdatapath, *locale, err); if(U_FAILURE(err)){ errln("Construction failed"); } uint32_t i; int32_t count, row=0, col=0; char buf[5]; UnicodeString expected; UnicodeString element("TE_IN"); UnicodeString action; for(i=0; i<UPRV_LENGTHOF(data); i=i+2){ action = "te_IN"; action +=".get("; action += data[i]; action +=", err)"; err=U_ZERO_ERROR; ResourceBundle bundle = test1.get(data[i], err); if(!U_FAILURE(err)){ action = "te_IN"; action +=".getKey()"; CONFIRM_EQ((UnicodeString)bundle.getKey(), (UnicodeString)data[i]); count=0; row=0; while(bundle.hasNext()){ action = data[i]; action +=".getNextString(err)"; row=count; UnicodeString got=bundle.getNextString(err); if(U_SUCCESS(err)){ expected=element; if(bundle.getSize() > 1){ CONFIRM_EQ(bundle.getType(), URES_ARRAY); expected+=itoa(row, buf); ResourceBundle rowbundle=bundle.get(row, err); if(!U_FAILURE(err) && rowbundle.getSize()>1){ col=0; while(rowbundle.hasNext()){ expected=element; got=rowbundle.getNextString(err); if(!U_FAILURE(err)){ expected+=itoa(row, buf); expected+=itoa(col, buf); col++; CONFIRM_EQ(got, expected); } } CONFIRM_EQ(col, rowbundle.getSize()); } } else{ CONFIRM_EQ(bundle.getType(), (int32_t)URES_STRING); } } CONFIRM_EQ(got, expected); count++; } action = data[i]; action +=".getSize()"; CONFIRM_EQ(bundle.getSize(), count); CONFIRM_EQ(count, atoi(data[i+1])); //after reaching the end err=U_ZERO_ERROR; ResourceBundle errbundle=bundle.getNext(err); action = "After reaching the end of the Iterator:- "; action +=data[i]; action +=".getNext()"; CONFIRM_NE(err, (int32_t)U_ZERO_ERROR); CONFIRM_EQ(u_errorName(err), u_errorName(U_INDEX_OUTOFBOUNDS_ERROR)); //reset the iterator err = U_ZERO_ERROR; bundle.resetIterator(); /* The following code is causing a crash ****CRASH****** */ bundle.getNext(err); if(U_FAILURE(err)){ errln("ERROR: getNext() throw an error"); } } } delete locale; }
void CompactDecimalFormatTest::TestCsShort() { CheckLocale("cs", UNUM_SHORT, kCsShort, UPRV_LENGTHOF(kCsShort)); }
void CompactDecimalFormatTest::TestSwahiliShortNegative() { CheckLocale("sw", UNUM_SHORT, kSwahiliShortNegative, UPRV_LENGTHOF(kSwahiliShortNegative)); }
void CompactDecimalFormatTest::TestSerbianLongNegative() { CheckLocale("sr", UNUM_LONG, kSerbianLongNegative, UPRV_LENGTHOF(kSerbianLongNegative)); }
void CompactDecimalFormatTest::TestJapaneseShort() { CheckLocale(Locale::getJapan(), UNUM_SHORT, kJapaneseShort, UPRV_LENGTHOF(kJapaneseShort)); }
void CompactDecimalFormatTest::TestSerbianShort() { CheckLocale("sr", UNUM_SHORT, kSerbianShort, UPRV_LENGTHOF(kSerbianShort)); }
void CompactDecimalFormatTest::TestEnglishShort() { CheckLocale("en", UNUM_SHORT, kEnglishShort, UPRV_LENGTHOF(kEnglishShort)); }
int main(int argc, char* argv[]) { UErrorCode status = U_ZERO_ERROR; const char *arg = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = NULL; const char *encoding = ""; int i; UBool illegalArg = FALSE; U_MAIN_INIT_ARGS(argc, argv); options[JAVA_PACKAGE].value = "com.ibm.icu.impl.data"; options[BUNDLE_NAME].value = "LocaleElements"; argc = u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); illegalArg = TRUE; } else if(argc<2) { illegalArg = TRUE; } if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); illegalArg = TRUE; } if(options[FORMAT_VERSION].doesOccur) { const char *s = options[FORMAT_VERSION].value; if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) { fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); illegalArg = TRUE; } else if(s[0] == '1' && (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) ) { fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); illegalArg = TRUE; } else { setFormatVersion(s[0] - '0'); } } if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && !options[WRITE_JAVA].doesOccur) { fprintf(stderr, "%s error: command line argument --java-package or --bundle-name " "without --write-java\n", argv[0]); illegalArg = TRUE; } if(options[VERSION].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); if(!illegalArg) { return U_ZERO_ERROR; } } if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) { /* * Broken into chunks because the C89 standard says the minimum * required supported string length is 509 bytes. */ fprintf(stderr, "Usage: %s [OPTIONS] [FILES]\n" "\tReads the list of resource bundle source files and creates\n" "\tbinary version of resource bundles (.res files)\n", argv[0]); fprintf(stderr, "Options:\n" "\t-h or -? or --help this usage text\n" "\t-q or --quiet do not display warnings\n" "\t-v or --verbose print extra information when processing files\n" "\t-V or --version prints out version number and exits\n" "\t-c or --copyright include copyright notice\n"); fprintf(stderr, "\t-e or --encoding encoding of source files\n" "\t-d of --destdir destination directory, followed by the path, defaults to %s\n" "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n" "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" "\t followed by path, defaults to %s\n", u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory()); fprintf(stderr, "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" "\t defaults to ASCII and \\uXXXX format.\n" "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n" "\t defaults to com.ibm.icu.impl.data\n"); fprintf(stderr, "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n" "\t defaults to LocaleElements\n" "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n" "\t an optional output file name.\n" "\t-k or --strict use pedantic parsing of syntax\n" /*added by Jing*/ "\t-l or --language for XLIFF: language code compliant with BCP 47.\n"); fprintf(stderr, "\t-C or --noBinaryCollation do not generate binary collation image;\n" "\t makes .res file smaller but collator instantiation much slower;\n" "\t maintains ability to get tailoring rules\n" "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n" "\t makes .res file smaller and maintains collator instantiation speed\n" "\t but tailoring rules will not be available (they are rarely used)\n"); fprintf(stderr, "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n" "\t for example, --formatVersion 1\n"); fprintf(stderr, "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n" "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n" "\t makes .res files smaller but dependent on the pool bundle\n" "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n"); return illegalArg ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[VERBOSE].doesOccur) { setVerbose(TRUE); } if(options[QUIET].doesOccur) { setShowWarning(FALSE); } if(options[STRICT].doesOccur) { setStrict(TRUE); } if(options[COPYRIGHT].doesOccur){ setIncludeCopyright(TRUE); } if(options[SOURCEDIR].doesOccur) { inputDir = options[SOURCEDIR].value; } if(options[DESTDIR].doesOccur) { outputDir = options[DESTDIR].value; } if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[ICUDATADIR].doesOccur) { u_setDataDirectory(options[ICUDATADIR].value); } /* Initialize ICU */ u_init(&status); if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { /* Note: u_init() will try to open ICU property data. * failures here are expected when building ICU from scratch. * ignore them. */ fprintf(stderr, "%s: can not initialize ICU. status = %s\n", argv[0], u_errorName(status)); exit(1); } status = U_ZERO_ERROR; if(options[WRITE_JAVA].doesOccur) { write_java = TRUE; outputEnc = options[WRITE_JAVA].value; } if(options[WRITE_XLIFF].doesOccur) { write_xliff = TRUE; if(options[WRITE_XLIFF].value != NULL){ xliffOutputFileName = options[WRITE_XLIFF].value; } } initParser(); /*added by Jing*/ if(options[LANGUAGE].doesOccur) { language = options[LANGUAGE].value; } LocalPointer<SRBRoot> newPoolBundle; if(options[WRITE_POOL_BUNDLE].doesOccur) { newPoolBundle.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL, TRUE, status), status); if(U_FAILURE(status)) { fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status)); return status; } else { const char *poolResName = "pool.res"; char *nameWithoutSuffix = static_cast<char *>(uprv_malloc(uprv_strlen(poolResName) + 1)); if (nameWithoutSuffix == NULL) { fprintf(stderr, "out of memory error\n"); return U_MEMORY_ALLOCATION_ERROR; } uprv_strcpy(nameWithoutSuffix, poolResName); *uprv_strrchr(nameWithoutSuffix, '.') = 0; newPoolBundle->fLocale = nameWithoutSuffix; } } if(options[USE_POOL_BUNDLE].doesOccur) { const char *poolResName = "pool.res"; FileStream *poolFile; int32_t poolFileSize; int32_t indexLength; /* * TODO: Consolidate inputDir/filename handling from main() and processFile() * into a common function, and use it here as well. * Try to create toolutil functions for dealing with dir/filenames and * loading ICU data files without udata_open(). * Share code with icupkg? * Also, make_res_filename() seems to be unused. Review and remove. */ CharString poolFileName; if (options[USE_POOL_BUNDLE].value!=NULL) { poolFileName.append(options[USE_POOL_BUNDLE].value, status); } else if (inputDir) { poolFileName.append(inputDir, status); } poolFileName.appendPathPart(poolResName, status); if (U_FAILURE(status)) { return status; } poolFile = T_FileStream_open(poolFileName.data(), "rb"); if (poolFile == NULL) { fprintf(stderr, "unable to open pool bundle file %s\n", poolFileName.data()); return 1; } poolFileSize = T_FileStream_size(poolFile); if (poolFileSize < 32) { fprintf(stderr, "the pool bundle file %s is too small\n", poolFileName.data()); return 1; } poolBundle.fBytes = new uint8_t[(poolFileSize + 15) & ~15]; if (poolFileSize > 0 && poolBundle.fBytes == NULL) { fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } UDataSwapper *ds; const DataHeader *header; int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize); if (bytesRead != poolFileSize) { fprintf(stderr, "unable to read the pool bundle file %s\n", poolFileName.data()); return 1; } /* * Swap the pool bundle so that a single checked-in file can be used. * The swapper functions also test that the data looks like * a well-formed .res file. */ ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status); if (U_FAILURE(status)) { fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n", poolFileName.data(), u_errorName(status)); return status; } ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status); udata_closeSwapper(ds); if (U_FAILURE(status)) { fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n", poolFileName.data(), u_errorName(status)); return status; } header = (const DataHeader *)poolBundle.fBytes; if (header->info.formatVersion[0] < 2) { fprintf(stderr, "invalid format of pool bundle file %s\n", poolFileName.data()); return U_INVALID_FORMAT_ERROR; } const int32_t *pRoot = (const int32_t *)( (const char *)header + header->dataHeader.headerSize); poolBundle.fIndexes = pRoot + 1; indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff; if (indexLength <= URES_INDEX_POOL_CHECKSUM) { fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", poolFileName.data()); return U_INVALID_FORMAT_ERROR; } int32_t keysBottom = 1 + indexLength; int32_t keysTop = poolBundle.fIndexes[URES_INDEX_KEYS_TOP]; poolBundle.fKeys = (const char *)(pRoot + keysBottom); poolBundle.fKeysLength = (keysTop - keysBottom) * 4; poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM]; for (i = 0; i < poolBundle.fKeysLength; ++i) { if (poolBundle.fKeys[i] == 0) { ++poolBundle.fKeysCount; } } // 16BitUnits[] begins with strings-v2. // The strings-v2 may optionally be terminated by what looks like // an explicit string length that exceeds the number of remaining 16-bit units. int32_t stringUnitsLength = (poolBundle.fIndexes[URES_INDEX_16BIT_TOP] - keysTop) * 2; if (stringUnitsLength >= 2 && getFormatVersion() >= 3) { poolBundle.fStrings = new PseudoListResource(NULL, status); if (poolBundle.fStrings == NULL) { fprintf(stderr, "unable to allocate memory for the pool bundle strings %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } // The PseudoListResource constructor call did not allocate further memory. assert(U_SUCCESS(status)); const UChar *p = (const UChar *)(pRoot + keysTop); int32_t remaining = stringUnitsLength; do { int32_t first = *p; int8_t numCharsForLength; int32_t length; if (!U16_IS_TRAIL(first)) { // NUL-terminated numCharsForLength = 0; for (length = 0; length < remaining && p[length] != 0; ++length) {} } else if (first < 0xdfef) { numCharsForLength = 1; length = first & 0x3ff; } else if (first < 0xdfff && remaining >= 2) { numCharsForLength = 2; length = ((first - 0xdfef) << 16) | p[1]; } else if (first == 0xdfff && remaining >= 3) { numCharsForLength = 3; length = ((int32_t)p[1] << 16) | p[2]; } else { break; // overrun } // Check for overrun before changing remaining, // so that it is always accurate after the loop body. if ((numCharsForLength + length) >= remaining || p[numCharsForLength + length] != 0) { break; // overrun or explicitly terminated } int32_t poolStringIndex = stringUnitsLength - remaining; // Maximum pool string index when suffix-sharing the last character. int32_t maxStringIndex = poolStringIndex + numCharsForLength + length - 1; if (maxStringIndex >= RES_MAX_OFFSET) { // pool string index overrun break; } p += numCharsForLength; remaining -= numCharsForLength; if (length != 0) { StringResource *sr = new StringResource(poolStringIndex, numCharsForLength, p, length, status); if (sr == NULL) { fprintf(stderr, "unable to allocate memory for a pool bundle string %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } poolBundle.fStrings->add(sr); poolBundle.fStringIndexLimit = maxStringIndex + 1; // The StringResource constructor did not allocate further memory. assert(U_SUCCESS(status)); } p += length + 1; remaining -= length + 1; } while (remaining > 0); if (poolBundle.fStrings->fCount == 0) { delete poolBundle.fStrings; poolBundle.fStrings = NULL; } } T_FileStream_close(poolFile); setUsePoolBundle(TRUE); if (isVerbose() && poolBundle.fStrings != NULL) { printf("number of shared strings: %d\n", (int)poolBundle.fStrings->fCount); int32_t length = poolBundle.fStringIndexLimit + 1; // incl. last NUL printf("16-bit units for strings: %6d = %6d bytes\n", (int)length, (int)length * 2); } } if(!options[FORMAT_VERSION].doesOccur && getFormatVersion() == 3 && poolBundle.fStrings == NULL && !options[WRITE_POOL_BUNDLE].doesOccur) { // If we just default to formatVersion 3 // but there are no pool bundle strings to share // and we do not write a pool bundle, // then write formatVersion 2 which is just as good. setFormatVersion(2); } if(options[INCLUDE_UNIHAN_COLL].doesOccur) { puts("genrb option --includeUnihanColl ignored: \n" "CLDR 26/ICU 54 unihan data is small, except\n" "the ucadata-unihan.icu version of the collation root data\n" "is about 300kB larger than the ucadata-implicithan.icu version."); } if((argc-1)!=1) { printf("genrb number of files: %d\n", argc - 1); } /* generate the binary files */ for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); CharString theCurrentFileName; if (inputDir) { theCurrentFileName.append(inputDir, status); } theCurrentFileName.appendPathPart(arg, status); if (U_FAILURE(status)) { break; } gCurrentFileName = theCurrentFileName.data(); if (isVerbose()) { printf("Processing file \"%s\"\n", theCurrentFileName.data()); } processFile(arg, encoding, inputDir, outputDir, NULL, newPoolBundle.getAlias(), options[NO_BINARY_COLLATION].doesOccur, status); } poolBundle.close(); if(U_SUCCESS(status) && options[WRITE_POOL_BUNDLE].doesOccur) { char outputFileName[256]; newPoolBundle->write(outputDir, NULL, outputFileName, sizeof(outputFileName), status); if(U_FAILURE(status)) { fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status)); } } u_cleanup(); /* Dont return warnings as a failure */ if (U_SUCCESS(status)) { return 0; } return status; }
/* Test exponential pattern*/ static void TestExponential(void) { int32_t pat_length, val_length, lval_length; int32_t ival, ilval, p, v, lneed; UNumberFormat *fmt; int32_t ppos; UChar *upat; UChar pattern[20]; UChar *str=NULL; UChar uvalfor[20], ulvalfor[20]; char tempMsgBug[256]; double a; UErrorCode status = U_ZERO_ERROR; #if U_PLATFORM == U_PF_OS390 static const double val[] = { 0.01234, 123456789, 1.23e75, -3.141592653e-78 }; #else static const double val[] = { 0.01234, 123456789, 1.23e300, -3.141592653e-271 }; #endif static const char* pat[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]" }; static const int32_t lval[] = { 0, -1, 1, 123456789 }; static const char* valFormat[] = { "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271", "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272", "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273", "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]" }; static const char* lvalFormat[] = { "0E0", "-1E0", "1E0", "1.2346E8", "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07", "0E000", "-1E000", "1E000", "123.4568E006", "0E0", "[1E0]", "1E0", "1.235E8" }; static const double valParse[] = { #if U_PLATFORM == U_PF_OS390 0.01234, 123460000, 1.23E75, -3.1416E-78, 0.01234, 123460000, 1.23E75, -3.1416E-78, 0.01234, 123456800, 1.23E75, -3.141593E-78, 0.01234, 123500000, 1.23E75, -3.142E-78 #else /* We define the whole IEEE 754 number in the 4th column because Visual Age 7 has a bug in rounding numbers. */ 0.01234, 123460000, 1.23E300, -3.1415999999999999E-271, 0.01234, 123460000, 1.23E300, -3.1415999999999999E-271, 0.01234, 123456800, 1.23E300, -3.1415929999999999E-271, 0.01234, 123500000, 1.23E300, -3.1420000000000001E-271 #endif }; static const int32_t lvalParse[] = { 0, -1, 1, 123460000, 0, -1, 1, 123460000, 0, -1, 1, 123456800, 0, -1, 1, 123500000 }; pat_length = UPRV_LENGTHOF(pat); val_length = UPRV_LENGTHOF(val); lval_length = UPRV_LENGTHOF(lval); ival = 0; ilval = 0; for (p=0; p < pat_length; ++p) { upat=(UChar*)malloc(sizeof(UChar) * (strlen(pat[p])+1) ); u_uastrcpy(upat, pat[p]); fmt=unum_open(UNUM_IGNORE,upat, u_strlen(upat), "en_US",NULL, &status); if (U_FAILURE(status)) { log_err_status(status, "FAIL: Bad status returned by Number format construction with pattern %s -> %s\n", pat[p], u_errorName(status)); continue; } lneed= u_strlen(upat) + 1; unum_toPattern(fmt, FALSE, pattern, lneed, &status); log_verbose("Pattern \" %s \" -toPattern-> \" %s \" \n", upat, u_austrcpy(tempMsgBug, pattern) ); for (v=0; v<val_length; ++v) { /*format*/ lneed=0; lneed=unum_formatDouble(fmt, val[v], NULL, lneed, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); unum_formatDouble(fmt, val[v], str, lneed+1, NULL, &status); } if(U_FAILURE(status)) { log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) ); } u_uastrcpy(uvalfor, valFormat[v+ival]); if(u_strcmp(str, uvalfor) != 0) log_verbose("FAIL: Expected %s ( %s )\n", valFormat[v+ival], u_austrcpy(tempMsgBug, uvalfor) ); /*parsing*/ ppos=0; a=unum_parseDouble(fmt, str, u_strlen(str), &ppos, &status); if (ppos== u_strlen(str)) { if (a != valParse[v+ival]) log_err("FAIL: Expected: %e, Got: %g\n", valParse[v+ival], a); } else log_err(" FAIL: Partial parse ( %d chars ) -> %e\n", ppos, a); free(str); } for (v=0; v<lval_length; ++v) { /*format*/ lneed=0; lneed=unum_formatDouble(fmt, lval[v], NULL, lneed, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); unum_formatDouble(fmt, lval[v], str, lneed+1, NULL, &status); } if(U_FAILURE(status)) { log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) ); } /*printf(" Format %e -> %s\n", lval[v], austrdup(str) );*/ u_uastrcpy(ulvalfor, lvalFormat[v+ilval]); if(u_strcmp(str, ulvalfor) != 0) log_err("FAIL: Expected %s ( %s )\n", valFormat[v+ilval], austrdup(ulvalfor) ); /*parsing*/ ppos=0; a=unum_parseDouble(fmt, str, u_strlen(str), &ppos, &status); if (ppos== u_strlen(str)) { /*printf(" Parse -> %e\n", a);*/ if (a != lvalParse[v+ilval]) log_err("FAIL: Expected : %e\n", valParse[v+ival]); } else log_err(" FAIL: Partial parse ( %d chars ) -> %e\n", ppos, a); free(str); } ival += val_length; ilval += lval_length; unum_close(fmt); free(upat); } }
void CompactDecimalFormatTest::TestArabicLong() { CheckLocale("ar", UNUM_LONG, kArabicLong, UPRV_LENGTHOF(kArabicLong)); }
static void TestCurrencyKeywords(void) { static const char * const currencies[] = { "ADD", "ADP", "AED", "AFA", "AFN", "AIF", "ALK", "ALL", "ALV", "ALX", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "AOS", "ARA", "ARM", "ARP", "ARS", "ATS", "AUD", "AUP", "AWG", "AZM", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BGX", "BHD", "BIF", "BMD", "BMP", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BSP", "BTN", "BTR", "BUK", "BUR", "BWP", "BYB", "BYL", "BYR", "BZD", "BZH", "CAD", "CDF", "CDG", "CDL", "CFF", "CHF", "CKD", "CLC", "CLE", "CLF", "CLP", "CMF", "CNP", "CNX", "CNY", "COB", "COF", "COP", "CRC", "CSC", "CSK", "CUP", "CUX", "CVE", "CWG", "CYP", "CZK", "DDM", "DEM", "DES", "DJF", "DKK", "DOP", "DZD", "DZF", "DZG", "ECS", "ECV", "EEK", "EGP", "ERN", "ESP", "ETB", "ETD", "EUR", "FIM", "FIN", "FJD", "FJP", "FKP", "FOK", "FRF", "FRG", "GAF", "GBP", "GEK", "GEL", "GHC", "GHO", "GHP", "GHR", "GIP", "GLK", "GMD", "GMP", "GNF", "GNI", "GNS", "GPF", "GQE", "GQF", "GQP", "GRD", "GRN", "GTQ", "GUF", "GWE", "GWM", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IBP", "IDG", "IDJ", "IDN", "IDR", "IEP", "ILL", "ILP", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "ITL", "JEP", "JMD", "JMP", "JOD", "JPY", "KES", "KGS", "KHO", "KHR", "KID", "KMF", "KPP", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZR", "KZT", "LAK", "LBP", "LIF", "LKR", "LNR", "LRD", "LSL", "LTL", "LTT", "LUF", "LVL", "LVR", "LYB", "LYD", "LYP", "MAD", "MAF", "MCF", "MCG", "MDC", "MDL", "MDR", "MGA", "MGF", "MHD", "MKD", "MKN", "MLF", "MMK", "MMX", "MNT", "MOP", "MQF", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MWP", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "NAD", "NCF", "NGN", "NGP", "NHF", "NIC", "NIG", "NIO", "NLG", "NOK", "NPR", "NZD", "NZP", "OMR", "OMS", "PAB", "PDK", "PDN", "PDR", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLX", "PLZ", "PSP", "PTC", "PTE", "PYG", "QAR", "REF", "ROL", "RON", "RUB", "RUR", "RWF", "SAR", "SAS", "SBD", "SCR", "SDD", "SDP", "SEK", "SGD", "SHP", "SIB", "SIT", "SKK", "SLL", "SML", "SOS", "SQS", "SRG", "SSP", "STD", "STE", "SUN", "SUR", "SVC", "SYP", "SZL", "TCC", "TDF", "THB", "TJR", "TJS", "TMM", "TND", "TOP", "TOS", "TPE", "TPP", "TRL", "TTD", "TTO", "TVD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYF", "UYP", "UYU", "UZC", "UZS", "VAL", "VDD", "VDN", "VDP", "VEB", "VGD", "VND", "VNN", "VNR", "VNS", "VUV", "WSP", "WST", "XAD", "XAF", "XAM", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XCF", "XDR", "XEF", "XEU", "XFO", "XFU", "XID", "XMF", "XNF", "XOF", "XPF", "XPS", "XSS", "XTR", "YDD", "YEI", "YER", "YUD", "YUF", "YUG", "YUM", "YUN", "YUO", "YUR", "ZAL", "ZAP", "ZAR", "ZMK", "ZMP", "ZRN", "ZRZ", "ZWD" }; UErrorCode status = U_ZERO_ERROR; int32_t i = 0, j = 0; int32_t noLocales = uloc_countAvailable(); char locale[256]; char currLoc[256]; UChar result[4]; UChar currBuffer[256]; for(i = 0; i < noLocales; i++) { strcpy(currLoc, uloc_getAvailable(i)); for(j = 0; j < UPRV_LENGTHOF(currencies); j++) { strcpy(locale, currLoc); strcat(locale, "@currency="); strcat(locale, currencies[j]); ucurr_forLocale(locale, result, 4, &status); u_charsToUChars(currencies[j], currBuffer, 3); currBuffer[3] = 0; if(u_strcmp(currBuffer, result) != 0) { log_err("Didn't get the right currency for %s\n", locale); } } } }
void BytesTrieTest::TestEmpty() { static const StringAndValue data[]={ { "", 0 } }; checkData(data, UPRV_LENGTHOF(data)); }
} param[] = { // "te" means test // "IN" means inherits // "NE" or "ne" means "does not exist" { "root", 0, U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }, { "te", 0, U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, { "te_IN", 0, U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, { "te_NE", 0, U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, { "te_IN_NE", 0, U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, { "ne", 0, U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } } }; static int32_t bundles_count = UPRV_LENGTHOF(param); //*************************************************************************************** /** * Return a random unsigned long l where 0N <= l <= ULONG_MAX. */ static uint32_t randul() { static UBool initialized = FALSE; if (!initialized) { srand((unsigned)time(NULL)); initialized = TRUE;
void BytesTrieTest::Test_a() { static const StringAndValue data[]={ { "a", 1 } }; checkData(data, UPRV_LENGTHOF(data)); }
void NewResourceBundleTest::TestOtherAPI(){ UErrorCode err = U_ZERO_ERROR; const char* testdatapath=loadTestData(err); UnicodeString tDataPathUS = UnicodeString(testdatapath, ""); if(U_FAILURE(err)) { dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); return; } /* Make sure that users using te_IN for the default locale don't get test failures. */ Locale originalDefault; if (Locale::getDefault() == Locale("te_IN")) { Locale::setDefault(Locale("en_US"), err); } Locale *locale=new Locale("te_IN"); ResourceBundle test0(tDataPathUS, *locale, err); if(U_FAILURE(err)){ errln("Construction failed"); return; } ResourceBundle test1(testdatapath, *locale, err); if(U_FAILURE(err)){ errln("Construction failed"); return; } logln("Testing getLocale()\n"); if(strcmp(test1.getLocale().getName(), locale->getName()) !=0 ){ errln("FAIL: ResourceBundle::getLocale() failed\n"); } delete locale; logln("Testing ResourceBundle(UErrorCode)\n"); ResourceBundle defaultresource(err); ResourceBundle explicitdefaultresource(NULL, Locale::getDefault(), err); if(U_FAILURE(err)){ errcheckln(err, "Construction of default resourcebundle failed - %s", u_errorName(err)); return; } // You can't compare the default locale to the resolved locale in the // resource bundle due to aliasing, keywords in the default locale // or the chance that the machine running these tests is using a locale // that isn't available in ICU. if(strcmp(defaultresource.getLocale().getName(), explicitdefaultresource.getLocale().getName()) != 0){ errln("Construction of default resourcebundle didn't take the defaultlocale. Expected %s Got %s err=%s\n", explicitdefaultresource.getLocale().getName(), defaultresource.getLocale().getName(), u_errorName(err)); } ResourceBundle copyRes(defaultresource); if(strcmp(copyRes.getName(), defaultresource.getName() ) !=0 || strcmp(test1.getName(), defaultresource.getName() ) ==0 || strcmp(copyRes.getLocale().getName(), defaultresource.getLocale().getName() ) !=0 || strcmp(test1.getLocale().getName(), defaultresource.getLocale().getName() ) ==0 ) { errln("copy construction failed\n"); } ResourceBundle defaultSub = defaultresource.get((int32_t)0, err); ResourceBundle defSubCopy(defaultSub); if(strcmp(defSubCopy.getName(), defaultSub.getName() ) !=0 || strcmp(defSubCopy.getLocale().getName(), defaultSub.getLocale().getName() ) !=0 ){ errln("copy construction for subresource failed\n"); } ResourceBundle *p; p = defaultresource.clone(); if(p == &defaultresource || !equalRB(*p, defaultresource)) { errln("ResourceBundle.clone() failed"); } delete p; p = defaultSub.clone(); if(p == &defaultSub || !equalRB(*p, defaultSub)) { errln("2nd ResourceBundle.clone() failed"); } delete p; UVersionInfo ver; copyRes.getVersion(ver); logln("Version returned: [%d.%d.%d.%d]\n", ver[0], ver[1], ver[2], ver[3]); logln("Testing C like UnicodeString APIs\n"); UResourceBundle *testCAPI = NULL, *bundle = NULL, *rowbundle = NULL, *temp = NULL; err = U_ZERO_ERROR; const char* data[]={ "string_in_Root_te_te_IN", "1", "array_in_Root_te_te_IN", "5", "array_2d_in_Root_te_te_IN", "4", }; testCAPI = ures_open(testdatapath, "te_IN", &err); if(U_SUCCESS(err)) { // Do the testing // first iteration uint32_t i; int32_t count, row=0, col=0; char buf[5]; UnicodeString expected; UnicodeString element("TE_IN"); UnicodeString action; for(i=0; i<UPRV_LENGTHOF(data); i=i+2){ action = "te_IN"; action +=".get("; action += data[i]; action +=", err)"; err=U_ZERO_ERROR; bundle = ures_getByKey(testCAPI, data[i], bundle, &err); if(!U_FAILURE(err)){ const char* key = NULL; action = "te_IN"; action +=".getKey()"; CONFIRM_EQ((UnicodeString)ures_getKey(bundle), (UnicodeString)data[i]); count=0; row=0; while(ures_hasNext(bundle)){ action = data[i]; action +=".getNextString(err)"; row=count; UnicodeString got=ures_getNextUnicodeString(bundle, &key, &err); if(U_SUCCESS(err)){ expected=element; if(ures_getSize(bundle) > 1){ CONFIRM_EQ(ures_getType(bundle), URES_ARRAY); expected+=itoa(row, buf); rowbundle=ures_getByIndex(bundle, row, rowbundle, &err); if(!U_FAILURE(err) && ures_getSize(rowbundle)>1){ col=0; while(ures_hasNext(rowbundle)){ expected=element; got=ures_getNextUnicodeString(rowbundle, &key, &err); temp = ures_getByIndex(rowbundle, col, temp, &err); UnicodeString bla = ures_getUnicodeString(temp, &err); UnicodeString bla2 = ures_getUnicodeStringByIndex(rowbundle, col, &err); if(!U_FAILURE(err)){ expected+=itoa(row, buf); expected+=itoa(col, buf); col++; CONFIRM_EQ(got, expected); CONFIRM_EQ(bla, expected); CONFIRM_EQ(bla2, expected); } } CONFIRM_EQ(col, ures_getSize(rowbundle)); } } else{ CONFIRM_EQ(ures_getType(bundle), (int32_t)URES_STRING); } } CONFIRM_EQ(got, expected); count++; } } } // Check that ures_getUnicodeString() & variants return a bogus string if failure. // Same relevant code path whether the failure code is passed in // or comes from a lookup error. UErrorCode failure = U_INTERNAL_PROGRAM_ERROR; assertTrue("ures_getUnicodeString(failure).isBogus()", ures_getUnicodeString(testCAPI, &failure).isBogus()); assertTrue("ures_getNextUnicodeString(failure).isBogus()", ures_getNextUnicodeString(testCAPI, NULL, &failure).isBogus()); assertTrue("ures_getUnicodeStringByIndex(failure).isBogus()", ures_getUnicodeStringByIndex(testCAPI, 999, &failure).isBogus()); assertTrue("ures_getUnicodeStringByKey(failure).isBogus()", ures_getUnicodeStringByKey(testCAPI, "bogus key", &failure).isBogus()); ures_close(temp); ures_close(rowbundle); ures_close(bundle); ures_close(testCAPI); } else { errln("failed to open a resource bundle\n"); } /* Restore the default locale for the other tests. */ Locale::setDefault(originalDefault, err); }
static void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) { static const UChar cr[] = { 0xA }; // LF /* int32_t noOfElements = ures_getSize(resource);*/ int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case URES_STRING : { int32_t len=0; const UChar* thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ if(opt_truncate && len > truncsize) { char msg[128]; printIndent(out, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, msg, -1); len = truncsize/2; } printIndent(out, indent); if(key != NULL) { static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ printCString(out, key, (int32_t)uprv_strlen(key)); printString(out, openStr, UPRV_LENGTHOF(openStr)); printString(out, string, len); printString(out, closeStr, UPRV_LENGTHOF(closeStr)); } else { static const UChar openStr[] = { 0x0022 }; /* "\"" */ static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ printString(out, openStr, UPRV_LENGTHOF(openStr)); printString(out, string, (int32_t)(u_strlen(string))); printString(out, closeStr, UPRV_LENGTHOF(closeStr)); } if(verbose) { printCString(out, "// STRING", -1); } printString(out, cr, UPRV_LENGTHOF(cr)); uprv_free(string); } break; case URES_INT : { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ UChar num[20]; printIndent(out, indent); if(key != NULL) { printCString(out, key, -1); } printString(out, openStr, UPRV_LENGTHOF(openStr)); uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); printString(out, num, u_strlen(num)); printString(out, closeStr, UPRV_LENGTHOF(closeStr)); if(verbose) { printCString(out, "// INT", -1); } printString(out, cr, UPRV_LENGTHOF(cr)); break; } case URES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(opt_truncate && len > truncsize) { char msg[128]; printIndent(out, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, msg, -1); len = truncsize; } if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ printIndent(out, indent); if(key != NULL) { printCString(out, key, -1); } printString(out, openStr, UPRV_LENGTHOF(openStr)); for(i = 0; i<len; i++) { printHex(out, *data++); } printString(out, closeStr, UPRV_LENGTHOF(closeStr)); if(verbose) { printCString(out, " // BINARY", -1); } printString(out, cr, UPRV_LENGTHOF(cr)); } else { reportError(pname, status, "getting binary value"); } } break; case URES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0076, 0x0065, 0x0063, 0x0074, 0x006F, 0x0072, 0x0020, 0x007B, 0x0020 }; /* ":intvector { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ UChar num[20]; printIndent(out, indent); if(key != NULL) { printCString(out, key, -1); } printString(out, openStr, UPRV_LENGTHOF(openStr)); for(i = 0; i < len - 1; i++) { int32_t numLen = uprv_itou(num, 20, data[i], 10, 0); num[numLen++] = 0x002C; /* ',' */ num[numLen++] = 0x0020; /* ' ' */ num[numLen] = 0; printString(out, num, u_strlen(num)); } if(len > 0) { uprv_itou(num, 20, data[len - 1], 10, 0); printString(out, num, u_strlen(num)); } printString(out, closeStr, UPRV_LENGTHOF(closeStr)); if(verbose) { printCString(out, "// INTVECTOR", -1); } printString(out, cr, UPRV_LENGTHOF(cr)); } else { reportError(pname, status, "getting int vector"); } } break; case URES_TABLE : case URES_ARRAY : { static const UChar openStr[] = { 0x007B }; /* "{" */ static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, indent); if(key != NULL) { printCString(out, key, -1); } printString(out, openStr, UPRV_LENGTHOF(openStr)); if(verbose) { if(ures_getType(resource) == URES_TABLE) { printCString(out, "// TABLE", -1); } else { printCString(out, "// ARRAY", -1); } } printString(out, cr, UPRV_LENGTHOF(cr)); if(suppressAliases == FALSE) { while(U_SUCCESS(*status) && ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); if(U_SUCCESS(*status)) { printOutBundle(out, t, indent+indentsize, pname, status); } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } else { /* we have to use low level access to do this */ Resource r; int32_t resSize = ures_getSize(resource); UBool isTable = (UBool)(ures_getType(resource) == URES_TABLE); for(i = 0; i < resSize; i++) { /* need to know if it's an alias */ if(isTable) { r = res_getTableItemByIndex(&resource->fResData, resource->fRes, i, &key); } else { r = res_getArrayItem(&resource->fResData, resource->fRes, i); } if(U_SUCCESS(*status)) { if(res_getPublicType(r) == URES_ALIAS) { printOutAlias(out, resource, r, key, indent+indentsize, pname, status); } else { t = ures_getByIndex(resource, i, t, status); printOutBundle(out, t, indent+indentsize, pname, status); } } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } printIndent(out, indent); printString(out, closeStr, UPRV_LENGTHOF(closeStr)); ures_close(t); } break; default: break; } }
UBool UnhandledEngine::handles(UChar32 c, int32_t breakType) const { return (breakType >= 0 && breakType < UPRV_LENGTHOF(fHandled) && fHandled[breakType] != 0 && fHandled[breakType]->contains(c)); }
extern int main(int argc, char* argv[]) { const char *encoding = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = "."; int tostdout = 0; int prbom = 0; const char *pname; UResourceBundle *bundle = NULL; int32_t i = 0; const char* arg; /* Get the name of tool. */ pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (!pname) { pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); } #endif if (!pname) { pname = *argv; } else { ++pname; } /* error handling, printing usage message */ argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", pname, argv[-argc]); } if(argc<0 || options[0].doesOccur || options[1].doesOccur) { fprintf(argc < 0 ? stderr : stdout, "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" " [ -t, --truncate [ size ] ]\n" " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" " [ -A, --suppressAliases]\n" " bundle ...\n", argc < 0 ? 'u' : 'U', pname); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[10].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(options[2].doesOccur) { encoding = options[2].value; } if (options[3].doesOccur) { if(options[2].doesOccur) { fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); return 3; } tostdout = 1; } if(options[4].doesOccur) { opt_truncate = TRUE; if(options[4].value != NULL) { truncsize = atoi(options[4].value); /* user defined printable size */ } else { truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ } } else { opt_truncate = FALSE; } if(options[5].doesOccur) { verbose = TRUE; } if (options[6].doesOccur) { outputDir = options[6].value; } if(options[7].doesOccur) { inputDir = options[7].value; /* we'll use users resources */ } if (options[8].doesOccur) { prbom = 1; } if (options[9].doesOccur) { u_setDataDirectory(options[9].value); } if (options[11].doesOccur) { suppressAliases = TRUE; } fflush(stderr); // use ustderr now. ustderr = u_finit(stderr, NULL, NULL); for (i = 1; i < argc; ++i) { static const UChar sp[] = { 0x0020 }; /* " " */ arg = getLongPathname(argv[i]); if (verbose) { u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); } icu::CharString locale; UErrorCode status = U_ZERO_ERROR; { const char *p = findBasename(arg); const char *q = uprv_strrchr(p, '.'); if (q == NULL) { locale.append(p, status); } else { locale.append(p, (int32_t)(q - p), status); } } if (U_FAILURE(status)) { return status; } icu::CharString infile; const char *thename = NULL; UBool fromICUData = !uprv_strcmp(inputDir, "-"); if (!fromICUData) { UBool absfilename = *arg == U_FILE_SEP_CHAR; #if U_PLATFORM_HAS_WIN32_API if (!absfilename) { absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); } #endif if (absfilename) { thename = arg; } else { const char *q = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (q == NULL) { q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif infile.append(inputDir, status); if(q != NULL) { infile.appendPathPart(icu::StringPiece(arg, (int32_t)(q - arg)), status); } if (U_FAILURE(status)) { return status; } thename = infile.data(); } } if (thename) { bundle = ures_openDirect(thename, locale.data(), &status); } else { bundle = ures_open(fromICUData ? 0 : inputDir, locale.data(), &status); } if (U_SUCCESS(status)) { UFILE *out = NULL; const char *filename = 0; const char *ext = 0; if (locale.isEmpty() || !tostdout) { filename = findBasename(arg); ext = uprv_strrchr(filename, '.'); if (!ext) { ext = uprv_strchr(filename, 0); } } if (tostdout) { out = u_get_stdout(); } else { icu::CharString thefile; if (outputDir) { thefile.append(outputDir, status); } thefile.appendPathPart(filename, status); if (*ext) { thefile.truncate(thefile.length() - (int32_t)uprv_strlen(ext)); } thefile.append(".txt", status); if (U_FAILURE(status)) { return status; } out = u_fopen(thefile.data(), "w", NULL, encoding); if (!out) { u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile.data()); u_fclose(ustderr); return 4; } } // now, set the callback. ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); if (U_FAILURE(status)) { u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); u_fclose(ustderr); if(!tostdout) { u_fclose(out); } return 3; } if (prbom) { /* XXX: Should be done only for UTFs */ u_fputc(0xFEFF, out); } u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); u_fprintf(out, "// This file was dumped by derb(8) from "); if (thename) { u_fprintf(out, "%s", thename); } else if (fromICUData) { u_fprintf(out, "the ICU internal %s locale", locale.data()); } u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); if (!locale.isEmpty()) { u_fprintf(out, "%s", locale.data()); } else { u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, UPRV_LENGTHOF(sp), sp); } printOutBundle(out, bundle, 0, pname, &status); if (!tostdout) { u_fclose(out); } } else { reportError(pname, &status, "opening resource file"); } ures_close(bundle); } return 0; }
IdentifierInfo &IdentifierInfo::setIdentifier(const UnicodeString &identifier, UErrorCode &status) { if (U_FAILURE(status)) { return *this; } *fIdentifier = identifier; clear(); ScriptSet scriptsForCP; UChar32 cp; for (int32_t i = 0; i < identifier.length(); i += U16_LENGTH(cp)) { cp = identifier.char32At(i); // Store a representative character for each kind of decimal digit if (u_charType(cp) == U_DECIMAL_DIGIT_NUMBER) { // Just store the zero character as a representative for comparison. Unicode guarantees it is cp - value fNumerics->add(cp - (UChar32)u_getNumericValue(cp)); } UScriptCode extensions[500]; int32_t extensionsCount = uscript_getScriptExtensions(cp, extensions, UPRV_LENGTHOF(extensions), &status); if (U_FAILURE(status)) { return *this; } scriptsForCP.resetAll(); for (int32_t j=0; j<extensionsCount; j++) { scriptsForCP.set(extensions[j], status); } scriptsForCP.reset(USCRIPT_COMMON, status); scriptsForCP.reset(USCRIPT_INHERITED, status); switch (scriptsForCP.countMembers()) { case 0: break; case 1: // Single script, record it. fRequiredScripts->Union(scriptsForCP); break; default: if (!fRequiredScripts->intersects(scriptsForCP) && !uhash_geti(fScriptSetSet, &scriptsForCP)) { // If the set hasn't been added already, add it // (Add a copy, fScriptSetSet takes ownership of the copy.) uhash_puti(fScriptSetSet, new ScriptSet(scriptsForCP), 1, &status); } break; } } // Now make a final pass through ScriptSetSet to remove alternates that came before singles. // [Kana], [Kana Hira] => [Kana] // This is relatively infrequent, so doesn't have to be optimized. // We also compute any commonalities among the alternates. if (uhash_count(fScriptSetSet) > 0) { fCommonAmongAlternates->setAll(); for (int32_t it = UHASH_FIRST;;) { const UHashElement *nextHashEl = uhash_nextElement(fScriptSetSet, &it); if (nextHashEl == NULL) { break; } ScriptSet *next = static_cast<ScriptSet *>(nextHashEl->key.pointer); // [Kana], [Kana Hira] => [Kana] if (fRequiredScripts->intersects(*next)) { uhash_removeElement(fScriptSetSet, nextHashEl); } else { fCommonAmongAlternates->intersect(*next); // [[Arab Syrc Thaa]; [Arab Syrc]] => [[Arab Syrc]] for (int32_t otherIt = UHASH_FIRST;;) { const UHashElement *otherHashEl = uhash_nextElement(fScriptSetSet, &otherIt); if (otherHashEl == NULL) { break; } ScriptSet *other = static_cast<ScriptSet *>(otherHashEl->key.pointer); if (next != other && next->contains(*other)) { uhash_removeElement(fScriptSetSet, nextHashEl); break; } } } } } if (uhash_count(fScriptSetSet) == 0) { fCommonAmongAlternates->resetAll(); } return *this; }
U_CDECL_END U_CDECL_BEGIN static void U_CALLCONV DataDrivenScanf(void) { #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO UErrorCode errorCode; TestDataModule *dataModule; TestData *testData; const DataMap *testCase; DataDrivenLogger logger; UChar uBuffer[512]; char cBuffer[512]; char cExpected[sizeof(cBuffer)]; UnicodeString tempStr; UChar format[512]; UChar expectedResult[512]; UChar argument[512]; int32_t i; int8_t i8, expected8; int16_t i16, expected16; int32_t i32, expected32; int64_t i64, expected64; double dbl, expectedDbl; volatile float flt, expectedFlt; // Use volatile in order to get around an Intel compiler issue. int32_t uBufferLenReturned; //const char *fileLocale = "en_US_POSIX"; //int32_t uFileBufferLenReturned; //UFILE *testFile; errorCode=U_ZERO_ERROR; dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode); if(U_SUCCESS(errorCode)) { testData=dataModule->createTestData("scanf", errorCode); if(U_SUCCESS(errorCode)) { for(i=0; testData->nextCase(testCase, errorCode); ++i) { if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } /* testFile = u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8"); if (!testFile) { log_err("Can't open test file - %s\n", STANDARD_TEST_FILE); }*/ u_memset(uBuffer, 0x2A, UPRV_LENGTHOF(uBuffer)); uBuffer[UPRV_LENGTHOF(uBuffer)-1] = 0; tempStr=testCase->getString("format", errorCode); tempStr.extract(format, UPRV_LENGTHOF(format), errorCode); tempStr=testCase->getString("result", errorCode); tempStr.extract(expectedResult, UPRV_LENGTHOF(expectedResult), errorCode); tempStr=testCase->getString("argument", errorCode); tempStr.extract(argument, UPRV_LENGTHOF(argument), errorCode); u_austrncpy(cBuffer, format, sizeof(cBuffer)); if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } log_verbose("Test %d: format=\"%s\"\n", i, cBuffer); switch (testCase->getString("argumentType", errorCode)[0]) { case 0x64: // 'd' double expectedDbl = atof(u_austrcpy(cBuffer, expectedResult)); uBufferLenReturned = u_sscanf_u(argument, format, &dbl); //uFileBufferLenReturned = u_fscanf_u(testFile, format, dbl); if (dbl != expectedDbl) { log_err("error in scanf test case[%d] Got: %f Exp: %f\n", i, dbl, expectedDbl); } break; case 0x66: // 'f' float expectedFlt = (float)atof(u_austrcpy(cBuffer, expectedResult)); uBufferLenReturned = u_sscanf_u(argument, format, &flt); //uFileBufferLenReturned = u_fscanf_u(testFile, format, flt); if (flt != expectedFlt) { log_err("error in scanf test case[%d] Got: %f Exp: %f\n", i, flt, expectedFlt); } break; case 0x31: // '1' int8_t expected8 = (int8_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i8); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i8); if (i8 != expected8) { log_err("error in scanf test case[%d] Got: %02X Exp: %02X\n", i, i8, expected8); } break; case 0x32: // '2' int16_t expected16 = (int16_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i16); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i16); if (i16 != expected16) { log_err("error in scanf test case[%d] Got: %04X Exp: %04X\n", i, i16, expected16); } break; case 0x34: // '4' int32_t expected32 = (int32_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i32); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i32); if (i32 != expected32) { log_err("error in scanf test case[%d] Got: %08X Exp: %08X\n", i, i32, expected32); } break; case 0x38: // '8' int64_t expected64 = uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i64); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i64); if (i64 != expected64) { log_err("error in scanf 64-bit. Test case = %d\n", i); } break; case 0x73: // 's' char * u_austrcpy(cExpected, expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, cBuffer); //uFileBufferLenReturned = u_fscanf_u(testFile, format, cBuffer); if (strcmp(cBuffer, cExpected) != 0) { log_err("error in scanf char * string. Got \"%s\" Expected \"%s\". Test case = %d\n", cBuffer, cExpected, i); } break; case 0x53: // 'S' UChar * uBufferLenReturned = u_sscanf_u(argument, format, uBuffer); //uFileBufferLenReturned = u_fscanf_u(testFile, format, argument); if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrcpy(cExpected, format); u_austrcpy(cBuffer, uBuffer); log_err("error in scanf UChar * string %s Got: \"%s\". Test case = %d\n", cExpected, cBuffer, i); } break; default: uBufferLenReturned = 0; //uFileBufferLenReturned = 0; log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i); } if (uBufferLenReturned != 1) { log_err("error scanf converted %d arguments. Test case = %d\n", uBufferLenReturned, i); } /* if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); u_austrncpy(cFormat, format, sizeof(cFormat)); u_austrncpy(cExpected, expectedResult, sizeof(cExpected)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE string test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n", i, cFormat, cBuffer, cExpected); } if (uBuffer[uBufferLenReturned-1] == 0 || uBuffer[uBufferLenReturned] != 0 || uBuffer[uBufferLenReturned+1] != 0x2A || uBuffer[uBufferLenReturned+2] != 0x2A) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n", i, cBuffer, uBufferLenReturned); }*/ /* u_fclose(testFile); testFile = u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8"); if (!testFile) { log_err("Can't open test file - %s\n", STANDARD_TEST_FILE); } uBuffer[0]; u_fgets(uBuffer, UPRV_LENGTHOF(uBuffer), testFile); if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); u_austrncpy(cFormat, format, sizeof(cFormat)); u_austrncpy(cExpected, expectedResult, sizeof(cExpected)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE file test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n", i, cFormat, cBuffer, cExpected); } if (uFileBufferLenReturned != uBufferLenReturned) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE uFileBufferLenReturned(%d) != uBufferLenReturned(%d)\n", uFileBufferLenReturned, uBufferLenReturned); } */ if(U_FAILURE(errorCode)) { log_err("error running icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } // u_fclose(testFile); } delete testData; } delete dataModule; } else { log_data_err("Failed: could not load test icuio data\n"); } #endif }
ScriptSet &ScriptSet::intersect(const ScriptSet &other) { for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) { bits[i] &= other.bits[i]; } return *this; }
U_CDECL_END U_CDECL_BEGIN static void U_CALLCONV DataDrivenPrintfPrecision(void) { #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO UErrorCode errorCode; TestDataModule *dataModule; TestData *testData; const DataMap *testCase; DataDrivenLogger logger; UChar uBuffer[512]; char cBuffer[512]; char cFormat[sizeof(cBuffer)]; char cExpected[sizeof(cBuffer)]; UnicodeString tempStr; UChar format[512]; UChar expectedResult[512]; UChar argument[512]; int32_t precision; int32_t i; int8_t i8; int16_t i16; int32_t i32; int64_t i64; double dbl; int32_t uBufferLenReturned; errorCode=U_ZERO_ERROR; dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode); if(U_SUCCESS(errorCode)) { testData=dataModule->createTestData("printfPrecision", errorCode); if(U_SUCCESS(errorCode)) { for(i=0; testData->nextCase(testCase, errorCode); ++i) { if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } u_memset(uBuffer, 0x2A, UPRV_LENGTHOF(uBuffer)); uBuffer[UPRV_LENGTHOF(uBuffer)-1] = 0; tempStr=testCase->getString("format", errorCode); tempStr.extract(format, UPRV_LENGTHOF(format), errorCode); tempStr=testCase->getString("result", errorCode); tempStr.extract(expectedResult, UPRV_LENGTHOF(expectedResult), errorCode); tempStr=testCase->getString("argument", errorCode); tempStr.extract(argument, UPRV_LENGTHOF(argument), errorCode); precision=testCase->getInt28("precision", errorCode); u_austrncpy(cBuffer, format, sizeof(cBuffer)); if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } log_verbose("Test %d: format=\"%s\"\n", i, cBuffer); switch (testCase->getString("argumentType", errorCode)[0]) { case 0x64: // 'd' double dbl = atof(u_austrcpy(cBuffer, argument)); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, dbl); break; case 0x31: // '1' int8_t i8 = (int8_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i8); break; case 0x32: // '2' int16_t i16 = (int16_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i16); break; case 0x34: // '4' int32_t i32 = (int32_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i32); break; case 0x38: // '8' int64_t i64 = uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i64); break; case 0x73: // 's' char * u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, cBuffer); break; case 0x53: // 'S' UChar * uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, argument); break; default: uBufferLenReturned = 0; log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i); } if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); u_austrncpy(cFormat, format, sizeof(cFormat)); u_austrncpy(cExpected, expectedResult, sizeof(cExpected)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n", i, cFormat, cBuffer, cExpected); } if (uBufferLenReturned <= 0) { log_err("FAILURE test case %d - \"%s\" is an empty string.\n", i, cBuffer); } else if (uBuffer[uBufferLenReturned-1] == 0 || uBuffer[uBufferLenReturned] != 0 || uBuffer[uBufferLenReturned+1] != 0x2A || uBuffer[uBufferLenReturned+2] != 0x2A) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n", i, cBuffer, uBufferLenReturned); } if(U_FAILURE(errorCode)) { log_err("error running icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } } delete testData; } delete dataModule; } else { log_data_err("Failed: could not load test icuio data\n"); } #endif }
ScriptSet & ScriptSet::operator =(const ScriptSet &other) { for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) { bits[i] = other.bits[i]; } return *this; }
void UTS46Test::TestAPI() { UErrorCode errorCode=U_ZERO_ERROR; UnicodeString result; IDNAInfo info; UnicodeString input=UNICODE_STRING_SIMPLE("www.eXample.cOm"); UnicodeString expected=UNICODE_STRING_SIMPLE("www.example.com"); trans->nameToASCII(input, result, info, errorCode); if(U_FAILURE(errorCode) || info.hasErrors() || result!=expected) { errln("T.nameToASCII(www.example.com) info.errors=%04lx result matches=%d %s", (long)info.getErrors(), result==expected, u_errorName(errorCode)); } errorCode=U_USELESS_COLLATOR_ERROR; trans->nameToUnicode(input, result, info, errorCode); if(errorCode!=U_USELESS_COLLATOR_ERROR || !result.isBogus()) { errln("T.nameToUnicode(U_FAILURE) did not preserve the errorCode " "or not result.setToBogus() - %s", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; input.setToBogus(); result=UNICODE_STRING_SIMPLE("quatsch"); nontrans->labelToASCII(input, result, info, errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || !result.isBogus()) { errln("N.labelToASCII(bogus) did not set illegal-argument-error " "or not result.setToBogus() - %s", u_errorName(errorCode)); } errorCode=U_ZERO_ERROR; input=UNICODE_STRING_SIMPLE("xn--bcher.de-65a"); expected=UNICODE_STRING_SIMPLE("xn--bcher\\uFFFDde-65a").unescape(); nontrans->labelToASCII(input, result, info, errorCode); if( U_FAILURE(errorCode) || info.getErrors()!=(UIDNA_ERROR_LABEL_HAS_DOT|UIDNA_ERROR_INVALID_ACE_LABEL) || result!=expected ) { errln("N.labelToASCII(label-with-dot) failed with errors %04lx - %s", info.getErrors(), u_errorName(errorCode)); } // UTF-8 char buffer[100]; TestCheckedArrayByteSink sink(buffer, UPRV_LENGTHOF(buffer)); errorCode=U_ZERO_ERROR; nontrans->labelToUnicodeUTF8(StringPiece(NULL, 5), sink, info, errorCode); if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || sink.NumberOfBytesWritten()!=0) { errln("N.labelToUnicodeUTF8(StringPiece(NULL, 5)) did not set illegal-argument-error ", "or did output something - %s", u_errorName(errorCode)); } sink.Reset(); errorCode=U_ZERO_ERROR; nontrans->nameToASCII_UTF8(StringPiece(), sink, info, errorCode); if(U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=0 || !sink.calledFlush) { errln("N.nameToASCII_UTF8(empty) failed - %s", u_errorName(errorCode)); } static const char s[]={ 0x61, (char)0xc3, (char)0x9f }; sink.Reset(); errorCode=U_USELESS_COLLATOR_ERROR; nontrans->nameToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode); if(errorCode!=U_USELESS_COLLATOR_ERROR || sink.NumberOfBytesWritten()!=0) { errln("N.nameToUnicode_UTF8(U_FAILURE) did not preserve the errorCode " "or did output something - %s", u_errorName(errorCode)); } sink.Reset(); errorCode=U_ZERO_ERROR; trans->labelToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode); if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=3 || buffer[0]!=0x61 || buffer[1]!=0x73 || buffer[2]!=0x73 || !sink.calledFlush ) { errln("T.labelToUnicodeUTF8(a sharp-s) failed - %s", u_errorName(errorCode)); } sink.Reset(); errorCode=U_ZERO_ERROR; // "eXampLe.cOm" static const char eX[]={ 0x65, 0x58, 0x61, 0x6d, 0x70, 0x4c, 0x65, 0x2e, 0x63, 0x4f, 0x6d, 0 }; // "example.com" static const char ex[]={ 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d }; trans->nameToUnicodeUTF8(eX, sink, info, errorCode); if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=11 || 0!=memcmp(ex, buffer, 11) || !sink.calledFlush ) { errln("T.nameToUnicodeUTF8(eXampLe.cOm) failed - %s", u_errorName(errorCode)); } }