]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/nccbtst.c
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / cintltst / nccbtst.c
index d426b989008b01cc523b397f5139e2e26590d471..66551a7382e4840f465e9ed36634387d78cc7841 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) 1997-2006,2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*
@@ -16,6 +18,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include "cmemory.h"
 #include "cstring.h"
 #include "unicode/uloc.h"
 #include "unicode/ucnv.h"
 #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)
-#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
 
 static int32_t  gInBufferSize = 0;
 static int32_t  gOutBufferSize = 0;
@@ -181,12 +185,12 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const int32_t  toIBM949Offsskip [] = { 0, 1, 1, 2, 2, 4, 4 };
         static const int32_t  toIBM943Offsskip [] = { 0, 0, 1, 1, 3, 3 };
 
-        if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expskipIBM_949, sizeof(expskipIBM_949), "ibm-949",
+        if(!testConvertFromUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+                expskipIBM_949, UPRV_LENGTHOF(expskipIBM_949), "ibm-949",
                 UCNV_FROM_U_CALLBACK_SKIP, toIBM949Offsskip, NULL, 0 ))
             log_err("u-> ibm-949 with skip did not match.\n");
-        if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-                expskipIBM_943, sizeof(expskipIBM_943), "ibm-943",
+        if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+                expskipIBM_943, UPRV_LENGTHOF(expskipIBM_943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_SKIP, toIBM943Offsskip, NULL, 0 ))
             log_err("u-> ibm-943 with skip did not match.\n");
     }
@@ -197,8 +201,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const int32_t fromUOffsets[] = { 0, 2, 3, 3, 3, 5, 5, 6, 6, 8, 8, 8, 8 };
 
         /* test ibm-930 (EBCDIC_STATEFUL) with fallbacks that are not taken to check correct state transitions */
-        if(!testConvertFromUnicode(fromU, sizeof(fromU)/U_SIZEOF_UCHAR,
-                                   fromUBytes, sizeof(fromUBytes),
+        if(!testConvertFromUnicode(fromU, UPRV_LENGTHOF(fromU),
+                                   fromUBytes, UPRV_LENGTHOF(fromUBytes),
                                    "ibm-930",
                                    UCNV_FROM_U_CALLBACK_SKIP, fromUOffsets,
                                    NULL, 0)
@@ -218,8 +222,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const int32_t latin1FromUOffsets[] = { 0, 1, 3, 6 };
 
         /* US-ASCII */
-        if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
-                                   usasciiFromUBytes, sizeof(usasciiFromUBytes),
+        if(!testConvertFromUnicode(usasciiFromU, UPRV_LENGTHOF(usasciiFromU),
+                                   usasciiFromUBytes, UPRV_LENGTHOF(usasciiFromUBytes),
                                    "US-ASCII",
                                    UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
                                    NULL, 0)
@@ -229,8 +233,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
         /* SBCS NLTC codepage 367 for US-ASCII */
-        if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
-                                   usasciiFromUBytes, sizeof(usasciiFromUBytes),
+        if(!testConvertFromUnicode(usasciiFromU, UPRV_LENGTHOF(usasciiFromU),
+                                   usasciiFromUBytes, UPRV_LENGTHOF(usasciiFromUBytes),
                                    "ibm-367",
                                    UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
                                    NULL, 0)
@@ -240,8 +244,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 #endif
 
         /* ISO-Latin-1 */
-        if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
-                                   latin1FromUBytes, sizeof(latin1FromUBytes),
+        if(!testConvertFromUnicode(latin1FromU, UPRV_LENGTHOF(latin1FromU),
+                                   latin1FromUBytes, UPRV_LENGTHOF(latin1FromUBytes),
                                    "LATIN_1",
                                    UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
                                    NULL, 0)
@@ -251,8 +255,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
         /* windows-1252 */
-        if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
-                                   latin1FromUBytes, sizeof(latin1FromUBytes),
+        if(!testConvertFromUnicode(latin1FromU, UPRV_LENGTHOF(latin1FromU),
+                                   latin1FromUBytes, UPRV_LENGTHOF(latin1FromUBytes),
                                    "windows-1252",
                                    UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
                                    NULL, 0)
@@ -418,82 +422,82 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         };
         static const int32_t from_isciiOffs1 [] ={0,2};
 
-        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
-                toIBM943, sizeof(toIBM943), "ibm-943",
+        if(!testConvertFromUnicode(inputTest, UPRV_LENGTHOF(inputTest),
+                toIBM943, UPRV_LENGTHOF(toIBM943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_SKIP, offset, NULL, 0 ))
             log_err("u-> ibm-943 with skip did not match.\n");
 
-        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
-                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
+        if(!testConvertFromUnicode(euc_jp_inputText, UPRV_LENGTHOF(euc_jp_inputText),
+                to_euc_jp, UPRV_LENGTHOF(to_euc_jp), "IBM-eucJP",
                 UCNV_FROM_U_CALLBACK_SKIP, fromEUC_JPOffs, NULL, 0 ))
             log_err("u-> euc-jp with skip did not match.\n");
 
-        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
-                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
+        if(!testConvertFromUnicode(euc_tw_inputText, UPRV_LENGTHOF(euc_tw_inputText),
+                to_euc_tw, UPRV_LENGTHOF(to_euc_tw), "euc-tw",
                 UCNV_FROM_U_CALLBACK_SKIP, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with skip did not match.\n");  
         
         /*iso_2022_jp*/
-        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
-                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText, UPRV_LENGTHOF(iso_2022_jp_inputText),
+                to_iso_2022_jp, UPRV_LENGTHOF(to_iso_2022_jp), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs, NULL, 0 ))
             log_err("u-> iso-2022-jp with skip did not match.\n"); 
         
         /* with context */
-        if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
-                to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
+        if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, UPRV_LENGTHOF(iso_2022_jp_inputText2),
+                to_iso_2022_jp2, UPRV_LENGTHOF(to_iso_2022_jp2), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs2, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> iso-2022-jp with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
     
         /*iso_2022_cn*/
-        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
-                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
+        if(!testConvertFromUnicode(iso_2022_cn_inputText, UPRV_LENGTHOF(iso_2022_cn_inputText),
+                to_iso_2022_cn, UPRV_LENGTHOF(to_iso_2022_cn), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs, NULL, 0 ))
             log_err("u-> iso-2022-cn with skip did not match.\n"); 
         /*with context*/
-        if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
-                to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
+        if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText1, UPRV_LENGTHOF(iso_2022_cn_inputText1),
+                to_iso_2022_cn1, UPRV_LENGTHOF(to_iso_2022_cn1), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> iso-2022-cn with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
         /*iso_2022_kr*/
-        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
-                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
+        if(!testConvertFromUnicode(iso_2022_kr_inputText, UPRV_LENGTHOF(iso_2022_kr_inputText),
+                to_iso_2022_kr, UPRV_LENGTHOF(to_iso_2022_kr), "iso-2022-kr",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs, NULL, 0 ))
             log_err("u-> iso-2022-kr with skip did not match.\n"); 
           /*with context*/
-        if(!testConvertFromUnicodeWithContext(iso_2022_kr_inputText1, sizeof(iso_2022_kr_inputText1)/sizeof(iso_2022_kr_inputText1[0]),
-                to_iso_2022_kr1, sizeof(to_iso_2022_kr1), "iso-2022-kr",
+        if(!testConvertFromUnicodeWithContext(iso_2022_kr_inputText1, UPRV_LENGTHOF(iso_2022_kr_inputText1),
+                to_iso_2022_kr1, UPRV_LENGTHOF(to_iso_2022_kr1), "iso-2022-kr",
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> iso-2022-kr with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
         /*hz*/
-        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
-                to_hz, sizeof(to_hz), "HZ",
+        if(!testConvertFromUnicode(hz_inputText, UPRV_LENGTHOF(hz_inputText),
+                to_hz, UPRV_LENGTHOF(to_hz), "HZ",
                 UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs, NULL, 0 ))
             log_err("u-> HZ with skip did not match.\n"); 
           /*with context*/
-        if(!testConvertFromUnicodeWithContext(hz_inputText1, sizeof(hz_inputText1)/sizeof(hz_inputText1[0]),
-                to_hz1, sizeof(to_hz1), "hz",
+        if(!testConvertFromUnicodeWithContext(hz_inputText1, UPRV_LENGTHOF(hz_inputText1),
+                to_hz1, UPRV_LENGTHOF(to_hz1), "hz",
                 UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> hz with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
 #endif
         
         /*SCSU*/
-        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
-                to_SCSU, sizeof(to_SCSU), "SCSU",
+        if(!testConvertFromUnicode(SCSU_inputText, UPRV_LENGTHOF(SCSU_inputText),
+                to_SCSU, UPRV_LENGTHOF(to_SCSU), "SCSU",
                 UCNV_FROM_U_CALLBACK_SKIP, from_SCSUOffs, NULL, 0 ))
             log_err("u-> SCSU with skip did not match.\n");
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
         /*ISCII*/
-        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
-                to_iscii, sizeof(to_iscii), "ISCII,version=0",
+        if(!testConvertFromUnicode(iscii_inputText, UPRV_LENGTHOF(iscii_inputText),
+                to_iscii, UPRV_LENGTHOF(to_iscii), "ISCII,version=0",
                 UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs, NULL, 0 ))
             log_err("u-> iscii with skip did not match.\n"); 
         /*with context*/
-        if(!testConvertFromUnicodeWithContext(iscii_inputText1, sizeof(iscii_inputText1)/sizeof(iscii_inputText1[0]),
-                to_iscii1, sizeof(to_iscii1), "ISCII,version=0",
+        if(!testConvertFromUnicodeWithContext(iscii_inputText1, UPRV_LENGTHOF(iscii_inputText1),
+                to_iscii1, UPRV_LENGTHOF(to_iscii1), "ISCII,version=0",
                 UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> iscii with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
 #endif     
@@ -578,8 +582,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         };
 
         /* BOCU-1 fromUnicode never calls callbacks, so this only tests single-byte and offsets behavior */
-        if(!testConvertFromUnicode(expected, ARRAY_LENGTH(expected),
-                                 sampleText, sizeof(sampleText),
+        if(!testConvertFromUnicode(expected, UPRV_LENGTHOF(expected),
+                                 sampleText, UPRV_LENGTHOF(sampleText),
                                  "BOCU-1",
                                  UCNV_FROM_U_CALLBACK_SKIP, offsets, NULL, 0)
         ) {
@@ -626,8 +630,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         /* CESU-8 fromUnicode never calls callbacks, so this only tests conversion and offsets behavior */
 
         /* without offsets */
-        if(!testConvertFromUnicode(expected, ARRAY_LENGTH(expected),
-                                 sampleText, sizeof(sampleText),
+        if(!testConvertFromUnicode(expected, UPRV_LENGTHOF(expected),
+                                 sampleText, UPRV_LENGTHOF(sampleText),
                                  "CESU-8",
                                  UCNV_FROM_U_CALLBACK_SKIP, NULL, NULL, 0)
         ) {
@@ -635,8 +639,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         }
 
         /* with offsets */
-        if(!testConvertFromUnicode(expected, ARRAY_LENGTH(expected),
-                                 sampleText, sizeof(sampleText),
+        if(!testConvertFromUnicode(expected, UPRV_LENGTHOF(expected),
+                                 sampleText, UPRV_LENGTHOF(sampleText),
                                  "CESU-8",
                                  UCNV_FROM_U_CALLBACK_SKIP, offsets, NULL, 0)
         ) {
@@ -658,24 +662,24 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const int32_t  fromIBM943Offs [] = { 0, 2, 4};
         static const int32_t  fromIBM930Offs [] = { 1, 3, 5};
 
-        if(!testConvertToUnicode(expskipIBM_949, sizeof(expskipIBM_949),
-                 IBM_949skiptoUnicode, sizeof(IBM_949skiptoUnicode)/sizeof(IBM_949skiptoUnicode),"ibm-949",
+        if(!testConvertToUnicode(expskipIBM_949, UPRV_LENGTHOF(expskipIBM_949),
+                 IBM_949skiptoUnicode, UPRV_LENGTHOF(IBM_949skiptoUnicode),"ibm-949",
                 UCNV_TO_U_CALLBACK_SKIP, fromIBM949Offs, NULL, 0 ))
             log_err("ibm-949->u with skip did not match.\n");
-        if(!testConvertToUnicode(expskipIBM_943, sizeof(expskipIBM_943),
-                 IBM_943skiptoUnicode, sizeof(IBM_943skiptoUnicode)/sizeof(IBM_943skiptoUnicode[0]),"ibm-943",
+        if(!testConvertToUnicode(expskipIBM_943, UPRV_LENGTHOF(expskipIBM_943),
+                 IBM_943skiptoUnicode, UPRV_LENGTHOF(IBM_943skiptoUnicode),"ibm-943",
                 UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offs, NULL, 0 ))
             log_err("ibm-943->u with skip did not match.\n");
 
 
-        if(!testConvertToUnicode(expskipIBM_930, sizeof(expskipIBM_930),
-                 IBM_930skiptoUnicode, sizeof(IBM_930skiptoUnicode)/sizeof(IBM_930skiptoUnicode[0]),"ibm-930",
+        if(!testConvertToUnicode(expskipIBM_930, UPRV_LENGTHOF(expskipIBM_930),
+                 IBM_930skiptoUnicode, UPRV_LENGTHOF(IBM_930skiptoUnicode),"ibm-930",
                 UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs, NULL, 0 ))
             log_err("ibm-930->u with skip did not match.\n");
 
     
-        if(!testConvertToUnicodeWithContext(expskipIBM_930, sizeof(expskipIBM_930),
-                 IBM_930skiptoUnicode, sizeof(IBM_930skiptoUnicode)/sizeof(IBM_930skiptoUnicode[0]),"ibm-930",
+        if(!testConvertToUnicodeWithContext(expskipIBM_930, UPRV_LENGTHOF(expskipIBM_930),
+                 IBM_930skiptoUnicode, UPRV_LENGTHOF(IBM_930skiptoUnicode),"ibm-930",
                 UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs, NULL, 0,"i",U_ILLEGAL_CHAR_FOUND ))
             log_err("ibm-930->u with skip did not match.\n");
     }
@@ -691,8 +695,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const int32_t latin1ToUOffsets[] = { 0, 1, 2 };
 
         /* US-ASCII */
-        if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
-                                 usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
+        if(!testConvertToUnicode(usasciiToUBytes, UPRV_LENGTHOF(usasciiToUBytes),
+                                 usasciiToU, UPRV_LENGTHOF(usasciiToU),
                                  "US-ASCII",
                                  UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
                                  NULL, 0)
@@ -702,8 +706,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
         /* SBCS NLTC codepage 367 for US-ASCII */
-        if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
-                                 usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
+        if(!testConvertToUnicode(usasciiToUBytes, UPRV_LENGTHOF(usasciiToUBytes),
+                                 usasciiToU, UPRV_LENGTHOF(usasciiToU),
                                  "ibm-367",
                                  UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
                                  NULL, 0)
@@ -713,8 +717,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 #endif
 
         /* ISO-Latin-1 */
-        if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
-                                 latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
+        if(!testConvertToUnicode(latin1ToUBytes, UPRV_LENGTHOF(latin1ToUBytes),
+                                 latin1ToU, UPRV_LENGTHOF(latin1ToU),
                                  "LATIN_1",
                                  UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
                                  NULL, 0)
@@ -724,8 +728,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
         /* windows-1252 */
-        if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
-                                 latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
+        if(!testConvertToUnicode(latin1ToUBytes, UPRV_LENGTHOF(latin1ToUBytes),
+                                 latin1ToU, UPRV_LENGTHOF(latin1ToU),
                                  "windows-1252",
                                  UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
                                  NULL, 0)
@@ -763,8 +767,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
                 /*iso-2022-jp*/
         static const uint8_t sampleTxt_iso_2022_jp[]={ 
             0x41,
-            0x1b,   0x24,   0x42,   0x2A, 0x44, /*unassigned*/
-             0x1b,   0x28,   0x42,   0x42,
+            0x1b,   0x24,   0x42,   0x3a, 0x1a, /*unassigned*/
+            0x1b,   0x28,   0x42,   0x42,
             
         };
         static const UChar iso_2022_jptoUnicode[]={    0x41,0x42 };
@@ -844,56 +848,56 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         static const UChar LMBCSToUnicode[]={ 0x4e2e, 0xe5c4};
         static const int32_t fromLMBCS[] = {0, 6};
  
-        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
-             EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
+        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, UPRV_LENGTHOF(sampleTxtEBCIDIC_STATEFUL),
+             EBCIDIC_STATEFUL_toUnicode, UPRV_LENGTHOF(EBCIDIC_STATEFUL_toUnicode),"ibm-930",
             UCNV_TO_U_CALLBACK_SKIP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
         log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
 
-        if(!testConvertToUnicodeWithContext(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
-             EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
+        if(!testConvertToUnicodeWithContext(sampleTxtEBCIDIC_STATEFUL, UPRV_LENGTHOF(sampleTxtEBCIDIC_STATEFUL),
+             EBCIDIC_STATEFUL_toUnicode, UPRV_LENGTHOF(EBCIDIC_STATEFUL_toUnicode),"ibm-930",
             UCNV_TO_U_CALLBACK_SKIP, from_EBCIDIC_STATEFULOffsets, NULL, 0,"i",U_ILLEGAL_CHAR_FOUND ))
         log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
-                 euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
+        if(!testConvertToUnicode(sampleTxt_euc_jp, UPRV_LENGTHOF(sampleTxt_euc_jp),
+                 euc_jptoUnicode, UPRV_LENGTHOF(euc_jptoUnicode),"IBM-eucJP",
                 UCNV_TO_U_CALLBACK_SKIP, from_euc_jpOffs , NULL, 0))
             log_err("euc-jp->u with skip did not match.\n");
 
 
 
-        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
-                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
+        if(!testConvertToUnicode(sampleTxt_euc_tw, UPRV_LENGTHOF(sampleTxt_euc_tw),
+                 euc_twtoUnicode, UPRV_LENGTHOF(euc_twtoUnicode),"euc-tw",
                 UCNV_TO_U_CALLBACK_SKIP, from_euc_twOffs , NULL, 0))
             log_err("euc-tw->u with skip did not match.\n");
 
         
-        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                 iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                 iso_2022_jptoUnicode, UPRV_LENGTHOF(iso_2022_jptoUnicode),"iso-2022-jp",
                 UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_jpOffs , NULL, 0))
             log_err("iso-2022-jp->u with skip did not match.\n");
         
-        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
-                 iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, UPRV_LENGTHOF(sampleTxt_iso_2022_cn),
+                 iso_2022_cntoUnicode, UPRV_LENGTHOF(iso_2022_cntoUnicode),"iso-2022-cn",
                 UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_cnOffs , NULL, 0))
             log_err("iso-2022-cn->u with skip did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
-                 iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, UPRV_LENGTHOF(sampleTxt_iso_2022_kr),
+                 iso_2022_krtoUnicode, UPRV_LENGTHOF(iso_2022_krtoUnicode),"iso-2022-kr",
                 UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_krOffs , NULL, 0))
             log_err("iso-2022-kr->u with skip did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
-                 hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
+        if(!testConvertToUnicode(sampleTxt_hz, UPRV_LENGTHOF(sampleTxt_hz),
+                 hztoUnicode, UPRV_LENGTHOF(hztoUnicode),"HZ",
                 UCNV_TO_U_CALLBACK_SKIP, from_hzOffs , NULL, 0))
             log_err("HZ->u with skip did not match.\n");
         
-        if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
-                 isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
+        if(!testConvertToUnicode(sampleTxt_iscii, UPRV_LENGTHOF(sampleTxt_iscii),
+                 isciitoUnicode, UPRV_LENGTHOF(isciitoUnicode),"ISCII,version=0",
                 UCNV_TO_U_CALLBACK_SKIP, from_isciiOffs , NULL, 0))
             log_err("iscii->u with skip did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
-                LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS-1",
+        if(!testConvertToUnicode(sampleTxtLMBCS, UPRV_LENGTHOF(sampleTxtLMBCS),
+                LMBCSToUnicode, UPRV_LENGTHOF(LMBCSToUnicode),"LMBCS-1",
                 UCNV_TO_U_CALLBACK_SKIP, fromLMBCS , NULL, 0))
             log_err("LMBCS->u with skip did not match.\n");
 
@@ -907,10 +911,10 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         UChar    expected1[] = {  0x0031, 0x4e8c, 0x0061};
         int32_t offsets1[] = {   0x0000, 0x0001, 0x0006};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"utf8",
                 UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
-            log_err("utf8->u with skip did not match.\n");;
+            log_err("utf8->u with skip did not match.\n");
     }
 
     log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SKIP \n");
@@ -919,8 +923,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061,0xfffe,0xfffe};
         int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003,4,5};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"SCSU",
                 UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
             log_err("scsu->u with skip did not match.\n");
     }
@@ -1000,8 +1004,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
             71, 72
         };
 
-        if(!testConvertToUnicode(sampleText, sizeof(sampleText),
-                                 expected, ARRAY_LENGTH(expected), "BOCU-1",
+        if(!testConvertToUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+                                 expected, UPRV_LENGTHOF(expected), "BOCU-1",
                                  UCNV_TO_U_CALLBACK_SKIP, offsets, NULL, 0)
         ) {
             log_err("BOCU-1->u with skip did not match.\n");
@@ -1053,16 +1057,16 @@ static void TestSkip(int32_t inputsize, int32_t outputsize)
         };
 
         /* without offsets */
-        if(!testConvertToUnicode(sampleText, sizeof(sampleText),
-                                 expected, ARRAY_LENGTH(expected), "CESU-8",
+        if(!testConvertToUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+                                 expected, UPRV_LENGTHOF(expected), "CESU-8",
                                  UCNV_TO_U_CALLBACK_SKIP, NULL, NULL, 0)
         ) {
             log_err("CESU-8->u with skip did not match.\n");
         }
 
         /* with offsets */
-        if(!testConvertToUnicode(sampleText, sizeof(sampleText),
-                                 expected, ARRAY_LENGTH(expected), "CESU-8",
+        if(!testConvertToUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+                                 expected, UPRV_LENGTHOF(expected), "CESU-8",
                                  UCNV_TO_U_CALLBACK_SKIP, offsets, NULL, 0)
         ) {
             log_err("CESU-8->u with skip did not match.\n");
@@ -1103,16 +1107,16 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
     /*From Unicode*/
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
-    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-            expstopIBM_949, sizeof(expstopIBM_949), "ibm-949",
+    if(!testConvertFromUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+            expstopIBM_949, UPRV_LENGTHOF(expstopIBM_949), "ibm-949",
             UCNV_FROM_U_CALLBACK_STOP, toIBM949Offsstop, NULL, 0 ))
         log_err("u-> ibm-949 with stop did not match.\n");
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expstopIBM_943, sizeof(expstopIBM_943), "ibm-943",
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expstopIBM_943, UPRV_LENGTHOF(expstopIBM_943), "ibm-943",
             UCNV_FROM_U_CALLBACK_STOP, toIBM943Offsstop , NULL, 0))
         log_err("u-> ibm-943 with stop did not match.\n");
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expstopIBM_930, sizeof(expstopIBM_930), "ibm-930",
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expstopIBM_930, UPRV_LENGTHOF(expstopIBM_930), "ibm-930",
             UCNV_FROM_U_CALLBACK_STOP, toIBM930Offsstop, NULL, 0 ))
         log_err("u-> ibm-930 with stop did not match.\n");
 
@@ -1187,48 +1191,48 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
             0,           
         };
 
-        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
-                toIBM943, sizeof(toIBM943), "ibm-943",
+        if(!testConvertFromUnicode(inputTest, UPRV_LENGTHOF(inputTest),
+                toIBM943, UPRV_LENGTHOF(toIBM943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_STOP, offset, NULL, 0 ))
             log_err("u-> ibm-943 with stop did not match.\n");
 
-        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
-                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
+        if(!testConvertFromUnicode(euc_jp_inputText, UPRV_LENGTHOF(euc_jp_inputText),
+                to_euc_jp, UPRV_LENGTHOF(to_euc_jp), "IBM-eucJP",
                 UCNV_FROM_U_CALLBACK_STOP, fromEUC_JPOffs, NULL, 0 ))
             log_err("u-> euc-jp with stop did not match.\n");
 
-        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
-                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
+        if(!testConvertFromUnicode(euc_tw_inputText, UPRV_LENGTHOF(euc_tw_inputText),
+                to_euc_tw, UPRV_LENGTHOF(to_euc_tw), "euc-tw",
                 UCNV_FROM_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with stop did not match.\n");  
 
-        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
-                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText, UPRV_LENGTHOF(iso_2022_jp_inputText),
+                to_iso_2022_jp, UPRV_LENGTHOF(to_iso_2022_jp), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
             log_err("u-> iso-2022-jp with stop did not match.\n");  
 
-        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
-                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText, UPRV_LENGTHOF(iso_2022_jp_inputText),
+                to_iso_2022_jp, UPRV_LENGTHOF(to_iso_2022_jp), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
             log_err("u-> iso-2022-jp with stop did not match.\n");  
         
-        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
-                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
+        if(!testConvertFromUnicode(iso_2022_cn_inputText, UPRV_LENGTHOF(iso_2022_cn_inputText),
+                to_iso_2022_cn, UPRV_LENGTHOF(to_iso_2022_cn), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_cnOffs, NULL, 0 ))
             log_err("u-> iso-2022-cn with stop did not match.\n");  
 
-        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
-                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
+        if(!testConvertFromUnicode(iso_2022_kr_inputText, UPRV_LENGTHOF(iso_2022_kr_inputText),
+                to_iso_2022_kr, UPRV_LENGTHOF(to_iso_2022_kr), "iso-2022-kr",
                 UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_krOffs, NULL, 0 ))
             log_err("u-> iso-2022-kr with stop did not match.\n");  
         
-        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
-                to_hz, sizeof(to_hz), "HZ",
+        if(!testConvertFromUnicode(hz_inputText, UPRV_LENGTHOF(hz_inputText),
+                to_hz, UPRV_LENGTHOF(to_hz), "HZ",
                 UCNV_FROM_U_CALLBACK_STOP, from_hzOffs, NULL, 0 ))
             log_err("u-> HZ with stop did not match.\n");\
                 
-        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
-                to_iscii, sizeof(to_iscii), "ISCII,version=0",
+        if(!testConvertFromUnicode(iscii_inputText, UPRV_LENGTHOF(iscii_inputText),
+                to_iscii, UPRV_LENGTHOF(to_iscii), "ISCII,version=0",
                 UCNV_FROM_U_CALLBACK_STOP, from_isciiOffs, NULL, 0 ))
             log_err("u-> iscii with stop did not match.\n"); 
 
@@ -1248,8 +1252,8 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
             0,
 
         };
-        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
-                to_SCSU, sizeof(to_SCSU), "SCSU",
+        if(!testConvertFromUnicode(SCSU_inputText, UPRV_LENGTHOF(SCSU_inputText),
+                to_SCSU, UPRV_LENGTHOF(to_SCSU), "SCSU",
                 UCNV_FROM_U_CALLBACK_STOP, from_SCSUOffs, NULL, 0 ))
             log_err("u-> SCSU with skip did not match.\n");
     
@@ -1258,16 +1262,16 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
     /*to Unicode*/
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
-    if(!testConvertToUnicode(expstopIBM_949, sizeof(expstopIBM_949),
-             IBM_949stoptoUnicode, sizeof(IBM_949stoptoUnicode)/sizeof(IBM_949stoptoUnicode[0]),"ibm-949",
+    if(!testConvertToUnicode(expstopIBM_949, UPRV_LENGTHOF(expstopIBM_949),
+             IBM_949stoptoUnicode, UPRV_LENGTHOF(IBM_949stoptoUnicode),"ibm-949",
             UCNV_TO_U_CALLBACK_STOP, fromIBM949Offs, NULL, 0 ))
         log_err("ibm-949->u with stop did not match.\n");
-    if(!testConvertToUnicode(expstopIBM_943, sizeof(expstopIBM_943),
-             IBM_943stoptoUnicode, sizeof(IBM_943stoptoUnicode)/sizeof(IBM_943stoptoUnicode[0]),"ibm-943",
+    if(!testConvertToUnicode(expstopIBM_943, UPRV_LENGTHOF(expstopIBM_943),
+             IBM_943stoptoUnicode, UPRV_LENGTHOF(IBM_943stoptoUnicode),"ibm-943",
             UCNV_TO_U_CALLBACK_STOP, fromIBM943Offs, NULL, 0 ))
         log_err("ibm-943->u with stop did not match.\n");
-    if(!testConvertToUnicode(expstopIBM_930, sizeof(expstopIBM_930),
-             IBM_930stoptoUnicode, sizeof(IBM_930stoptoUnicode)/sizeof(IBM_930stoptoUnicode[0]),"ibm-930",
+    if(!testConvertToUnicode(expstopIBM_930, UPRV_LENGTHOF(expstopIBM_930),
+             IBM_930stoptoUnicode, UPRV_LENGTHOF(IBM_930stoptoUnicode),"ibm-930",
             UCNV_TO_U_CALLBACK_STOP, fromIBM930Offs, NULL, 0 ))
         log_err("ibm-930->u with stop did not match.\n");
 
@@ -1299,18 +1303,18 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
 
 
 
-         if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
-             EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
+         if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, UPRV_LENGTHOF(sampleTxtEBCIDIC_STATEFUL),
+             EBCIDIC_STATEFUL_toUnicode, UPRV_LENGTHOF(EBCIDIC_STATEFUL_toUnicode),"ibm-930",
             UCNV_TO_U_CALLBACK_STOP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
         log_err("EBCIDIC_STATEFUL->u with stop did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
-             euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
+        if(!testConvertToUnicode(sampleTxt_euc_jp, UPRV_LENGTHOF(sampleTxt_euc_jp),
+             euc_jptoUnicode, UPRV_LENGTHOF(euc_jptoUnicode),"IBM-eucJP",
             UCNV_TO_U_CALLBACK_STOP, from_euc_jpOffs , NULL, 0))
         log_err("euc-jp->u with stop did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
-                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
+        if(!testConvertToUnicode(sampleTxt_euc_tw, UPRV_LENGTHOF(sampleTxt_euc_tw),
+                 euc_twtoUnicode, UPRV_LENGTHOF(euc_twtoUnicode),"euc-tw",
                 UCNV_TO_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
             log_err("euc-tw->u with stop did not match.\n");
     }
@@ -1323,10 +1327,10 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
         static const UChar    expected1[] = {  0x0031, 0x4e8c,};
         static const int32_t offsets1[] = {   0x0000, 0x0001};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"utf8",
                 UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
-            log_err("utf8->u with stop did not match.\n");;
+            log_err("utf8->u with stop did not match.\n");
     }
     log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_STOP \n");
     {
@@ -1334,10 +1338,10 @@ static void TestStop(int32_t inputsize, int32_t outputsize)
         static const UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061};
         static const int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"SCSU",
                 UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
-            log_err("scsu->u with stop did not match.\n");;
+            log_err("scsu->u with stop did not match.\n");
     }
 
 }
@@ -1374,16 +1378,16 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
     /*from unicode*/
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
-    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-            expsubIBM_949, sizeof(expsubIBM_949), "ibm-949", 
+    if(!testConvertFromUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+            expsubIBM_949, UPRV_LENGTHOF(expsubIBM_949), "ibm-949",
             UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM949Offssub, NULL, 0 ))
         log_err("u-> ibm-949 with subst did not match.\n");
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expsubIBM_943, sizeof(expsubIBM_943), "ibm-943",
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expsubIBM_943, UPRV_LENGTHOF(expsubIBM_943), "ibm-943",
             UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM943Offssub , NULL, 0))
         log_err("u-> ibm-943 with subst did not match.\n");
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expsubIBM_930, sizeof(expsubIBM_930), "ibm-930", 
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expsubIBM_930, UPRV_LENGTHOF(expsubIBM_930), "ibm-930",
             UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM930Offssub, NULL, 0 ))
         log_err("u-> ibm-930 with subst did not match.\n");
 
@@ -1412,18 +1416,18 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
 
         static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7, 8,};
 
-        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
-                toIBM943, sizeof(toIBM943), "ibm-943",
+        if(!testConvertFromUnicode(inputTest, UPRV_LENGTHOF(inputTest),
+                toIBM943, UPRV_LENGTHOF(toIBM943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset, NULL, 0 ))
             log_err("u-> ibm-943 with substitute did not match.\n");
 
-        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
-                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
+        if(!testConvertFromUnicode(euc_jp_inputText, UPRV_LENGTHOF(euc_jp_inputText),
+                to_euc_jp, UPRV_LENGTHOF(to_euc_jp), "IBM-eucJP",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, fromEUC_JPOffs, NULL, 0 ))
             log_err("u-> euc-jp with substitute did not match.\n");
 
-        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
-                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
+        if(!testConvertFromUnicode(euc_tw_inputText, UPRV_LENGTHOF(euc_tw_inputText),
+                to_euc_tw, UPRV_LENGTHOF(to_euc_tw), "euc-tw",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with substitute did not match.\n");
     }
@@ -1454,13 +1458,13 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             0,
 
         };
-        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
-                to_SCSU, sizeof(to_SCSU), "SCSU",
+        if(!testConvertFromUnicode(SCSU_inputText, UPRV_LENGTHOF(SCSU_inputText),
+                to_SCSU, UPRV_LENGTHOF(to_SCSU), "SCSU",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_SCSUOffs, NULL, 0 ))
             log_err("u-> SCSU with substitute did not match.\n");
                 
-        if(!testConvertFromUnicodeWithContext(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
-                to_SCSU_1, sizeof(to_SCSU_1), "SCSU",
+        if(!testConvertFromUnicodeWithContext(SCSU_inputText, UPRV_LENGTHOF(SCSU_inputText),
+                to_SCSU_1, UPRV_LENGTHOF(to_SCSU_1), "SCSU",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_SCSUOffs_1, NULL, 0,"i",U_ILLEGAL_CHAR_FOUND ))
             log_err("u-> SCSU with substitute did not match.\n");
     }
@@ -1475,10 +1479,10 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
                            
         };
         static const int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
-        if(!testConvertFromUnicode(testinput, sizeof(testinput)/sizeof(testinput[0]),
-                expectedUTF8, sizeof(expectedUTF8), "utf8",
+        if(!testConvertFromUnicode(testinput, UPRV_LENGTHOF(testinput),
+                expectedUTF8, UPRV_LENGTHOF(expectedUTF8), "utf8",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0 )) {
-            log_err("u-> utf8 with stop did not match.\n");
+            log_err("u-> utf8 with substitute did not match.\n");
         }
     }
 
@@ -1501,8 +1505,8 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             -1, -1, 0, 0, 1, 1
         };
 
-        if(!testConvertFromUnicode(in, ARRAY_LENGTH(in),
-                                   out, sizeof(out), "UTF-16",
+        if(!testConvertFromUnicode(in, UPRV_LENGTHOF(in),
+                                   out, UPRV_LENGTHOF(out), "UTF-16",
                                    UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
         ) {
             log_err("u->UTF-16 with substitute did not match.\n");
@@ -1528,8 +1532,8 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1
         };
 
-        if(!testConvertFromUnicode(in, ARRAY_LENGTH(in),
-                                   out, sizeof(out), "UTF-32",
+        if(!testConvertFromUnicode(in, UPRV_LENGTHOF(in),
+                                   out, UPRV_LENGTHOF(out), "UTF-32",
                                    UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
         ) {
             log_err("u->UTF-32 with substitute did not match.\n");
@@ -1539,16 +1543,16 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
     /*to unicode*/
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
-    if(!testConvertToUnicode(expsubIBM_949, sizeof(expsubIBM_949),
-             IBM_949subtoUnicode, sizeof(IBM_949subtoUnicode)/sizeof(IBM_949subtoUnicode[0]),"ibm-949",
+    if(!testConvertToUnicode(expsubIBM_949, UPRV_LENGTHOF(expsubIBM_949),
+             IBM_949subtoUnicode, UPRV_LENGTHOF(IBM_949subtoUnicode),"ibm-949",
             UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM949Offs, NULL, 0 ))
         log_err("ibm-949->u with substitute did not match.\n");
-    if(!testConvertToUnicode(expsubIBM_943, sizeof(expsubIBM_943),
-             IBM_943subtoUnicode, sizeof(IBM_943subtoUnicode)/sizeof(IBM_943subtoUnicode[0]),"ibm-943",
+    if(!testConvertToUnicode(expsubIBM_943, UPRV_LENGTHOF(expsubIBM_943),
+             IBM_943subtoUnicode, UPRV_LENGTHOF(IBM_943subtoUnicode),"ibm-943",
             UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offs, NULL, 0 ))
         log_err("ibm-943->u with substitute did not match.\n");
-    if(!testConvertToUnicode(expsubIBM_930, sizeof(expsubIBM_930),
-             IBM_930subtoUnicode, sizeof(IBM_930subtoUnicode)/sizeof(IBM_930subtoUnicode[0]),"ibm-930",
+    if(!testConvertToUnicode(expsubIBM_930, UPRV_LENGTHOF(expsubIBM_930),
+             IBM_930subtoUnicode, UPRV_LENGTHOF(IBM_930subtoUnicode),"ibm-930",
             UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM930Offs, NULL, 0 ))
         log_err("ibm-930->u with substitute did not match.\n");
  
@@ -1581,26 +1585,26 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
         int32_t from_euc_twOffs [] ={ 0, 1, 3, 7, 11, 13};
 
        
-        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
-           EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
+        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, UPRV_LENGTHOF(sampleTxtEBCIDIC_STATEFUL),
+           EBCIDIC_STATEFUL_toUnicode, UPRV_LENGTHOF(EBCIDIC_STATEFUL_toUnicode),"ibm-930",
           UCNV_TO_U_CALLBACK_SUBSTITUTE, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
             log_err("EBCIDIC_STATEFUL->u with substitute did not match.\n");
 
 
-        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
-           euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
+        if(!testConvertToUnicode(sampleTxt_euc_jp, UPRV_LENGTHOF(sampleTxt_euc_jp),
+           euc_jptoUnicode, UPRV_LENGTHOF(euc_jptoUnicode),"IBM-eucJP",
           UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_jpOffs, NULL, 0 ))
             log_err("euc-jp->u with substitute did not match.\n");
 
         
-        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
-           euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
+        if(!testConvertToUnicode(sampleTxt_euc_tw, UPRV_LENGTHOF(sampleTxt_euc_tw),
+           euc_twtoUnicode, UPRV_LENGTHOF(euc_twtoUnicode),"euc-tw",
           UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
             log_err("euc-tw->u with substitute  did not match.\n");
 
         
-        if(!testConvertToUnicodeWithContext(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
-           euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
+        if(!testConvertToUnicodeWithContext(sampleTxt_euc_jp, UPRV_LENGTHOF(sampleTxt_euc_jp),
+           euc_jptoUnicode, UPRV_LENGTHOF(euc_jptoUnicode),"IBM-eucJP",
           UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_jpOffs, NULL, 0 ,"i", U_ILLEGAL_CHAR_FOUND))
             log_err("euc-jp->u with substitute did not match.\n");
     }
@@ -1610,13 +1614,13 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
     {
         const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c, 
             0xe0, 0x80,  0x61,};
-        UChar    expected1[] = {  0x0031, 0x4e8c, 0xfffd, 0x0061};
-        int32_t offsets1[] = {   0x0000, 0x0001, 0x0004, 0x0006};
+        UChar    expected1[] = {  0x0031, 0x4e8c, 0xfffd, 0xfffd, 0x0061};
+        int32_t offsets1[] = {   0x0000, 0x0001, 0x0004, 0x0005, 0x0006};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"utf8",
                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
-            log_err("utf8->u with substitute did not match.\n");;
+            log_err("utf8->u with substitute did not match.\n");
     }
     log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
     {
@@ -1624,10 +1628,10 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
         UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061,0xfffd,0xfffd};
         int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003,4,5};
 
-        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
-                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
+        if(!testConvertToUnicode(sampleText1, UPRV_LENGTHOF(sampleText1),
+                 expected1, UPRV_LENGTHOF(expected1),"SCSU",
                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
-            log_err("scsu->u with stop did not match.\n");;
+            log_err("scsu->u with stop did not match.\n");
     }
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
@@ -1641,13 +1645,13 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
         static const uint8_t s2[]={       0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfc, 0xfc, 0x46, 0x6b, 0x0f, 0x57 };
         static const int32_t offsets2[]={ 1,                3,          5,          7,          10 };
 
-        if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), s1, ARRAY_LENGTH(s1), "ibm-930", 
+        if(!testConvertFromUnicode(u1, UPRV_LENGTHOF(u1), s1, UPRV_LENGTHOF(s1), "ibm-930",
                                    UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
         ) {
             log_err("u->ibm-930 subchar/subchar1 did not match.\n");
         }
 
-        if(!testConvertToUnicode(s2, ARRAY_LENGTH(s2), u2, ARRAY_LENGTH(u2), "ibm-930", 
+        if(!testConvertToUnicode(s2, UPRV_LENGTHOF(s2), u2, UPRV_LENGTHOF(u2), "ibm-930",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
         ) {
             log_err("ibm-930->u subchar/subchar1 did not match.\n");
@@ -1663,7 +1667,7 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
         static const int32_t offsets2[]={
             0, 1, 2, 6, 8, 10, 12, 16, 20, 20, 24, 28, 28 };
 
-        if(!testConvertToUnicode(gb2, ARRAY_LENGTH(gb2), u2, ARRAY_LENGTH(u2), "gb18030", 
+        if(!testConvertToUnicode(gb2, UPRV_LENGTHOF(gb2), u2, UPRV_LENGTHOF(u2), "gb18030",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
         ) {
             log_err("gb18030->u with substitute did not match.\n");
@@ -1674,17 +1678,17 @@ 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", 
+        if(!testConvertToUnicode(utf7, UPRV_LENGTHOF(utf7), unicode, UPRV_LENGTHOF(unicode), "UTF-7",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
         ) {
             log_err("UTF-7->u with substitute did not match.\n");
@@ -1708,19 +1712,19 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             offsets2[]={ 2, 4 },
             offsets3[]={ 0, 2, 4 };
 
-        if(!testConvertToUnicode(in1, ARRAY_LENGTH(in1), out1, ARRAY_LENGTH(out1), "UTF-16", 
+        if(!testConvertToUnicode(in1, UPRV_LENGTHOF(in1), out1, UPRV_LENGTHOF(out1), "UTF-16",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
         ) {
             log_err("UTF-16 (BE BOM)->u with substitute did not match.\n");
         }
 
-        if(!testConvertToUnicode(in2, ARRAY_LENGTH(in2), out2, ARRAY_LENGTH(out2), "UTF-16", 
+        if(!testConvertToUnicode(in2, UPRV_LENGTHOF(in2), out2, UPRV_LENGTHOF(out2), "UTF-16",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
         ) {
             log_err("UTF-16 (LE BOM)->u with substitute did not match.\n");
         }
 
-        if(!testConvertToUnicode(in3, ARRAY_LENGTH(in3), out3, ARRAY_LENGTH(out3), "UTF-16", 
+        if(!testConvertToUnicode(in3, UPRV_LENGTHOF(in3), out3, UPRV_LENGTHOF(out3), "UTF-16",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets3, NULL, 0)
         ) {
             log_err("UTF-16 (no BOM)->u with substitute did not match.\n");
@@ -1736,10 +1740,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 },
@@ -1747,25 +1751,25 @@ static void TestSub(int32_t inputsize, int32_t outputsize)
             offsets3[]={ 0, 4, 4, 8, 12 },
             offsets4[]={ 0, 0, 4, 8 };
 
-        if(!testConvertToUnicode(in1, ARRAY_LENGTH(in1), out1, ARRAY_LENGTH(out1), "UTF-32", 
+        if(!testConvertToUnicode(in1, UPRV_LENGTHOF(in1), out1, UPRV_LENGTHOF(out1), "UTF-32",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
         ) {
             log_err("UTF-32 (BE BOM)->u with substitute did not match.\n");
         }
 
-        if(!testConvertToUnicode(in2, ARRAY_LENGTH(in2), out2, ARRAY_LENGTH(out2), "UTF-32", 
+        if(!testConvertToUnicode(in2, UPRV_LENGTHOF(in2), out2, UPRV_LENGTHOF(out2), "UTF-32",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
         ) {
             log_err("UTF-32 (LE BOM)->u with substitute did not match.\n");
         }
 
-        if(!testConvertToUnicode(in3, ARRAY_LENGTH(in3), out3, ARRAY_LENGTH(out3), "UTF-32", 
+        if(!testConvertToUnicode(in3, UPRV_LENGTHOF(in3), out3, UPRV_LENGTHOF(out3), "UTF-32",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets3, NULL, 0)
         ) {
             log_err("UTF-32 (no BOM)->u with substitute did not match.\n");
         }
 
-        if(!testConvertToUnicode(in4, ARRAY_LENGTH(in4), out4, ARRAY_LENGTH(out4), "UTF-32", 
+        if(!testConvertToUnicode(in4, UPRV_LENGTHOF(in4), out4, UPRV_LENGTHOF(out4), "UTF-32",
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets4, NULL, 0)
         ) {
             log_err("UTF-32 (no BOM, with error)->u with substitute did not match.\n");
@@ -1799,18 +1803,18 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
     /*from Unicode*/
 
 #if !UCONFIG_NO_LEGACY_CONVERSION
-    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-            expsubwvalIBM_949, sizeof(expsubwvalIBM_949), "ibm-949", 
+    if(!testConvertFromUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+            expsubwvalIBM_949, UPRV_LENGTHOF(expsubwvalIBM_949), "ibm-949",
             UCNV_FROM_U_CALLBACK_ESCAPE, toIBM949Offs, NULL, 0 ))
         log_err("u-> ibm-949 with subst with value did not match.\n");
 
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expsubwvalIBM_943, sizeof(expsubwvalIBM_943), "ibm-943",
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expsubwvalIBM_943, UPRV_LENGTHOF(expsubwvalIBM_943), "ibm-943",
             UCNV_FROM_U_CALLBACK_ESCAPE, toIBM943Offs, NULL, 0 ))
         log_err("u-> ibm-943 with sub with value did not match.\n");
 
-    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-            expsubwvalIBM_930, sizeof(expsubwvalIBM_930), "ibm-930", 
+    if(!testConvertFromUnicode(sampleText2, UPRV_LENGTHOF(sampleText2),
+            expsubwvalIBM_930, UPRV_LENGTHOF(expsubwvalIBM_930), "ibm-930",
             UCNV_FROM_U_CALLBACK_ESCAPE, toIBM930Offs, NULL, 0 ))
         log_err("u-> ibm-930 with subst with value did not match.\n");
 
@@ -2043,33 +2047,33 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
             6,
         };
 
-        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
-                toIBM943, sizeof(toIBM943), "ibm-943",
+        if(!testConvertFromUnicode(inputTest, UPRV_LENGTHOF(inputTest),
+                toIBM943, UPRV_LENGTHOF(toIBM943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_ESCAPE, offset, NULL, 0 ))
             log_err("u-> ibm-943 with subst with value did not match.\n");
 
-        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
-                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
+        if(!testConvertFromUnicode(euc_jp_inputText, UPRV_LENGTHOF(euc_jp_inputText),
+                to_euc_jp, UPRV_LENGTHOF(to_euc_jp), "IBM-eucJP",
                 UCNV_FROM_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0 ))
             log_err("u-> euc-jp with subst with value did not match.\n");
 
-        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
-                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
+        if(!testConvertFromUnicode(euc_tw_inputText, UPRV_LENGTHOF(euc_tw_inputText),
+                to_euc_tw, UPRV_LENGTHOF(to_euc_tw), "euc-tw",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with subst with value did not match.\n");  
         
-        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
-                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText1, UPRV_LENGTHOF(iso_2022_jp_inputText1),
+                to_iso_2022_jp1, UPRV_LENGTHOF(to_iso_2022_jp1), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
             log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
         
-        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
-                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText1, UPRV_LENGTHOF(iso_2022_jp_inputText1),
+                to_iso_2022_jp1, UPRV_LENGTHOF(to_iso_2022_jp1), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
             log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
         
-        if(!testConvertFromUnicode(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
-                to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
+        if(!testConvertFromUnicode(iso_2022_jp_inputText2, UPRV_LENGTHOF(iso_2022_jp_inputText2),
+                to_iso_2022_jp2, UPRV_LENGTHOF(to_iso_2022_jp2), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2, NULL, 0 ))
             log_err("u-> iso_2022_jp with subst with value did not match.\n");
         /*ESCAPE OPTIONS*/
@@ -2098,8 +2102,8 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                 7,7,7,7,7,7,7,7,7
             };
 
-            if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText3, sizeof(iso_2022_jp_inputText3)/sizeof(iso_2022_jp_inputText3[0]),
-                    to_iso_2022_jp3_v2, sizeof(to_iso_2022_jp3_v2), "iso-2022-jp",
+            if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText3, UPRV_LENGTHOF(iso_2022_jp_inputText3),
+                    to_iso_2022_jp3_v2, UPRV_LENGTHOF(to_iso_2022_jp3_v2), "iso-2022-jp",
                     UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs3_v2, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
                 log_err("u-> iso-2022-jp with sub & UCNV_ESCAPE_XML_DEC did not match.\n"); 
         }
@@ -2125,8 +2129,8 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                 6, 
                 7,7,7,7,7,7
             };
-            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText5, sizeof(iso_2022_cn_inputText5)/sizeof(iso_2022_cn_inputText5[0]),
-                to_iso_2022_cn5_v2, sizeof(to_iso_2022_cn5_v2), "iso-2022-cn",
+            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText5, UPRV_LENGTHOF(iso_2022_cn_inputText5),
+                to_iso_2022_cn5_v2, UPRV_LENGTHOF(to_iso_2022_cn5_v2), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs5_v2, NULL, 0,UCNV_ESCAPE_JAVA,U_ZERO_ERROR ))
                 log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_JAVA did not match.\n"); 
 
@@ -2149,8 +2153,8 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                     6, 
                     7,  7,  7,  7,  7,  7,  7,  7,
             };
-            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText6, sizeof(iso_2022_cn_inputText6)/sizeof(iso_2022_cn_inputText6[0]),
-                to_iso_2022_cn6_v2, sizeof(to_iso_2022_cn6_v2), "iso-2022-cn",
+            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText6, UPRV_LENGTHOF(iso_2022_cn_inputText6),
+                to_iso_2022_cn6_v2, UPRV_LENGTHOF(to_iso_2022_cn6_v2), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs6_v2, NULL, 0,UCNV_ESCAPE_UNICODE,U_ZERO_ERROR ))
                 log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_UNICODE did not match.\n"); 
 
@@ -2172,11 +2176,44 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                                 6,  
                                 7,  7,  7,  7,  7,  7,
             };
-            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText7, sizeof(iso_2022_cn_inputText7)/sizeof(iso_2022_cn_inputText7[0]),
-                to_iso_2022_cn7_v2, sizeof(to_iso_2022_cn7_v2), "iso-2022-cn",
+            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText7, UPRV_LENGTHOF(iso_2022_cn_inputText7),
+                to_iso_2022_cn7_v2, UPRV_LENGTHOF(to_iso_2022_cn7_v2), "iso-2022-cn",
                 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, UPRV_LENGTHOF(iso_2022_cn_inputText8),
+                to_iso_2022_cn8_v2, UPRV_LENGTHOF(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[]={  
@@ -2198,41 +2235,41 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
                 6
 
             };
-            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
-                to_iso_2022_cn4_v3, sizeof(to_iso_2022_cn4_v3), "iso-2022-cn",
+            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, UPRV_LENGTHOF(iso_2022_cn_inputText4),
+                to_iso_2022_cn4_v3, UPRV_LENGTHOF(to_iso_2022_cn4_v3), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4_v3, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
             {
                 log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_C did not match.\n"); 
             }
         }
-        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
-                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
+        if(!testConvertFromUnicode(iso_2022_cn_inputText, UPRV_LENGTHOF(iso_2022_cn_inputText),
+                to_iso_2022_cn, UPRV_LENGTHOF(to_iso_2022_cn), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0 ))
             log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
-        if(!testConvertFromUnicode(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
-                to_iso_2022_cn4, sizeof(to_iso_2022_cn4), "iso-2022-cn",
+        if(!testConvertFromUnicode(iso_2022_cn_inputText4, UPRV_LENGTHOF(iso_2022_cn_inputText4),
+                to_iso_2022_cn4, UPRV_LENGTHOF(to_iso_2022_cn4), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4, NULL, 0 ))
             log_err("u-> iso_2022_cn with subst with value did not match.\n");
-        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
-                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
+        if(!testConvertFromUnicode(iso_2022_kr_inputText, UPRV_LENGTHOF(iso_2022_kr_inputText),
+                to_iso_2022_kr, UPRV_LENGTHOF(to_iso_2022_kr), "iso-2022-kr",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0 ))
             log_err("u-> iso_2022_kr with subst with value did not match.\n");
-        if(!testConvertFromUnicode(iso_2022_kr_inputText2, sizeof(iso_2022_kr_inputText2)/sizeof(iso_2022_kr_inputText2[0]),
-                to_iso_2022_kr2, sizeof(to_iso_2022_kr2), "iso-2022-kr",
+        if(!testConvertFromUnicode(iso_2022_kr_inputText2, UPRV_LENGTHOF(iso_2022_kr_inputText2),
+                to_iso_2022_kr2, UPRV_LENGTHOF(to_iso_2022_kr2), "iso-2022-kr",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs2, NULL, 0 ))
             log_err("u-> iso_2022_kr2 with subst with value did not match.\n");
-        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
-                to_hz, sizeof(to_hz), "HZ",
+        if(!testConvertFromUnicode(hz_inputText, UPRV_LENGTHOF(hz_inputText),
+                to_hz, UPRV_LENGTHOF(to_hz), "HZ",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0 ))
             log_err("u-> hz with subst with value did not match.\n");
-        if(!testConvertFromUnicode(hz_inputText2, sizeof(hz_inputText2)/sizeof(hz_inputText2[0]),
-                to_hz2, sizeof(to_hz2), "HZ",
+        if(!testConvertFromUnicode(hz_inputText2, UPRV_LENGTHOF(hz_inputText2),
+                to_hz2, UPRV_LENGTHOF(to_hz2), "HZ",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs2, NULL, 0 ))
             log_err("u-> hz with subst with value did not match.\n");
 
-        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
-                to_iscii, sizeof(to_iscii), "ISCII,version=0",
+        if(!testConvertFromUnicode(iscii_inputText, UPRV_LENGTHOF(iscii_inputText),
+                to_iscii, UPRV_LENGTHOF(to_iscii), "ISCII,version=0",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0 ))
             log_err("u-> iscii with subst with value did not match.\n");
     }
@@ -2279,13 +2316,14 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
         /*iso-2022-jp*/
         static const uint8_t sampleTxt_iso_2022_jp[]={ 
             0x1b,   0x28,   0x42,   0x41,
-            0x1b,   0x24,   0x42,   0x2A, 0x44, /*unassigned*/
+            0x1b,   0x24,   0x42,   0x3a, 0x1a, /*unassigned*/
             0x1b,   0x28,   0x42,   0x42,
             
         };
-        static const UChar iso_2022_jptoUnicode[]={    0x41,0x25,0x58,0x32,0x41,0x25,0x58,0x34,0x34, 0x42 };
+                                                   /*     A    %    X    3    A    %    X    1    A     B    */
+        static const UChar iso_2022_jptoUnicode[]={    0x41,0x25,0x58,0x33,0x41,0x25,0x58,0x31,0x41, 0x42 };
         static const int32_t from_iso_2022_jpOffs [] ={  3,   7,   7,   7,   7,   7,   7,   7,   7,    12   };
-        
+
         /*iso-2022-cn*/
         static const uint8_t sampleTxt_iso_2022_cn[]={ 
             0x0f,   0x41,   0x44,
@@ -2393,28 +2431,28 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
 
 
 #if !UCONFIG_NO_LEGACY_CONVERSION        
-        if(!testConvertToUnicode(sampleTxtToU, sizeof(sampleTxtToU),
-                 IBM_943toUnicode, sizeof(IBM_943toUnicode)/sizeof(IBM_943toUnicode[0]),"ibm-943",
+        if(!testConvertToUnicode(sampleTxtToU, UPRV_LENGTHOF(sampleTxtToU),
+                 IBM_943toUnicode, UPRV_LENGTHOF(IBM_943toUnicode),"ibm-943",
                 UCNV_TO_U_CALLBACK_ESCAPE, fromIBM943Offs, NULL, 0 ))
             log_err("ibm-943->u with substitute with value did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_EUC_JP, sizeof(sampleTxt_EUC_JP),
-                 EUC_JPtoUnicode, sizeof(EUC_JPtoUnicode)/sizeof(EUC_JPtoUnicode[0]),"euc-jp",
+        if(!testConvertToUnicode(sampleTxt_EUC_JP, UPRV_LENGTHOF(sampleTxt_EUC_JP),
+                 EUC_JPtoUnicode, UPRV_LENGTHOF(EUC_JPtoUnicode),"IBM-eucJP",
                 UCNV_TO_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0))
             log_err("euc-jp->u with substitute with value did not match.\n");
 
-        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
-                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
+        if(!testConvertToUnicode(sampleTxt_euc_tw, UPRV_LENGTHOF(sampleTxt_euc_tw),
+                 euc_twtoUnicode, UPRV_LENGTHOF(euc_twtoUnicode),"euc-tw",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0))
             log_err("euc-tw->u with substitute with value did not match.\n");
             
-        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                 iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                 iso_2022_jptoUnicode, UPRV_LENGTHOF(iso_2022_jptoUnicode),"iso-2022-jp",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0))
             log_err("iso-2022-jp->u with substitute with value did not match.\n");
        
-        if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                 iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+        if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                 iso_2022_jptoUnicode, UPRV_LENGTHOF(iso_2022_jptoUnicode),"iso-2022-jp",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0,"K",U_ZERO_ERROR))
             log_err("iso-2022-jp->u with substitute with value did not match.\n");
         
@@ -2422,67 +2460,69 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
             {
                 static const UChar iso_2022_jptoUnicodeDec[]={
                                                   0x0041,   
-                                                  0x0026,   0x0023,   0x0034,   0x0032,   0x003b,   
-                                                  0x0026,   0x0023,   0x0036,   0x0038,   0x003b,   
+                                                  /*   &         #         5         8         ;   */
+                                                  0x0026,   0x0023,   0x0035,   0x0038,   0x003b,   
+                                                  0x0026,   0x0023,   0x0032,   0x0036,   0x003b,   
                                                   0x0042 };
                 static const int32_t from_iso_2022_jpOffsDec [] ={ 3,7,7,7,7,7,7,7,7,7,7,12,  };
-                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                     iso_2022_jptoUnicodeDec, sizeof(iso_2022_jptoUnicodeDec)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                     iso_2022_jptoUnicodeDec, UPRV_LENGTHOF(iso_2022_jptoUnicodeDec),"iso-2022-jp",
                     UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsDec, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
                 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_DEC did not match.\n");
             }
             {
                 static const UChar iso_2022_jptoUnicodeHex[]={
                                                   0x0041, 
-                                                  0x0026, 0x0023, 0x0078, 0x0032, 0x0041, 0x003b, 
-                                                  0x0026, 0x0023, 0x0078, 0x0034, 0x0034, 0x003b, 
+                                                  /*   &       #       x       3       A       ;  */
+                                                  0x0026, 0x0023, 0x0078, 0x0033, 0x0041, 0x003b, 
+                                                  0x0026, 0x0023, 0x0078, 0x0031, 0x0041, 0x003b, 
                                                   0x0042 };
                 static const int32_t from_iso_2022_jpOffsHex [] ={  3,7,7,7,7,7,7,7,7,7,7,7,7,12   };
-                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                     iso_2022_jptoUnicodeHex, sizeof(iso_2022_jptoUnicodeHex)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                     iso_2022_jptoUnicodeHex, UPRV_LENGTHOF(iso_2022_jptoUnicodeHex),"iso-2022-jp",
                     UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsHex, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
                 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_HEX did not match.\n");
             }
             {
                 static const UChar iso_2022_jptoUnicodeC[]={
                                                 0x0041, 
-                                                0x005C, 0x0078, 0x0032, 0x0041,
-                                                0x005C, 0x0078, 0x0034, 0x0034, 
+                                                0x005C, 0x0078, 0x0033, 0x0041,   /*  \x3A */
+                                                0x005C, 0x0078, 0x0031, 0x0041,   /*  \x1A */
                                                 0x0042 };
                 int32_t from_iso_2022_jpOffsC [] ={  3,7,7,7,7,7,7,7,7,12   };
-                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
-                     iso_2022_jptoUnicodeC, sizeof(iso_2022_jptoUnicodeC)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
+                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, UPRV_LENGTHOF(sampleTxt_iso_2022_jp),
+                     iso_2022_jptoUnicodeC, UPRV_LENGTHOF(iso_2022_jptoUnicodeC),"iso-2022-jp",
                     UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsC, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
                 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_C did not match.\n");
             }
         }
-        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
-                 iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, UPRV_LENGTHOF(sampleTxt_iso_2022_cn),
+                 iso_2022_cntoUnicode, UPRV_LENGTHOF(iso_2022_cntoUnicode),"iso-2022-cn",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0))
             log_err("iso-2022-cn->u with substitute with value did not match.\n");
         
-        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
-                 iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
+        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, UPRV_LENGTHOF(sampleTxt_iso_2022_kr),
+                 iso_2022_krtoUnicode, UPRV_LENGTHOF(iso_2022_krtoUnicode),"iso-2022-kr",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0))
             log_err("iso-2022-kr->u with substitute with value did not match.\n");
 
-         if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
-                 hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
+         if(!testConvertToUnicode(sampleTxt_hz, UPRV_LENGTHOF(sampleTxt_hz),
+                 hztoUnicode, UPRV_LENGTHOF(hztoUnicode),"HZ",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0))
             log_err("hz->u with substitute with value did not match.\n");
 
-         if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
-                 isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
+         if(!testConvertToUnicode(sampleTxt_iscii, UPRV_LENGTHOF(sampleTxt_iscii),
+                 isciitoUnicode, UPRV_LENGTHOF(isciitoUnicode),"ISCII,version=0",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0))
             log_err("ISCII ->u with substitute with value did not match.\n");
 #endif
 
-        if(!testConvertToUnicode(sampleTxtUTF8, sizeof(sampleTxtUTF8),
-                UTF8ToUnicode, sizeof(UTF8ToUnicode)/sizeof(UTF8ToUnicode[0]),"UTF-8",
+        if(!testConvertToUnicode(sampleTxtUTF8, UPRV_LENGTHOF(sampleTxtUTF8),
+                UTF8ToUnicode, UPRV_LENGTHOF(UTF8ToUnicode),"UTF-8",
                 UCNV_TO_U_CALLBACK_ESCAPE, fromUTF8, NULL, 0))
             log_err("UTF8->u with UCNV_TO_U_CALLBACK_ESCAPE with value did not match.\n"); 
-        if(!testConvertToUnicodeWithContext(sampleTxtUTF8, sizeof(sampleTxtUTF8),
-                UTF8ToUnicodeXML_DEC, sizeof(UTF8ToUnicodeXML_DEC)/sizeof(UTF8ToUnicodeXML_DEC[0]),"UTF-8",
+        if(!testConvertToUnicodeWithContext(sampleTxtUTF8, UPRV_LENGTHOF(sampleTxtUTF8),
+                UTF8ToUnicodeXML_DEC, UPRV_LENGTHOF(UTF8ToUnicodeXML_DEC),"UTF-8",
                 UCNV_TO_U_CALLBACK_ESCAPE, fromUTF8XML_DEC, NULL, 0, UCNV_ESCAPE_XML_DEC, U_ZERO_ERROR))
             log_err("UTF8->u with UCNV_TO_U_CALLBACK_ESCAPE with value did not match.\n"); 
     }
@@ -2509,25 +2549,25 @@ static void TestLegalAndOthers(int32_t inputsize, int32_t outputsize)
     gInBufferSize = inputsize;
     gOutBufferSize = outputsize;
     /*checking with a legal value*/
-    if(!testConvertFromUnicode(legalText, sizeof(legalText)/sizeof(legalText[0]),
-            templegal949, sizeof(templegal949), "ibm-949",
+    if(!testConvertFromUnicode(legalText, UPRV_LENGTHOF(legalText),
+            templegal949, UPRV_LENGTHOF(templegal949), "ibm-949",
             UCNV_FROM_U_CALLBACK_SKIP, to949legal, NULL, 0 ))
         log_err("u-> ibm-949 with skip did not match.\n");
 
     /*checking illegal value for ibm-943 with substitute*/ 
-    if(!testConvertToUnicode(text943, sizeof(text943),
-             toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
+    if(!testConvertToUnicode(text943, UPRV_LENGTHOF(text943),
+             toUnicode943sub, UPRV_LENGTHOF(toUnicode943sub),"ibm-943",
             UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
         log_err("ibm-943->u with subst did not match.\n");
     /*checking illegal value for ibm-943 with skip */
-    if(!testConvertToUnicode(text943, sizeof(text943),
-             toUnicode943skip, sizeof(toUnicode943skip)/sizeof(toUnicode943skip[0]),"ibm-943",
+    if(!testConvertToUnicode(text943, UPRV_LENGTHOF(text943),
+             toUnicode943skip, UPRV_LENGTHOF(toUnicode943skip),"ibm-943",
             UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offsskip, NULL, 0 ))
         log_err("ibm-943->u with skip did not match.\n");
 
     /*checking illegal value for ibm-943 with stop */
-    if(!testConvertToUnicode(text943, sizeof(text943),
-             toUnicode943stop, sizeof(toUnicode943stop)/sizeof(toUnicode943stop[0]),"ibm-943",
+    if(!testConvertToUnicode(text943, UPRV_LENGTHOF(text943),
+             toUnicode943stop, UPRV_LENGTHOF(toUnicode943stop),"ibm-943",
             UCNV_TO_U_CALLBACK_STOP, fromIBM943Offsstop, NULL, 0 ))
         log_err("ibm-943->u with stop did not match.\n");
 
@@ -2544,8 +2584,8 @@ static void TestSingleByte(int32_t inputsize, int32_t outputsize)
     gInBufferSize = inputsize;
     gOutBufferSize = outputsize;
 
-    if(!testConvertToUnicode(sampleText, sizeof(sampleText),
-             toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
+    if(!testConvertToUnicode(sampleText, UPRV_LENGTHOF(sampleText),
+             toUnicode943sub, UPRV_LENGTHOF(toUnicode943sub),"ibm-943",
             UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
         log_err("ibm-943->u with subst did not match.\n");
 }
@@ -2566,13 +2606,13 @@ static void TestEBCDIC_STATEFUL_Sub(int32_t inputsize, int32_t outputsize)
     gInBufferSize = inputsize;
     gOutBufferSize = outputsize;
 
-    if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
-        toIBM930, sizeof(toIBM930), "ibm-930",
+    if(!testConvertFromUnicode(ebcdic_inputTest, UPRV_LENGTHOF(ebcdic_inputTest),
+        toIBM930, UPRV_LENGTHOF(toIBM930), "ibm-930",
         UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930, NULL, 0 ))
             log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst did not match.\n");
     
-    if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
-        toIBM930_subvaried, sizeof(toIBM930_subvaried), "ibm-930",
+    if(!testConvertFromUnicode(ebcdic_inputTest, UPRV_LENGTHOF(ebcdic_inputTest),
+        toIBM930_subvaried, UPRV_LENGTHOF(toIBM930_subvaried), "ibm-930",
         UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930_subvaried, mySubChar, 1 ))
             log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst(setSubChar=0x3f) did not match.\n");
 }
@@ -2644,7 +2684,7 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const uint8_t
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = source + sourceLen;
 
@@ -2686,14 +2726,11 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const uint8_t
         UChar errChars[50]; /* should be sufficient */
         int8_t errLen = 50;
         UErrorCode err = U_ZERO_ERROR;
-        const UChar* limit= NULL;
         const UChar* start= NULL;
         ucnv_getInvalidUChars(conv,errChars, &errLen, &err);
         if(U_FAILURE(err)){
             log_err("ucnv_getInvalidUChars failed with error : %s\n",u_errorName(err));
         }
-        /* src points to limit of invalid chars */
-        limit = src;
         /* length of in invalid chars should be equal to returned length*/
         start = src - errLen;
         if(u_strncmp(errChars,start,errLen)!=0){
@@ -2710,7 +2747,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;
@@ -2828,7 +2865,7 @@ UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *e
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = src + sourcelen;
     /*----setting the callback routine----*/
@@ -2884,14 +2921,11 @@ UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *e
         char errChars[50]; /* should be sufficient */
         int8_t errLen = 50;
         UErrorCode err = U_ZERO_ERROR;
-        const char* limit= NULL;
         const char* start= NULL;
         ucnv_getInvalidChars(conv,errChars, &errLen, &err);
         if(U_FAILURE(err)){
             log_err("ucnv_getInvalidChars failed with error : %s\n",u_errorName(err));
         }
-        /* src points to limit of invalid chars */
-        limit = src;
         /* length of in invalid chars should be equal to returned length*/
         start = src - errLen;
         if(uprv_strncmp(errChars,start,errLen)!=0){
@@ -2908,7 +2942,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;
@@ -3041,7 +3075,7 @@ UBool testConvertFromUnicodeWithContext(const UChar *source, int sourceLen,  con
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = source + sourceLen;
 
@@ -3087,7 +3121,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;
@@ -3204,7 +3238,7 @@ UBool testConvertToUnicodeWithContext( const uint8_t *source, int sourcelen, con
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = src + sourcelen;
     /*----setting the callback routine----*/
@@ -3265,7 +3299,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 +3385,3 @@ static void TestCallBackFailure(void) {
         log_err("Error: ucnv_cbToUWriteUChars did not react correctly to a bad UErrorCode\n");
     }
 }
-