]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/ccapitst.c
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccapitst.c
index 9d529e3deab0544a3fd015f63dcfbacfdaa1908d..16c9d9de2c234055c8c636ced4b30b48c00a674b 100644 (file)
@@ -1,11 +1,11 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2014, International Business Machines Corporation and
+ * Copyright (c) 1997-2015, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*****************************************************************************
 *
-* File CU_CAPITST.C
+* File ccapitst.c
 *
 * Modification History:
 *        Name                      Description            
@@ -28,8 +28,6 @@
 #include "ccapitst.h"
 #include "cstring.h"
 
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
 #define NUM_CODEPAGE 1
 #define MAX_FILE_LEN 1024*20
 #define UCS_FILE_NAME_SIZE 512
@@ -1151,13 +1149,11 @@ static void TestAlias() {
     const char* ISO_2022_NAMES[] = 
         {"ISO_2022,locale=ja,version=2", "ISO-2022-JP-2", "csISO2022JP2",
          "Iso-2022jP2", "isO-2022_Jp_2", "iSo--2022,locale=ja,version=2"};
-    int32_t ISO_2022_NAMES_LENGTH =
-        sizeof(ISO_2022_NAMES) / sizeof(ISO_2022_NAMES[0]);
+    int32_t ISO_2022_NAMES_LENGTH = UPRV_LENGTHOF(ISO_2022_NAMES);
     const char *UTF8_NAMES[] =
         { "UTF-8", "utf-8", "utf8", "ibm-1208",
           "utf_8", "ibm1208", "cp1208" };
-    int32_t UTF8_NAMES_LENGTH =
-        sizeof(UTF8_NAMES) / sizeof(UTF8_NAMES[0]);
+    int32_t UTF8_NAMES_LENGTH = UPRV_LENGTHOF(UTF8_NAMES);
 
     struct {
         const char *name;
@@ -1198,7 +1194,7 @@ static void TestAlias() {
             if (strcmp(ucnv_getName(cnv, &status), name) != 0 
                 && (strstr(name, "PlatformEndian") == 0 && strstr(name, "OppositeEndian") == 0)) {
                 log_err("FAIL: Converter \"%s\" returned \"%s\" for getName. "
-                        "The should be the same\n",
+                        "They should be the same\n",
                         name, ucnv_getName(cnv, &status));
             }
         }
@@ -1680,7 +1676,7 @@ static void TestConvertSafeClone()
     };
 
     /* store the actual sizes of each converter */
-    int32_t actualSizes[LENGTHOF(names)];
+    int32_t actualSizes[UPRV_LENGTHOF(names)];
 
     static const int32_t bufferSizes[] = {
         U_CNV_SAFECLONE_BUFFERSIZE,
@@ -1794,8 +1790,8 @@ static void TestConvertSafeClone()
 
     /* Do these cloned converters work at all - shuffle UChars to chars & back again..*/
 
-    for(j = 0; j < LENGTHOF(bufferSizes); ++j) {
-        for (idx = 0; idx < LENGTHOF(names); idx++)
+    for(j = 0; j < UPRV_LENGTHOF(bufferSizes); ++j) {
+        for (idx = 0; idx < UPRV_LENGTHOF(names); idx++)
         {
             err = U_ZERO_ERROR;
             cnv = ucnv_open(names[idx], &err);
@@ -2004,6 +2000,7 @@ static void bug2()
 {
     /* US-ASCII "1234567890" */
     static const char source[]={ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
+#if !UCONFIG_ONLY_HTML_CONVERSION
     static const char sourceUTF8[]={ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, (char)0xef, (char)0x80, (char)0x80 };
     static const char sourceUTF32[]={ 0x00, 0x00, 0x00, 0x30,
                                       0x00, 0x00, 0x00, 0x31,
@@ -2015,6 +2012,8 @@ static void bug2()
                                       0x00, 0x00, 0x00, 0x37,
                                       0x00, 0x00, 0x00, 0x38,
                                       0x00, 0x00, (char)0xf0, 0x00};
+#endif
+
     static char target[5];
 
     UErrorCode err = U_ZERO_ERROR;
@@ -2034,6 +2033,7 @@ static void bug2()
         log_data_err("error j932 bug 2 us-ascii->iso-8859-1: got preflighting size %d instead of 10\n", size);
     }
 
+#if !UCONFIG_ONLY_HTML_CONVERSION
     err = U_ZERO_ERROR;
     /* do the conversion */
     size = ucnv_convert("UTF-32BE", /* out */
@@ -2063,6 +2063,7 @@ static void bug2()
         /* bug2: size is 5, should be 12 */
         log_err("error j932 bug 2 UTF-32BE->UTF-8: got preflighting size %d instead of 12\n", size);
     }
+#endif
 }
 
 /*
@@ -2071,7 +2072,7 @@ static void bug2()
  */
 static void bug3()
 {
-#if !UCONFIG_NO_LEGACY_CONVERSION
+#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION
     char char_in[CHUNK_SIZE*4];
     char target[5];
     UErrorCode err = U_ZERO_ERROR;
@@ -2519,7 +2520,7 @@ static void testFromTruncatedUTF8(UConverter *utf8Cnv, UConverter *cnv, const ch
 
     memcpy(utf8, charUTF8, charUTF8Length);
 
-    for(i=0; i<LENGTHOF(badUTF8); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(badUTF8); ++i) {
         /* truncated sequence? */
         int32_t length=strlen(badUTF8[i]);
         if(length>=(1+U8_COUNT_TRAIL_BYTES(badUTF8[i][0]))) {
@@ -2538,7 +2539,7 @@ static void testFromTruncatedUTF8(UConverter *utf8Cnv, UConverter *cnv, const ch
         ucnv_convertEx(cnv, utf8Cnv,
                        &target, output+sizeof(output),
                        &source, utf8+utf8Length,
-                       pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+LENGTHOF(pivotBuffer),
+                       pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+UPRV_LENGTHOF(pivotBuffer),
                        TRUE, TRUE, /* reset & flush */
                        &errorCode);
         outputLength=(int32_t)(target-output);
@@ -2583,7 +2584,7 @@ static void testFromBadUTF8(UConverter *utf8Cnv, UConverter *cnv, const char *co
     memcpy(expect, char0, char0Length);
     expectLength=char0Length;
 
-    for(i=0; i<LENGTHOF(badUTF8); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(badUTF8); ++i) {
         int32_t length=strlen(badUTF8[i]);
         memcpy(utf8+utf8Length, badUTF8[i], length);
         utf8Length+=length;
@@ -2633,7 +2634,7 @@ static void TestConvertExFromUTF8() {
         return;
     }
 
-    for(i=0; i<LENGTHOF(converterNames); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(converterNames); ++i) {
         errorCode=U_ZERO_ERROR;
         cnv=ucnv_open(converterNames[i], &errorCode);
         if(U_FAILURE(errorCode)) {
@@ -2692,7 +2693,7 @@ static void TestConvertExFromUTF8_C5F0() {
         return;
     }
 
-    for(i=0; i<LENGTHOF(converterNames); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(converterNames); ++i) {
         errorCode=U_ZERO_ERROR;
         cnv=ucnv_open(converterNames[i], &errorCode);
         ucnv_setFromUCallBack(cnv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC,
@@ -2705,7 +2706,7 @@ static void TestConvertExFromUTF8_C5F0() {
         src=bad_utf8;
         target=dest;
         uprv_memset(dest, 9, sizeof(dest));
-        if(i==LENGTHOF(converterNames)-1) {
+        if(i==UPRV_LENGTHOF(converterNames)-1) {
             /* conversion to UTF-8 yields two U+FFFD directly */
             expected=twoFFFD;
             expectedLength=6;
@@ -2722,7 +2723,7 @@ static void TestConvertExFromUTF8_C5F0() {
             cnv, utf8Cnv,
             &target, dest+expectedLength,
             &src, bad_utf8+sizeof(bad_utf8),
-            pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+LENGTHOF(pivotBuffer),
+            pivotBuffer, &pivotSource, &pivotTarget, pivotBuffer+UPRV_LENGTHOF(pivotBuffer),
             TRUE, TRUE, &errorCode);
         if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || src!=bad_utf8+2 ||
             target!=dest+expectedLength || 0!=uprv_memcmp(dest, expected, expectedLength) ||
@@ -2755,10 +2756,12 @@ TestConvertAlgorithmic() {
   /*},*/
     utf16[]={
         0xfe, 0xff /* BOM only, no text */
-    },
-    utf32[]={
+    };
+#if !UCONFIG_ONLY_HTML_CONVERSION
+    static const uint8_t utf32[]={
         0xff, 0xfe, 0, 0 /* BOM only, no text */
     };
+#endif
 
     char target[100], utf8NUL[100], shiftJISNUL[100];
 
@@ -2828,6 +2831,7 @@ TestConvertAlgorithmic() {
                 u_errorName(errorCode), length);
     }
 
+#if !UCONFIG_ONLY_HTML_CONVERSION
     errorCode=U_ZERO_ERROR;
     length=ucnv_fromAlgorithmic(cnv, UCNV_UTF32, target, 0, (const char *)utf32, 4, &errorCode);
     if( errorCode!=U_STRING_NOT_TERMINATED_WARNING ||
@@ -2836,6 +2840,7 @@ TestConvertAlgorithmic() {
         log_err("ucnv_fromAlgorithmic(UTF-32 only BOM -> Shift-JIS) fails (%s expect U_STRING_NOT_TERMINATED_WARNING), returns %d expect 0\n",
                 u_errorName(errorCode), length);
     }
+#endif
 
     /* bad arguments */
     errorCode=U_MESSAGE_PARSE_ERROR;
@@ -2913,7 +2918,7 @@ static void TestLMBCSMaxChar(void) {
     };
     int32_t idx;
 
-    for (idx = 0; idx < LENGTHOF(converter); idx++) {
+    for (idx = 0; idx < UPRV_LENGTHOF(converter); idx++) {
         UErrorCode status = U_ZERO_ERROR;
         UConverter *cnv = cnv_open(converter[idx].name, &status);
         if (U_FAILURE(status)) {
@@ -3075,12 +3080,12 @@ testSwap(const char *name, UBool swap) {
     /* convert to EBCDIC */
     pcu=text;
     pc=normal;
-    ucnv_fromUnicode(cnv, &pc, normal+LENGTHOF(normal), &pcu, text+LENGTHOF(text), NULL, TRUE, &errorCode);
+    ucnv_fromUnicode(cnv, &pc, normal+UPRV_LENGTHOF(normal), &pcu, text+UPRV_LENGTHOF(text), NULL, TRUE, &errorCode);
     normalLength=(int32_t)(pc-normal);
 
     pcu=text;
     pc=swapped;
-    ucnv_fromUnicode(swapCnv, &pc, swapped+LENGTHOF(swapped), &pcu, text+LENGTHOF(text), NULL, TRUE, &errorCode);
+    ucnv_fromUnicode(swapCnv, &pc, swapped+UPRV_LENGTHOF(swapped), &pcu, text+UPRV_LENGTHOF(text), NULL, TRUE, &errorCode);
     swappedLength=(int32_t)(pc-swapped);
 
     if(U_FAILURE(errorCode)) {
@@ -3113,12 +3118,12 @@ testSwap(const char *name, UBool swap) {
     /* convert back to Unicode (may not roundtrip) */
     pc=normal;
     pu=uNormal;
-    ucnv_toUnicode(cnv, &pu, uNormal+LENGTHOF(uNormal), (const char **)&pc, normal+normalLength, NULL, TRUE, &errorCode);
+    ucnv_toUnicode(cnv, &pu, uNormal+UPRV_LENGTHOF(uNormal), (const char **)&pc, normal+normalLength, NULL, TRUE, &errorCode);
     normalLength=(int32_t)(pu-uNormal);
 
     pc=normal;
     pu=uSwapped;
-    ucnv_toUnicode(swapCnv, &pu, uSwapped+LENGTHOF(uSwapped), (const char **)&pc, normal+swappedLength, NULL, TRUE, &errorCode);
+    ucnv_toUnicode(swapCnv, &pu, uSwapped+UPRV_LENGTHOF(uSwapped), (const char **)&pc, normal+swappedLength, NULL, TRUE, &errorCode);
     swappedLength=(int32_t)(pu-uSwapped);
 
     if(U_FAILURE(errorCode)) {
@@ -3169,7 +3174,7 @@ TestEBCDICSwapLFNL() {
 
     int i;
 
-    for(i=0; i<LENGTHOF(tests); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(tests); ++i) {
         testSwap(tests[i].name, tests[i].swap);
     }
 }
@@ -3200,7 +3205,7 @@ static void TestFromUCountPending(){
         log_data_err("Could not create converter for test3. Error: %s\n", u_errorName(status));
         return;
     }
-    for(i=0; i<LENGTHOF(fromUnicodeTests); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(fromUnicodeTests); ++i) {
         char tgt[10];
         char* target = tgt;
         char* targetLimit = target + 10;
@@ -3306,7 +3311,7 @@ TestToUCountPending(){
         return;
     }
     ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, oldToUAction, NULL, &status);
-    for(i=0; i<LENGTHOF(toUnicodeTests); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(toUnicodeTests); ++i) {
         UChar tgt[20];
         UChar* target = tgt;
         UChar* targetLimit = target + 20;
@@ -3430,7 +3435,7 @@ static void TestDefaultName(void) {
     TestOneDefaultNameChange("ISCII,version=2", "UTF-8");
     TestOneDefaultNameChange("ISO-8859-1", "UTF-8");
 #else
-# if !UCONFIG_NO_LEGACY_CONVERSION
+# if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION
     TestOneDefaultNameChange("ISCII,version=1", "ISCII,version=1");
     TestOneDefaultNameChange("ISCII,version=2", "ISCII,version=2");
 # endif
@@ -3544,7 +3549,7 @@ TestSubstString() {
         log_data_err("ucnv_open(ISO-8859-1) failed - %s\n", u_errorName(errorCode));
         return;
     }
-    ucnv_setSubstString(cnv, sub, LENGTHOF(sub), &errorCode);
+    ucnv_setSubstString(cnv, sub, UPRV_LENGTHOF(sub), &errorCode);
     if(U_FAILURE(errorCode)) {
         log_err("ucnv_setSubstString(ISO-8859-1, sub[5]) failed - %s\n", u_errorName(errorCode));
     } else {
@@ -3564,7 +3569,7 @@ TestSubstString() {
         log_data_err("ucnv_open(HZ) failed - %s\n", u_errorName(errorCode));
         return;
     }
-    ucnv_setSubstString(cnv, sub, LENGTHOF(sub), &errorCode);
+    ucnv_setSubstString(cnv, sub, UPRV_LENGTHOF(sub), &errorCode);
     if(U_FAILURE(errorCode)) {
         log_err("ucnv_setSubstString(HZ, sub[5]) failed - %s\n", u_errorName(errorCode));
     } else {
@@ -3649,7 +3654,7 @@ static void TestGetName() {
         "x-UTF-16LE-BOM",           "UTF-16LE,version=1"
     };
     int32_t i;
-    for(i = 0; i < LENGTHOF(names); i += 2) {
+    for(i = 0; i < UPRV_LENGTHOF(names); i += 2) {
         UErrorCode errorCode = U_ZERO_ERROR;
         UConverter *cnv = ucnv_open(names[i], &errorCode);
         if(U_SUCCESS(errorCode)) {
@@ -3692,7 +3697,7 @@ static void TestUTFBOM() {
     char bytes[10];
     int32_t i;
 
-    for(i = 0; i < LENGTHOF(names); ++i) {
+    for(i = 0; i < UPRV_LENGTHOF(names); ++i) {
         UErrorCode errorCode = U_ZERO_ERROR;
         UConverter *cnv = ucnv_open(names[i], &errorCode);
         int32_t length = 0;