| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2013, International Business Machines Corporation and | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 /***************************************************************************** | 6 /***************************************************************************** |
| 7 * | 7 * |
| 8 * File CCONVTST.C | 8 * File CCONVTST.C |
| 9 * | 9 * |
| 10 * Modification History: | 10 * Modification History: |
| 11 * Name Description | 11 * Name Description |
| 12 * Madhu Katragadda 7/7/2000 Converter Tests for extended c
ode coverage | 12 * Madhu Katragadda 7/7/2000 Converter Tests for extended c
ode coverage |
| 13 ****************************************************************************** | 13 ****************************************************************************** |
| 14 */ | 14 */ |
| 15 #include <stdio.h> | 15 #include <stdio.h> |
| 16 #include <stdlib.h> | 16 #include <stdlib.h> |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 #include "unicode/uloc.h" | 18 #include "unicode/uloc.h" |
| 19 #include "unicode/ucnv.h" | 19 #include "unicode/ucnv.h" |
| 20 #include "unicode/utypes.h" | 20 #include "unicode/utypes.h" |
| 21 #include "unicode/ustring.h" | 21 #include "unicode/ustring.h" |
| 22 #include "unicode/uset.h" | 22 #include "unicode/uset.h" |
| 23 #include "cintltst.h" | 23 #include "cintltst.h" |
| 24 #include "cmemory.h" |
| 24 | 25 |
| 25 #define MAX_LENGTH 999 | 26 #define MAX_LENGTH 999 |
| 26 | 27 |
| 27 #define UNICODE_LIMIT 0x10FFFF | 28 #define UNICODE_LIMIT 0x10FFFF |
| 28 #define SURROGATE_HIGH_START 0xD800 | 29 #define SURROGATE_HIGH_START 0xD800 |
| 29 #define SURROGATE_LOW_END 0xDFFF | 30 #define SURROGATE_LOW_END 0xDFFF |
| 30 | 31 |
| 31 static int32_t gInBufferSize = 0; | 32 static int32_t gInBufferSize = 0; |
| 32 static int32_t gOutBufferSize = 0; | 33 static int32_t gOutBufferSize = 0; |
| 33 static char gNuConvTestName[1024]; | 34 static char gNuConvTestName[1024]; |
| 34 | 35 |
| 35 #define nct_min(x,y) ((x<y) ? x : y) | 36 #define nct_min(x,y) ((x<y) ? x : y) |
| 36 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
| 37 | 37 |
| 38 static void printSeq(const unsigned char* a, int len); | 38 static void printSeq(const unsigned char* a, int len); |
| 39 static void printSeqErr(const unsigned char* a, int len); | 39 static void printSeqErr(const unsigned char* a, int len); |
| 40 static void printUSeq(const UChar* a, int len); | 40 static void printUSeq(const UChar* a, int len); |
| 41 static void printUSeqErr(const UChar* a, int len); | 41 static void printUSeqErr(const UChar* a, int len); |
| 42 static UBool convertFromU( const UChar *source, int sourceLen, const uint8_t *e
xpect, int expectLen, | 42 static UBool convertFromU( const UChar *source, int sourceLen, const uint8_t *e
xpect, int expectLen, |
| 43 const char *codepage, const int32_t *expectOffsets, UBool doFlus
h, UErrorCode expectedStatus); | 43 const char *codepage, const int32_t *expectOffsets, UBool doFlus
h, UErrorCode expectedStatus); |
| 44 static UBool convertToU( const uint8_t *source, int sourceLen, const UChar *expe
ct, int expectLen, | 44 static UBool convertToU( const uint8_t *source, int sourceLen, const UChar *expe
ct, int expectLen, |
| 45 const char *codepage, const int32_t *expectOffsets, UBool doFlush
, UErrorCode expectedStatus); | 45 const char *codepage, const int32_t *expectOffsets, UBool doFlush
, UErrorCode expectedStatus); |
| 46 | 46 |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 if(U_FAILURE(errorCode)) { | 1785 if(U_FAILURE(errorCode)) { |
| 1786 log_data_err("error TestTruncated: unable to set the stop callback on \"
%s\" - %s\n", | 1786 log_data_err("error TestTruncated: unable to set the stop callback on \"
%s\" - %s\n", |
| 1787 cnvName, u_errorName(errorCode)); | 1787 cnvName, u_errorName(errorCode)); |
| 1788 ucnv_close(cnv); | 1788 ucnv_close(cnv); |
| 1789 return; | 1789 return; |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 source=(const char *)bytes; | 1792 source=(const char *)bytes; |
| 1793 sourceLimit=source+length; | 1793 sourceLimit=source+length; |
| 1794 target=buffer; | 1794 target=buffer; |
| 1795 targetLimit=buffer+LENGTHOF(buffer); | 1795 targetLimit=buffer+UPRV_LENGTHOF(buffer); |
| 1796 | 1796 |
| 1797 /* 1. input bytes with flush=FALSE, then input nothing with flush=TRUE */ | 1797 /* 1. input bytes with flush=FALSE, then input nothing with flush=TRUE */ |
| 1798 ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, FALSE,
&errorCode); | 1798 ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, FALSE,
&errorCode); |
| 1799 if(U_FAILURE(errorCode) || source!=sourceLimit || target!=buffer) { | 1799 if(U_FAILURE(errorCode) || source!=sourceLimit || target!=buffer) { |
| 1800 log_err("error TestTruncated(%s, 1a): input bytes[%d], flush=FALSE: %s,
input left %d, output %d\n", | 1800 log_err("error TestTruncated(%s, 1a): input bytes[%d], flush=FALSE: %s,
input left %d, output %d\n", |
| 1801 cnvName, length, u_errorName(errorCode), (int)(sourceLimit-sourc
e), (int)(target-buffer)); | 1801 cnvName, length, u_errorName(errorCode), (int)(sourceLimit-sourc
e), (int)(target-buffer)); |
| 1802 } | 1802 } |
| 1803 | 1803 |
| 1804 errorCode=U_ZERO_ERROR; | 1804 errorCode=U_ZERO_ERROR; |
| 1805 source=sourceLimit; | 1805 source=sourceLimit; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 | 1859 |
| 1860 { "Shift-JIS", { 0xe0 }, 1 }, | 1860 { "Shift-JIS", { 0xe0 }, 1 }, |
| 1861 | 1861 |
| 1862 { "ibm-939", { 0x0e, 0x41 }, 2 } /* SO 0x41 */ | 1862 { "ibm-939", { 0x0e, 0x41 }, 2 } /* SO 0x41 */ |
| 1863 #else | 1863 #else |
| 1864 { "BOCU-1", { 0xd5 }, 1 ,} | 1864 { "BOCU-1", { 0xd5 }, 1 ,} |
| 1865 #endif | 1865 #endif |
| 1866 }; | 1866 }; |
| 1867 int32_t i; | 1867 int32_t i; |
| 1868 | 1868 |
| 1869 for(i=0; i<LENGTHOF(testCases); ++i) { | 1869 for(i=0; i<UPRV_LENGTHOF(testCases); ++i) { |
| 1870 doTestTruncated(testCases[i].cnvName, testCases[i].bytes, testCases[i].l
ength); | 1870 doTestTruncated(testCases[i].cnvName, testCases[i].bytes, testCases[i].l
ength); |
| 1871 } | 1871 } |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 typedef struct NameRange { | 1874 typedef struct NameRange { |
| 1875 const char *name; | 1875 const char *name; |
| 1876 UChar32 start, end, start2, end2, notStart, notEnd; | 1876 UChar32 start, end, start2, end2, notStart, notEnd; |
| 1877 } NameRange; | 1877 } NameRange; |
| 1878 | 1878 |
| 1879 static void | 1879 static void |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", | 1954 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", |
| 1955 name, u_errorName(errorCode)); | 1955 name, u_errorName(errorCode)); |
| 1956 } else if(uset_size(set)==0) { | 1956 } else if(uset_size(set)==0) { |
| 1957 log_err("error: ucnv_getUnicodeSet(%s) returns an empty set\n", name
); | 1957 log_err("error: ucnv_getUnicodeSet(%s) returns an empty set\n", name
); |
| 1958 } | 1958 } |
| 1959 | 1959 |
| 1960 ucnv_close(cnv); | 1960 ucnv_close(cnv); |
| 1961 } | 1961 } |
| 1962 | 1962 |
| 1963 /* test converters that are known to convert all of Unicode (except maybe fo
r surrogates) */ | 1963 /* test converters that are known to convert all of Unicode (except maybe fo
r surrogates) */ |
| 1964 for(i=0; i<LENGTHOF(completeSetNames); ++i) { | 1964 for(i=0; i<UPRV_LENGTHOF(completeSetNames); ++i) { |
| 1965 errorCode=U_ZERO_ERROR; | 1965 errorCode=U_ZERO_ERROR; |
| 1966 name=completeSetNames[i]; | 1966 name=completeSetNames[i]; |
| 1967 cnv=ucnv_open(name, &errorCode); | 1967 cnv=ucnv_open(name, &errorCode); |
| 1968 if(U_FAILURE(errorCode)) { | 1968 if(U_FAILURE(errorCode)) { |
| 1969 log_data_err("error: unable to open converter %s - %s\n", | 1969 log_data_err("error: unable to open converter %s - %s\n", |
| 1970 name, u_errorName(errorCode)); | 1970 name, u_errorName(errorCode)); |
| 1971 continue; | 1971 continue; |
| 1972 } | 1972 } |
| 1973 | 1973 |
| 1974 uset_clear(set); | 1974 uset_clear(set); |
| 1975 ucnv_getUnicodeSet(cnv, set, UCNV_ROUNDTRIP_SET, &errorCode); | 1975 ucnv_getUnicodeSet(cnv, set, UCNV_ROUNDTRIP_SET, &errorCode); |
| 1976 if(U_FAILURE(errorCode)) { | 1976 if(U_FAILURE(errorCode)) { |
| 1977 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", | 1977 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", |
| 1978 name, u_errorName(errorCode)); | 1978 name, u_errorName(errorCode)); |
| 1979 } else if(!uset_containsRange(set, 0, 0xd7ff) || !uset_containsRange(set
, 0xe000, 0x10ffff)) { | 1979 } else if(!uset_containsRange(set, 0, 0xd7ff) || !uset_containsRange(set
, 0xe000, 0x10ffff)) { |
| 1980 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicod
e set\n", name); | 1980 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicod
e set\n", name); |
| 1981 } | 1981 } |
| 1982 | 1982 |
| 1983 ucnv_close(cnv); | 1983 ucnv_close(cnv); |
| 1984 } | 1984 } |
| 1985 | 1985 |
| 1986 #if !UCONFIG_NO_LEGACY_CONVERSION | 1986 #if !UCONFIG_NO_LEGACY_CONVERSION |
| 1987 /* test LMBCS variants which convert all of Unicode except for U+F6xx */ | 1987 /* test LMBCS variants which convert all of Unicode except for U+F6xx */ |
| 1988 for(i=0; i<LENGTHOF(lmbcsNames); ++i) { | 1988 for(i=0; i<UPRV_LENGTHOF(lmbcsNames); ++i) { |
| 1989 errorCode=U_ZERO_ERROR; | 1989 errorCode=U_ZERO_ERROR; |
| 1990 name=lmbcsNames[i]; | 1990 name=lmbcsNames[i]; |
| 1991 cnv=ucnv_open(name, &errorCode); | 1991 cnv=ucnv_open(name, &errorCode); |
| 1992 if(U_FAILURE(errorCode)) { | 1992 if(U_FAILURE(errorCode)) { |
| 1993 log_data_err("error: unable to open converter %s - %s\n", | 1993 log_data_err("error: unable to open converter %s - %s\n", |
| 1994 name, u_errorName(errorCode)); | 1994 name, u_errorName(errorCode)); |
| 1995 continue; | 1995 continue; |
| 1996 } | 1996 } |
| 1997 | 1997 |
| 1998 uset_clear(set); | 1998 uset_clear(set); |
| 1999 ucnv_getUnicodeSet(cnv, set, UCNV_ROUNDTRIP_SET, &errorCode); | 1999 ucnv_getUnicodeSet(cnv, set, UCNV_ROUNDTRIP_SET, &errorCode); |
| 2000 if(U_FAILURE(errorCode)) { | 2000 if(U_FAILURE(errorCode)) { |
| 2001 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", | 2001 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n", |
| 2002 name, u_errorName(errorCode)); | 2002 name, u_errorName(errorCode)); |
| 2003 } else if(!uset_containsRange(set, 0, 0xf5ff) || !uset_containsRange(set
, 0xf700, 0x10ffff)) { | 2003 } else if(!uset_containsRange(set, 0, 0xf5ff) || !uset_containsRange(set
, 0xf700, 0x10ffff)) { |
| 2004 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicod
e set (minus U+F6xx)\n", name); | 2004 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicod
e set (minus U+F6xx)\n", name); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 ucnv_close(cnv); | 2007 ucnv_close(cnv); |
| 2008 } | 2008 } |
| 2009 #endif | 2009 #endif |
| 2010 | 2010 |
| 2011 /* test specific sets */ | 2011 /* test specific sets */ |
| 2012 for(i=0; i<LENGTHOF(nameRanges); ++i) { | 2012 for(i=0; i<UPRV_LENGTHOF(nameRanges); ++i) { |
| 2013 errorCode=U_ZERO_ERROR; | 2013 errorCode=U_ZERO_ERROR; |
| 2014 name=nameRanges[i].name; | 2014 name=nameRanges[i].name; |
| 2015 cnv=ucnv_open(name, &errorCode); | 2015 cnv=ucnv_open(name, &errorCode); |
| 2016 if(U_FAILURE(errorCode)) { | 2016 if(U_FAILURE(errorCode)) { |
| 2017 log_data_err("error: unable to open converter %s - %s\n", | 2017 log_data_err("error: unable to open converter %s - %s\n", |
| 2018 name, u_errorName(errorCode)); | 2018 name, u_errorName(errorCode)); |
| 2019 continue; | 2019 continue; |
| 2020 } | 2020 } |
| 2021 | 2021 |
| 2022 uset_clear(set); | 2022 uset_clear(set); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2047 } | 2047 } |
| 2048 errorCode = U_PARSE_ERROR; | 2048 errorCode = U_PARSE_ERROR; |
| 2049 /* Make sure that it does nothing if an error is passed in. Difficult to pro
per test for. */ | 2049 /* Make sure that it does nothing if an error is passed in. Difficult to pro
per test for. */ |
| 2050 ucnv_getUnicodeSet(NULL, NULL, UCNV_ROUNDTRIP_SET, &errorCode); | 2050 ucnv_getUnicodeSet(NULL, NULL, UCNV_ROUNDTRIP_SET, &errorCode); |
| 2051 if (errorCode != U_PARSE_ERROR) { | 2051 if (errorCode != U_PARSE_ERROR) { |
| 2052 log_err("error: ucnv_getUnicodeSet(NULL) returned wrong status code %s\n
", u_errorName(errorCode)); | 2052 log_err("error: ucnv_getUnicodeSet(NULL) returned wrong status code %s\n
", u_errorName(errorCode)); |
| 2053 } | 2053 } |
| 2054 | 2054 |
| 2055 uset_close(set); | 2055 uset_close(set); |
| 2056 } | 2056 } |
| OLD | NEW |