diff --git a/icu4c/source/test/intltest/callimts.cpp b/icu4c/source/test/intltest/callimts.cpp index ea15308de8e..2a2719f818d 100644 --- a/icu4c/source/test/intltest/callimts.cpp +++ b/icu4c/source/test/intltest/callimts.cpp @@ -32,20 +32,19 @@ void CalendarLimitTest::runIndexedTest( int32_t index, UBool exec, char* &name, // ***************************************************************************** // class CalendarLimitTest // ***************************************************************************** - + // this is 2^52 - 1, the largest allowable mantissa with a 0 exponent in a 64-bit double const UDate CalendarLimitTest::EARLIEST_SUPPORTED_MILLIS = - 4503599627370495.0; const UDate CalendarLimitTest::LATEST_SUPPORTED_MILLIS = 4503599627370495.0; - + // ------------------------------------- - + void CalendarLimitTest::test(UDate millis, Calendar* cal, DateFormat* fmt) { UErrorCode exception = U_ZERO_ERROR; UnicodeString theDate; UErrorCode status = U_ZERO_ERROR; - UDate d = millis; cal->setTime(millis, exception); if (U_SUCCESS(exception)) { fmt->format(millis, theDate); @@ -152,7 +151,7 @@ CalendarLimitTest::explore3(UDate expectedLateLimit) int32_t* fields = new int32_t[3]; int32_t oldYear = -1; int32_t newYear = -1; - while (TRUE) { + for (;;) { if(! timeToFields(millis, fields)) break; newYear = fields[0]; @@ -166,7 +165,7 @@ CalendarLimitTest::explore3(UDate expectedLateLimit) oldYear = -1; newYear = -1; millis /= 2; - while (TRUE) { + for (;;) { if(! timeToFields(millis, fields)) break; newYear = fields[0]; diff --git a/icu4c/source/test/intltest/cppcnvt.cpp b/icu4c/source/test/intltest/cppcnvt.cpp index 86e408a607f..de05946e985 100644 --- a/icu4c/source/test/intltest/cppcnvt.cpp +++ b/icu4c/source/test/intltest/cppcnvt.cpp @@ -41,25 +41,17 @@ void ConvertTest::runIndexedTest( int32_t index, UBool exec, char* &name, char* void ConvertTest::TestConvert() { - char subchar [4] = {(char)0xBE, (char)0xEF}; char myptr[4]; char save[4]; int32_t testLong1; int16_t rest = 0; - FILE* f = NULL; - FILE* f2 = NULL; - int32_t uniLen = 0; - int32_t len = 0; int32_t x = 0; FILE* ucs_file_in = NULL; UChar BOM = 0x0000; UChar myUChar = 0x0000; - char myChar = 0x00; char mytarget[MAX_FILE_LEN]; char* mytarget_1 = mytarget; char* mytarget_use = mytarget; - UChar* consumedUni = NULL; - char* consumedChar = NULL; char* consumed = NULL; char output_cp_buffer [MAX_FILE_LEN]; UChar ucs_file_buffer [MAX_FILE_LEN]; @@ -68,9 +60,7 @@ void ConvertTest::TestConvert() UChar* my_ucs_file_buffer_1 = my_ucs_file_buffer; int32_t i = 0; int8_t ii = 0; - uint16_t ij = 0; int32_t j = 0; - int32_t k = 0; uint16_t codepage_index = 0; int32_t cp = 0; UErrorCode err = U_ZERO_ERROR; @@ -79,8 +69,6 @@ void ConvertTest::TestConvert() UConverterFromUCallback MIA1, MIA1_2; UConverterToUCallback MIA2, MIA2_2; void *MIA1Context, *MIA1Context2, *MIA2Context, *MIA2Context2; - UChar myUnitarget[MAX_FILE_LEN]; - UChar *myUnitarget_1 = myUnitarget; UnicodeConverter* someConverters[5]; /****************************************************************** Checking Unicode -> ksc @@ -98,7 +86,7 @@ void ConvertTest::TestConvert() }; - const int32_t CodePagesAsciiControls[NUM_CODEPAGE] = +/* const int32_t CodePagesAsciiControls[NUM_CODEPAGE] = { 0xFFFFFFFF @@ -108,7 +96,7 @@ void ConvertTest::TestConvert() const int32_t CodePagesOtherControls[NUM_CODEPAGE] = { 0x00000005 - }; + };*/ const int8_t CodePagesMinChars[NUM_CODEPAGE] = @@ -141,7 +129,7 @@ void ConvertTest::TestConvert() }; - const UConverterToUCallback CodePagesMissingCharAction[NUM_CODEPAGE] = +/* const UConverterToUCallback CodePagesMissingCharAction[NUM_CODEPAGE] = { UCNV_TO_U_CALLBACK_SUBSTITUTE }; @@ -149,16 +137,26 @@ void ConvertTest::TestConvert() const UConverterFromUCallback CodePagesMissingUnicodeAction[NUM_CODEPAGE] = { UCNV_FROM_U_CALLBACK_SUBSTITUTE - }; + };*/ const Locale CodePagesLocale[NUM_CODEPAGE] = { Locale::KOREAN }; - UChar CodePagesFlakySequence[NUM_CODEPAGE][20] = +/* UChar CodePagesFlakySequence[NUM_CODEPAGE][20] = { - {(UChar)0xAC10,(UChar)0xAC11, (UChar)0xAC12, (UChar)0xAC13 , (UChar)0xAC14, (UChar)0xAC15, (UChar)0xAC16, (UChar)0xAC17, (UChar)0xd7a4 /*Offensive Codepoint*/, (UChar)0xAC14, (UChar)0xAC15} + {(UChar)0xAC10, + (UChar)0xAC11, + (UChar)0xAC12, + (UChar)0xAC13, + (UChar)0xAC14, + (UChar)0xAC15, + (UChar)0xAC16, + (UChar)0xAC17, + (UChar)0xd7a4, /*Offensive Codepoint*/ +/* (UChar)0xAC14, + (UChar)0xAC15} }; char CodePagesFlakyCharSequence[NUM_CODEPAGE][20] = @@ -168,10 +166,10 @@ void ConvertTest::TestConvert() (char)0xB0, (char)0xAA, (char)0xB0, (char)0xAB, (char)0xb0, (char)0xff,/*Offensive Codepoint*/ - (char)0xB0, (char)0xAC, +/* (char)0xB0, (char)0xAC, (char)0xB0, (char)0xAD } - }; + };*/ UConverterFromUCallback fromUAction = NULL; void* fromUContext = NULL; UConverterToUCallback toUAction = NULL; @@ -314,7 +312,7 @@ void ConvertTest::TestConvert() ii=4; myConverter->getSubstitutionChars(myptr,ii,err); - for(x=0;x> 8) | (myUChar << 8)); /*adjust if BIG_ENDIAN*/ + ucs_file_buffer[i-1] = (UChar)((BOM==0xFEFF)?myUChar:((myUChar >> 8) | (myUChar << 8))); /*adjust if BIG_ENDIAN*/ } myUChar = ucs_file_buffer[i-1]; - ucs_file_buffer[i-1] = (BOM==0xFEFF)?myUChar:((myUChar >> 8) | (myUChar << 8)); /*adjust if BIG_ENDIAN Corner Case*/ + ucs_file_buffer[i-1] = (UChar)((BOM==0xFEFF)?myUChar:((myUChar >> 8) | (myUChar << 8))); /*adjust if BIG_ENDIAN Corner Case*/ UnicodeString* uniString = new UnicodeString(ucs_file_buffer,i); UnicodeString* uniString3 = new UnicodeString(ucs_file_buffer,i); @@ -510,7 +508,7 @@ void ConvertTest::TestConvert() /*AIX Compiler hacks*/ const UChar* tmp_ucs_buf = ucs_file_buffer_use; - const UChar* tmp_consumedUni = NULL; + //const UChar* tmp_consumedUni = NULL; myConverter->fromUnicode(mytarget_1, mytarget + MAX_FILE_LEN, diff --git a/icu4c/source/test/intltest/ittxtbd.cpp b/icu4c/source/test/intltest/ittxtbd.cpp index 8b26b459b4e..0df2571f285 100644 --- a/icu4c/source/test/intltest/ittxtbd.cpp +++ b/icu4c/source/test/intltest/ittxtbd.cpp @@ -63,24 +63,24 @@ public: void addElement(UnicodeString text) { fEnd->fLink = new TextLink(&fBase, text); fEnd = fEnd->fLink; ++fSize; } void insertElementAt(UnicodeString text, int pos) { - if(pos >= fSize || pos < 0) - ; - else if(pos == 0){ + if(pos >= fSize || pos < 0) + ; + else if(pos == 0){ TextLink* insert = new TextLink(&fBase, text); - insert->fLink=fBase.fLink; - ++fSize; - fBase.fLink=insert; - } - else{ + insert->fLink=fBase.fLink; + ++fSize; + fBase.fLink=insert; + } + else{ TextLink* link = fBase.fLink; - while(--pos > 0) + while(--pos > 0) link=link->fLink; TextLink* insert = new TextLink(&fBase, text); - insert->fLink =link->fLink; + insert->fLink =link->fLink; link->fLink=insert; - ++fSize; + ++fSize; - } + } } UnicodeString elementAt(int32_t pos) { @@ -534,12 +534,12 @@ void IntlTestTextBoundary::addTestCharacterData() UnicodeString IntlTestTextBoundary::createTestData(Enumeration* e) { - UnicodeString result = ""; + UnicodeString result = ""; - while (e->hasMoreElements()) { - result += e->nextElement(); - } - return result; + while (e->hasMoreElements()) { + result += e->nextElement(); + } + return result; } //--------------------------------------------- @@ -614,8 +614,8 @@ void IntlTestTextBoundary::TestCharacterIteration() errln("Failed to create the BreakIterator for default locale in TestCharacterIteration.\n"); return; } - // generalIteratorTest(*e, testCharacterText, characterSelectionData); - generalIteratorTest(*e, characterSelectionData); + // generalIteratorTest(*e, testCharacterText, characterSelectionData); + generalIteratorTest(*e, characterSelectionData); delete e; } void IntlTestTextBoundary::TestCharacterInvariants() @@ -763,17 +763,17 @@ thaiLineSelection->addElement(CharsToUnicodeString("\\u0e2b\\u0e19\\u0e49\\u0e32 thaiLineSelection->addElement(CharsToUnicodeString("\\u0e17\\u0e35\\u0e48")); thaiLineSelection->addElement(CharsToUnicodeString("\\u0e19\\u0e31\\u0e49\\u0e19")); - BreakIterator* e = BreakIterator::createLineInstance( + BreakIterator* e = BreakIterator::createLineInstance( Locale("th"), status); if (U_FAILURE(status)) { errln("Failed to create the BreakIterator for default locale in TestThaiLineBreak.\n"); return; } - + generalIteratorTest(*e, thaiLineSelection); - delete e; - delete thaiLineSelection; + delete e; + delete thaiLineSelection; } void IntlTestTextBoundary::TestMixedThaiLineBreak() @@ -830,18 +830,18 @@ thaiLineSelection->addElement(CharsToUnicodeString("(\\u0e1b\\u0e23\\u0e30\\u0e4 thaiLineSelection->addElement(CharsToUnicodeString("\\u0e19\\u0e31\\u0e49\\u0e19 ")); thaiLineSelection->addElement(CharsToUnicodeString("(\"\\u0e2e\\u0e32\\u0e23\\u0e4c\\u0e14\\u0e14\\u0e34\\u0e2a\\u0e01\\u0e4c\").")); - BreakIterator* e = BreakIterator::createLineInstance( + BreakIterator* e = BreakIterator::createLineInstance( Locale("th"), status); if (U_FAILURE(status)) { errln("Failed to create the BreakIterator for default locale in TestMixedThaiLineBreak.\n"); return; } - - + + generalIteratorTest(*e, thaiLineSelection); - delete e; - delete thaiLineSelection; + delete e; + delete thaiLineSelection; } @@ -860,17 +860,17 @@ void IntlTestTextBoundary::TestMaiyamok() thaiLineSelection->addElement(CharsToUnicodeString("\\u0e40\\u0e03\\u0e35\\u0e22\\u0e07")); thaiLineSelection->addElement(CharsToUnicodeString("\\u0e43\\u0e2b\\u0e21\\u0e48")); - BreakIterator* e = BreakIterator::createLineInstance( + BreakIterator* e = BreakIterator::createLineInstance( Locale("th"), status); - + if (U_FAILURE(status)) { errln("Failed to create the BreakIterator for default locale in TestMaiyamok.\n"); return; } generalIteratorTest(*e, thaiLineSelection); - delete e; - delete thaiLineSelection; + delete e; + delete thaiLineSelection; } /** @@ -954,7 +954,7 @@ void IntlTestTextBoundary::TestGetAvailableLocales() if (locCount == 0) errln("getAvailableLocales() returned an empty list!"); - // I have no idea how to test this function... + // Todo: I have no idea how to test this function... } //Testing the BreakIterator::getDisplayName() function @@ -1010,7 +1010,6 @@ void IntlTestTextBoundary::TestBug4153072() { UnicodeString str("...Hello, World!..."); int32_t begin = 3; int32_t end = str.length() - 3; - UBool gotException = FALSE; UBool dummy; StringCharacterIterator* textIterator = new StringCharacterIterator(str, begin, end, begin); @@ -1062,31 +1061,30 @@ void IntlTestTextBoundary::runIndexedTest( int32_t index, UBool exec, char* &nam { if (exec) logln("TestSuite TextBoundary: "); switch (index) { - case 0: name = "TestSentenceIteration"; if(exec) TestSentenceIteration(); break; - case 1: name = "TestWordIteration"; if(exec) TestWordIteration(); break; + case 0: name = "TestSentenceIteration"; if(exec) TestSentenceIteration(); break; + case 1: name = "TestWordIteration"; if(exec) TestWordIteration(); break; case 2: name = "TestLineIteration"; if(exec) TestLineIteration(); break; - case 3: name = "TestCharacterIteration"; if(exec) TestCharacterIteration(); break; - case 4: name = "TestSentenceInvariants"; if(exec) TestSentenceInvariants();break; - case 5: name = "TestWordInvariants"; if(exec) TestWordInvariants();break; - case 6: name = "TestLineInvariants"; if(exec) TestLineInvariants();break; - case 7: name = "TestCharacterInvariants"; if(exec) TestCharacterInvariants();break; - - case 8: name = "TestEmptyString"; if (exec) TestEmptyString(); break; + case 3: name = "TestCharacterIteration"; if(exec) TestCharacterIteration(); break; + case 4: name = "TestSentenceInvariants"; if(exec) TestSentenceInvariants();break; + case 5: name = "TestWordInvariants"; if(exec) TestWordInvariants();break; + case 6: name = "TestLineInvariants"; if(exec) TestLineInvariants();break; + case 7: name = "TestCharacterInvariants"; if(exec) TestCharacterInvariants();break; + + case 8: name = "TestEmptyString"; if (exec) TestEmptyString(); break; case 9: name = "TestGetAvailableLocales"; if (exec) TestGetAvailableLocales(); break; case 10: name = "TestGetDisplayName"; if (exec) TestGetDisplayName(); break; case 11: name = "TestPreceding"; if (exec) TestPreceding(); break; case 12: name = "TestBug4153072"; if (exec) TestBug4153072(); break; case 13: name = "TestEndBehaviour"; if (exec) TestEndBehaviour(); break; - + case 14: name = "TestJapaneseLineBreak"; if (exec) TestJapaneseLineBreak(); break; case 15: name = "TestThaiLineBreak"; if(exec) TestThaiLineBreak(); break; case 16: name = "TestMixedThaiLineBreak"; if(exec) TestMixedThaiLineBreak(); break; case 17: name = "TestMaiyamok"; if(exec) TestMaiyamok(); break; - - - + + default: name = ""; break; //needed to end loop } } @@ -1099,8 +1097,8 @@ void IntlTestTextBoundary::runIndexedTest( int32_t index, UBool exec, char* &nam void IntlTestTextBoundary::generalIteratorTest(BreakIterator& bi, Vector* expectedResult) { Enumeration *elems = expectedResult->elements(); - UnicodeString text = createTestData(elems); - delete elems; + UnicodeString text = createTestData(elems); + delete elems; bi.setText(&text); @@ -1109,14 +1107,14 @@ void IntlTestTextBoundary::generalIteratorTest(BreakIterator& bi, Vector* expect logln("comparing forward and backward..."); int errs = getErrors(); - UnicodeString str1="forward iteration"; - UnicodeString str2="backward iteration"; + UnicodeString str1="forward iteration"; + UnicodeString str2="backward iteration"; compareFragmentLists(str1, str2, nextResults, previousResults); if (getErrors() == errs) { logln("comparing expected and actual..."); - str1="expected result"; - str2="actual result"; + str1="expected result"; + str2="actual result"; compareFragmentLists(str1, str2, expectedResult, nextResults); } @@ -1127,10 +1125,10 @@ void IntlTestTextBoundary::generalIteratorTest(BreakIterator& bi, Vector* expect for (int i = 0; i < expectedResult->size(); i++) boundaries[i + 2] = boundaries[i + 1] + ((UnicodeString)expectedResult->elementAt(i)). length(); - + int len = expectedResult->size() + 3 -1; - boundaries[len] = BreakIterator::DONE; - + boundaries[len] = BreakIterator::DONE; + testFollowing(bi, text, boundaries); testPreceding(bi, text, boundaries); testIsBoundary(bi, text, boundaries); @@ -1172,7 +1170,7 @@ Vector* IntlTestTextBoundary::testLastAndPrevious(BreakIterator& bi, UnicodeStri int32_t p = bi.last(); int32_t lastP = p; Vector *result = new Vector(); - UnicodeString selection; + UnicodeString selection; if (p != text.length()) errln((UnicodeString)"last() returned " + p + (UnicodeString)" instead of " + text.length()); @@ -1192,7 +1190,7 @@ Vector* IntlTestTextBoundary::testLastAndPrevious(BreakIterator& bi, UnicodeStri } lastP = p; } - return result; + return result; } void IntlTestTextBoundary::compareFragmentLists(UnicodeString& f1Name, UnicodeString& f2Name, Vector* f1, Vector* f2) @@ -1203,7 +1201,7 @@ void IntlTestTextBoundary::compareFragmentLists(UnicodeString& f1Name, UnicodeSt UnicodeString s2; int32_t t1 = 0; int32_t t2 = 0; - UnicodeString target; + UnicodeString target; while (p1 < f1->size() && p2 < f2->size()) { s1 = (UnicodeString)f1->elementAt(p1); diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 2da98128552..80ce46f680a 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -737,7 +737,6 @@ LocaleTest::TestGetLangsAndCountries() const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", "ja", "ko", "zh", "th", "he", "id", "iu", "ug", "yi", "za" }; - int32_t spotLen = 15; int32_t i; diff --git a/icu4c/source/test/intltest/numrgts.cpp b/icu4c/source/test/intltest/numrgts.cpp index e030883dc5e..95fa5ab9b92 100644 --- a/icu4c/source/test/intltest/numrgts.cpp +++ b/icu4c/source/test/intltest/numrgts.cpp @@ -677,7 +677,6 @@ void NumberFormatRegressionTest::Test4087244 (void) { const DecimalFormatSymbols *sym = df->getDecimalFormatSymbols(); UChar decSep = sym->getDecimalSeparator(); UChar monSep = sym->getMonetaryDecimalSeparator(); - UChar zero = sym->getZeroDigit(); if (decSep == monSep) { errln("ERROR in test: want decimal sep != monetary sep"); return; @@ -2257,7 +2256,7 @@ void NumberFormatRegressionTest::Test4243108(void) { failure(status, "DecimalFormatSymbols ct"); DecimalFormat fmt(UnicodeString("#.#"), sym, status); failure(status, "DecimalFormat ct"); - + UnicodeString str; FieldPosition pos; @@ -2289,5 +2288,5 @@ void NumberFormatRegressionTest::Test4243108(void) { } else { errln(UnicodeString("FAIL 0.0 x #.# = ") + str + ", want " + exp); - } + } } diff --git a/icu4c/source/test/intltest/tfsmalls.cpp b/icu4c/source/test/intltest/tfsmalls.cpp index 7e647f629ae..f426d7ed88a 100644 --- a/icu4c/source/test/intltest/tfsmalls.cpp +++ b/icu4c/source/test/intltest/tfsmalls.cpp @@ -36,7 +36,7 @@ void test_ParsePosition( void ) } delete pp1; - + { UTextOffset to = 5; ParsePosition pp2( to ); @@ -157,8 +157,6 @@ void test_FieldPosition( void ) void test_Formattable( void ) { - UErrorCode status = U_ZERO_ERROR; - Formattable* ftp = new Formattable(); if (!ftp || !(ftp->getType() == Formattable::kLong) || !(ftp->getLong() == 0)) { it_errln("*** Formattable constructor or getType or getLong"); diff --git a/icu4c/source/test/intltest/transapi.cpp b/icu4c/source/test/intltest/transapi.cpp index 090f5a2be79..82d24abf562 100644 --- a/icu4c/source/test/intltest/transapi.cpp +++ b/icu4c/source/test/intltest/transapi.cpp @@ -23,13 +23,13 @@ int32_t getInt(UnicodeString str) { char buffer[20]; - int len=str.length(); + int len=str.length(); if(len>=20) { len=19; } str.extract(0, len, buffer, ""); buffer[len]=0; - return atoi(buffer); + return atoi(buffer); } //--------------------------------------------- @@ -43,7 +43,7 @@ void TransliteratorAPITest::runIndexedTest( int32_t index, UBool exec, char* &na case 0: name = "TestgetInverse"; if (exec) TestgetInverse(); break; case 1: name = "TestgetID"; if (exec) TestgetID(); break; - case 2: name = "TestGetDisplayName"; if (exec) TestGetDisplayName(); break; + case 2: name = "TestGetDisplayName"; if (exec) TestGetDisplayName(); break; case 3: name = "TestTransliterate1"; if (exec) TestTransliterate1(); break; case 4: name = "TestTransliterate2"; if (exec) TestTransliterate2(); break; case 5: name = "TestTransliterate3"; if (exec) TestTransliterate3(); break; @@ -51,8 +51,8 @@ void TransliteratorAPITest::runIndexedTest( int32_t index, UBool exec, char* &na case 7: name = "TestKeyboardTransliterator1"; if (exec) TestKeyboardTransliterator1(); break; case 8: name = "TestKeyboardTransliterator2"; if (exec) TestKeyboardTransliterator2(); break; case 9: name = "TestKeyboardTransliterator3"; if (exec) TestKeyboardTransliterator3(); break; - case 10: name = "TestGetAdoptFilter"; if (exec) TestGetAdoptFilter(); break; - case 11: name = "TestClone"; if (exec) TestClone(); break; + case 10: name = "TestGetAdoptFilter"; if (exec) TestGetAdoptFilter(); break; + case 11: name = "TestClone"; if (exec) TestClone(); break; case 12: name = "TestNullTransliterator"; if (exec) TestNullTransliterator(); break; case 13: name = "TestRegisterUnregister"; if(exec) TestRegisterUnregister(); break; default: name = ""; break; /*needed to end loop*/ @@ -61,67 +61,63 @@ void TransliteratorAPITest::runIndexedTest( int32_t index, UBool exec, char* &na void TransliteratorAPITest::TestgetID() { - UnicodeString trans="Latin-Greek"; - UnicodeString ID; - Transliterator* t= Transliterator::createInstance(trans); - if(t==0) - errln("FAIL: construction"); - else{ - ID= t->getID(); - if( ID != trans) + UnicodeString trans="Latin-Greek"; + UnicodeString ID; + Transliterator* t= Transliterator::createInstance(trans); + if(t==0) + errln("FAIL: construction"); + else{ + ID= t->getID(); + if(ID != trans) errln("FAIL: getID returned " + ID + " instead of Latin-Greek"); - } - int i; - for (i=0; igetID()) - errln("FAIL: getID() returned " + t->getID() + " instead of " + ID); - } - ID=(UnicodeString)Transliterator::getAvailableID(i); - if(ID != (UnicodeString)Transliterator::getAvailableID(0)){ - errln("FAIL: calling getAvailableID(index > coundAvailableIDs) should make index=0\n"); - } + } + int i; + for (i=0; igetID()) + errln("FAIL: getID() returned " + t->getID() + " instead of " + ID); + } + ID=(UnicodeString)Transliterator::getAvailableID(i); + if(ID != (UnicodeString)Transliterator::getAvailableID(0)){ + errln("FAIL: calling getAvailableID(index > coundAvailableIDs) should make index=0\n"); + } - delete t; + delete t; - - Transliterator* t1=Transliterator::createInstance("Latin-Devanagari"); - Transliterator* t2=Transliterator::createInstance("Latin-Hebrew"); - if(t1 ==0 || t2 == 0){ - errln("FAIL: construction"); - return; - } - Transliterator* t3=t1->clone(); - Transliterator* t4=t2->clone(); + Transliterator* t1=Transliterator::createInstance("Latin-Devanagari"); + Transliterator* t2=Transliterator::createInstance("Latin-Hebrew"); + if(t1 ==0 || t2 == 0){ + errln("FAIL: construction"); + return; + } + Transliterator* t3=t1->clone(); + Transliterator* t4=t2->clone(); - if(t1->getID() != t3->getID() || t2->getID() != t4->getID() || - t1->getID() == t4->getID() || t2->getID() == t3->getID() || - t1->getID()== t4->getID() ) - errln("FAIL: getID or clone failed"); + if(t1->getID() != t3->getID() || t2->getID() != t4->getID() || + t1->getID() == t4->getID() || t2->getID() == t3->getID() || + t1->getID()== t4->getID() ) + errln("FAIL: getID or clone failed"); - - Transliterator* t5=Transliterator::createInstance("Latin-Devanagari"); - if(t5 == 0) - errln("FAIL: construction"); - if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID()) - errln("FAIL: getID or clone failed"); - + Transliterator* t5=Transliterator::createInstance("Latin-Devanagari"); + if(t5 == 0) + errln("FAIL: construction"); + if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID()) + errln("FAIL: getID or clone failed"); + - delete t1; - delete t2; - delete t3; - delete t4; - delete t5; + delete t1; + delete t2; + delete t3; + delete t4; + delete t5; +} - - - } void TransliteratorAPITest::TestgetInverse() { Transliterator* t1 = Transliterator::createInstance("Kana-Latin"); Transliterator* invt1 = Transliterator::createInstance("Latin-Kana"); @@ -129,7 +125,7 @@ void TransliteratorAPITest::TestgetInverse() { Transliterator* invt2 = Transliterator::createInstance("Devanagari-Latin"); if(t1 == 0 || invt1 == 0 || t2 == 0 || invt2 == 0) { errln("FAIL: in instantiation"); - return; + return; } Transliterator* inverse1=t1->createInverse(); @@ -157,387 +153,381 @@ void TransliteratorAPITest::TestgetInverse() { "Hex-Unicode" }; for(int i=0; icreateInverse(); if(inverse1->getID() != TransID[i+1] ) errln("FAIL :getInverse() for " + TransID[i] + " returned " + inverse1->getID() + " instead of " + TransID[i+1]); } delete t1; - delete t2; - delete invt1; - delete invt2; + delete t2; + delete invt1; + delete invt2; } void TransliteratorAPITest::TestClone(){ Transliterator *t1, *t2, *t3, *t4; - t1=Transliterator::createInstance("Latin-Devanagari"); - t2=Transliterator::createInstance("Latin-Hebrew"); - if(t1 == 0 || t2 == 0){ - errln("FAIL: construction"); - return; - } - t3=t1->clone(); - t4=t2->clone(); + t1=Transliterator::createInstance("Latin-Devanagari"); + t2=Transliterator::createInstance("Latin-Hebrew"); + if(t1 == 0 || t2 == 0){ + errln("FAIL: construction"); + return; + } + t3=t1->clone(); + t4=t2->clone(); - if(t1->getID() != t3->getID() || t2->getID() != t4->getID() ) - errln("FAIL: clone or getID failed"); - if(t1->getID()==t4->getID() || t2->getID()==t3->getID() || t1->getID()==t4->getID()) - errln("FAIL: clone or getID failed"); + if(t1->getID() != t3->getID() || t2->getID() != t4->getID() ) + errln("FAIL: clone or getID failed"); + if(t1->getID()==t4->getID() || t2->getID()==t3->getID() || t1->getID()==t4->getID()) + errln("FAIL: clone or getID failed"); - delete t1; - delete t2; + delete t1; + delete t2; } void TransliteratorAPITest::TestGetDisplayName() { UnicodeString dispNames[]= { - //ID, displayName - "CurlyQuotes-StraightQuotes" ,"CurlyQuotes to StraightQuotes", - "Unicode-Hex" ,"Unicode to Hex Escape", - "Halfwidth-Fullwidth" ,"Halfwidth to Fullwidth" , - "Latin-Arabic" ,"Latin to Arabic" , - "Latin-Devanagari" ,"Latin to Devanagari" , - "Greek-Latin" ,"Greek to Latin" , - "Arabic-Latin" ,"Arabic to Latin" , - "Hex-Unicode" ,"Hex Escape to Unicode", - "Cyrillic-Latin" ,"Cyrillic to Latin" , - "Latin-Greek" ,"Latin to Greek" , - "Latin-Kana" ,"Latin to Kana" , - "Latin-Hebrew" ,"Latin to Hebrew" , - "Kana-Latin" ,"Kana to Latin" - }; - UnicodeString name=""; - Transliterator* t; - UnicodeString message; - for (int32_t i=0; igetDisplayName(t->getID(), name); - message="Display name for ID:" + t->getID(); - // doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!! - name=""; - t->getDisplayName(t->getID(), Locale::US, name); - message.remove(); - message.append("Display name for on english locale ID:"); - message.append(t->getID()); - // message="Display name for on english locale ID:" + t->getID(); - doTest(message, name, dispNames[i+1]); - name=""; - + //ID, displayName + "CurlyQuotes-StraightQuotes" ,"CurlyQuotes to StraightQuotes", + "Unicode-Hex" ,"Unicode to Hex Escape", + "Halfwidth-Fullwidth" ,"Halfwidth to Fullwidth" , + "Latin-Arabic" ,"Latin to Arabic" , + "Latin-Devanagari" ,"Latin to Devanagari" , + "Greek-Latin" ,"Greek to Latin" , + "Arabic-Latin" ,"Arabic to Latin" , + "Hex-Unicode" ,"Hex Escape to Unicode", + "Cyrillic-Latin" ,"Cyrillic to Latin" , + "Latin-Greek" ,"Latin to Greek" , + "Latin-Kana" ,"Latin to Kana" , + "Latin-Hebrew" ,"Latin to Hebrew" , + "Kana-Latin" ,"Kana to Latin" + }; + UnicodeString name=""; + Transliterator* t; + UnicodeString message; + for (int32_t i=0; igetDisplayName(t->getID(), name); + message="Display name for ID:" + t->getID(); + // doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!! + name=""; + t->getDisplayName(t->getID(), Locale::US, name); + message.remove(); + message.append("Display name for on english locale ID:"); + message.append(t->getID()); + // message="Display name for on english locale ID:" + t->getID(); + doTest(message, name, dispNames[i+1]); + name=""; + } -delete t; - + delete t; -} +} void TransliteratorAPITest::TestTransliterate1(){ - - UnicodeString Data[]={ - //ID, input string, transliterated string - "Unicode-Hex", "hello", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") , - "Hex-Unicode", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello" , - "Latin-Devanagari", "bhaarata", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") , - "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "bhaarata" , - // "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"); - - for(int i=0;itransliterate(gotResult); - message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + Data[i+1]; - doTest(message, gotResult, Data[i+2]); + UnicodeString Data[]={ + //ID, input string, transliterated string + "Unicode-Hex", "hello", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") , + "Hex-Unicode", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello" , + "Latin-Devanagari", "bhaarata", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") , + "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "bhaarata" , + // "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" + }; - //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]); - - } - delete t; + UnicodeString gotResult; + UnicodeString temp; + UnicodeString message; + Transliterator* t; + logln("Testing transliterate"); - + for(int i=0;itransliterate(gotResult); + message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + 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]); + } + + delete t; } + void TransliteratorAPITest::TestTransliterate2(){ - //testing tranliterate(String text, int start, int limit, StringBuffer result) - UnicodeString Data2[]={ - //ID, input string, start, limit, transliterated string - "Unicode-Hex", "hello! How are you?", "0", "5", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F! How are you?", "") , - "Unicode-Hex", "hello! How are you?", "7", "12", UnicodeString("\\u0048\\u006F\\u0077\\u0020\\u0061", ""), UnicodeString("hello! \\u0048\\u006F\\u0077\\u0020\\u0061re you?", ""), - "Hex-Unicode", 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", "aa", CharsToUnicodeString("\\u092Daa\\u0930\\u0924") + //testing tranliterate(String text, int start, int limit, StringBuffer result) + UnicodeString Data2[]={ + //ID, input string, start, limit, transliterated string + "Unicode-Hex", "hello! How are you?", "0", "5", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F! How are you?", "") , + "Unicode-Hex", "hello! How are you?", "7", "12", UnicodeString("\\u0048\\u006F\\u0077\\u0020\\u0061", ""), UnicodeString("hello! \\u0048\\u006F\\u0077\\u0020\\u0061re you?", ""), + "Hex-Unicode", 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", "aa", CharsToUnicodeString("\\u092Daa\\u0930\\u0924") - }; - logln("\n Testing transliterate(String, int, int, StringBuffer)"); - Transliterator* t; - UnicodeString gotResBuf; - UnicodeString temp; - int32_t start, limit; - for(int32_t i=0; itransliterate(gotResBuf); - // errln("FAIL: calling transliterate on " + t->getID()); - doTest(t->getID() + ".transliterate(UnicodeString, int32_t, int32_t, UnicodeString):(" + start + "," + limit + ") for \n\t source: " + 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: " + Data2[i+1], temp, Data2[i+5]); - } + }; + logln("\n Testing transliterate(String, int, int, StringBuffer)"); + Transliterator* t; + UnicodeString gotResBuf; + UnicodeString temp; + int32_t start, limit; + for(int32_t i=0; itransliterate(gotResBuf); + // errln("FAIL: calling transliterate on " + t->getID()); + doTest(t->getID() + ".transliterate(UnicodeString, int32_t, int32_t, UnicodeString):(" + start + "," + limit + ") for \n\t source: " + Data2[i+1], gotResBuf, Data2[i+4]); - - logln("\n Try calling transliterate with illegal start and limit values"); - t=Transliterator::createInstance("Unicode-Hex"); - 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); - - delete t; + temp=Data2[i+1]; + t->transliterate(temp, start, limit); + doTest(t->getID() + ".transliterate(Replaceable, int32_t, int32_t, ):(" + start + "," + limit + ") for \n\t source: " + Data2[i+1], temp, Data2[i+5]); + } + logln("\n Try calling transliterate with illegal start and limit values"); + t=Transliterator::createInstance("Unicode-Hex"); + 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); + + delete t; + } void TransliteratorAPITest::TestTransliterate3(){ - UnicodeString rs="This is the replaceable String"; - UnicodeString Data[] = { - "0", "0", "This is the replaceable String", - "2", "3", UnicodeString("Th\\u0069s is the replaceable String", ""), - "21", "23", UnicodeString("Th\\u0069s is the repl\\u0061\\u0063eable String", ""), - "14", "17", UnicodeString("Th\\u0069s is t\\u0068\\u0065\\u0020repl\\u0061\\u0063eable String", ""), - - }; - int start, limit; - UnicodeString message; - Transliterator *t=Transliterator::createInstance("Unicode-Hex"); - if(t == 0) - errln("FAIL : construction"); - for(int i=0; itransliterate(rs, start, limit); - message=t->getID() + ".transliterate(ReplaceableString, start, limit):("+start+","+limit+"):"; - doTest(message, rs, Data[i+2]); - } + UnicodeString rs="This is the replaceable String"; + UnicodeString Data[] = { + "0", "0", "This is the replaceable String", + "2", "3", UnicodeString("Th\\u0069s is the replaceable String", ""), + "21", "23", UnicodeString("Th\\u0069s is the repl\\u0061\\u0063eable String", ""), + "14", "17", UnicodeString("Th\\u0069s is t\\u0068\\u0065\\u0020repl\\u0061\\u0063eable String", ""), + }; + int start, limit; + UnicodeString message; + Transliterator *t=Transliterator::createInstance("Unicode-Hex"); + if(t == 0) + errln("FAIL : construction"); + for(int i=0; itransliterate(rs, start, limit); + message=t->getID() + ".transliterate(ReplaceableString, start, limit):("+start+","+limit+"):"; + doTest(message, rs, Data[i+2]); + } } void TransliteratorAPITest::TestSimpleKeyboardTransliterator(){ - logln("simple call to transliterate"); - UErrorCode status=U_ZERO_ERROR; - Transliterator* t=Transliterator::createInstance("Unicode-Hex"); - if(t == 0) - errln("FAIL : construction"); - UTransPosition index={19,20,20,20}; - UnicodeString rs= "Transliterate this-''"; - UnicodeString insertion="abc"; - UnicodeString expected=UnicodeString("Transliterate this-'\\u0061\\u0062\\u0063'", ""); - t->transliterate(rs, index, insertion, status); - if(U_FAILURE(status)) - errln("FAIL: " + t->getID()+ ".translitere(Replaceable, int[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); - t->finishTransliteration(rs, index); - UnicodeString message="transliterate"; - doTest(message, rs, expected); - - logln("try calling transliterate with invalid index values"); - UTransPosition index1[]={ - //START, LIMIT, CURSOR - {10, 10, 12, 10}, //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT - {17, 16, 17, 17}, //invalid since START>LIMIT valid:-0<=START<=LIMIT - {-1, 16, 14, 16}, //invalid since START<0 - {3, 50, 2, 50} //invalid since LIMIT>text.length() - }; - for(int i=0; itransliterate(rs, index1[i], insertion, status); - if(status == U_ILLEGAL_ARGUMENT_ERROR) - logln("OK: invalid index values handled correctly"); - else - errln("FAIL: invalid index values didn't throw U_ILLEGAL_ARGUMENT_ERROR throw" + (UnicodeString)u_errorName(status)); - } + logln("simple call to transliterate"); + UErrorCode status=U_ZERO_ERROR; + Transliterator* t=Transliterator::createInstance("Unicode-Hex"); + if(t == 0) + errln("FAIL : construction"); + UTransPosition index={19,20,20,20}; + UnicodeString rs= "Transliterate this-''"; + UnicodeString insertion="abc"; + UnicodeString expected=UnicodeString("Transliterate this-'\\u0061\\u0062\\u0063'", ""); + t->transliterate(rs, index, insertion, status); + if(U_FAILURE(status)) + errln("FAIL: " + t->getID()+ ".translitere(Replaceable, int[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); + t->finishTransliteration(rs, index); + UnicodeString message="transliterate"; + doTest(message, rs, expected); - delete t; -} -void TransliteratorAPITest::TestKeyboardTransliterator1(){ - UnicodeString Data[]={ - //insertion, buffer - "a", UnicodeString("\\u0061", "") , - "bbb", UnicodeString("\\u0061\\u0062\\u0062\\u0062", "") , - "ca", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061", "") , - " ", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , - "", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , - - "a", UnicodeString("\\u0061", "") , - "b", UnicodeString("\\u0061\\u0062", "") , - "z", UnicodeString("\\u0061\\u0062\\u007A", "") , - "", UnicodeString("\\u0061\\u0062\\u007A", "") - - }; - Transliterator* t=Transliterator::createInstance("Unicode-Hex"); - //keyboardAux(t, Data); - UTransPosition index={0, 0, 0, 0}; - UErrorCode status=U_ZERO_ERROR; - UnicodeString s; - int i; - logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); - for (i=0; i<10; i=i+2) { - UnicodeString log; - if (Data[i+0] != "") { - log = s + " + " + Data[i+0] + " -> "; - t->transliterate(s, index, Data[i+0], status); - if(U_FAILURE(status)){ - errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); - continue; - } - }else { - log = s + " => "; - t->finishTransliteration(s, index); - } - // Show the start index '{' and the cursor '|' - displayOutput(s, Data[i+1], log, index); - - } - - s=""; - status=U_ZERO_ERROR; - index.contextStart = index.contextLimit = index.start = index.limit = 0; - logln("Testing transliterate(Replaceable, int32_t, UChar, UErrorCode)"); - for(i=10; i "; - UChar c=Data[i+0].charAt(0); - t->transliterate(s, index, c, status); - if(U_FAILURE(status)) - errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UChar, UErrorCode)-->" + (UnicodeString)u_errorName(status)); - continue; - }else { - log = s + " => "; - t->finishTransliteration(s, index); - } - // Show the start index '{' and the cursor '|' - displayOutput(s, Data[i+1], log, index); - } - - delete t; -} -void TransliteratorAPITest::TestKeyboardTransliterator2(){ - UnicodeString Data[]={ - //insertion, buffer, index[START], index[LIMIT], index[CURSOR] - //data for Unicode-Hex - "abc", UnicodeString("Initial String: add-\\u0061\\u0062\\u0063-", ""), "19", "20", "20", - "a", UnicodeString("In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "2", "3", "2" , - "b", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , - "", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , - //data for Latin-Devanagiri - "aa", CharsToUnicodeString("Hindi -\\u0906-"), "6", "7", "6", - "maa", CharsToUnicodeString("Hindi -\\u0906\\u092E\\u093E-"), "7", "8", "7", - "raa", CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"), "1", "2", "2", - "", CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"), "1", "2", "2" - //data for contracted-Expanded - // CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"), "1", "2", "1" , - // CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", - // "", CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", - }; - Transliterator *t; - UnicodeString rs; - UnicodeString dataStr; - logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); - - rs="Initial String: add--"; - t=Transliterator::createInstance("Unicode-Hex"); - if(t == 0) - errln("FAIL : construction"); - else { - keyboardAux(t, Data, rs, 0, 20); - delete t; - } - - rs="Hindi --"; - t=Transliterator::createInstance("Latin-Devanagari"); - if(t == 0) - errln("FAIL : construction"); + logln("try calling transliterate with invalid index values"); + UTransPosition index1[]={ + //START, LIMIT, CURSOR + {10, 10, 12, 10}, //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT + {17, 16, 17, 17}, //invalid since START>LIMIT valid:-0<=START<=LIMIT + {-1, 16, 14, 16}, //invalid since START<0 + {3, 50, 2, 50} //invalid since LIMIT>text.length() + }; + for(int i=0; itransliterate(rs, index1[i], insertion, status); + if(status == U_ILLEGAL_ARGUMENT_ERROR) + logln("OK: invalid index values handled correctly"); else - keyboardAux(t, Data, rs, 20, 40); + errln("FAIL: invalid index values didn't throw U_ILLEGAL_ARGUMENT_ERROR throw" + (UnicodeString)u_errorName(status)); + } - - // rs="Add here:"; - // t=Transliterator::createInstance("Contracted-Expanded"); - // keyboardAux(t, Data, rs, 35, 55); + delete t; +} +void TransliteratorAPITest::TestKeyboardTransliterator1(){ + UnicodeString Data[]={ + //insertion, buffer + "a", UnicodeString("\\u0061", "") , + "bbb", UnicodeString("\\u0061\\u0062\\u0062\\u0062", "") , + "ca", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061", "") , + " ", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , + "", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , + + "a", UnicodeString("\\u0061", "") , + "b", UnicodeString("\\u0061\\u0062", "") , + "z", UnicodeString("\\u0061\\u0062\\u007A", "") , + "", UnicodeString("\\u0061\\u0062\\u007A", "") + + }; + Transliterator* t=Transliterator::createInstance("Unicode-Hex"); + //keyboardAux(t, Data); + UTransPosition index={0, 0, 0, 0}; + UErrorCode status=U_ZERO_ERROR; + UnicodeString s; + int i; + logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); + for (i=0; i<10; i=i+2) { + UnicodeString log; + if (Data[i+0] != "") { + log = s + " + " + Data[i+0] + " -> "; + t->transliterate(s, index, Data[i+0], status); + if(U_FAILURE(status)){ + errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); + continue; + } + }else { + log = s + " => "; + t->finishTransliteration(s, index); + } + // Show the start index '{' and the cursor '|' + displayOutput(s, Data[i+1], log, index); + + } + + s=""; + status=U_ZERO_ERROR; + index.contextStart = index.contextLimit = index.start = index.limit = 0; + logln("Testing transliterate(Replaceable, int32_t, UChar, UErrorCode)"); + for(i=10; i "; + UChar c=Data[i+0].charAt(0); + t->transliterate(s, index, c, status); + if(U_FAILURE(status)) + errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UChar, UErrorCode)-->" + (UnicodeString)u_errorName(status)); + continue; + }else { + log = s + " => "; + t->finishTransliteration(s, index); + } + // Show the start index '{' and the cursor '|' + displayOutput(s, Data[i+1], log, index); + } + + delete t; +} + +void TransliteratorAPITest::TestKeyboardTransliterator2(){ + UnicodeString Data[]={ + //insertion, buffer, index[START], index[LIMIT], index[CURSOR] + //data for Unicode-Hex + "abc", UnicodeString("Initial String: add-\\u0061\\u0062\\u0063-", ""), "19", "20", "20", + "a", UnicodeString("In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "2", "3", "2" , + "b", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , + "", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , + //data for Latin-Devanagiri + "aa", CharsToUnicodeString("Hindi -\\u0906-"), "6", "7", "6", + "maa", CharsToUnicodeString("Hindi -\\u0906\\u092E\\u093E-"), "7", "8", "7", + "raa", CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"), "1", "2", "2", + "", CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"), "1", "2", "2" + //data for contracted-Expanded + // CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"), "1", "2", "1" , + // CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", + // "", CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", + }; + Transliterator *t; + UnicodeString rs; + UnicodeString dataStr; + logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); + + rs="Initial String: add--"; + t=Transliterator::createInstance("Unicode-Hex"); + if(t == 0) + errln("FAIL : construction"); + else { + keyboardAux(t, Data, rs, 0, 20); + delete t; + } + + rs="Hindi --"; + t=Transliterator::createInstance("Latin-Devanagari"); + if(t == 0) + errln("FAIL : construction"); + else + keyboardAux(t, Data, rs, 20, 40); - delete t; -} + // rs="Add here:"; + // t=Transliterator::createInstance("Contracted-Expanded"); + // keyboardAux(t, Data, rs, 35, 55); + + + delete t; +} + void TransliteratorAPITest::TestKeyboardTransliterator3(){ - UnicodeString s="This is the main string"; - UnicodeString Data[] = { - "0", "0", "0", "This is the main string", - "1", "3", "2", UnicodeString("Th\\u0069s is the main string", ""), - "20", "21", "20", UnicodeString("Th\\u0069s is the mai\\u006E string", "") - }; - - UErrorCode status=U_ZERO_ERROR; - UTransPosition index={0, 0, 0, 0}; - logln("Testing transliterate(Replaceable, int32_t, UErrorCode)"); - Transliterator *t=Transliterator::createInstance("Unicode-Hex"); - if(t == 0) - errln("FAIL : construction"); - for(int32_t i=0; itransliterate(s, index, status); if(U_FAILURE(status)){ errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UErrorCode)-->" + (UnicodeString)u_errorName(status)); - continue; - } - t->finishTransliteration(s, index); - log = s + " => "; - // Show the start index '{' and the cursor '|' + continue; + } + t->finishTransliteration(s, index); + log = s + " => "; + // Show the start index '{' and the cursor '|' displayOutput(s, Data[i+3], log, index); - } + } - delete t; + delete t; } void TransliteratorAPITest::TestNullTransliterator(){ UnicodeString s("Transliterate using null transliterator"); - UErrorCode status=U_ZERO_ERROR; NullTransliterator *nullTrans=new NullTransliterator(); int32_t transLimit; int32_t start=0; @@ -610,7 +600,6 @@ void TransliteratorAPITest::TestRegisterUnregister(){ return; } - } @@ -654,9 +643,9 @@ class TestFilter3 : public UnicodeFilter { void TransliteratorAPITest::TestGetAdoptFilter(){ - Transliterator *t=Transliterator::createInstance("Unicode-Hex"); - if(t == 0) - errln("FAIL : construction"); + Transliterator *t=Transliterator::createInstance("Unicode-Hex"); + if(t == 0) + errln("FAIL : construction"); const UnicodeFilter *u=t->getFilter(); if(u != NULL){ errln("FAIL: getFilter failed. Didn't return null when the transliterator used no filtering"); @@ -665,13 +654,13 @@ void TransliteratorAPITest::TestGetAdoptFilter(){ UnicodeString got, temp, message; UnicodeString data="ABCabcbbCBa"; temp = data; - t->transliterate(temp); - t->adoptFilter(new TestFilter1); + t->transliterate(temp); + t->adoptFilter(new TestFilter1); got = data; - t->transliterate(got); + t->transliterate(got); UnicodeString exp=UnicodeString("A\\u0042Ca\\u0062c\\u0062\\u0062C\\u0042a", ""); - message="transliteration after adoptFilter(a,A,c,C) "; + message="transliteration after adoptFilter(a,A,c,C) "; doTest(message, got, exp); logln("Testing round trip"); @@ -687,93 +676,92 @@ void TransliteratorAPITest::TestGetAdoptFilter(){ message="transliteration after adopting null filter"; doTest(message, got, exp); message="adoptFilter round trip"; - doTest("adoptFilter round trip", got, temp); + doTest("adoptFilter round trip", got, temp); t->adoptFilter(new TestFilter2); data="heelloe"; - exp=UnicodeString("\\u0068eell\\u006Fe", ""); + exp=UnicodeString("\\u0068eell\\u006Fe", ""); got = data; - t->transliterate(got); - message="transliteration using (e,l) filter"; + t->transliterate(got); + message="transliteration using (e,l) filter"; doTest("transliteration using (e,l) filter", got, exp); - - data="are well"; - exp=UnicodeString("\\u0061\\u0072e\\u0020\\u0077ell", ""); + + data="are well"; + exp=UnicodeString("\\u0061\\u0072e\\u0020\\u0077ell", ""); got = data; t->transliterate(got); - doTest(message, got, exp); - + doTest(message, got, exp); + t->adoptFilter(new TestFilter3); - data="ho, wow!"; - exp=UnicodeString("\\u0068o\\u002C\\u0020wow\\u0021", ""); + data="ho, wow!"; + exp=UnicodeString("\\u0068o\\u002C\\u0020wow\\u0021", ""); got = data; t->transliterate(got); - message="transliteration using (o,w) filter"; + message="transliteration using (o,w) filter"; doTest("transliteration using (o,w) filter", got, exp); data="owl"; - exp=UnicodeString("ow\\u006C", ""); + exp=UnicodeString("ow\\u006C", ""); got = data; t->transliterate(got); - doTest("transliteration using (o,w) filter", got, exp); + doTest("transliteration using (o,w) filter", got, exp); + + delete t; - delete t; - } void TransliteratorAPITest::keyboardAux(Transliterator *t, UnicodeString DATA[], UnicodeString& s, int32_t begin, int32_t end) { - UTransPosition index={0, 0, 0, 0}; - UErrorCode status=U_ZERO_ERROR; - for (int32_t i=begin; i "; - index.contextStart=getInt(DATA[i+2]); - index.contextLimit=index.limit=getInt(DATA[i+3]); - index.start=getInt(DATA[i+4]); - t->transliterate(s, index, DATA[i+0], status); - if(U_FAILURE(status)){ - errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); - continue; - } - } else { - log = s + " => "; - t->finishTransliteration(s, index); - } - // Show the start index '{' and the cursor '|' - displayOutput(s, DATA[i+1], log, index); - + UTransPosition index={0, 0, 0, 0}; + UErrorCode status=U_ZERO_ERROR; + for (int32_t i=begin; i "; + index.contextStart=getInt(DATA[i+2]); + index.contextLimit=index.limit=getInt(DATA[i+3]); + index.start=getInt(DATA[i+4]); + t->transliterate(s, index, DATA[i+0], status); + if(U_FAILURE(status)){ + errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); + continue; + } + } else { + log = s + " => "; + t->finishTransliteration(s, index); } + // Show the start index '{' and the cursor '|' + displayOutput(s, DATA[i+1], log, index); + + } } void TransliteratorAPITest::displayOutput(const UnicodeString& got, const UnicodeString& expected, UnicodeString& log, UTransPosition& index){ - // Show the start index '{' and the cursor '|' - UnicodeString a, b, c; - got.extractBetween(0, index.contextStart, a); - got.extractBetween(index.contextStart, index.start, b); - got.extractBetween(index.start, got.length(), c); - log.append(a). - append((UChar)0x7b/*{*/). - append(b). - append((UChar)0x7c/*|*/). - append(c); - if (got == expected) - logln("OK:" + prettify(log)); - else - errln("FAIL: " + prettify(log) + ", expected " + prettify(expected)); + // Show the start index '{' and the cursor '|' + UnicodeString a, b, c; + got.extractBetween(0, index.contextStart, a); + got.extractBetween(index.contextStart, index.start, b); + got.extractBetween(index.start, got.length(), c); + log.append(a). + append((UChar)0x7b/*{*/). + append(b). + append((UChar)0x7c/*|*/). + append(c); + if (got == expected) + logln("OK:" + prettify(log)); + else + errln("FAIL: " + prettify(log) + ", expected " + prettify(expected)); } /*Internal Functions used*/ void TransliteratorAPITest::doTest(const UnicodeString& message, const UnicodeString& result, const UnicodeString& expected){ - if (result == expected) - logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\""); - else - errln((UnicodeString)"FAIL:" + message + " failed Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) ); - - } + if (result == expected) + logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\""); + else + errln((UnicodeString)"FAIL:" + message + " failed Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) ); +} diff --git a/icu4c/source/test/intltest/transtst.cpp b/icu4c/source/test/intltest/transtst.cpp index d3bdbb885ed..37e5a47c65c 100644 --- a/icu4c/source/test/intltest/transtst.cpp +++ b/icu4c/source/test/intltest/transtst.cpp @@ -511,11 +511,11 @@ void TransliteratorTest::TestJ277(void) { UChar sigma = 0x3C3; UChar upsilon = 0x3C5; UChar nu = 0x3BD; - UChar PHI = 0x3A6; +// UChar PHI = 0x3A6; UChar alpha = 0x3B1; - UChar omega = 0x3C9; - UChar omicron = 0x3BF; - UChar epsilon = 0x3B5; +// UChar omega = 0x3C9; +// UChar omicron = 0x3BF; +// UChar epsilon = 0x3B5; // sigma upsilon nu -> syn UnicodeString syn; @@ -940,4 +940,4 @@ void TransliteratorTest::expectAux(const UnicodeString& tag, } } -static UChar toHexString(int32_t i) { return i + (i < 10 ? ZERO : (UPPER_A - 10)); } +static UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? ZERO : (UPPER_A - 10))); } diff --git a/icu4c/source/test/intltest/tstnorm.cpp b/icu4c/source/test/intltest/tstnorm.cpp index 32c8289322f..108ff5b4cd8 100644 --- a/icu4c/source/test/intltest/tstnorm.cpp +++ b/icu4c/source/test/intltest/tstnorm.cpp @@ -477,7 +477,6 @@ void BasicNormalizerTest::assertEqual(const UnicodeString& input, Normalizer* iter, const UnicodeString& errPrefix) { - int index = 0; UnicodeString result; for (UChar32 ch = iter->first(); ch != iter->DONE; ch = iter->next()) { diff --git a/icu4c/source/test/intltest/tztest.cpp b/icu4c/source/test/intltest/tztest.cpp index 6e8d6846bca..53c85618abe 100644 --- a/icu4c/source/test/intltest/tztest.cpp +++ b/icu4c/source/test/intltest/tztest.cpp @@ -147,7 +147,6 @@ TimeZoneTest::TestGenericAPI() logln(UnicodeString("Value returned from t_timezone = ") + tzoffset); // Invert sign because UNIX semantics are backwards if (tzoffset < 0) tzoffset = -tzoffset; - UErrorCode status = U_ZERO_ERROR; // --- The following test would fail outside PST now that // --- PST is generally set to be default timezone in format tests //if ((*saveDefault == *pstZone) && (tzoffset != 28800)) { diff --git a/icu4c/source/test/intltest/usettest.cpp b/icu4c/source/test/intltest/usettest.cpp index 3684fa027c8..efaa7f779d1 100644 --- a/icu4c/source/test/intltest/usettest.cpp +++ b/icu4c/source/test/intltest/usettest.cpp @@ -39,7 +39,7 @@ UnicodeSetTest::runIndexedTest(int32_t index, UBool exec, CASE(4,TestMinimalRep); CASE(5,TestAPI); CASE(6,TestExhaustive); - default: name = ""; break; + default: name = ""; break; } } @@ -75,7 +75,6 @@ UnicodeSetTest::TestCategories(void) { int32_t failures = 0; // Make sure generation of L doesn't pollute cached Lu set // First generate L, then Lu - UChar32 TOP = 0x200; // Don't need to go over the whole range: set.applyPattern("[:L:]", status); if (U_FAILURE(status)) { errln("FAIL"); return; } for (i=0; i<0x200; ++i) { @@ -158,7 +157,6 @@ UnicodeSetTest::TestCloneEqualHash(void) { } void UnicodeSetTest::TestAddRemove(void) { - UErrorCode status = U_ZERO_ERROR; UnicodeSet set; // Construct empty set doAssert(set.isEmpty() == TRUE, "set should be empty"); doAssert(set.size() == 0, "size should be 0"); @@ -640,7 +638,7 @@ UnicodeSetTest::expectPairs(const UnicodeSet& set, const UnicodeString& expected } } -static UChar toHexString(int32_t i) { return i + (i < 10 ? 0x30 : (0x41 - 10)); } +static UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); } void UnicodeSetTest::doAssert(UBool condition, const char *message)