]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/cnormtst.c
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cnormtst.c
index 4acbc2084302461e45f98cca66501ff3083a7b9f..fe7237abc818a945a69b65caaa9ea6bfd43a16db 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT:
  * Copyright (c) 1997-2016, International Business Machines Corporation and
@@ -157,6 +159,7 @@ void addNormTest(TestNode** root)
 }
 
 static const char* const modeStrings[]={
+    "?",
     "UNORM_NONE",
     "UNORM_NFD",
     "UNORM_NFKD",
@@ -181,7 +184,7 @@ static void TestNormCases(UNormalizationMode mode,
         length2= unorm_normalize(source, -1, mode, 0, NULL, 0, &status2);
         if(neededLen!=length2) {
           log_err("ERROR in unorm_normalize(%s)[%d]: "
-                  "preflight length/NUL %d!=%d preflight length/srcLength\n",
+                  "preflight length/srcLength %d!=%d preflight length/NUL\n",
                   modeStrings[mode], (int)x, (int)neededLen, (int)length2);
         }
         if(status==U_BUFFER_OVERFLOW_ERROR)
@@ -190,14 +193,14 @@ static void TestNormCases(UNormalizationMode mode,
         }
         length2=unorm_normalize(source, u_strlen(source), mode, 0, result, UPRV_LENGTHOF(result), &status); 
         if(U_FAILURE(status) || neededLen!=length2) {
-            log_data_err("ERROR in unorm_normalize(%s/NUL) at %s:  %s - (Are you missing data?)\n",
+            log_data_err("ERROR in unorm_normalize(%s/srcLength) at %s:  %s - (Are you missing data?)\n",
                          modeStrings[mode], austrdup(source), myErrorName(status));
         } else {
             assertEqual(result, cases[x][expIndex], x);
         }
         length2=unorm_normalize(source, -1, mode, 0, result, UPRV_LENGTHOF(result), &status); 
         if(U_FAILURE(status) || neededLen!=length2) {
-            log_data_err("ERROR in unorm_normalize(%s/srcLength) at %s:  %s - (Are you missing data?)\n",
+            log_data_err("ERROR in unorm_normalize(%s/NUL) at %s:  %s - (Are you missing data?)\n",
                          modeStrings[mode], austrdup(source), myErrorName(status));
         } else {
             assertEqual(result, cases[x][expIndex], x);
@@ -664,12 +667,12 @@ void TestCheckFCD()
     UChar nfd[100];
     int normsize = 0;
     int nfdsize = 0;
-    
+
     while (size != 19) {
-      data[size] = datachar[(rand() * 50) / RAND_MAX];
+      data[size] = datachar[rand() % UPRV_LENGTHOF(datachar)];
       log_verbose("0x%x", data[size]);
-      normsize += unorm_normalize(data + size, 1, UNORM_NFD, 0, 
-                                  norm + normsize, 100 - normsize, &status);       
+      normsize += unorm_normalize(data + size, 1, UNORM_NFD, 0,
+                                  norm + normsize, 100 - normsize, &status);
       if (U_FAILURE(status)) {
         log_data_err("unorm_quickCheck(FCD) failed: exception occured at data generation - (Are you missing data?)\n");
         break;
@@ -678,8 +681,8 @@ void TestCheckFCD()
     }
     log_verbose("\n");
 
-    nfdsize = unorm_normalize(data, size, UNORM_NFD, 0, 
-                              nfd, 100, &status);       
+    nfdsize = unorm_normalize(data, size, UNORM_NFD, 0,
+                              nfd, 100, &status);
     if (U_FAILURE(status)) {
       log_data_err("unorm_quickCheck(FCD) failed: exception occured at normalized data generation - (Are you missing data?)\n");
     }
@@ -1406,6 +1409,10 @@ TestQuickCheckPerCP() {
         }
 
         length=unorm_normalize(s, length, UNORM_NFD, 0, nfd, UPRV_LENGTHOF(nfd), &errorCode);
+        if (U_FAILURE(errorCode)) {
+            log_data_err("%s:%d errorCode=%s\n", __FILE__, __LINE__, u_errorName(errorCode));
+            break;
+        }
         /* length-length == 0 is used to get around a compiler warning. */
         U16_GET(nfd, 0, length-length, length, lead);
         U16_GET(nfd, 0, length-1, length, trail);