]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/ncnvfbts.c
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ncnvfbts.c
index 342e1bdcc7f61117d5f21b91a1a1cd14f5c235b7..407e4fcbf41ba8320596a70f5abc1ceb960c4408 100644 (file)
@@ -1,16 +1,18 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2003, International Business Machines Corporation and
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ***************************************************************************/
-/*******************************************************************************
+/*****************************************************************************
 *
 * File NCNVCBTS
 *
 * Modification History:
 *      Name              Date                  Description            
 * Madhu Katragadda    06/23/2000     Tests for Conveter FallBack API and Functionality
-**********************************************************************************
+******************************************************************************
 */
 #include <stdio.h>
 #include "unicode/uloc.h"
@@ -23,6 +25,7 @@
 #include "cmemory.h"
 #include "cstring.h"
 
+#if !UCONFIG_NO_LEGACY_CONVERSION
 #define NEW_MAX_BUFFER 999
 
 
@@ -103,7 +106,9 @@ void addTestConverterFallBack(TestNode** root);
 
 void addTestConverterFallBack(TestNode** root)
 {
+#if !UCONFIG_NO_FILE_IO
    addTest(root, &TestConverterFallBack, "tsconv/ncnvfbts/TestConverterFallBack");
+#endif
  
 }
 
@@ -115,11 +120,11 @@ void addTestConverterFallBack(TestNode** root)
 
 static void setNuConvTestName(const char *codepage, const char *direction)
 {
-  sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
-      codepage,
-      direction,
-      gInBufferSize,
-      gOutBufferSize);
+    sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
+        codepage,
+        direction,
+        (int)gInBufferSize,
+        (int)gOutBufferSize);
 }
 
 
@@ -130,25 +135,25 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const u
 
     UErrorCode status = U_ZERO_ERROR;
     UConverter *conv = 0;
-    uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
+    char junkout[NEW_MAX_BUFFER]; /* FIX */
     int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
     const UChar *src;
-    uint8_t *end;
-    uint8_t *targ;
+    char *end;
+    char *targ;
     int32_t *offs;
     int i;
     int32_t   realBufferSize;
-    uint8_t *realBufferEnd;
+    char *realBufferEnd;
     const UChar *realSourceEnd;
     const UChar *sourceLimit;
     UBool checkOffsets = TRUE;
     UBool doFlush;
     UBool action=FALSE;
-    uint8_t *p;
+    char *p;
 
 
     for(i=0;i<NEW_MAX_BUFFER;i++)
-        junkout[i] = 0xF0;
+        junkout[i] = (char)0xF0;
     for(i=0;i<NEW_MAX_BUFFER;i++)
         junokout[i] = 0xFF;
     setNuConvTestName(codepage, "FROM");
@@ -175,7 +180,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const u
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = source + sourceLen;
 
@@ -221,7 +226,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const u
 
     log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
         sourceLen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
         char junk[9999];
         char offset_str[9999];
@@ -250,7 +255,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const u
     {
         log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
         log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
-        printSeqErr((const unsigned char*)junkout, targ-junkout);
+        printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
         printSeqErr((const unsigned char*)expect, expectLen);
         return FALSE;
     }
@@ -261,7 +266,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const u
         if(uprv_memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
             log_err("\ndid not get the expected offsets while %s \n", gNuConvTestName);
             log_err("Got  : ");
-            printSeqErr((const unsigned char*)junkout, targ-junkout);
+            printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
             for(p=junkout;p<targ;p++)
                 log_err("%d, ", junokout[p-junkout]); 
             log_err("\nExpected: ");
@@ -293,9 +298,9 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U
     UConverter *conv = 0;
     UChar   junkout[NEW_MAX_BUFFER]; /* FIX */
     int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
-    const uint8_t *src;
-    const uint8_t *realSourceEnd;
-    const uint8_t *srcLimit;
+    const char *src;
+    const char *realSourceEnd;
+    const char *srcLimit;
     UChar *targ;
     UChar *end;
     int32_t *offs;
@@ -329,11 +334,11 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U
 
     log_verbose("Converter opened..\n");
 
-    src = source;
+    src = (const char *)source;
     targ = junkout;
     offs = junokout;
 
-    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
+    realBufferSize = UPRV_LENGTHOF(junkout);
     realBufferEnd = junkout + realBufferSize;
     realSourceEnd = src + sourcelen;
     /*----setting the fallback routine----*/
@@ -384,7 +389,7 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U
 
     log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
         sourcelen, targ-junkout);
-    if(VERBOSITY)
+    if(getTestOption(VERBOSITY_OPTION))
     {
 
         junk[0] = 0;
@@ -424,7 +429,7 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U
             for(i=0; i<(targ-junkout); i++)
                 log_err("0x%04X,", junkout[i]);
             log_err("");
-            for(i=0; i<(src-source); i++)
+            for(i=0; i<(src-(const char *)source); i++)
                 log_err("0x%04X,", (unsigned char)source[i]);
         }
     }
@@ -518,7 +523,10 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
     
     static const char* nativeCodePage[]={
         /*NLCS Mapping*/
-        "ibm-367",
+        "ibm-437",
+        "ibm-850",
+        "ibm-878",
+        "ibm-923",
         "ibm-1051",
         "ibm-1089",
         "ibm-1250",
@@ -529,7 +537,6 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         "ibm-1256",
         "ibm-1257",
         "ibm-1258",
-        "ibm-1275",
         "ibm-1276"
     };
 
@@ -537,34 +544,34 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
     gInBufferSize = insize;
     gOutBufferSize = outsize;
 
-    for(i=0; i<sizeof(nativeCodePage)/sizeof(nativeCodePage[0]); i++){
+    for(i=0; i<UPRV_LENGTHOF(nativeCodePage); i++){
         log_verbose("Testing %s\n", nativeCodePage[i]);
-        if(!testConvertFromUnicode(SBCSText, sizeof(SBCSText)/sizeof(SBCSText[0]),
+        if(!testConvertFromUnicode(SBCSText, UPRV_LENGTHOF(SBCSText),
             expectedNative, sizeof(expectedNative), nativeCodePage[i], TRUE, toNativeOffs ))
             log_err("u-> %s(SBCS) with FallBack did not match.\n", nativeCodePage[i]);
 
         if(!testConvertToUnicode(expectedNative, sizeof(expectedNative), 
-            retrievedSBCSText, sizeof(retrievedSBCSText)/sizeof(retrievedSBCSText[0]), nativeCodePage[i], TRUE, fromNativeoffs ))
+            retrievedSBCSText, UPRV_LENGTHOF(retrievedSBCSText), nativeCodePage[i], TRUE, fromNativeoffs ))
             log_err("%s->u(SBCS) with Fallback did not match.\n", nativeCodePage[i]);
     }
     
     /*DBCS*/
-    if(!testConvertFromUnicode(DBCSText, sizeof(DBCSText)/sizeof(DBCSText[0]),
+    if(!testConvertFromUnicode(DBCSText, UPRV_LENGTHOF(DBCSText),
         expectedIBM1363_DBCS, sizeof(expectedIBM1363_DBCS), "ibm-1363", TRUE, toIBM1363Offs_DBCS ))
        log_err("u-> ibm-1363(DBCS portion) with FallBack did not match.\n");
 
     if(!testConvertToUnicode(expectedIBM1363_DBCS, sizeof(expectedIBM1363_DBCS), 
-        retrievedDBCSText, sizeof(retrievedDBCSText)/sizeof(retrievedDBCSText[0]),"ibm-1363", TRUE, fromIBM1363offs_DBCS ))
+        retrievedDBCSText, UPRV_LENGTHOF(retrievedDBCSText),"ibm-1363", TRUE, fromIBM1363offs_DBCS ))
         log_err("ibm-1363->u(DBCS portion) with Fallback did not match.\n");
 
   
     /*MBCS*/
-    if(!testConvertFromUnicode(MBCSText, sizeof(MBCSText)/sizeof(MBCSText[0]),
+    if(!testConvertFromUnicode(MBCSText, UPRV_LENGTHOF(MBCSText),
         expectedIBM950, sizeof(expectedIBM950), "ibm-950", TRUE, toIBM950Offs ))
        log_err("u-> ibm-950(MBCS) with FallBack did not match.\n");
 
     if(!testConvertToUnicode(expectedIBM950, sizeof(expectedIBM950), 
-        retrievedMBCSText, sizeof(retrievedMBCSText)/sizeof(retrievedMBCSText[0]),"ibm-950", TRUE, fromIBM950offs ))
+        retrievedMBCSText, UPRV_LENGTHOF(retrievedMBCSText),"ibm-950", TRUE, fromIBM950offs ))
         log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
     
    /*commented untill data table is available*/
@@ -579,10 +586,10 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         UChar expectedFallbackFalse[]= { 0x5165, 0x5165, 0x516b, 0x516b, 0x9ef9, 0x9ef9};
 
         if(!testConvertToUnicode(IBM950input, sizeof(IBM950input), 
-                expectedUnicodeText, sizeof(expectedUnicodeText)/sizeof(expectedUnicodeText[0]),"ibm-950", TRUE, fromIBM950inputOffs ))
+                expectedUnicodeText, UPRV_LENGTHOF(expectedUnicodeText),"ibm-950", TRUE, fromIBM950inputOffs ))
             log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
         if(!testConvertToUnicode(IBM950input, sizeof(IBM950input), 
-                expectedFallbackFalse, sizeof(expectedFallbackFalse)/sizeof(expectedFallbackFalse[0]),"ibm-950", FALSE, fromIBM950inputOffs ))
+                expectedFallbackFalse, UPRV_LENGTHOF(expectedFallbackFalse),"ibm-950", FALSE, fromIBM950inputOffs ))
             log_err("ibm-950->u(MBCS) with Fallback  did not match.\n");
 
     }
@@ -598,11 +605,11 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         UChar expectedFallbackFalse[]= { 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278};
 
         if(!testConvertToUnicode(euc_tw_input, sizeof(euc_tw_input), 
-                expectedUnicodeText, sizeof(expectedUnicodeText)/sizeof(expectedUnicodeText[0]),"euc-tw", TRUE, from_euc_tw_offs ))
+                expectedUnicodeText, UPRV_LENGTHOF(expectedUnicodeText),"euc-tw", TRUE, from_euc_tw_offs ))
             log_err("from euc-tw->u with Fallback did not match.\n");
 
         if(!testConvertToUnicode(euc_tw_input, sizeof(euc_tw_input), 
-                expectedFallbackFalse, sizeof(expectedFallbackFalse)/sizeof(expectedFallbackFalse[0]),"euc-tw", FALSE, from_euc_tw_offs ))
+                expectedFallbackFalse, UPRV_LENGTHOF(expectedFallbackFalse),"euc-tw", FALSE, from_euc_tw_offs ))
             log_err("from euc-tw->u with Fallback false did not match.\n");
 
 
@@ -622,19 +629,19 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         int32_t to_euc_tw_offs []  =   {  0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 
             6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12};
 
-        if(!testConvertFromUnicode(inputText, sizeof(inputText)/sizeof(inputText[0]),
+        if(!testConvertFromUnicode(inputText, UPRV_LENGTHOF(inputText),
                 expected_euc_tw, sizeof(expected_euc_tw), "euc-tw", TRUE, to_euc_tw_offs ))
             log_err("u-> euc-tw with FallBack did not match.\n");
 
     }
 
     /*MBCS 1363*/
-    if(!testConvertFromUnicode(MBCSText1363, sizeof(MBCSText1363)/sizeof(MBCSText1363[0]),
+    if(!testConvertFromUnicode(MBCSText1363, UPRV_LENGTHOF(MBCSText1363),
         expectedIBM1363, sizeof(expectedIBM1363), "ibm-1363", TRUE, toIBM1363Offs ))
        log_err("u-> ibm-1363(MBCS) with FallBack did not match.\n");
 
     if(!testConvertToUnicode(expectedIBM1363, sizeof(expectedIBM1363), 
-        retrievedMBCSText1363, sizeof(retrievedMBCSText1363)/sizeof(retrievedMBCSText1363[0]),"ibm-1363", TRUE, fromIBM1363offs ))
+        retrievedMBCSText1363, UPRV_LENGTHOF(retrievedMBCSText1363),"ibm-1363", TRUE, fromIBM1363offs ))
         log_err("ibm-1363->u(MBCS) with Fallback did not match.\n");
 
 
@@ -652,13 +659,13 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         int32_t fromtest1Offs[]       = { 0, 1, 2, 3, 3, 4,5};
 
         /*from Unicode*/
-        if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
+        if(!testConvertFromUnicode(unicodeInput, UPRV_LENGTHOF(unicodeInput),
                 expectedtest1, sizeof(expectedtest1), "@test1", TRUE, totest1Offs ))
             log_err("u-> test1(MBCS conversion with single-byte) did not match.\n");
         
         /*to Unicode*/
         if(!testConvertToUnicode(test1input, sizeof(test1input),
-               expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test1", TRUE, fromtest1Offs ))
+               expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test1", TRUE, fromtest1Offs ))
             log_err("test1(MBCS conversion with single-byte) -> u  did not match.\n");
 
     }
@@ -679,13 +686,13 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         int32_t fromtest3Offs[]       = { 0, 1, 2, 3, 6, 6, 7, 7, 10, 13, 13, 16, 17};  
 
         /*from Unicode*/
-        if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
+        if(!testConvertFromUnicode(unicodeInput, UPRV_LENGTHOF(unicodeInput),
                 expectedtest3, sizeof(expectedtest3), "@test3", TRUE, totest3Offs ))
             log_err("u-> test3(MBCS conversion with three-byte) did not match.\n");
         
         /*to Unicode*/
         if(!testConvertToUnicode(test3input, sizeof(test3input),
-               expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", TRUE, fromtest3Offs ))
+               expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test3", TRUE, fromtest3Offs ))
             log_err("test3(MBCS conversion with three-byte) -> u  did not match.\n"); 
 
     }
@@ -709,18 +716,18 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
                 0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0e, 0x01, 0x02, 0x03, 0x0d, 0x03, 0x01, 0x02, 0x03, 0x0c,};
         const UChar expectedUnicode[] = 
                 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
-                  0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0xfffd, 0xfffd}; 
+                  0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x1a, 0xfffd}; 
         int32_t fromtest4Offs[]       = 
                 { 0, 1, 2, 3, 7, 7, 8, 8, 9, 9, 13, 17, 17, 21, 22,};
 
         /*from Unicode*/
-        if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
+        if(!testConvertFromUnicode(unicodeInput, UPRV_LENGTHOF(unicodeInput),
                 expectedtest4, sizeof(expectedtest4), "@test4", TRUE, totest4Offs ))
             log_err("u-> test4(MBCS conversion with four-byte) did not match.\n");
         
         /*to Unicode*/
         if(!testConvertToUnicode(test4input, sizeof(test4input),
-               expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", TRUE, fromtest4Offs ))
+               expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test4", TRUE, fromtest4Offs ))
             log_err("test4(MBCS conversion with four-byte) -> u  did not match.\n"); 
 
     }
@@ -733,13 +740,14 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
         const UChar expectedUnicode[] = {0x203e,         0x2014,     0xff5c,    0x004c,    0x5f5e,         0x223c };
         int32_t fromtest1Offs[]       = {1,              3,          5,         8,         10,             12 };
         /*from Unicode*/
-        if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
+        if(!testConvertFromUnicode(unicodeInput, UPRV_LENGTHOF(unicodeInput),
                 expectedtest1, sizeof(expectedtest1), "ibm-1371", TRUE, totest1Offs ))
             log_err("u-> ibm-1371(MBCS conversion with single-byte) did not match.,\n");
         /*to Unicode*/
         if(!testConvertToUnicode(test1input, sizeof(test1input),
-               expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "ibm-1371", TRUE, fromtest1Offs ))
+               expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "ibm-1371", TRUE, fromtest1Offs ))
             log_err("ibm-1371(MBCS conversion with single-byte) -> u  did not match.,\n");
     }
 
 }
+#endif