void 
IntlTestNumberFormat::tryIt(int32_t aNumber)
{
    Formattable number(aNumber);
    UnicodeString stringNum;
    UErrorCode status = U_ZERO_ERROR;

    fFormat->format(number, stringNum, status);
    if (U_FAILURE(status))
    {
        errln("**** FAIL: Formatting " + aNumber);
        return;
    }
    fFormat->parse(stringNum, number, status);
    if (U_FAILURE(status))
    {
        errln("**** FAIL: Parse of " + prettify(stringNum) + " failed.");
        return;
    }
    if (number.getType() != Formattable::kLong)
    {
        errln("**** FAIL: Parse of " + prettify(stringNum)
            + " returned non-long Formattable, type " + UnicodeString(formattableTypeName(number.getType()))
            + ", Locale=" + UnicodeString(fLocale.getName())
            + ", doubleValue=" + number.getDouble()
            + ", longValue=" + number.getLong()
            + ", origValue=" + aNumber
            );
    }
    if (number.getLong() != aNumber) {
        errln("**** FAIL: Parse of " + prettify(stringNum) + " failed. Got:" + number.getLong()
            + " Expected:" + aNumber);
    }
}
Beispiel #2
0
UBool NormalizerConformanceTest::assertEqual(const char *op, const char *op2,
                                             const UnicodeString& s,
                                             const UnicodeString& got,
                                             const UnicodeString& exp,
                                             const char *msg) {
    if (exp == got)
        return TRUE;

    char *sChars, *gotChars, *expChars;
    UnicodeString sPretty(prettify(s));
    UnicodeString gotPretty(prettify(got));
    UnicodeString expPretty(prettify(exp));

    sChars = new char[sPretty.length() + 1];
    gotChars = new char[gotPretty.length() + 1];
    expChars = new char[expPretty.length() + 1];

    sPretty.extract(0, sPretty.length(), sChars, sPretty.length() + 1);
    sChars[sPretty.length()] = 0;
    gotPretty.extract(0, gotPretty.length(), gotChars, gotPretty.length() + 1);
    gotChars[gotPretty.length()] = 0;
    expPretty.extract(0, expPretty.length(), expChars, expPretty.length() + 1);
    expChars[expPretty.length()] = 0;

    errln("    %s: %s%s(%s)=%s, exp. %s", msg, op, op2, sChars, gotChars, expChars);

    delete []sChars;
    delete []gotChars;
    delete []expChars;
    return FALSE;
}
Beispiel #3
0
void UTS46Test::TestNotSTD3() {
    IcuTestErrorCode errorCode(*this, "TestNotSTD3()");
    char buffer[400];
    LocalPointer<IDNA> not3(IDNA::createUTS46Instance(UIDNA_CHECK_BIDI, errorCode));
    if(errorCode.isFailure()) {
        return;
    }
    UnicodeString input=UNICODE_STRING_SIMPLE("\\u0000A_2+2=4\\u000A.e\\u00DFen.net").unescape();
    UnicodeString result;
    IDNAInfo info;
    if( not3->nameToUnicode(input, result, info, errorCode)!=
            UNICODE_STRING_SIMPLE("\\u0000a_2+2=4\\u000A.essen.net").unescape() ||
        info.hasErrors()
    ) {
        prettify(result).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
        errln("notSTD3.nameToUnicode(non-LDH ASCII) unexpected errors %04lx string %s",
              (long)info.getErrors(), buffer);
    }
    // A space (BiDi class WS) is not allowed in a BiDi domain name.
    input=UNICODE_STRING_SIMPLE("a z.xn--4db.edu");
    not3->nameToASCII(input, result, info, errorCode);
    if(result!=input || info.getErrors()!=UIDNA_ERROR_BIDI) {
        errln("notSTD3.nameToASCII(ASCII-with-space.alef.edu) failed");
    }
    // Characters that are canonically equivalent to sequences with non-LDH ASCII.
    input=UNICODE_STRING_SIMPLE("a\\u2260b\\u226Ec\\u226Fd").unescape();
    not3->nameToUnicode(input, result, info, errorCode);
    if(result!=input || info.hasErrors()) {
        prettify(result).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
        errln("notSTD3.nameToUnicode(equiv to non-LDH ASCII) unexpected errors %04lx string %s",
              (long)info.getErrors(), buffer);
    }
}
Beispiel #4
0
void NormalizerConformanceTest::compare(const UnicodeString& s1, const UnicodeString& s2){
    UErrorCode status=U_ZERO_ERROR;
     // TODO: Re-enable this tests after UTC fixes UAX 21
    if(s1.indexOf((UChar32)0x0345)>=0)return;
    if(Normalizer::compare(s1,s2,U_FOLD_CASE_DEFAULT,status)!=0){
        errln("Normalizer::compare() failed for s1: " + prettify(s1) + " s2: " +prettify(s2));
    }
}
Beispiel #5
0
void collectmailsesb::handleMailTable(QString h5, QDomElement eTable, QJsonObject* pDay)
{
    if(helpers::str_isempty(h5, true))
    {
        helpers::log("cmailsesb:handleMailTable !h5:'"+h5+"'", LOG_WRN, qApp, 0);
        return;
    }

    QDomElement eTHeadTr = eTable.firstChildElement("thead").firstChildElement("tr");
    QDomNodeList leTHeadTds = eTHeadTr.elementsByTagName("th");

    QDomElement eTBody   = eTable.firstChildElement("tbody");
    QDomElement eTBodyTr = eTBody.firstChildElement("tr");

    QJsonArray a;

    while(!eTBodyTr.isNull())
    {
        QDomNodeList leTBodyTds = eTBodyTr.elementsByTagName("td");

        if(leTHeadTds.size() == leTBodyTds.size())
        {
            QJsonObject service;
            for(int i=0;i<leTHeadTds.size();i++)
            {
                QString sVal = prettify(leTBodyTds.at(i).firstChild().nodeValue().trimmed());
                QString sKey = prettify(leTHeadTds.at(i).firstChild().nodeValue());

                if(helpers::str_isnum(sVal, true, true))
                {
                    if(sVal.indexOf('.') > 0)
                    {
                        service.insert(sKey, QJsonValue(sVal.toDouble()));
                    }
                    else
                    {
                        service.insert(sKey, QJsonValue(sVal.toInt()));
                    }
                }
                else
                {
                    service.insert(sKey, QJsonValue(sVal));
                }
            }

            a.append(service);
        }
        else
        {
            helpers::log("cmailsesb:handleMailTable step3: head <body>:"+QString::number((leTHeadTds.size()))+" != "+QString::number((leTBodyTds.size())), LOG_WRN, qApp, 0);
        }

        eTBodyTr = eTBodyTr.nextSiblingElement("tr");
    }
    pDay->insert(h5, QJsonValue(a));
}
void CompoundTransliteratorTest::expectAux(const UnicodeString& tag,
                                   const UnicodeString& summary, UBool pass,
                                   const UnicodeString& expectedResult) {
    if (pass) {
        logln(UnicodeString("(")+tag+") " + prettify(summary));
    } else {
        errln(UnicodeString("FAIL: (")+tag+") "
              + prettify(summary)
              + ", expected " + prettify(expectedResult));
    }
}
Beispiel #7
0
void RBBIAPITest::doTest(UnicodeString& testString, int32_t start, int32_t gotoffset, int32_t expectedOffset, const char* expectedString){
    UnicodeString selected;
    UnicodeString expected=CharsToUnicodeString(expectedString);

    if(gotoffset != expectedOffset)
         errln((UnicodeString)"ERROR:****returned #" + gotoffset + (UnicodeString)" instead of #" + expectedOffset);
    if(start <= gotoffset){
        testString.extractBetween(start, gotoffset, selected);
    }
    else{
        testString.extractBetween(gotoffset, start, selected);
    }
    if(selected.compare(expected) != 0)
         errln(prettify((UnicodeString)"ERROR:****selected \"" + selected + "\" instead of \"" + expected + "\""));
    else
        logln(prettify("****selected \"" + selected + "\""));
}
void DataDrivenNumberFormatTestSuite::showFailure(const UnicodeString &message) {
    UChar lineStr[20];
    uprv_itou(
            lineStr, UPRV_LENGTHOF(lineStr), (uint32_t) fFileLineNumber, 10, 1);
    UnicodeString fullMessage("line ");
    dataerrln(fullMessage.append(lineStr).append(": ")
            .append(prettify(message)));
    showLineInfo();
}
Beispiel #9
0
void CmdDlg::setText(const tstring &text)
{
	tstring buf(text);
	prettify(buf);
	if (buf.empty()) {
		return;
	}

	::SetDlgItemText(_hSelf, ID_DUMP, buf.c_str());
}
Aggregate::Aggregate(const std::string& url, const std::string& destination,
        const std::string& purgatory, unsigned txns,uintmax_t split):
    m_chunks(txns), m_url(url), m_filesize(0), m_failed(false), m_thread(NULL),
    m_splittable_size( (split>100*1024) ? split : 100*1024), m_speed_thread(NULL),
    m_hashedUrl(purgatory+"/"+md5(m_url)), m_prettyUrl(destination+"/"+prettify(m_url)),
    m_avgSpeed(0), m_instSpeed(0), m_hifiSpeed(0)
{
    // Directory session is used to find out about
    // previous download information
    std::vector<std::string> files;
    Directory session(m_hashedUrl);
    if ( session.exists() && !session.isEmpty() ) {
        files = session.list(Node::FILE,true);
        // Remove non-numeric names
        for(unsigned i=0;i<files.size();i++){
            if(!isNumeric(files[i]))
                files.erase(files.begin()+i);
        }
        // sort the files numerically
        sort(files.begin(),files.end(),numerically);
    }

    if( files.size()==0) {

        // If no numeric files are found!
        // It means there is no previous session
        File* newfile = new File(chunkName(0));
        BasicTransaction* newtxn = BasicTransaction::factory(m_url);
        Chunk* researcher = new Chunk(newtxn,newfile);
        m_chunk.push_back(researcher);

    } else {

        // Get the file size from the last file
        m_filesize = std::atoi(files.back().c_str());
        // the last file must not be with name "0"
        if(m_filesize==0)
            Throw(ex::filesystem::ZeroSize);
        // limiter file should be of zero size
        if( File(chunkName(m_filesize)).size() != 0 )
            Throw(ex::filesystem::NonZeroSize,"limiter");
        // '0' could be missing, error correction
        if(files[0]!="0")
            files.insert(files.begin(),"0");

        // Populate all the Chunks
        for(unsigned i=0; i < files.size()-1; i++){
            File* f = new File(chunkName(std::atoi(files[i].c_str())));
            Range r(std::atoi(files[i+1].c_str()),std::atoi(files[i].c_str())+f->size());
            BasicTransaction* t= BasicTransaction::factory(m_url,r);
            Chunk* c = new Chunk(t,f);
            m_chunk.push_back(c);
        }
    }
}
Beispiel #11
0
void IdnaConfTest::Call(){
    if (type == -1 || option == -1 || passfail == -1 || namebase.isBogus() || namezone.isBogus()){
        errln("Incomplete record");
    } else {
        UErrorCode status = U_ZERO_ERROR;
        UChar result[200] = {0,};   // simple life
        const UChar *p = namebase.getTerminatedBuffer();
        const int p_len = namebase.length();

        if (type == 0 && option == 0){
            uidna_IDNToASCII(p, p_len, result, 200, UIDNA_USE_STD3_RULES, NULL, &status);
        } else if (type == 0 && option == 1){
            uidna_IDNToASCII(p, p_len, result, 200, UIDNA_ALLOW_UNASSIGNED, NULL, &status);
        } else if (type == 1 && option == 0){
            uidna_IDNToUnicode(p, p_len, result, 200, UIDNA_USE_STD3_RULES, NULL, &status);
        } else if (type == 1 && option == 1){
            uidna_IDNToUnicode(p, p_len, result, 200, UIDNA_ALLOW_UNASSIGNED, NULL, &status);
        }
        if (passfail == 0){
            if (U_FAILURE(status)){
                id.append(" should pass, but failed. - ");
                id.append(u_errorName(status));
                errcheckln(status, id);
            } else{
                if (namezone.compare(result, -1) == 0){
                    // expected
                    logln(UnicodeString("namebase: ") + prettify(namebase) + UnicodeString(" result: ") + prettify(result));
                } else {
                    id.append(" no error, but result is not as expected.");
                    errln(id);
                }
            }
        } else if (passfail == 1){
            if (U_FAILURE(status)){
                // expected
                // TODO: Uncomment this when U_IDNA_ZERO_LENGTH_LABEL_ERROR is added to u_errorName
                //logln("Got the expected error: " + UnicodeString(u_errorName(status)));
            } else{
                if (namebase.compare(result, -1) == 0){
                    // garbage in -> garbage out
                    logln(UnicodeString("ICU will not recognize malformed ACE-Prefixes or incorrect ACE-Prefixes. ") + UnicodeString("namebase: ") + prettify(namebase) + UnicodeString(" result: ") + prettify(result));
                } else {
                    id.append(" should fail, but not failed. ");
                    id.append(u_errorName(status));
                    errln(id);
                }
            }
        }
    }
    type = option = passfail = -1;
    namebase.setToBogus();
    namezone.setToBogus();
    id.remove();
    return;
}
Beispiel #12
0
void TransliteratorAPITest::displayOutput(const UnicodeString& got, const UnicodeString& expected, UnicodeString& log, UTransPosition& index){
 // Show the start index '{' and the cursor '|'
    UnicodeString a, b, c, d, e;
    got.extractBetween(0, index.contextStart, a);
    got.extractBetween(index.contextStart, index.start, b);
    got.extractBetween(index.start, index.limit, c);
    got.extractBetween(index.limit, index.contextLimit, d);
    got.extractBetween(index.contextLimit, got.length(), e);
    log.append(a).
        append((UChar)0x7b/*{*/).
        append(b).
        append((UChar)0x7c/*|*/).
        append(c).
        append((UChar)0x7c).
        append(d).
        append((UChar)0x7d/*}*/).
        append(e);
    if (got == expected) 
        logln("OK:" + prettify(log));
    else 
        errln("FAIL: " + prettify(log)  + ", expected " + prettify(expected));
}
Beispiel #13
0
void CmdDlg::appendText(const tstring &text)
{
	tstring buf(text);
	prettify(buf);
	if (buf.empty()) {
		return;
	}

	HWND hEdit = GetDlgItem(_hSelf, ID_DUMP);
	int ndx = ::GetWindowTextLength(hEdit);
	::SendMessage(hEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
	::SendMessage(hEdit, EM_REPLACESEL, 0, (LPARAM)buf.c_str());
}
Beispiel #14
0
void TransliteratorAPITest::TestTransliterate1(){

    UnicodeString Data[]={ 
         //ID, input string, transliterated string
         "Any-Hex",         "hello",    UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") ,
         "Hex-Any",         UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello"  ,
         "Latin-Devanagari",CharsToUnicodeString("bha\\u0304rata"), CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") ,
         "Latin-Devanagari",UnicodeString("kra ksha khra gra cra dya dhya",""), CharsToUnicodeString("\\u0915\\u094D\\u0930 \\u0915\\u094D\\u0936 \\u0916\\u094D\\u0930 \\u0917\\u094D\\u0930 \\u091a\\u094D\\u0930 \\u0926\\u094D\\u092F \\u0927\\u094D\\u092F") ,

         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"),        CharsToUnicodeString("bh\\u0101rata"),
     //  "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"),               CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042") ,
     //  "Expanded-Contracted", CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042"), CharsToUnicodeString("\\u00C0\\u00C1\\u0042") ,
         //"Latin-Arabic",        "aap",                                 CharsToUnicodeString("\\u0627\\u06A4")     ,
         //"Arabic-Latin",        CharsToUnicodeString("\\u0627\\u06A4"),                      "aap" 
    };

    UnicodeString gotResult;
    UnicodeString temp;
    UnicodeString message;
    Transliterator* t;
    logln("Testing transliterate");
    UErrorCode status = U_ZERO_ERROR;
    UParseError parseError;

    for(uint32_t i=0;i<sizeof(Data)/sizeof(Data[0]); i=i+3){
        t=Transliterator::createInstance(Data[i+0], UTRANS_FORWARD, parseError, status);
        if(t==0){
            dataerrln("FAIL: construction: " + Data[i+0] + " Error: "  + u_errorName(status));
            dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) );
            status = U_ZERO_ERROR;
            continue;
        }
        gotResult = Data[i+1];
        t->transliterate(gotResult);
        message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + prettify(Data[i+1]);
        doTest(message, gotResult, Data[i+2]);

        //doubt here
        temp=Data[i+1];
        t->transliterate(temp);
        message.remove();
        message.append(t->getID());
        message.append("->transliterate(Replaceable) for \n\tSource:");
        message.append(Data[i][1]);
        doTest(message, temp, Data[i+2]);

        callEverything(t, __LINE__);
        delete t;
    }
}
Beispiel #15
0
static char *
get_pretty_str (const int base, const size_t n, mpfr_srcptr x, mpfr_rnd_t rnd)
{
  mp_exp_t expo;
  char *ugly;
  char *pretty;

  if (mpfr_zero_p (x))
    return pretty_zero (x);

  ugly = mpfr_get_str (NULL, &expo, base, n, x, rnd);
  MPC_ASSERT (ugly != NULL);
  pretty = prettify (ugly, expo, base, !mpfr_number_p (x));
  mpfr_free_str (ugly);

  return pretty;
}
Beispiel #16
0
static void
print_entry (FILE *stream, WispObject *entry, int long_p)
{
  if (!long_p)
    {
      char *name = (char *)NULL;
      char *home_phone = (char *)NULL;
      char *work_phone = (char *)NULL;
      char *bday = (char *)NULL;

      name = sassoc ("name:", entry);
      bday = sassoc ("birthday:", entry);
      if (!home_phone) home_phone = sassoc ("home:", entry);
      if (!home_phone) home_phone = sassoc ("phone:", entry);
      if (!work_phone) work_phone = sassoc ("work:", entry);
      if (!work_phone) work_phone = sassoc ("office:", entry);
      if (!work_phone) work_phone = sassoc ("pager:", entry);

      fprintf (stream, "%20s: (home: %14s), (work: %14s), (bday: %s)\n",
	       name,
	       home_phone ? home_phone : "",
	       work_phone ? work_phone : "",
	       bday ? bday : "*unknown*");
    }
  else
    {
      while (entry != NIL)
	{
	  char *tag, *value;
	  WispObject *pair;

	  pair = CAR (entry);
	  entry = CDR (entry);

	  tag = prettify (STRING_VALUE (CAR (pair)));
	  value = "";

	  if (CDR (pair) != NIL)
	    value = STRING_VALUE (CADR (pair));

	  fprintf (stream, "%14s  %s\n", tag, value);
	  free (tag);
	}
    }
}
Beispiel #17
0
static void dump_cmd_op(unsigned int op, unsigned int *n, int silent) {
	char buf[16];
	char out[1000];
	const char *pre;
	const char *p = catcmd(op, buf);
	const unsigned int opk = opKIND(op);
	const unsigned int opa = argKIND(op);

	if (strcmp(p, "???") == 0)
		return;
	if (! isRARG(op)) {
		if (opk == KIND_CMON && isNULL(monfuncs[opa].mondcmplx))
			return;
		if (opk == KIND_CDYA && isNULL(dyfuncs[opa].dydcmplx))
			return;
		if (opk == KIND_MON && isNULL(monfuncs[opa].mondreal) && isNULL(monfuncs[opa].monint))
			return ;
		if (opk == KIND_DYA && isNULL(dyfuncs[opa].dydreal) && isNULL(dyfuncs[opa].dydint))
			return ;
	}
	++*n;
	if (silent)
		return;
	pre = "";
	if (opk == KIND_CMON || opk == KIND_CDYA)
		pre = "[cmplx]";
	else if (isRARG(op) && RARG_CMD(op) == RARG_CONST_CMPLX)
		pre = "[cmplx]# ";
	else if (isRARG(op) && RARG_CMD(op) == RARG_CONST)
		pre = "# ";
	else if (isRARG(op) && RARG_CMD(op) == RARG_ALPHA)
		pre = "Alpha ";
	prettify(p, out, 0);
	if (strncmp("[cmplx]", out, 7) == 0 && !(isRARG(op) && RARG_CMD(op) == RARG_ALPHA))
		pre = "";
	printf("%-5u  %04x   %s%s\n", *n, op, pre, out);
}
Beispiel #18
0
void TransliteratorAPITest::TestTransliterate2(){
     //testing tranliterate(String text, int start, int limit, StringBuffer result)
   UnicodeString Data2[]={
         //ID, input string, start, limit, transliterated string
         "Any-Hex",         "hello! How are you?",  "0", "5", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F! How are you?", "") ,
         "Any-Hex",         "hello! How are you?",  "7", "12", UnicodeString("\\u0048\\u006F\\u0077\\u0020\\u0061", ""), UnicodeString("hello! \\u0048\\u006F\\u0077\\u0020\\u0061re you?", ""),
         "Hex-Any",         CharsToUnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F\\u0021\\u0020"), "0", "5",  "hello", "hello! "  ,
       //  "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"),        "1", "2",  CharsToUnicodeString("\\u0041\\u0301"), CharsToUnicodeString("\\u00C0\\u0041\\u0301\\u0042") ,
         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "0", "1",  "bha", CharsToUnicodeString("bha\\u093E\\u0930\\u0924") ,
         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "1", "2",  CharsToUnicodeString("\\u0314\\u0101"), CharsToUnicodeString("\\u092D\\u0314\\u0101\\u0930\\u0924")  

    };
    logln("\n   Testing transliterate(String, int, int, StringBuffer)");
    Transliterator* t;
    UnicodeString gotResBuf;
    UnicodeString temp;
    int32_t start, limit;
    UErrorCode status = U_ZERO_ERROR;
    UParseError parseError;

    for(uint32_t i=0; i<sizeof(Data2)/sizeof(Data2[0]); i=i+6){
        t=Transliterator::createInstance(Data2[i+0], UTRANS_FORWARD, parseError, status);
        if(t==0){
            dataerrln("FAIL: construction: " + prettify(Data2[i+0]) + " - " + u_errorName(status));
            continue;
        }
        start=getInt(Data2[i+2]);
        limit=getInt(Data2[i+3]);
        Data2[i+1].extractBetween(start, limit, gotResBuf);
        t->transliterate(gotResBuf);
        //  errln("FAIL: calling transliterate on " + t->getID());
        doTest(t->getID() + ".transliterate(UnicodeString, int32_t, int32_t, UnicodeString):(" + start + "," + limit + ")  for \n\t source: " + prettify(Data2[i+1]), gotResBuf, Data2[i+4]);

        temp=Data2[i+1];
        t->transliterate(temp, start, limit);
        doTest(t->getID() + ".transliterate(Replaceable, int32_t, int32_t, ):(" + start + "," + limit + ")  for \n\t source: " + prettify(Data2[i+1]), temp, Data2[i+5]);
        status = U_ZERO_ERROR;
        callEverything(t, __LINE__);
        delete t;
        t = NULL;
    }

    status = U_ZERO_ERROR;
    logln("\n   Try calling transliterate with illegal start and limit values");
    t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
    if(U_FAILURE(status)) {
      errln("Error creating transliterator %s", u_errorName(status));
      delete t;
      return;
    }
    gotResBuf = temp = "try start greater than limit";
    t->transliterate(gotResBuf, 10, 5);
    if(gotResBuf == temp) {
        logln("OK: start greater than limit value handled correctly");
    } else {
        errln("FAIL: start greater than limit value returned" + gotResBuf);
    }

    callEverything(t, __LINE__);
    delete t;

}
Beispiel #19
0
void collectmailsesb::handleMail(QJsonObject mail)
{
    QString sSubject = mail["Subject"].toString();
    if(helpers::str_isempty(sSubject, true))return;
    if(sSubject.indexOf('[') != 0)return;
    if(sSubject.indexOf(" ESB Notification") < 3)return;

    //[SOA-SALES-SERVICES Prod] [Cluster B] ESB Notification
    //[SEN-SOA-SALES-SERVICES Production] ESB Notification
    //[SOA-SALES-SERVICES] ESB Notification (TEST-Environment)

    sSubject = prettify(sSubject.replace("[UNIFY-", "[").replace("[SEN-", "["));

    //[SOA-SALES-SERVICES Prod] [Cluster B] ESB Notification
    //[SOA-SALES-SERVICES Production] ESB Notification
    //[SOA-SALES-SERVICES] ESB Notification (TEST-Environment)

    QJsonObject body = mail["Body"].toObject();
    QString sBody = body["Content"].toString();
    if(helpers::str_isempty(sBody, true))
    {
        helpers::log("cmailsesb:handleMail !sBody:'"+sSubject+"'", LOG_WRN, qApp, 0);
        return;
    }
    sBody = sBody.replace("<br>", "\n").replace("\\r\\n", "\n").replace("\\n\\n", "\n").trimmed().replace(".\n", "\n").replace("\\\"", "\"");
    //helpers::log("cmailsesb:handleMail sBody:'"+sSubject+"'----------\n"+sBody+"\n------------------------", LOG_INF, qApp, 0);

    //get html between <body ... </body>
    sBody = getBetween(sBody, "<body","</body>");
    {   //remove <hr ...>
        static QRegExp hr("<hr(.)[^>]*>");
        sBody = sBody.remove(hr);
    }

    QDomDocument doc(xml::GetRootEle(sBody));
    QString errorStr;
    int errorLine=0, errorColumn=0;
    if (!doc.setContent(sBody, true, &errorStr, &errorLine, &errorColumn))
    {
        helpers::log("cmailsesb:handleMail !xml:'"+sSubject+"'-----------------\n"+sBody+"\n----------------------", LOG_WRN, qApp, 0);
        return;
    }
    QDomElement root = doc.documentElement();
    QJsonObject day;
    {
        QDomElement e = root.firstChildElement();
        QString h5 = "";
        while (!e.isNull())
        {
            QString sTagName = e.nodeName().toLower().trimmed();
            if(sTagName.compare("h5", Qt::CaseInsensitive) == 0)
            {
                h5 = prettify(xml::getText(e));
            }
            else if(sTagName.compare("table", Qt::CaseInsensitive) == 0)
            {
                handleMailTable(h5, e, &day);
                h5 = "";
            }

            e = e.nextSiblingElement();
        }
    }
    {
        QString sDate = mail["DateTimeSent"].toString();
        day.insert("date", QJsonValue(sDate));
    }

    QJsonArray* pa = mailInfos[sSubject];
    if(!pa)
    {
        pa = new QJsonArray();
        mailInfos[sSubject] = pa;
    }
    pa->append(QJsonValue(day));
}
Beispiel #20
0
void IntlTestDateFormat::tryDate(UDate theDate)
{
    const int32_t DEPTH = 10;
    UDate date[DEPTH];
    UnicodeString string[DEPTH];

    int32_t dateMatch = 0;
    int32_t stringMatch = 0;
    UBool dump = FALSE;
#if defined (U_CAL_DEBUG)
    dump = TRUE;
#endif
    int32_t i;

    date[0] = theDate;
    fFormat->format(theDate, string[0]);

    for (i=1; i<DEPTH; ++i)
    {
        UErrorCode status = U_ZERO_ERROR;
        date[i] = fFormat->parse(string[i-1], status);
        if (U_FAILURE(status))
        {
            describeTest();
            errln("**** FAIL: Parse of " + prettify(string[i-1], FALSE) + " failed.");
            dump = TRUE;
            break;
        }
        fFormat->format(date[i], string[i]);
        if (dateMatch == 0 && date[i] == date[i-1])
            dateMatch = i;
        else if (dateMatch > 0 && date[i] != date[i-1])
        {
            describeTest();
            errln("**** FAIL: Date mismatch after match for " + string[i]);
            dump = TRUE;
            break;
        }
        if (stringMatch == 0 && string[i] == string[i-1])
            stringMatch = i;
        else if (stringMatch > 0 && string[i] != string[i-1])
        {
            describeTest();
            errln("**** FAIL: String mismatch after match for " + string[i]);
            dump = TRUE;
            break;
        }
        if (dateMatch > 0 && stringMatch > 0)
            break;
    }
    if (i == DEPTH)
        --i;

    if (stringMatch > fLimit || dateMatch > fLimit)
    {
        describeTest();
        errln((UnicodeString)"**** FAIL: No string and/or date match within " + fLimit
            + " iterations for the Date " + string[0] + "\t(" + theDate + ").");
        dump = TRUE;
    }

    if (dump)
    {
        for (int32_t k=0; k<=i; ++k)
        {
            logln((UnicodeString)"" + k + ": " + date[k] + " F> " +
                  string[k] + " P> ");
        }
    }
}
Beispiel #21
0
void
JamoTest::TestRealText() {
    // Test text taken from the Unicode web site
     static const char* const WHAT_IS_UNICODE[] = {
      "\\uc720\\ub2c8\\ucf54\\ub4dc\\uc5d0", "\\ub300\\ud574", "?",

      "\\uc5b4\\ub5a4", "\\ud50c\\ub7ab\\ud3fc,", "\\uc5b4\\ub5a4",
      "\\ud504\\ub85c\\uadf8\\ub7a8,", "\\uc5b4\\ub5a4", "\\uc5b8\\uc5b4\\uc5d0\\ub3c4",
      "\\uc0c1\\uad00\\uc5c6\\uc774", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294", "\\ubaa8\\ub4e0",
      "\\ubb38\\uc790\\uc5d0", "\\ub300\\ud574", "\\uace0\\uc720", "\\ubc88\\ud638\\ub97c",
      "\\uc81c\\uacf5\\ud569\\ub2c8\\ub2e4.",

      "\\uae30\\ubcf8\\uc801\\uc73c\\ub85c", "\\ucef4\\ud4e8\\ud130\\ub294",
      "\\uc22b\\uc790\\ub9cc", "\\ucc98\\ub9ac\\ud569\\ub2c8\\ub2e4.", "\\uae00\\uc790\\ub098",
      "\\ub2e4\\ub978", "\\ubb38\\uc790\\uc5d0\\ub3c4", "\\uc22b\\uc790\\ub97c",
      "\\uc9c0\\uc815\\ud558\\uc5ec",
      "\\uc800\\uc7a5\\ud569\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\uac00",
      "\\uac1c\\ubc1c\\ub418\\uae30", "\\uc804\\uc5d0\\ub294", "\\uc774\\ub7ec\\ud55c",
      "\\uc22b\\uc790\\ub97c", "\\uc9c0\\uc815\\ud558\\uae30", "\\uc704\\ud574", "\\uc218\\ubc31",
      "\\uac00\\uc9c0\\uc758", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654",
      "\\uc2dc\\uc2a4\\ud15c\\uc744",
      "\\uc0ac\\uc6a9\\ud588\\uc2b5\\ub2c8\\ub2e4.", "\\ub2e8\\uc77c", "\\uae30\\ud638\\ud654",
      "\\ubc29\\ubc95\\uc73c\\ub85c\\ub294", "\\ubaa8\\ub4e0", "\\ubb38\\uc790\\ub97c",
      "\\ud3ec\\ud568\\ud560", "\\uc218", "\\uc5c6\\uc5c8\\uc2b5\\ub2c8\\ub2e4.", "\\uc608\\ub97c",
      "\\ub4e4\\uc5b4", "\\uc720\\ub7fd", "\\uc5f0\\ud569\\uc5d0\\uc11c\\ub9cc",
      "\\ubcf4\\ub354\\ub77c\\ub3c4", "\\ubaa8\\ub4e0", "\\uac01", "\\ub098\\ub77c\\ubcc4",
      "\\uc5b8\\uc5b4\\ub97c", "\\ucc98\\ub9ac\\ud558\\ub824\\uba74", "\\uc5ec\\ub7ec",
      "\\uac1c\\uc758", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774",
      "\\ud544\\uc694\\ud569\\ub2c8\\ub2e4.", "\\uc601\\uc5b4\\uc640", "\\uac19\\uc740",
      "\\ub2e8\\uc77c", "\\uc5b8\\uc5b4\\uc758", "\\uacbd\\uc6b0\\ub3c4",
      "\\uacf5\\ud1b5\\uc801\\uc73c\\ub85c", "\\uc0ac\\uc6a9\\ub418\\ub294", "\\ubaa8\\ub4e0",
      "\\uae00\\uc790,", "\\ubb38\\uc7a5", "\\ubd80\\ud638", "\\ubc0f",
      "\\ud14c\\ud06c\\ub2c8\\uceec", "\\uae30\\ud638\\uc5d0", "\\ub9de\\ub294", "\\ub2e8\\uc77c",
      "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc744", "\\uac16\\uace0", "\\uc788\\uc9c0",
      "\\ubabb\\ud558\\uc600\\uc2b5\\ub2c8\\ub2e4.",

      "\\uc774\\ub7ec\\ud55c", "\\uae30\\ud638\\ud654", "\\uc2dc\\uc2a4\\ud15c\\uc740",
      "\\ub610\\ud55c", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\uc2dc\\uc2a4\\ud15c\\uacfc",
      "\\ucda9\\ub3cc\\ud569\\ub2c8\\ub2e4.", "\\uc989", "\\ub450", "\\uac00\\uc9c0",
      "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774", "\\ub450", "\\uac1c\\uc758", "\\ub2e4\\ub978",
      "\\ubb38\\uc790\\uc5d0", "\\ub300\\ud574", "\\uac19\\uc740", "\\ubc88\\ud638\\ub97c",
      "\\uc0ac\\uc6a9\\ud558\\uac70\\ub098", "\\uac19\\uc740", "\\ubb38\\uc790\\uc5d0",
      "\\ub300\\ud574", "\\ub2e4\\ub978", "\\ubc88\\ud638\\ub97c", "\\uc0ac\\uc6a9\\ud560", "\\uc218",
      "\\uc788\\uc2b5\\ub2c8\\ub2e4.", "\\uc8fc\\uc5b4\\uc9c4", "\\ubaa8\\ub4e0",
      "\\ucef4\\ud4e8\\ud130(\\ud2b9\\ud788", "\\uc11c\\ubc84)\\ub294", "\\uc11c\\ub85c",
      "\\ub2e4\\ub978", "\\uc5ec\\ub7ec", "\\uac00\\uc9c0", "\\uae30\\ud638\\ud654",
      "\\ubc29\\ubc95\\uc744", "\\uc9c0\\uc6d0\\ud574\\uc57c",
      "\\ud569\\ub2c8\\ub2e4.", "\\uadf8\\ub7ec\\ub098,", "\\ub370\\uc774\\ud130\\ub97c",
      "\\uc11c\\ub85c", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774\\ub098",
      "\\ud50c\\ub7ab\\ud3fc", "\\uac04\\uc5d0", "\\uc804\\ub2ec\\ud560", "\\ub54c\\ub9c8\\ub2e4",
      "\\uadf8", "\\ub370\\uc774\\ud130\\ub294", "\\ud56d\\uc0c1", "\\uc190\\uc0c1\\uc758",
      "\\uc704\\ud5d8\\uc744", "\\uacaa\\uac8c", "\\ub429\\ub2c8\\ub2e4.",

      "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub85c", "\\ubaa8\\ub4e0", "\\uac83\\uc744",
      "\\ud574\\uacb0\\ud560", "\\uc218", "\\uc788\\uc2b5\\ub2c8\\ub2e4!",
      "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294", "\\uc0ac\\uc6a9", "\\uc911\\uc778",
      "\\ud50c\\ub7ab\\ud3fc,", "\\ud504\\ub85c\\uadf8\\ub7a8,", "\\uc5b8\\uc5b4\\uc5d0",
      "\\uad00\\uacc4\\uc5c6\\uc774", "\\ubb38\\uc790\\ub9c8\\ub2e4", "\\uace0\\uc720\\ud55c",
      "\\uc22b\\uc790\\ub97c",
      "\\uc81c\\uacf5\\ud569\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc",
      "\\ud45c\\uc900\\uc740", // "Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, "
      // "Sun, Sybase, Unisys "
      "\\ubc0f", "\\uae30\\ud0c0", "\\uc5ec\\ub7ec",
      "\\ud68c\\uc0ac\\uc640", "\\uac19\\uc740", "\\uc5c5\\uacc4",
      "\\uc120\\ub450\\uc8fc\\uc790\\uc5d0", "\\uc758\\ud574",
      "\\ucc44\\ud0dd\\ub418\\uc5c8\\uc2b5\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294",
      // "XML, Java, ECMAScript(JavaScript), LDAP, CORBA 3.0, WML "
      "\\ub4f1\\uacfc",
      "\\uac19\\uc774", "\\ud604\\uc7ac", "\\ub110\\ub9ac", "\\uc0ac\\uc6a9\\ub418\\ub294",
      "\\ud45c\\uc900\\uc5d0\\uc11c", "\\ud544\\uc694\\ud558\\uba70", "\\uc774\\ub294", // "ISO/IEC",
      "10646\\uc744", "\\uad6c\\ud604\\ud558\\ub294", "\\uacf5\\uc2dd\\uc801\\uc778",
      "\\ubc29\\ubc95\\uc785\\ub2c8\\ub2e4.", "\\uc774\\ub294", "\\ub9ce\\uc740", "\\uc6b4\\uc601",
      "\\uccb4\\uc81c,", "\\uc694\\uc998", "\\uc0ac\\uc6a9\\ub418\\ub294", "\\ubaa8\\ub4e0",
      "\\ube0c\\ub77c\\uc6b0\\uc800", "\\ubc0f", "\\uae30\\ud0c0", "\\ub9ce\\uc740",
      "\\uc81c\\ud488\\uc5d0\\uc11c",
      "\\uc9c0\\uc6d0\\ub429\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc",
      "\\ud45c\\uc900\\uc758", "\\ubd80\\uc0c1\\uacfc", "\\uc774\\ub97c",
      "\\uc9c0\\uc6d0\\ud558\\ub294", "\\ub3c4\\uad6c\\uc758", "\\uac00\\uc6a9\\uc131\\uc740",
      "\\ucd5c\\uadfc", "\\uc804", "\\uc138\\uacc4\\uc5d0", "\\ubd88\\uace0", "\\uc788\\ub294",
      "\\uae30\\uc220", "\\uacbd\\ud5a5\\uc5d0\\uc11c", "\\uac00\\uc7a5", "\\uc911\\uc694\\ud55c",
      "\\ubd80\\ubd84\\uc744", "\\ucc28\\uc9c0\\ud558\\uace0", "\\uc788\\uc2b5\\ub2c8\\ub2e4.",

      "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub97c",
      // Replaced a hyphen with a space to make the test case work with CLDR1.5  
      //"\\ud074\\ub77c\\uc774\\uc5b8\\ud2b8-\\uc11c\\ubc84", "\\ub610\\ub294",
      "\\ud074\\ub77c\\uc774\\uc5b8\\ud2b8 \\uc11c\\ubc84", "\\ub610\\ub294",
      // Replaced a hyphen with a space.
      //"\\ub2e4\\uc911-\\uc5f0\\uacb0", "\\uc751\\uc6a9", "\\ud504\\ub85c\\uadf8\\ub7a8\\uacfc",
      "\\ub2e4\\uc911 \\uc5f0\\uacb0", "\\uc751\\uc6a9", "\\ud504\\ub85c\\uadf8\\ub7a8\\uacfc",
      "\\uc6f9", "\\uc0ac\\uc774\\ud2b8\\uc5d0", "\\ud1b5\\ud569\\ud558\\uba74",
      "\\ub808\\uac70\\uc2dc", "\\ubb38\\uc790", "\\uc138\\ud2b8", "\\uc0ac\\uc6a9\\uc5d0",
      "\\uc788\\uc5b4\\uc11c", "\\uc0c1\\ub2f9\\ud55c", "\\ube44\\uc6a9", "\\uc808\\uac10",
      "\\ud6a8\\uacfc\\uac00",
      "\\ub098\\ud0c0\\ub0a9\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub97c",
      "\\ud1b5\\ud574", "\\ub9ac\\uc5d4\\uc9c0\\ub2c8\\uc5b4\\ub9c1", "\\uc5c6\\uc774",
      "\\ub2e4\\uc911", "\\ud50c\\ub7ab\\ud3fc,", "\\uc5b8\\uc5b4", "\\ubc0f", "\\uad6d\\uac00",
      "\\uac04\\uc5d0", "\\ub2e8\\uc77c", "\\uc18c\\ud504\\ud2b8\\uc6e8\\uc5b4",
      "\\ud50c\\ub7ab\\ud3fc", "\\ub610\\ub294", "\\ub2e8\\uc77c", "\\uc6f9",
      "\\uc0ac\\uc774\\ud2b8\\ub97c", "\\ubaa9\\ud45c\\ub85c", "\\uc0bc\\uc744", "\\uc218",
      "\\uc788\\uc2b5\\ub2c8\\ub2e4.", "\\uc774\\ub97c", "\\uc0ac\\uc6a9\\ud558\\uba74",
      "\\ub370\\uc774\\ud130\\ub97c", "\\uc190\\uc0c1", "\\uc5c6\\uc774", "\\uc5ec\\ub7ec",
      "\\uc2dc\\uc2a4\\ud15c\\uc744", "\\ud1b5\\ud574", "\\uc804\\uc1a1\\ud560", "\\uc218",
      "\\uc788\\uc2b5\\ub2c8\\ub2e4.",

      "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc5d0", "\\ub300\\ud574",
      "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc740",
      "\\ube44\\uc601\\ub9ac", "\\uc870\\uc9c1\\uc73c\\ub85c\\uc11c", "\\ud604\\ub300",
      "\\uc18c\\ud504\\ud2b8\\uc6e8\\uc5b4", "\\uc81c\\ud488\\uacfc",
      "\\ud45c\\uc900\\uc5d0\\uc11c", "\\ud14d\\uc2a4\\ud2b8\\uc758", "\\ud45c\\ud604\\uc744",
      "\\uc9c0\\uc815\\ud558\\ub294", "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ud45c\\uc900\\uc758",
      "\\uc0ac\\uc6a9\\uc744", "\\uac1c\\ubc1c\\ud558\\uace0", "\\ud655\\uc7a5\\ud558\\uba70",
      "\\uc7a5\\ub824\\ud558\\uae30", "\\uc704\\ud574",
      "\\uc138\\uc6cc\\uc84c\\uc2b5\\ub2c8\\ub2e4.", "\\ucf58\\uc18c\\uc2dc\\uc5c4",
      "\\uba64\\ubc84\\uc27d\\uc740", "\\ucef4\\ud4e8\\ud130\\uc640", "\\uc815\\ubcf4",
      "\\ucc98\\ub9ac", "\\uc0b0\\uc5c5\\uc5d0", "\\uc885\\uc0ac\\ud558\\uace0", "\\uc788\\ub294",
      "\\uad11\\ubc94\\uc704\\ud55c", "\\ud68c\\uc0ac", "\\ubc0f", "\\uc870\\uc9c1\\uc758",
      "\\ubc94\\uc704\\ub97c",
      "\\ub098\\ud0c0\\ub0c5\\ub2c8\\ub2e4.", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc758",
      "\\uc7ac\\uc815\\uc740", "\\uc804\\uc801\\uc73c\\ub85c", "\\ud68c\\ube44\\uc5d0",
      "\\uc758\\ud574", "\\ucda9\\ub2f9\\ub429\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc",
      "\\ucee8\\uc18c\\uc2dc\\uc5c4\\uc5d0\\uc11c\\uc758", "\\uba64\\ubc84\\uc27d\\uc740",
      "\\uc804", "\\uc138\\uacc4", "\\uc5b4\\ub290", "\\uacf3\\uc5d0\\uc11c\\ub098",
      "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ud45c\\uc900\\uc744", "\\uc9c0\\uc6d0\\ud558\\uace0",
      "\\uadf8", "\\ud655\\uc7a5\\uacfc", "\\uad6c\\ud604\\uc744",
      "\\uc9c0\\uc6d0\\ud558\\uace0\\uc790\\ud558\\ub294", "\\uc870\\uc9c1\\uacfc",
      "\\uac1c\\uc778\\uc5d0\\uac8c", "\\uac1c\\ubc29\\ub418\\uc5b4",
      "\\uc788\\uc2b5\\ub2c8\\ub2e4.",

      "\\ub354", "\\uc790\\uc138\\ud55c", "\\ub0b4\\uc6a9\\uc740", "\\uc6a9\\uc5b4\\uc9d1,",
      "\\uc608\\uc81c", "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\uc0ac\\uc6a9", "\\uac00\\ub2a5",
      "\\uc81c\\ud488,", "\\uae30\\uc220", "\\uc815\\ubcf4", "\\ubc0f", "\\uae30\\ud0c0",
      "\\uc720\\uc6a9\\ud55c", "\\uc815\\ubcf4\\ub97c",
      "\\ucc38\\uc870\\ud558\\uc2ed\\uc2dc\\uc624."
    };

    enum { WHAT_IS_UNICODE_length = sizeof(WHAT_IS_UNICODE) / sizeof(WHAT_IS_UNICODE[0]) };

    UParseError parseError;
    UErrorCode status = U_ZERO_ERROR;
    Transliterator* latinJamo = Transliterator::createInstance("Latin-Jamo", UTRANS_FORWARD, parseError, status);
    Transliterator* jamoHangul = Transliterator::createInstance("NFC(NFD)", UTRANS_FORWARD, parseError, status);
    if (latinJamo == 0 || jamoHangul == 0 || U_FAILURE(status)) {
        delete latinJamo;
        delete jamoHangul;
        dataerrln("FAIL: createInstance returned NULL - %s", u_errorName(status));
        return;
    }
    Transliterator* jamoLatin = latinJamo->createInverse(status);
    Transliterator* hangulJamo = jamoHangul->createInverse(status);
    if (jamoLatin == 0 || hangulJamo == 0) {
        errln("FAIL: createInverse returned NULL");
        delete latinJamo;
        delete jamoLatin;
        delete jamoHangul;
        delete hangulJamo;
        return;
    }

    Transliterator* tarray[4] =
        { hangulJamo, jamoLatin, latinJamo, jamoHangul };
    CompoundTransliterator rt(tarray, 4);
    
    UnicodeString buf;
    int32_t total = 0;
    int32_t errors = 0;
    int32_t i;
    for (i=0; i < WHAT_IS_UNICODE_length; ++i) {
        ++total;
        UnicodeString hangul = UnicodeString(WHAT_IS_UNICODE[i], -1, US_INV);
        hangul = hangul.unescape(); // Parse backslash-u escapes
        UnicodeString hangulX = hangul;
        rt.transliterate(hangulX);
        if (hangul != hangulX) {
            ++errors;
            UnicodeString jamo = hangul; hangulJamo->transliterate(jamo);
            UnicodeString latin = jamo; jamoLatin->transliterate(latin);
            UnicodeString jamo2 = latin; latinJamo->transliterate(jamo2);
            UnicodeString hangul2 = jamo2; jamoHangul->transliterate(hangul2);
            
            buf.remove(0);
            buf.append("FAIL: ");
            if (hangul2 != hangulX) {
                buf.append((UnicodeString)"(Weird: " + hangulX + " != " + hangul2 + ")");
            }
            // The Hangul-Jamo conversion is not usually the
            // bug here, so we hide it from display.
            // Uncomment lines to see the Hangul.
            buf.append(//hangul + " => " +
                       jamoToName(jamo) + " => " +
                       latin + " => " + jamoToName(jamo2)
                       //+ " => " + hangul2
                       );
            errln(prettify(buf));
        }
    }
    if (errors != 0) {
        errln((UnicodeString)"Test word failures: " + errors + " out of " + total);
    } else {
        logln((UnicodeString)"All " + total + " test words passed");
    }

    delete latinJamo;
    delete jamoLatin;
    delete jamoHangul;
    delete hangulJamo;
}
Beispiel #22
0
/**
 * Read the external dictionary file, which is already in proper
 * sorted order, and confirm that the collator compares each line as
 * preceding the following line.
 */
void CollationThaiTest::TestDictionary(void) {
    if (coll == 0) {
        errln("Error: could not construct Thai collator");
        return;
    }

    UErrorCode ec = U_ZERO_ERROR;
    TextFile riwords("riwords.txt", "UTF8", ec);
    if (U_FAILURE(ec)) {
        logln("Can't open riwords.txt: %s; skipping test",
              u_errorName(ec));
        return;
    }

    //
    // Loop through each word in the dictionary and compare it to the previous
    // word.  They should be in sorted order.
    //
    UnicodeString lastWord, word;
    int32_t failed = 0;
    int32_t wordCount = 0;
    while (riwords.readLineSkippingComments(word, ec, FALSE) && U_SUCCESS(ec)) {

        // Show the first 8 words being compared, so we can see what's happening
        ++wordCount;
        if (wordCount <= 8) {
            UnicodeString str;
            logln((UnicodeString)"Word " + wordCount + ": " + IntlTest::prettify(word, str));
        }

        if (lastWord.length() > 0) {
            int32_t result = coll->compare(lastWord, word);

            if (result > 0) {
                failed++;
                if (MAX_FAILURES_TO_SHOW < 0 || failed <= MAX_FAILURES_TO_SHOW) {
                    UnicodeString str;
                    UnicodeString msg =
                        UnicodeString("--------------------------------------------\n")
                        + riwords.getLineNumber()
                        + " compare(" + IntlTest::prettify(lastWord, str);
                    msg += UnicodeString(", ")
                        + IntlTest::prettify(word, str) + ") returned " + result
                        + ", expected -1\n";
                    UErrorCode status = U_ZERO_ERROR;
                    CollationKey k1, k2;
                    coll->getCollationKey(lastWord, k1, status);
                    coll->getCollationKey(word, k2, status);
                    if (U_FAILURE(status)) {
                        errln((UnicodeString)"Fail: getCollationKey returned " + u_errorName(status));
                        return;
                    }
                    msg.append("key1: ").append(prettify(k1, str)).append("\n");
                    msg.append("key2: ").append(prettify(k2, str));
                    errln(msg);
                }
            }
        }
        lastWord = word;
    }

    assertSuccess("readLine", ec);

    if (failed != 0) {
        if (failed > MAX_FAILURES_TO_SHOW) {
            errln((UnicodeString)"Too many failures; only the first " +
                  MAX_FAILURES_TO_SHOW + " failures were shown");
        }
        errln((UnicodeString)"Summary: " + failed + " of " + (riwords.getLineNumber() - 1) +
              " comparisons failed");
    }

    logln((UnicodeString)"Words checked: " + wordCount);
}
Beispiel #23
0
void CollationThaiTest::compareArray(Collator& c, const char* tests[],
                                     int32_t testsLength) {
    for (int32_t i = 0; i < testsLength; i += 3) {

        Collator::EComparisonResult expect;
        if (tests[i+1][0] == '<') {
          expect = Collator::LESS;
        } else if (tests[i+1][0] == '>') {
          expect = Collator::GREATER;
        } else if (tests[i+1][0] == '=') {
          expect = Collator::EQUAL;
        } else {
            // expect = Integer.decode(tests[i+1]).intValue();
            errln((UnicodeString)"Error: unknown operator " + tests[i+1]);
            return;
        }

        UnicodeString s1, s2;
        parseChars(s1, tests[i]);
        parseChars(s2, tests[i+2]);

        doTest(&c, s1, s2, expect);
#if 0
        UErrorCode status = U_ZERO_ERROR;
        int32_t result = c.compare(s1, s2);
        if (sign(result) != sign(expect))
        {
            UnicodeString t1, t2;
            errln(UnicodeString("") +
                  i/3 + ": compare(" + IntlTest::prettify(s1, t1)
                  + " , " + IntlTest::prettify(s2, t2)
                  + ") got " + result + "; expected " + expect);

            CollationKey k1, k2;
            c.getCollationKey(s1, k1, status);
            c.getCollationKey(s2, k2, status);
            if (U_FAILURE(status)) {
                errln((UnicodeString)"Fail: getCollationKey returned " + u_errorName(status));
                return;
            }
            errln((UnicodeString)"  key1: " + prettify(k1, t1) );
            errln((UnicodeString)"  key2: " + prettify(k2, t2) );
        }
        else
        {
            // Collator.compare worked OK; now try the collation keys
            CollationKey k1, k2;
            c.getCollationKey(s1, k1, status);
            c.getCollationKey(s2, k2, status);
            if (U_FAILURE(status)) {
                errln((UnicodeString)"Fail: getCollationKey returned " + u_errorName(status));
                return;
            }

            result = k1.compareTo(k2);
            if (sign(result) != sign(expect)) {
                UnicodeString t1, t2;
                errln(UnicodeString("") +
                      i/3 + ": key(" + IntlTest::prettify(s1, t1)
                      + ").compareTo(key(" + IntlTest::prettify(s2, t2)
                      + ")) got " + result + "; expected " + expect);
                
                errln((UnicodeString)"  " + prettify(k1, t1) + " vs. " + prettify(k2, t2));
            }
        }
#endif
    }
}
Beispiel #24
0
/*Internal Functions used*/
void TransliteratorAPITest::doTest(const UnicodeString& message, const UnicodeString& result, const UnicodeString& expected){
    if (prettify(result) == prettify(expected)) 
        logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\"");
    else 
        dataerrln((UnicodeString)"FAIL:" + message + " failed  Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) );
}
Beispiel #25
0
void
DateFormatMiscTests::test4117335()
{
    //UnicodeString bc = "\u7d00\u5143\u524d";
    UChar bcC [] = {
        0x7D00,
        0x5143,
        0x524D
    };
    UnicodeString bc(bcC, 3, 3);

    //UnicodeString ad = "\u897f\u66a6";
    UChar adC [] = {
        0x897F,
        0x66A6
    };
    UnicodeString ad(adC, 2, 2);
    
    //UnicodeString jstLong = "\u65e5\u672c\u6a19\u6e96\u6642";
    UChar jstLongC [] = {
        0x65e5,
        0x672c,
        0x6a19,
        0x6e96,
        0x6642
    };
    UChar jdtLongC [] = {0x65E5, 0x672C, 0x590F, 0x6642, 0x9593};

    UnicodeString jstLong(jstLongC, 5, 5);

    UnicodeString jstShort = "JST";
    
    UnicodeString tzID = "Asia/Tokyo";

    UnicodeString jdtLong(jdtLongC, 5, 5);
 
    UnicodeString jdtShort = "JDT";
    UErrorCode status = U_ZERO_ERROR;
    DateFormatSymbols *symbols = new DateFormatSymbols(Locale::getJapan(), status);
    if(U_FAILURE(status)) {
      errcheckln(status, "Failure creating DateFormatSymbols, %s", u_errorName(status));
      delete symbols;
      return;
    }
    failure(status, "new DateFormatSymbols");
    int32_t eraCount = 0;
    const UnicodeString *eras = symbols->getEraNames(eraCount);
    
    logln(UnicodeString("BC = ") + eras[0]);
    if (eras[0] != bc) {
        errln("*** Should have been " + bc);
        //throw new Exception("Error in BC");
    }

    logln(UnicodeString("AD = ") + eras[1]);
    if (eras[1] != ad) {
        errln("*** Should have been " + ad);
        //throw new Exception("Error in AD");
    }

    int32_t rowCount, colCount;
    const UnicodeString **zones = symbols->getZoneStrings(rowCount, colCount);
    //don't hard code the index .. compute it.
    int32_t index = -1;
    for (int32_t i = 0; i < rowCount; ++i) {
        if (tzID == (zones[i][0])) {
            index = i;
            break;
        }
    }
    logln(UnicodeString("Long zone name = ") + zones[index][1]);
    if (zones[index][1] != jstLong) {
        errln("*** Should have been " + prettify(jstLong)+ " but it is: " + prettify(zones[index][1]));
        //throw new Exception("Error in long TZ name");
    }
    logln(UnicodeString("Short zone name = ") + zones[index][2]);
    if (zones[index][2] != jstShort) {
        errln("*** Should have been " + prettify(jstShort) + " but it is: " + prettify(zones[index][2]));
        //throw new Exception("Error in short TZ name");
    }
    logln(UnicodeString("Long zone name = ") + zones[index][3]);
    if (zones[index][3] != jdtLong) {
        errln("*** Should have been " + prettify(jstLong) + " but it is: " + prettify(zones[index][3]));
        //throw new Exception("Error in long TZ name");
    }
    logln(UnicodeString("SHORT zone name = ") + zones[index][4]);
    if (zones[index][4] != jdtShort) {
        errln("*** Should have been " + prettify(jstShort)+ " but it is: " + prettify(zones[index][4]));
        //throw new Exception("Error in short TZ name");
    }
    delete symbols;

}
Beispiel #26
0
int main(int argc, char *argv[])
{
    set_main_thread();
    setup_fork_guards();

    wsetlocale(LC_ALL, L"");
    program_name=L"fish_indent";

    env_init();
    input_init();

    /* Types of output we support */
    enum
    {
        output_type_plain_text,
        output_type_ansi,
        output_type_html
    } output_type = output_type_plain_text;

    /* Whether to indent (true) or just reformat to one job per line (false) */
    bool do_indent = true;

    while (1)
    {
        const struct option long_options[] =
        {
            { "no-indent", no_argument, 0, 'i' },
            { "help", no_argument, 0, 'h' },
            { "version", no_argument, 0, 'v' },
            { "html", no_argument, 0, 1 },
            { "ansi", no_argument, 0, 2 },
            { 0, 0, 0, 0 }
        };

        int opt_index = 0;
        int opt = getopt_long(argc, argv, "hvi", long_options, &opt_index);
        if (opt == -1)
            break;

        switch (opt)
        {
            case 0:
            {
                break;
            }

            case 'h':
            {
                print_help("fish_indent", 1);
                exit(0);
                assert(0 && "Unreachable code reached");
                break;
            }

            case 'v':
            {
                fwprintf(stderr, _(L"%ls, version %s\n"), program_name, get_fish_version());
                exit(0);
                assert(0 && "Unreachable code reached");
                break;
            }

            case 'i':
            {
                do_indent = false;
                break;
            }

            case 1:
            {
                output_type = output_type_html;
                break;
            }

            case 2:
            {
                output_type = output_type_ansi;
                break;
            }

            case '?':
            {
                exit(1);
            }
        }
    }

    const wcstring src = read_file(stdin);
    const wcstring output_wtext = prettify(src, do_indent);

    /* Maybe colorize */
    std::vector<highlight_spec_t> colors;
    if (output_type != output_type_plain_text)
    {
        highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL, env_vars_snapshot_t::current());
    }

    std::string colored_output;
    switch (output_type)
    {
        case output_type_plain_text:
            colored_output = no_colorize(output_wtext);
            break;

        case output_type_ansi:
            colored_output = ansi_colorize(output_wtext, colors);
            break;

        case output_type_html:
            colored_output = html_colorize(output_wtext, colors);
            break;
    }

    fputs(colored_output.c_str(), stdout);
    return 0;
}
Beispiel #27
0
int main(int argc, char *argv[]) {
    program_name = L"fish_indent";
    set_main_thread();
    setup_fork_guards();
    // Using the user's default locale could be a problem if it doesn't use UTF-8 encoding. That's
    // because the fish project assumes Unicode UTF-8 encoding in all of its scripts.
    //
    // TODO: Auto-detect the encoding of the script. We should look for a vim style comment
    // (e.g., "# vim: set fileencoding=<encoding-name>:") or an emacs style comment
    // (e.g., "# -*- coding: <encoding-name> -*-").
    setlocale(LC_ALL, "");
    env_init();

    // Types of output we support.
    enum {
        output_type_plain_text,
        output_type_file,
        output_type_ansi,
        output_type_html
    } output_type = output_type_plain_text;
    const char *output_location = "";
    bool do_indent = true;

    const char *short_opts = "+d:hvwiD:";
    const struct option long_opts[] = {{"debug-level", required_argument, NULL, 'd'},
                                       {"debug-stack-frames", required_argument, NULL, 'D'},
                                       {"dump-parse-tree", no_argument, NULL, 'P'},
                                       {"no-indent", no_argument, NULL, 'i'},
                                       {"help", no_argument, NULL, 'h'},
                                       {"version", no_argument, NULL, 'v'},
                                       {"write", no_argument, NULL, 'w'},
                                       {"html", no_argument, NULL, 1},
                                       {"ansi", no_argument, NULL, 2},
                                       {NULL, 0, NULL, 0}};

    int opt;
    while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
        switch (opt) {
            case 'P': {
                dump_parse_tree = true;
                break;
            }
            case 'h': {
                print_help("fish_indent", 1);
                exit(0);
                break;
            }
            case 'v': {
                fwprintf(stderr, _(L"%ls, version %s\n"), program_name, get_fish_version());
                exit(0);
                break;
            }
            case 'w': {
                output_type = output_type_file;
                break;
            }
            case 'i': {
                do_indent = false;
                break;
            }
            case 1: {
                output_type = output_type_html;
                break;
            }
            case 2: {
                output_type = output_type_ansi;
                break;
            }
            case 'd': {
                char *end;
                long tmp;

                errno = 0;
                tmp = strtol(optarg, &end, 10);

                if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
                    debug_level = (int)tmp;
                } else {
                    fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
                    exit(1);
                }
                break;
            }
            case 'D': {
                char *end;
                long tmp;

                errno = 0;
                tmp = strtol(optarg, &end, 10);

                if (tmp > 0 && tmp <= 128 && !*end && !errno) {
                    debug_stack_frames = (int)tmp;
                } else {
                    fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
                    exit(1);
                }
                break;
            }
            default: {
                // We assume getopt_long() has already emitted a diagnostic msg.
                exit(1);
                break;
            }
        }
    }

    argc -= optind;
    argv += optind;

    wcstring src;
    if (argc == 0) {
        if (output_type == output_type_file) {
            fwprintf(stderr, _(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
                     program_name);
            exit(1);
        }
        src = read_file(stdin);
    } else if (argc == 1) {
        FILE *fh = fopen(*argv, "r");
        if (fh) {
            src = read_file(fh);
            fclose(fh);
            output_location = *argv;
        } else {
            fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, strerror(errno));
            exit(1);
        }
    } else {
        fwprintf(stderr, _(L"Too many arguments\n"));
        exit(1);
    }

    const wcstring output_wtext = prettify(src, do_indent);

    // Maybe colorize.
    std::vector<highlight_spec_t> colors;
    if (output_type != output_type_plain_text) {
        highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL,
                              env_vars_snapshot_t::current());
    }

    std::string colored_output;
    switch (output_type) {
        case output_type_plain_text: {
            colored_output = no_colorize(output_wtext);
            break;
        }
        case output_type_file: {
            FILE *fh = fopen(output_location, "w");
            if (fh) {
                fputws(output_wtext.c_str(), fh);
                fclose(fh);
                exit(0);
            } else {
                fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
                         strerror(errno));
                exit(1);
            }
            break;
        }
        case output_type_ansi: {
            colored_output = ansi_colorize(output_wtext, colors);
            break;
        }
        case output_type_html: {
            colored_output = html_colorize(output_wtext, colors);
            break;
        }
    }

    fputws(str2wcstring(colored_output).c_str(), stdout);
    return 0;
}
Beispiel #28
0
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;
        }
    }
}
Beispiel #29
0
void LocaleAliasTest::TestDisplayName() {
    int32_t availableNum =0;
    const Locale* available = Locale::getAvailableLocales(availableNum);
    for (int i=0; i<_LOCALE_NUMBER; i++) {
        Locale oldLoc(_LOCALE_ALIAS[i][0]);
        Locale newLoc(_LOCALE_ALIAS[i][1]);
        if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
            logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
            continue;
        }
        for(int j=0; j<availableNum; j++){
            UnicodeString dipLocName = UnicodeString(available[j].getName());
            const UnicodeString oldCountry = oldLoc.getDisplayCountry(dipLocName);
            const UnicodeString newCountry = newLoc.getDisplayCountry(dipLocName);
            const UnicodeString oldLang = oldLoc.getDisplayLanguage(dipLocName);
            const UnicodeString newLang = newLoc.getDisplayLanguage(dipLocName);

            // is  there  display name for the current country ID               
            if(newCountry != newLoc.getCountry()){
                if(oldCountry!=newCountry){
                    errln("getCountry() failed for "+ UnicodeString(oldLoc.getName()) +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ UnicodeString(available[j].getName()));
                }
            }
            //there is a display name for the current lang ID               
            if(newLang != newLoc.getLanguage()){
                if(oldLang != newLang){
                    errln("getLanguage() failed for " + UnicodeString(oldLoc.getName()) + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+UnicodeString(available[j].getName()));
                }
            }
        }
    }
}
Beispiel #30
0
// used for collation result reporting, defined here for convenience
// (maybe moved later)
void
IntlTestCollator::reportCResult( const UnicodeString &source, const UnicodeString &target,
             CollationKey &sourceKey, CollationKey &targetKey,
             Collator::EComparisonResult compareResult,
             Collator::EComparisonResult keyResult,
                                Collator::EComparisonResult incResult,
                         Collator::EComparisonResult expectedResult )
{
    if (expectedResult < -1 || expectedResult > 1)
    {
        errln("***** invalid call to reportCResult ****");
        return;
    }

    UBool ok1 = (compareResult == expectedResult);
    UBool ok2 = (keyResult == expectedResult);
    UBool ok3 = (incResult == expectedResult);


    if (ok1 && ok2 && ok3 && !verbose) {
        // Keep non-verbose, passing tests fast
        return;
    } else {
        UnicodeString msg1(ok1 ? "Ok: compare(" : "FAIL: compare(");
        UnicodeString msg2(", "), msg3(") returned "), msg4("; expected ");
        UnicodeString prettySource, prettyTarget, sExpect, sResult;

        IntlTest::prettify(source, prettySource);
        IntlTest::prettify(target, prettyTarget);
        appendCompareResult(compareResult, sResult);
        appendCompareResult(expectedResult, sExpect);

        if (ok1) {
            logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
        } else {
            errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);
        }

        msg1 = UnicodeString(ok2 ? "Ok: key(" : "FAIL: key(");
        msg2 = ").compareTo(key(";
        msg3 = ")) returned ";

        appendCompareResult(keyResult, sResult);

        if (ok2) {
            logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
        } else {
            errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);

            msg1 = "  ";
            msg2 = " vs. ";

            prettify(sourceKey, prettySource);
            prettify(targetKey, prettyTarget);

            errln(msg1 + prettySource + msg2 + prettyTarget);
        }
        msg1 = UnicodeString (ok3 ? "Ok: incCompare(" : "FAIL: incCompare(");
        msg2 = ", ";
        msg3 = ") returned ";

        appendCompareResult(incResult, sResult);

        if (ok3) {
            logln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult);
        } else {
            errln(msg1 + prettySource + msg2 + prettyTarget + msg3 + sResult + msg4 + sExpect);
        }
    }
}