X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..4f1e1a09ce4daed860e35d359ce2fceccb0764e8:/icuSources/test/intltest/transapi.cpp diff --git a/icuSources/test/intltest/transapi.cpp b/icuSources/test/intltest/transapi.cpp index d876636c..76597d28 100644 --- a/icuSources/test/intltest/transapi.cpp +++ b/icuSources/test/intltest/transapi.cpp @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /************************************************************************ * COPYRIGHT: - * Copyright (c) 2000-2005, International Business Machines Corporation + * Copyright (c) 2000-2016, International Business Machines Corporation * and others. All Rights Reserved. ************************************************************************/ /************************************************************************ @@ -16,10 +18,9 @@ #include "transapi.h" #include "unicode/utypes.h" #include "unicode/translit.h" -#include "rbt.h" #include "unicode/unifilt.h" #include "cpdtrans.h" -#include "nultrans.h" +#include "cmemory.h" #include #include #include @@ -74,7 +75,7 @@ void TransliteratorAPITest::TestgetID() { UErrorCode status = U_ZERO_ERROR; Transliterator* t= Transliterator::createInstance(trans, UTRANS_FORWARD, parseError, status); if(t==0 || U_FAILURE(status)){ - errln("FAIL: construction of Latin-Greek"); + dataerrln("FAIL: construction of Latin-Greek - %s",u_errorName(status)); return; }else{ ID= t->getID(); @@ -121,7 +122,7 @@ void TransliteratorAPITest::TestgetID() { Transliterator* t5=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); if(t5 == 0) errln("FAIL: construction"); - if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID()) + else if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID()) errln("FAIL: getID or clone failed"); @@ -140,7 +141,7 @@ void TransliteratorAPITest::TestgetInverse() { Transliterator* t2 = Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); Transliterator* invt2 = Transliterator::createInstance("Devanagari-Latin", UTRANS_FORWARD, parseError, status); if(t1 == 0 || invt1 == 0 || t2 == 0 || invt2 == 0) { - errln("FAIL: in instantiation"); + dataerrln("FAIL: in instantiation - %s", u_errorName(status)); return; } @@ -168,7 +169,7 @@ void TransliteratorAPITest::TestgetInverse() { "Any-Hex", "Hex-Any" }; - for(uint32_t i=0; iclone(); @@ -242,10 +243,10 @@ void TransliteratorAPITest::TestGetDisplayName() { return; #else - for (uint32_t i=0; itransliterate(rs, start, limit); @@ -448,7 +449,7 @@ void TransliteratorAPITest::TestSimpleKeyboardTransliterator(){ {-1, 16, 14, 16}, //invalid since START<0 {3, 50, 2, 50} //invalid since LIMIT>text.length() }; - for(uint32_t i=0; itransliterate(rs, index1[i], insertion, status); if(status == U_ILLEGAL_ARGUMENT_ERROR) @@ -509,7 +510,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator1(){ 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 "; @@ -556,7 +557,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator2(){ rs="Initial String: add--"; t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); if(t == 0) - errln("FAIL : construction"); + dataerrln("FAIL : construction - %s", u_errorName(status)); else { keyboardAux(t, Data, rs, 0, 20); delete t; @@ -565,7 +566,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator2(){ rs="Hindi --"; t=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); if(t == 0) - errln("FAIL : construction"); + dataerrln("FAIL : construction - %s", u_errorName(status)); else keyboardAux(t, Data, rs, 20, 40); @@ -591,14 +592,12 @@ void TransliteratorAPITest::TestKeyboardTransliterator3(){ UTransPosition index={0, 0, 0, 0}; logln("Testing transliterate(Replaceable, int32_t, UErrorCode)"); Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); - if(U_FAILURE(status)) { + if(t == 0 || U_FAILURE(status)) { errln("Error creating transliterator %s", u_errorName(status)); delete t; return; } - if(t == 0) - errln("FAIL : construction"); - for(uint32_t i=0; ihandleTransliterate(replaceable, index, TRUE); + nullTrans->finishTransliteration(replaceable, index); if(index.start != limit){ errln("ERROR: NullTransliterator->handleTransliterate() failed"); } @@ -648,9 +648,8 @@ void TransliteratorAPITest::TestNullTransliterator(){ void TransliteratorAPITest::TestRegisterUnregister(){ UErrorCode status=U_ZERO_ERROR; - UParseError parseError; /* Make sure it doesn't exist */ - if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, parseError, status) != NULL) { + if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) { errln("FAIL: TestA-TestB already registered\n"); return; } @@ -664,14 +663,16 @@ void TransliteratorAPITest::TestRegisterUnregister(){ status =U_ZERO_ERROR; /* Create it */ - Transliterator *t = new RuleBasedTransliterator("TestA-TestB", + UParseError parseError; + Transliterator *t = Transliterator::createFromRules("TestA-TestB", "a<>b", + UTRANS_FORWARD, parseError, status); /* Register it */ Transliterator::registerInstance(t); /* Now check again -- should exist now*/ - Transliterator *s = Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, parseError, status); + Transliterator *s = Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status); if (s == NULL) { errln("FAIL: TestA-TestB not registered\n"); return; @@ -693,7 +694,7 @@ void TransliteratorAPITest::TestRegisterUnregister(){ /*unregister the instance*/ Transliterator::unregister("TestA-TestB"); /* now Make sure it doesn't exist */ - if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, parseError, status) != NULL) { + if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) { errln("FAIL: TestA-TestB isn't unregistered\n"); return; } @@ -777,18 +778,18 @@ void TransliteratorAPITest::TestGetAdoptFilter(){ UErrorCode status = U_ZERO_ERROR; UParseError parseError; Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); - if(U_FAILURE(status)) { - errln("Error creating transliterator %s", u_errorName(status)); - delete t; - return; + if(t == 0 || U_FAILURE(status)) { + errln("Error creating transliterator %s", u_errorName(status)); + delete t; + return; } - 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"); + errln("FAIL: getFilter failed. Didn't return null when the transliterator used no filtering"); + delete t; + return; } - + UnicodeString got, temp, message; UnicodeString data="ABCabcbbCBa"; temp = data; @@ -904,7 +905,7 @@ void TransliteratorAPITest::doTest(const UnicodeString& message, const UnicodeSt if (prettify(result) == prettify(expected)) logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\""); else - errln((UnicodeString)"FAIL:" + message + " failed Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) ); + dataerrln((UnicodeString)"FAIL:" + message + " failed Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) ); }