]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/transapi.cpp
ICU-62123.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / transapi.cpp
index 6f497c68b5a40baeb6592103139e2ab2a1d62117..76597d28a213c5412ca67ef503457a8b3bc91399 100644 (file)
@@ -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-2008, International Business Machines Corporation
+ * Copyright (c) 2000-2016, International Business Machines Corporation
  * and others. All Rights Reserved.
  ************************************************************************/
 /************************************************************************
@@ -18,6 +20,7 @@
 #include "unicode/translit.h"
 #include "unicode/unifilt.h"
 #include "cpdtrans.h"
+#include "cmemory.h"
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -72,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();
@@ -138,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;
      }
 
@@ -166,7 +169,7 @@ void TransliteratorAPITest::TestgetInverse() {
        "Any-Hex",
        "Hex-Any"
      };
-     for(uint32_t i=0; i<sizeof(TransID)/sizeof(TransID[0]); i=i+2){
+     for(uint32_t i=0; i<UPRV_LENGTHOF(TransID); i=i+2){
          Transliterator *trans1=Transliterator::createInstance(TransID[i], UTRANS_FORWARD, parseError, status);
          if(t1 == 0){
            errln("FAIL: in instantiation for" + TransID[i]);
@@ -194,7 +197,7 @@ void TransliteratorAPITest::TestClone(){
     t1=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
     t2=Transliterator::createInstance("Latin-Greek", UTRANS_FORWARD, parseError, status);
     if(t1 == 0 || t2 == 0){
-        errln("FAIL: construction");
+        dataerrln("FAIL: construction - %s", u_errorName(status));
         return;
     }
     t3=t1->clone();
@@ -240,10 +243,10 @@ void TransliteratorAPITest::TestGetDisplayName() {
     return;
 #else
 
-    for (uint32_t i=0; i<sizeof(dispNames)/sizeof(dispNames[0]); i=i+2 ) {
+    for (uint32_t i=0; i<UPRV_LENGTHOF(dispNames); i=i+2 ) {
         t = Transliterator::createInstance(dispNames[i+0], UTRANS_FORWARD, parseError, status);
         if(t==0){
-             errln("FAIL: construction: " + dispNames[i+0]);
+             dataerrln("FAIL: construction: " + dispNames[i+0] + " - " + u_errorName(status));
              status = U_ZERO_ERROR;
              continue;
         }
@@ -289,11 +292,11 @@ void TransliteratorAPITest::TestTransliterate1(){
     UErrorCode status = U_ZERO_ERROR;
     UParseError parseError;
 
-    for(uint32_t i=0;i<sizeof(Data)/sizeof(Data[0]); i=i+3){
+    for(uint32_t i=0;i<UPRV_LENGTHOF(Data); i=i+3){
         t=Transliterator::createInstance(Data[i+0], UTRANS_FORWARD, parseError, status);
         if(t==0){
-            errln("FAIL: construction: " + Data[i+0] + " Error: "  + u_errorName(status));
-            errln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) );
+            dataerrln("FAIL: construction: " + Data[i+0] + " Error: "  + u_errorName(status));
+            dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) );
             status = U_ZERO_ERROR;
             continue;
         }
@@ -336,10 +339,10 @@ void TransliteratorAPITest::TestTransliterate2(){
     UErrorCode status = U_ZERO_ERROR;
     UParseError parseError;
 
-    for(uint32_t i=0; i<sizeof(Data2)/sizeof(Data2[0]); i=i+6){
+    for(uint32_t i=0; i<UPRV_LENGTHOF(Data2); i=i+6){
         t=Transliterator::createInstance(Data2[i+0], UTRANS_FORWARD, parseError, status);
         if(t==0){
-            errln("FAIL: construction: " + prettify(Data2[i+0]));
+            dataerrln("FAIL: construction: " + prettify(Data2[i+0]) + " - " + u_errorName(status));
             continue;
         }
         start=getInt(Data2[i+2]);
@@ -399,7 +402,7 @@ void TransliteratorAPITest::TestTransliterate3(){
 
     if(t == 0)
         errln("FAIL : construction");
-    for(uint32_t i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+3){
+    for(uint32_t i=0; i<UPRV_LENGTHOF(Data); i=i+3){
         start=getInt(Data[i+0]);
         limit=getInt(Data[i+1]);
         t->transliterate(rs, start, limit);
@@ -446,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; i<sizeof(index1)/sizeof(index1[0]); i++){
+    for(uint32_t i=0; i<UPRV_LENGTHOF(index1); i++){
         status=U_ZERO_ERROR;
         t->transliterate(rs, index1[i], insertion, status);
         if(status == U_ILLEGAL_ARGUMENT_ERROR)
@@ -507,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<sizeof(Data)/sizeof(Data[0]); i=i+2){
+    for(i=10; i<UPRV_LENGTHOF(Data); i=i+2){
         UnicodeString log;
          if (Data[i+0] != "") {
            log = s + " + " + Data[i+0] + " -> ";
@@ -554,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;
@@ -563,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);
 
@@ -594,7 +597,7 @@ void TransliteratorAPITest::TestKeyboardTransliterator3(){
       delete t;
       return;
     }
-    for(uint32_t i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+4){
+    for(uint32_t i=0; i<UPRV_LENGTHOF(Data); i=i+4){
         UnicodeString log;
         index.contextStart=getInt(Data[i+0]);
         index.contextLimit=index.limit=getInt(Data[i+1]);
@@ -902,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) );
 }