]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/idnaref.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / intltest / idnaref.cpp
index a292bb8482ab571fc14ff606732aaf3beecebbbe..afec7c9f505da1583eb2e097f1cb906d8740a08f 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
  *******************************************************************************
  *
@@ -6,7 +8,7 @@
  *
  *******************************************************************************
  *   file name:  idnaref.cpp
- *   encoding:   US-ASCII
+ *   encoding:   UTF-8
  *   tab size:   8 (not used)
  *   indentation:4
  *
@@ -196,6 +198,17 @@ CLEANUP:
     return b2Len;
 }
 
+
+static NamePrepTransform* getInstance(UErrorCode& status){
+    TestIDNA *thisTest = dynamic_cast<TestIDNA *>(IntlTest::gTest);
+    if (thisTest == nullptr && U_SUCCESS(status)) {
+        status = U_INTERNAL_PROGRAM_ERROR;
+    }
+    if (U_FAILURE(status)) return nullptr;
+    return thisTest->getInstance(status);
+}
+
+
 static int32_t convertFromPuny(  const UChar* src, int32_t srcLength,
                                  UChar* dest, int32_t destCapacity,
                                  UErrorCode& status){
@@ -286,7 +299,7 @@ idnaref_toASCII(const UChar* src, int32_t srcLength,
         b1[b1Len++] = src[j];
     }
 
-    NamePrepTransform* prep = TestIDNA::getInstance(*status);
+    NamePrepTransform* prep = getInstance(*status);
     if(U_FAILURE(*status)){
         goto CLEANUP;
     }
@@ -437,7 +450,7 @@ idnaref_toUnicode(const UChar* src, int32_t srcLength,
             reqLength=0;
 //    UParseError parseError;
 
-    NamePrepTransform* prep = TestIDNA::getInstance(*status);
+    NamePrepTransform* prep = getInstance(*status);
     b1Len = 0;
     UBool* caseFlags = NULL;
 
@@ -692,7 +705,7 @@ idnaref_IDNToASCII(  const UChar* src, int32_t srcLength,
     int32_t reqLength = 0;
 //    UParseError parseError;
 
-    NamePrepTransform* prep = TestIDNA::getInstance(*status);
+    NamePrepTransform* prep = getInstance(*status);
 
     //initialize pointers to stack buffers
     UChar b1Stack[MAX_LABEL_BUFFER_SIZE];
@@ -813,7 +826,7 @@ idnaref_IDNToASCII(  const UChar* src, int32_t srcLength,
             }
 
             labelStart = delimiter;
-            remainingLen = srcLength - (delimiter - src);
+            remainingLen = static_cast<int32_t>(srcLength - (delimiter - src));
         }
     }
 
@@ -848,7 +861,7 @@ idnaref_IDNToUnicode(  const UChar* src, int32_t srcLength,
 
     UBool done = FALSE;
 
-    NamePrepTransform* prep = TestIDNA::getInstance(*status);
+    NamePrepTransform* prep = getInstance(*status);
 
     //initialize pointers to stack buffers
     UChar b1Stack[MAX_LABEL_BUFFER_SIZE];
@@ -970,7 +983,7 @@ idnaref_IDNToUnicode(  const UChar* src, int32_t srcLength,
             }
 
             labelStart = delimiter;
-            remainingLen = srcLength - (delimiter - src);
+            remainingLen = static_cast<int32_t>(srcLength - (delimiter - src));
         }
     }