]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/nccbtst.c
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / nccbtst.c
index d426b989008b01cc523b397f5139e2e26590d471..f4e3c37d71f72ead0b9315d27ae4d1113ac6379c 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2006,2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2011, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*
@@ -25,6 +25,8 @@
 #include "unicode/ustring.h"
 #include "nccbtst.h"
 #include "unicode/ucnv_cb.h"
+#include "unicode/utf16.h"
+
 #define NEW_MAX_BUFFER 999
 
 #define nct_min(x,y)  ((x<y) ? x : y)
@@ -1674,14 +1676,14 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
     log_verbose("Testing UTF-7 toUnicode with substitute callbacks\n");
     {
         static const uint8_t utf7[]={
-         /* a~            a+AB~                         a+AB\x0c                      a+AB-                         a+AB.                         a+. */
-            0x61, 0x7e,   0x61, 0x2b, 0x41, 0x42, 0x7e, 0x61, 0x2b, 0x41, 0x42, 0x0c, 0x61, 0x2b, 0x41, 0x42, 0x2d, 0x61, 0x2b, 0x41, 0x42, 0x2e, 0x61, 0x2b, 0x2e
+         /* a~            a+AB~                           a+AB\x0c                        a+AB-                         a+AB.                         a+. */
+            0x61, 0x7e,   0x61, 0x2b, 0x41, 0x42, 0x7e,   0x61, 0x2b, 0x41, 0x42, 0x0c,   0x61, 0x2b, 0x41, 0x42, 0x2d, 0x61, 0x2b, 0x41, 0x42, 0x2e, 0x61, 0x2b,   0x2e
         };
         static const UChar unicode[]={
-            0x61, 0xfffd, 0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61, 0xfffd
+            0x61, 0xfffd, 0x61,       0xfffd,     0xfffd, 0x61,       0xfffd,     0xfffd, 0x61,       0xfffd,           0x61,       0xfffd,     0x2e, 0x61, 0xfffd, 0x2e
         };
         static const int32_t offsets[]={
-            0,    1,      2,          4,                7,          9,                12,         14,               17,         19,               22,   23
+            0,    1,      2,          4,          6,      7,          9,          11,     12,         14,               17,         19,         21,   22,   23,     24
         };
 
         if(!testConvertToUnicode(utf7, ARRAY_LENGTH(utf7), unicode, ARRAY_LENGTH(unicode), "UTF-7", 
@@ -1736,10 +1738,10 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             in4[]={ 0x00, 0x01, 0x02, 0x03,   0x00, 0x11, 0x12, 0x00,   0x00, 0x00, 0x4e, 0x00 };
 
         static const UChar
-            out1[]={ UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfeff },
-            out2[]={ UTF16_LEAD(0x0f1000), UTF16_TRAIL(0x0f1000), 0xfffe },
-            out3[]={ 0xfefe, UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfffd, 0xfffd },
-            out4[]={ UTF16_LEAD(0x10203), UTF16_TRAIL(0x10203), 0xfffd, 0x4e00 };
+            out1[]={ U16_LEAD(0x100f00), U16_TRAIL(0x100f00), 0xfeff },
+            out2[]={ U16_LEAD(0x0f1000), U16_TRAIL(0x0f1000), 0xfffe },
+            out3[]={ 0xfefe, U16_LEAD(0x100f00), U16_TRAIL(0x100f00), 0xfffd, 0xfffd },
+            out4[]={ U16_LEAD(0x10203), U16_TRAIL(0x10203), 0xfffd, 0x4e00 };
 
         static const int32_t
             offsets1[]={ 4, 4, 8 },
@@ -2177,6 +2179,39 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs7_v2, NULL, 0,"K" ,U_ZERO_ERROR ))
                 log_err("u-> iso-2022-cn with sub & K did not match.\n"); 
 
+        }
+        {
+            static const UChar iso_2022_cn_inputText8[]={
+                                0x3000,
+                                0xD84D, 0xDC56,
+                                0x3001,
+                                0xD84D, 0xDC56,
+                                0xDBFF, 0xDFFF,
+                                0x0042,
+                                0x0902};
+            static const uint8_t to_iso_2022_cn8_v2[]={  
+                                0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
+                                0x0f,   0x5c,   0x32,   0x33,   0x34,   0x35,   0x36,   0x20,   
+                                0x0e,   0x21,   0x22,   
+                                0x0f,   0x5c,   0x32,   0x33,   0x34,   0x35,   0x36,   0x20,   
+                                0x5c,   0x31,   0x30,   0x46,   0x46,   0x46,   0x46,   0x20,   
+                                0x42,   
+                                0x5c,   0x39,   0x30,   0x32,   0x20
+                             };
+            static const int32_t from_iso_2022_cnOffs8_v2 [] ={
+                    0,  0,  0,  0,  0,  0,  0,
+                    1,  1,  1,  1,  1,  1,  1,  1,
+                    3,  3,  3,
+                    4,  4,  4,  4,  4,  4,  4,  4,
+                    6,  6,  6,  6,  6,  6,  6,  6,
+                    8,
+                    9,  9,  9,  9,  9
+            };
+            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText8, sizeof(iso_2022_cn_inputText8)/sizeof(iso_2022_cn_inputText8[0]),
+                to_iso_2022_cn8_v2, sizeof(to_iso_2022_cn8_v2), "iso-2022-cn",
+                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs8_v2, NULL, 0,UCNV_ESCAPE_CSS2,U_ZERO_ERROR ))
+                log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_CSS2 did not match.\n"); 
+
         }
         {
             static const uint8_t to_iso_2022_cn4_v3[]={  
@@ -2710,7 +2745,7 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const uint8_t
 
     log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
         sourceLen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
 
         junk[0] = 0;
@@ -2908,7 +2943,7 @@ UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *e
 
     log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
         sourcelen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
 
         junk[0] = 0;
@@ -3087,7 +3122,7 @@ UBool testConvertFromUnicodeWithContext(const UChar *source, int sourceLen,  con
 
     log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
         sourceLen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
 
         junk[0] = 0;
@@ -3265,7 +3300,7 @@ UBool testConvertToUnicodeWithContext( const uint8_t *source, int sourcelen, con
 
     log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
         sourcelen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
 
         junk[0] = 0;
@@ -3351,4 +3386,3 @@ static void TestCallBackFailure(void) {
         log_err("Error: ucnv_cbToUWriteUChars did not react correctly to a bad UErrorCode\n");
     }
 }
-