12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 32e5b6d6dSopenharmony_ci/******************************************************************** 42e5b6d6dSopenharmony_ci * COPYRIGHT: 52e5b6d6dSopenharmony_ci * Copyright (c) 1997-2016, International Business Machines Corporation and 62e5b6d6dSopenharmony_ci * others. All Rights Reserved. 72e5b6d6dSopenharmony_ci ********************************************************************/ 82e5b6d6dSopenharmony_ci/******************************************************************************* 92e5b6d6dSopenharmony_ci* 102e5b6d6dSopenharmony_ci* File nucnvtst.c 112e5b6d6dSopenharmony_ci* 122e5b6d6dSopenharmony_ci* Modification History: 132e5b6d6dSopenharmony_ci* Name Description 142e5b6d6dSopenharmony_ci* Steven R. Loomis 7/8/1999 Adding input buffer test 152e5b6d6dSopenharmony_ci******************************************************************************** 162e5b6d6dSopenharmony_ci*/ 172e5b6d6dSopenharmony_ci#include <stdbool.h> 182e5b6d6dSopenharmony_ci#include <stdio.h> 192e5b6d6dSopenharmony_ci#include "cstring.h" 202e5b6d6dSopenharmony_ci#include "unicode/uloc.h" 212e5b6d6dSopenharmony_ci#include "unicode/ucnv.h" 222e5b6d6dSopenharmony_ci#include "unicode/ucnv_err.h" 232e5b6d6dSopenharmony_ci#include "unicode/ucnv_cb.h" 242e5b6d6dSopenharmony_ci#include "cintltst.h" 252e5b6d6dSopenharmony_ci#include "unicode/utypes.h" 262e5b6d6dSopenharmony_ci#include "unicode/ustring.h" 272e5b6d6dSopenharmony_ci#include "unicode/ucol.h" 282e5b6d6dSopenharmony_ci#include "unicode/utf16.h" 292e5b6d6dSopenharmony_ci#include "cmemory.h" 302e5b6d6dSopenharmony_ci#include "nucnvtst.h" 312e5b6d6dSopenharmony_ci 322e5b6d6dSopenharmony_cistatic void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message); 332e5b6d6dSopenharmony_cistatic void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message); 342e5b6d6dSopenharmony_ci#if !UCONFIG_NO_COLLATION 352e5b6d6dSopenharmony_cistatic void TestJitterbug981(void); 362e5b6d6dSopenharmony_ci#endif 372e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 382e5b6d6dSopenharmony_cistatic void TestJitterbug1293(void); 392e5b6d6dSopenharmony_ci#endif 402e5b6d6dSopenharmony_cistatic void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ; 412e5b6d6dSopenharmony_cistatic void TestConverterTypesAndStarters(void); 422e5b6d6dSopenharmony_cistatic void TestAmbiguous(void); 432e5b6d6dSopenharmony_cistatic void TestSignatureDetection(void); 442e5b6d6dSopenharmony_cistatic void TestUTF7(void); 452e5b6d6dSopenharmony_cistatic void TestIMAP(void); 462e5b6d6dSopenharmony_cistatic void TestUTF8(void); 472e5b6d6dSopenharmony_cistatic void TestCESU8(void); 482e5b6d6dSopenharmony_cistatic void TestUTF16(void); 492e5b6d6dSopenharmony_cistatic void TestUTF16BE(void); 502e5b6d6dSopenharmony_cistatic void TestUTF16LE(void); 512e5b6d6dSopenharmony_cistatic void TestUTF32(void); 522e5b6d6dSopenharmony_cistatic void TestUTF32BE(void); 532e5b6d6dSopenharmony_cistatic void TestUTF32LE(void); 542e5b6d6dSopenharmony_cistatic void TestLATIN1(void); 552e5b6d6dSopenharmony_ci 562e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 572e5b6d6dSopenharmony_cistatic void TestSBCS(void); 582e5b6d6dSopenharmony_cistatic void TestDBCS(void); 592e5b6d6dSopenharmony_cistatic void TestMBCS(void); 602e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO 612e5b6d6dSopenharmony_cistatic void TestICCRunout(void); 622e5b6d6dSopenharmony_ci#endif 632e5b6d6dSopenharmony_ci 642e5b6d6dSopenharmony_ci#ifdef U_ENABLE_GENERIC_ISO_2022 652e5b6d6dSopenharmony_cistatic void TestISO_2022(void); 662e5b6d6dSopenharmony_ci#endif 672e5b6d6dSopenharmony_ci 682e5b6d6dSopenharmony_cistatic void TestISO_2022_JP(void); 692e5b6d6dSopenharmony_cistatic void TestISO_2022_JP_1(void); 702e5b6d6dSopenharmony_cistatic void TestISO_2022_JP_2(void); 712e5b6d6dSopenharmony_cistatic void TestISO_2022_KR(void); 722e5b6d6dSopenharmony_cistatic void TestISO_2022_KR_1(void); 732e5b6d6dSopenharmony_cistatic void TestISO_2022_CN(void); 742e5b6d6dSopenharmony_ci#if 0 752e5b6d6dSopenharmony_ci /* 762e5b6d6dSopenharmony_ci * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 772e5b6d6dSopenharmony_ci */ 782e5b6d6dSopenharmony_cistatic void TestISO_2022_CN_EXT(void); 792e5b6d6dSopenharmony_ci#endif 802e5b6d6dSopenharmony_cistatic void TestJIS(void); 812e5b6d6dSopenharmony_cistatic void TestHZ(void); 822e5b6d6dSopenharmony_ci#endif 832e5b6d6dSopenharmony_ci 842e5b6d6dSopenharmony_cistatic void TestSCSU(void); 852e5b6d6dSopenharmony_ci 862e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 872e5b6d6dSopenharmony_cistatic void TestEBCDIC_STATEFUL(void); 882e5b6d6dSopenharmony_cistatic void TestGB18030(void); 892e5b6d6dSopenharmony_cistatic void TestLMBCS(void); 902e5b6d6dSopenharmony_cistatic void TestJitterbug255(void); 912e5b6d6dSopenharmony_cistatic void TestEBCDICUS4XML(void); 922e5b6d6dSopenharmony_ci#if 0 932e5b6d6dSopenharmony_ci /* 942e5b6d6dSopenharmony_ci * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 952e5b6d6dSopenharmony_ci */ 962e5b6d6dSopenharmony_cistatic void TestJitterbug915(void); 972e5b6d6dSopenharmony_ci#endif 982e5b6d6dSopenharmony_cistatic void TestISCII(void); 992e5b6d6dSopenharmony_ci 1002e5b6d6dSopenharmony_cistatic void TestCoverageMBCS(void); 1012e5b6d6dSopenharmony_cistatic void TestJitterbug2346(void); 1022e5b6d6dSopenharmony_cistatic void TestJitterbug2411(void); 1032e5b6d6dSopenharmony_cistatic void TestJB5275(void); 1042e5b6d6dSopenharmony_cistatic void TestJB5275_1(void); 1052e5b6d6dSopenharmony_cistatic void TestJitterbug6175(void); 1062e5b6d6dSopenharmony_ci 1072e5b6d6dSopenharmony_cistatic void TestIsFixedWidth(void); 1082e5b6d6dSopenharmony_ci#endif 1092e5b6d6dSopenharmony_ci 1102e5b6d6dSopenharmony_cistatic void TestInBufSizes(void); 1112e5b6d6dSopenharmony_ci 1122e5b6d6dSopenharmony_cistatic void TestRoundTrippingAllUTF(void); 1132e5b6d6dSopenharmony_cistatic void TestConv(const uint16_t in[], 1142e5b6d6dSopenharmony_ci int len, 1152e5b6d6dSopenharmony_ci const char* conv, 1162e5b6d6dSopenharmony_ci const char* lang, 1172e5b6d6dSopenharmony_ci char byteArr[], 1182e5b6d6dSopenharmony_ci int byteArrLen); 1192e5b6d6dSopenharmony_ci 1202e5b6d6dSopenharmony_ci/* open a converter, using test data if it begins with '@' */ 1212e5b6d6dSopenharmony_cistatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err); 1222e5b6d6dSopenharmony_ci 1232e5b6d6dSopenharmony_ci 1242e5b6d6dSopenharmony_ci#define NEW_MAX_BUFFER 999 1252e5b6d6dSopenharmony_ci 1262e5b6d6dSopenharmony_cistatic int32_t gInBufferSize = NEW_MAX_BUFFER; 1272e5b6d6dSopenharmony_cistatic int32_t gOutBufferSize = NEW_MAX_BUFFER; 1282e5b6d6dSopenharmony_cistatic char gNuConvTestName[1024]; 1292e5b6d6dSopenharmony_ci 1302e5b6d6dSopenharmony_ci#define nct_min(x,y) ((x<y) ? x : y) 1312e5b6d6dSopenharmony_ci 1322e5b6d6dSopenharmony_cistatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err) 1332e5b6d6dSopenharmony_ci{ 1342e5b6d6dSopenharmony_ci if(cnv && cnv[0] == '@') { 1352e5b6d6dSopenharmony_ci return ucnv_openPackage(loadTestData(err), cnv+1, err); 1362e5b6d6dSopenharmony_ci } else { 1372e5b6d6dSopenharmony_ci return ucnv_open(cnv, err); 1382e5b6d6dSopenharmony_ci } 1392e5b6d6dSopenharmony_ci} 1402e5b6d6dSopenharmony_ci 1412e5b6d6dSopenharmony_cistatic void printSeq(const unsigned char* a, int len) 1422e5b6d6dSopenharmony_ci{ 1432e5b6d6dSopenharmony_ci int i=0; 1442e5b6d6dSopenharmony_ci log_verbose("{"); 1452e5b6d6dSopenharmony_ci while (i<len) 1462e5b6d6dSopenharmony_ci log_verbose("0x%02x ", a[i++]); 1472e5b6d6dSopenharmony_ci log_verbose("}\n"); 1482e5b6d6dSopenharmony_ci} 1492e5b6d6dSopenharmony_ci 1502e5b6d6dSopenharmony_cistatic void printUSeq(const UChar* a, int len) 1512e5b6d6dSopenharmony_ci{ 1522e5b6d6dSopenharmony_ci int i=0; 1532e5b6d6dSopenharmony_ci log_verbose("{U+"); 1542e5b6d6dSopenharmony_ci while (i<len) log_verbose("0x%04x ", a[i++]); 1552e5b6d6dSopenharmony_ci log_verbose("}\n"); 1562e5b6d6dSopenharmony_ci} 1572e5b6d6dSopenharmony_ci 1582e5b6d6dSopenharmony_cistatic void printSeqErr(const unsigned char* a, int len) 1592e5b6d6dSopenharmony_ci{ 1602e5b6d6dSopenharmony_ci int i=0; 1612e5b6d6dSopenharmony_ci fprintf(stderr, "{"); 1622e5b6d6dSopenharmony_ci while (i<len) 1632e5b6d6dSopenharmony_ci fprintf(stderr, "0x%02x ", a[i++]); 1642e5b6d6dSopenharmony_ci fprintf(stderr, "}\n"); 1652e5b6d6dSopenharmony_ci} 1662e5b6d6dSopenharmony_ci 1672e5b6d6dSopenharmony_cistatic void printUSeqErr(const UChar* a, int len) 1682e5b6d6dSopenharmony_ci{ 1692e5b6d6dSopenharmony_ci int i=0; 1702e5b6d6dSopenharmony_ci fprintf(stderr, "{U+"); 1712e5b6d6dSopenharmony_ci while (i<len) 1722e5b6d6dSopenharmony_ci fprintf(stderr, "0x%04x ", a[i++]); 1732e5b6d6dSopenharmony_ci fprintf(stderr,"}\n"); 1742e5b6d6dSopenharmony_ci} 1752e5b6d6dSopenharmony_ci 1762e5b6d6dSopenharmony_cistatic void 1772e5b6d6dSopenharmony_ciTestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message) 1782e5b6d6dSopenharmony_ci{ 1792e5b6d6dSopenharmony_ci const char* s0; 1802e5b6d6dSopenharmony_ci const char* s=(char*)source; 1812e5b6d6dSopenharmony_ci const int32_t *r=results; 1822e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 1832e5b6d6dSopenharmony_ci UChar32 c; 1842e5b6d6dSopenharmony_ci 1852e5b6d6dSopenharmony_ci while(s<limit) { 1862e5b6d6dSopenharmony_ci s0=s; 1872e5b6d6dSopenharmony_ci c=ucnv_getNextUChar(cnv, &s, limit, &errorCode); 1882e5b6d6dSopenharmony_ci if(errorCode==U_INDEX_OUTOFBOUNDS_ERROR) { 1892e5b6d6dSopenharmony_ci break; /* no more significant input */ 1902e5b6d6dSopenharmony_ci } else if(U_FAILURE(errorCode)) { 1912e5b6d6dSopenharmony_ci log_err("%s ucnv_getNextUChar() failed: %s\n", message, u_errorName(errorCode)); 1922e5b6d6dSopenharmony_ci break; 1932e5b6d6dSopenharmony_ci } else if( 1942e5b6d6dSopenharmony_ci /* test the expected number of input bytes only if >=0 */ 1952e5b6d6dSopenharmony_ci (*r>=0 && (int32_t)(s-s0)!=*r) || 1962e5b6d6dSopenharmony_ci c!=*(r+1) 1972e5b6d6dSopenharmony_ci ) { 1982e5b6d6dSopenharmony_ci log_err("%s ucnv_getNextUChar() result %lx from %d bytes, should have been %lx from %d bytes.\n", 1992e5b6d6dSopenharmony_ci message, c, (s-s0), *(r+1), *r); 2002e5b6d6dSopenharmony_ci break; 2012e5b6d6dSopenharmony_ci } 2022e5b6d6dSopenharmony_ci r+=2; 2032e5b6d6dSopenharmony_ci } 2042e5b6d6dSopenharmony_ci} 2052e5b6d6dSopenharmony_ci 2062e5b6d6dSopenharmony_cistatic void 2072e5b6d6dSopenharmony_ciTestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message) 2082e5b6d6dSopenharmony_ci{ 2092e5b6d6dSopenharmony_ci const char* s=(char*)source; 2102e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 2112e5b6d6dSopenharmony_ci uint32_t c; 2122e5b6d6dSopenharmony_ci c=ucnv_getNextUChar(cnv, &s, limit, &errorCode); 2132e5b6d6dSopenharmony_ci if(errorCode != expected){ 2142e5b6d6dSopenharmony_ci log_err("FAIL: Expected:%s when %s-----Got:%s\n", myErrorName(expected), message, myErrorName(errorCode)); 2152e5b6d6dSopenharmony_ci } 2162e5b6d6dSopenharmony_ci if(c != 0xFFFD && c != 0xffff){ 2172e5b6d6dSopenharmony_ci log_err("FAIL: Expected return value of 0xfffd or 0xffff when %s-----Got 0x%lx\n", message, c); 2182e5b6d6dSopenharmony_ci } 2192e5b6d6dSopenharmony_ci 2202e5b6d6dSopenharmony_ci} 2212e5b6d6dSopenharmony_ci 2222e5b6d6dSopenharmony_cistatic void TestInBufSizes(void) 2232e5b6d6dSopenharmony_ci{ 2242e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,1); 2252e5b6d6dSopenharmony_ci#if 1 2262e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,2); 2272e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,3); 2282e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,4); 2292e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,5); 2302e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,6); 2312e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(1,1); 2322e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(2,3); 2332e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(3,2); 2342e5b6d6dSopenharmony_ci#endif 2352e5b6d6dSopenharmony_ci} 2362e5b6d6dSopenharmony_ci 2372e5b6d6dSopenharmony_cistatic void TestOutBufSizes(void) 2382e5b6d6dSopenharmony_ci{ 2392e5b6d6dSopenharmony_ci#if 1 2402e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,NEW_MAX_BUFFER); 2412e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(1,NEW_MAX_BUFFER); 2422e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(2,NEW_MAX_BUFFER); 2432e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(3,NEW_MAX_BUFFER); 2442e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(4,NEW_MAX_BUFFER); 2452e5b6d6dSopenharmony_ci TestNewConvertWithBufferSizes(5,NEW_MAX_BUFFER); 2462e5b6d6dSopenharmony_ci 2472e5b6d6dSopenharmony_ci#endif 2482e5b6d6dSopenharmony_ci} 2492e5b6d6dSopenharmony_ci 2502e5b6d6dSopenharmony_ci 2512e5b6d6dSopenharmony_civoid addTestNewConvert(TestNode** root) 2522e5b6d6dSopenharmony_ci{ 2532e5b6d6dSopenharmony_ci#if !UCONFIG_NO_FILE_IO 2542e5b6d6dSopenharmony_ci addTest(root, &TestInBufSizes, "tsconv/nucnvtst/TestInBufSizes"); 2552e5b6d6dSopenharmony_ci addTest(root, &TestOutBufSizes, "tsconv/nucnvtst/TestOutBufSizes"); 2562e5b6d6dSopenharmony_ci#endif 2572e5b6d6dSopenharmony_ci addTest(root, &TestConverterTypesAndStarters, "tsconv/nucnvtst/TestConverterTypesAndStarters"); 2582e5b6d6dSopenharmony_ci addTest(root, &TestAmbiguous, "tsconv/nucnvtst/TestAmbiguous"); 2592e5b6d6dSopenharmony_ci addTest(root, &TestSignatureDetection, "tsconv/nucnvtst/TestSignatureDetection"); 2602e5b6d6dSopenharmony_ci addTest(root, &TestUTF7, "tsconv/nucnvtst/TestUTF7"); 2612e5b6d6dSopenharmony_ci addTest(root, &TestIMAP, "tsconv/nucnvtst/TestIMAP"); 2622e5b6d6dSopenharmony_ci addTest(root, &TestUTF8, "tsconv/nucnvtst/TestUTF8"); 2632e5b6d6dSopenharmony_ci 2642e5b6d6dSopenharmony_ci /* test ucnv_getNextUChar() for charsets that encode single surrogates with complete byte sequences */ 2652e5b6d6dSopenharmony_ci addTest(root, &TestCESU8, "tsconv/nucnvtst/TestCESU8"); 2662e5b6d6dSopenharmony_ci addTest(root, &TestUTF16, "tsconv/nucnvtst/TestUTF16"); 2672e5b6d6dSopenharmony_ci addTest(root, &TestUTF16BE, "tsconv/nucnvtst/TestUTF16BE"); 2682e5b6d6dSopenharmony_ci addTest(root, &TestUTF16LE, "tsconv/nucnvtst/TestUTF16LE"); 2692e5b6d6dSopenharmony_ci addTest(root, &TestUTF32, "tsconv/nucnvtst/TestUTF32"); 2702e5b6d6dSopenharmony_ci addTest(root, &TestUTF32BE, "tsconv/nucnvtst/TestUTF32BE"); 2712e5b6d6dSopenharmony_ci addTest(root, &TestUTF32LE, "tsconv/nucnvtst/TestUTF32LE"); 2722e5b6d6dSopenharmony_ci 2732e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 2742e5b6d6dSopenharmony_ci addTest(root, &TestLMBCS, "tsconv/nucnvtst/TestLMBCS"); 2752e5b6d6dSopenharmony_ci#endif 2762e5b6d6dSopenharmony_ci 2772e5b6d6dSopenharmony_ci addTest(root, &TestLATIN1, "tsconv/nucnvtst/TestLATIN1"); 2782e5b6d6dSopenharmony_ci 2792e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 2802e5b6d6dSopenharmony_ci addTest(root, &TestSBCS, "tsconv/nucnvtst/TestSBCS"); 2812e5b6d6dSopenharmony_ci#if !UCONFIG_NO_FILE_IO 2822e5b6d6dSopenharmony_ci addTest(root, &TestDBCS, "tsconv/nucnvtst/TestDBCS"); 2832e5b6d6dSopenharmony_ci addTest(root, &TestICCRunout, "tsconv/nucnvtst/TestICCRunout"); 2842e5b6d6dSopenharmony_ci#endif 2852e5b6d6dSopenharmony_ci addTest(root, &TestMBCS, "tsconv/nucnvtst/TestMBCS"); 2862e5b6d6dSopenharmony_ci 2872e5b6d6dSopenharmony_ci#ifdef U_ENABLE_GENERIC_ISO_2022 2882e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022, "tsconv/nucnvtst/TestISO_2022"); 2892e5b6d6dSopenharmony_ci#endif 2902e5b6d6dSopenharmony_ci 2912e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_JP, "tsconv/nucnvtst/TestISO_2022_JP"); 2922e5b6d6dSopenharmony_ci addTest(root, &TestJIS, "tsconv/nucnvtst/TestJIS"); 2932e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_JP_1, "tsconv/nucnvtst/TestISO_2022_JP_1"); 2942e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_JP_2, "tsconv/nucnvtst/TestISO_2022_JP_2"); 2952e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_KR, "tsconv/nucnvtst/TestISO_2022_KR"); 2962e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_KR_1, "tsconv/nucnvtst/TestISO_2022_KR_1"); 2972e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_CN, "tsconv/nucnvtst/TestISO_2022_CN"); 2982e5b6d6dSopenharmony_ci /* 2992e5b6d6dSopenharmony_ci * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 3002e5b6d6dSopenharmony_ci addTest(root, &TestISO_2022_CN_EXT, "tsconv/nucnvtst/TestISO_2022_CN_EXT"); 3012e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug915, "tsconv/nucnvtst/TestJitterbug915"); 3022e5b6d6dSopenharmony_ci */ 3032e5b6d6dSopenharmony_ci addTest(root, &TestHZ, "tsconv/nucnvtst/TestHZ"); 3042e5b6d6dSopenharmony_ci#endif 3052e5b6d6dSopenharmony_ci 3062e5b6d6dSopenharmony_ci addTest(root, &TestSCSU, "tsconv/nucnvtst/TestSCSU"); 3072e5b6d6dSopenharmony_ci 3082e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 3092e5b6d6dSopenharmony_ci addTest(root, &TestEBCDIC_STATEFUL, "tsconv/nucnvtst/TestEBCDIC_STATEFUL"); 3102e5b6d6dSopenharmony_ci addTest(root, &TestGB18030, "tsconv/nucnvtst/TestGB18030"); 3112e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug255, "tsconv/nucnvtst/TestJitterbug255"); 3122e5b6d6dSopenharmony_ci addTest(root, &TestEBCDICUS4XML, "tsconv/nucnvtst/TestEBCDICUS4XML"); 3132e5b6d6dSopenharmony_ci addTest(root, &TestISCII, "tsconv/nucnvtst/TestISCII"); 3142e5b6d6dSopenharmony_ci addTest(root, &TestJB5275, "tsconv/nucnvtst/TestJB5275"); 3152e5b6d6dSopenharmony_ci addTest(root, &TestJB5275_1, "tsconv/nucnvtst/TestJB5275_1"); 3162e5b6d6dSopenharmony_ci#if !UCONFIG_NO_COLLATION 3172e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug981, "tsconv/nucnvtst/TestJitterbug981"); 3182e5b6d6dSopenharmony_ci#endif 3192e5b6d6dSopenharmony_ci 3202e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug1293, "tsconv/nucnvtst/TestJitterbug1293"); 3212e5b6d6dSopenharmony_ci#endif 3222e5b6d6dSopenharmony_ci 3232e5b6d6dSopenharmony_ci 3242e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO 3252e5b6d6dSopenharmony_ci addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS"); 3262e5b6d6dSopenharmony_ci#endif 3272e5b6d6dSopenharmony_ci 3282e5b6d6dSopenharmony_ci addTest(root, &TestRoundTrippingAllUTF, "tsconv/nucnvtst/TestRoundTrippingAllUTF"); 3292e5b6d6dSopenharmony_ci 3302e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 3312e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346"); 3322e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411"); 3332e5b6d6dSopenharmony_ci addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175"); 3342e5b6d6dSopenharmony_ci 3352e5b6d6dSopenharmony_ci addTest(root, &TestIsFixedWidth, "tsconv/nucnvtst/TestIsFixedWidth"); 3362e5b6d6dSopenharmony_ci#endif 3372e5b6d6dSopenharmony_ci} 3382e5b6d6dSopenharmony_ci 3392e5b6d6dSopenharmony_ci 3402e5b6d6dSopenharmony_ci/* Note that this test already makes use of statics, so it's not really 3412e5b6d6dSopenharmony_ci multithread safe. 3422e5b6d6dSopenharmony_ci This convenience function lets us make the error messages actually useful. 3432e5b6d6dSopenharmony_ci*/ 3442e5b6d6dSopenharmony_ci 3452e5b6d6dSopenharmony_cistatic void setNuConvTestName(const char *codepage, const char *direction) 3462e5b6d6dSopenharmony_ci{ 3472e5b6d6dSopenharmony_ci sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]", 3482e5b6d6dSopenharmony_ci codepage, 3492e5b6d6dSopenharmony_ci direction, 3502e5b6d6dSopenharmony_ci (int)gInBufferSize, 3512e5b6d6dSopenharmony_ci (int)gOutBufferSize); 3522e5b6d6dSopenharmony_ci} 3532e5b6d6dSopenharmony_ci 3542e5b6d6dSopenharmony_citypedef enum 3552e5b6d6dSopenharmony_ci{ 3562e5b6d6dSopenharmony_ci TC_OK = 0, /* test was OK */ 3572e5b6d6dSopenharmony_ci TC_MISMATCH = 1, /* Match failed - err was printed */ 3582e5b6d6dSopenharmony_ci TC_FAIL = 2 /* Test failed, don't print an err because it was already printed. */ 3592e5b6d6dSopenharmony_ci} ETestConvertResult; 3602e5b6d6dSopenharmony_ci 3612e5b6d6dSopenharmony_ci/* Note: This function uses global variables and it will not do offset 3622e5b6d6dSopenharmony_cichecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */ 3632e5b6d6dSopenharmony_cistatic ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, const uint8_t *expect, int expectLen, 3642e5b6d6dSopenharmony_ci const char *codepage, const int32_t *expectOffsets , UBool useFallback) 3652e5b6d6dSopenharmony_ci{ 3662e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3672e5b6d6dSopenharmony_ci UConverter *conv = 0; 3682e5b6d6dSopenharmony_ci char junkout[NEW_MAX_BUFFER]; /* FIX */ 3692e5b6d6dSopenharmony_ci int32_t junokout[NEW_MAX_BUFFER]; /* FIX */ 3702e5b6d6dSopenharmony_ci char *p; 3712e5b6d6dSopenharmony_ci const UChar *src; 3722e5b6d6dSopenharmony_ci char *end; 3732e5b6d6dSopenharmony_ci char *targ; 3742e5b6d6dSopenharmony_ci int32_t *offs; 3752e5b6d6dSopenharmony_ci int i; 3762e5b6d6dSopenharmony_ci int32_t realBufferSize; 3772e5b6d6dSopenharmony_ci char *realBufferEnd; 3782e5b6d6dSopenharmony_ci const UChar *realSourceEnd; 3792e5b6d6dSopenharmony_ci const UChar *sourceLimit; 3802e5b6d6dSopenharmony_ci UBool checkOffsets = true; 3812e5b6d6dSopenharmony_ci UBool doFlush; 3822e5b6d6dSopenharmony_ci 3832e5b6d6dSopenharmony_ci for(i=0;i<NEW_MAX_BUFFER;i++) 3842e5b6d6dSopenharmony_ci junkout[i] = (char)0xF0; 3852e5b6d6dSopenharmony_ci for(i=0;i<NEW_MAX_BUFFER;i++) 3862e5b6d6dSopenharmony_ci junokout[i] = 0xFF; 3872e5b6d6dSopenharmony_ci 3882e5b6d6dSopenharmony_ci setNuConvTestName(codepage, "FROM"); 3892e5b6d6dSopenharmony_ci 3902e5b6d6dSopenharmony_ci log_verbose("\n========= %s\n", gNuConvTestName); 3912e5b6d6dSopenharmony_ci 3922e5b6d6dSopenharmony_ci conv = my_ucnv_open(codepage, &status); 3932e5b6d6dSopenharmony_ci 3942e5b6d6dSopenharmony_ci if(U_FAILURE(status)) 3952e5b6d6dSopenharmony_ci { 3962e5b6d6dSopenharmony_ci log_data_err("Couldn't open converter %s\n",codepage); 3972e5b6d6dSopenharmony_ci return TC_FAIL; 3982e5b6d6dSopenharmony_ci } 3992e5b6d6dSopenharmony_ci if(useFallback){ 4002e5b6d6dSopenharmony_ci ucnv_setFallback(conv,useFallback); 4012e5b6d6dSopenharmony_ci } 4022e5b6d6dSopenharmony_ci 4032e5b6d6dSopenharmony_ci log_verbose("Converter opened..\n"); 4042e5b6d6dSopenharmony_ci 4052e5b6d6dSopenharmony_ci src = source; 4062e5b6d6dSopenharmony_ci targ = junkout; 4072e5b6d6dSopenharmony_ci offs = junokout; 4082e5b6d6dSopenharmony_ci 4092e5b6d6dSopenharmony_ci realBufferSize = UPRV_LENGTHOF(junkout); 4102e5b6d6dSopenharmony_ci realBufferEnd = junkout + realBufferSize; 4112e5b6d6dSopenharmony_ci realSourceEnd = source + sourceLen; 4122e5b6d6dSopenharmony_ci 4132e5b6d6dSopenharmony_ci if ( gOutBufferSize != realBufferSize || gInBufferSize != NEW_MAX_BUFFER ) 4142e5b6d6dSopenharmony_ci checkOffsets = false; 4152e5b6d6dSopenharmony_ci 4162e5b6d6dSopenharmony_ci do 4172e5b6d6dSopenharmony_ci { 4182e5b6d6dSopenharmony_ci end = nct_min(targ + gOutBufferSize, realBufferEnd); 4192e5b6d6dSopenharmony_ci sourceLimit = nct_min(src + gInBufferSize, realSourceEnd); 4202e5b6d6dSopenharmony_ci 4212e5b6d6dSopenharmony_ci doFlush = (UBool)(sourceLimit == realSourceEnd); 4222e5b6d6dSopenharmony_ci 4232e5b6d6dSopenharmony_ci if(targ == realBufferEnd) { 4242e5b6d6dSopenharmony_ci log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName); 4252e5b6d6dSopenharmony_ci return TC_FAIL; 4262e5b6d6dSopenharmony_ci } 4272e5b6d6dSopenharmony_ci log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"true":"false"); 4282e5b6d6dSopenharmony_ci 4292e5b6d6dSopenharmony_ci 4302e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4312e5b6d6dSopenharmony_ci 4322e5b6d6dSopenharmony_ci ucnv_fromUnicode (conv, 4332e5b6d6dSopenharmony_ci &targ, 4342e5b6d6dSopenharmony_ci end, 4352e5b6d6dSopenharmony_ci &src, 4362e5b6d6dSopenharmony_ci sourceLimit, 4372e5b6d6dSopenharmony_ci checkOffsets ? offs : NULL, 4382e5b6d6dSopenharmony_ci doFlush, /* flush if we're at the end of the input data */ 4392e5b6d6dSopenharmony_ci &status); 4402e5b6d6dSopenharmony_ci } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && sourceLimit < realSourceEnd) ); 4412e5b6d6dSopenharmony_ci 4422e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 4432e5b6d6dSopenharmony_ci log_err("Problem doing fromUnicode to %s, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName); 4442e5b6d6dSopenharmony_ci return TC_FAIL; 4452e5b6d6dSopenharmony_ci } 4462e5b6d6dSopenharmony_ci 4472e5b6d6dSopenharmony_ci log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", 4482e5b6d6dSopenharmony_ci sourceLen, targ-junkout); 4492e5b6d6dSopenharmony_ci 4502e5b6d6dSopenharmony_ci if(getTestOption(VERBOSITY_OPTION)) 4512e5b6d6dSopenharmony_ci { 4522e5b6d6dSopenharmony_ci char junk[9999]; 4532e5b6d6dSopenharmony_ci char offset_str[9999]; 4542e5b6d6dSopenharmony_ci char *ptr; 4552e5b6d6dSopenharmony_ci 4562e5b6d6dSopenharmony_ci junk[0] = 0; 4572e5b6d6dSopenharmony_ci offset_str[0] = 0; 4582e5b6d6dSopenharmony_ci for(ptr = junkout;ptr<targ;ptr++) { 4592e5b6d6dSopenharmony_ci sprintf(junk + strlen(junk), "0x%02x, ", (int)(0xFF & *ptr)); 4602e5b6d6dSopenharmony_ci sprintf(offset_str + strlen(offset_str), "0x%02x, ", (int)(0xFF & junokout[ptr-junkout])); 4612e5b6d6dSopenharmony_ci } 4622e5b6d6dSopenharmony_ci 4632e5b6d6dSopenharmony_ci log_verbose(junk); 4642e5b6d6dSopenharmony_ci printSeq((const uint8_t *)expect, expectLen); 4652e5b6d6dSopenharmony_ci if ( checkOffsets ) { 4662e5b6d6dSopenharmony_ci log_verbose("\nOffsets:"); 4672e5b6d6dSopenharmony_ci log_verbose(offset_str); 4682e5b6d6dSopenharmony_ci } 4692e5b6d6dSopenharmony_ci log_verbose("\n"); 4702e5b6d6dSopenharmony_ci } 4712e5b6d6dSopenharmony_ci ucnv_close(conv); 4722e5b6d6dSopenharmony_ci 4732e5b6d6dSopenharmony_ci if(expectLen != targ-junkout) { 4742e5b6d6dSopenharmony_ci log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); 4752e5b6d6dSopenharmony_ci log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); 4762e5b6d6dSopenharmony_ci fprintf(stderr, "Got:\n"); 4772e5b6d6dSopenharmony_ci printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout)); 4782e5b6d6dSopenharmony_ci fprintf(stderr, "Expected:\n"); 4792e5b6d6dSopenharmony_ci printSeqErr((const unsigned char*)expect, expectLen); 4802e5b6d6dSopenharmony_ci return TC_MISMATCH; 4812e5b6d6dSopenharmony_ci } 4822e5b6d6dSopenharmony_ci 4832e5b6d6dSopenharmony_ci if (checkOffsets && (expectOffsets != 0) ) { 4842e5b6d6dSopenharmony_ci log_verbose("comparing %d offsets..\n", targ-junkout); 4852e5b6d6dSopenharmony_ci if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){ 4862e5b6d6dSopenharmony_ci log_err("did not get the expected offsets. %s\n", gNuConvTestName); 4872e5b6d6dSopenharmony_ci printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout)); 4882e5b6d6dSopenharmony_ci log_err("\n"); 4892e5b6d6dSopenharmony_ci log_err("Got : "); 4902e5b6d6dSopenharmony_ci for(p=junkout;p<targ;p++) { 4912e5b6d6dSopenharmony_ci log_err("%d,", junokout[p-junkout]); 4922e5b6d6dSopenharmony_ci } 4932e5b6d6dSopenharmony_ci log_err("\n"); 4942e5b6d6dSopenharmony_ci log_err("Expected: "); 4952e5b6d6dSopenharmony_ci for(i=0; i<(targ-junkout); i++) { 4962e5b6d6dSopenharmony_ci log_err("%d,", expectOffsets[i]); 4972e5b6d6dSopenharmony_ci } 4982e5b6d6dSopenharmony_ci log_err("\n"); 4992e5b6d6dSopenharmony_ci } 5002e5b6d6dSopenharmony_ci } 5012e5b6d6dSopenharmony_ci 5022e5b6d6dSopenharmony_ci log_verbose("comparing..\n"); 5032e5b6d6dSopenharmony_ci if(!memcmp(junkout, expect, expectLen)) { 5042e5b6d6dSopenharmony_ci log_verbose("Matches!\n"); 5052e5b6d6dSopenharmony_ci return TC_OK; 5062e5b6d6dSopenharmony_ci } else { 5072e5b6d6dSopenharmony_ci log_err("String does not match u->%s\n", gNuConvTestName); 5082e5b6d6dSopenharmony_ci printUSeqErr(source, sourceLen); 5092e5b6d6dSopenharmony_ci fprintf(stderr, "Got:\n"); 5102e5b6d6dSopenharmony_ci printSeqErr((const unsigned char *)junkout, expectLen); 5112e5b6d6dSopenharmony_ci fprintf(stderr, "Expected:\n"); 5122e5b6d6dSopenharmony_ci printSeqErr((const unsigned char *)expect, expectLen); 5132e5b6d6dSopenharmony_ci 5142e5b6d6dSopenharmony_ci return TC_MISMATCH; 5152e5b6d6dSopenharmony_ci } 5162e5b6d6dSopenharmony_ci} 5172e5b6d6dSopenharmony_ci 5182e5b6d6dSopenharmony_ci/* Note: This function uses global variables and it will not do offset 5192e5b6d6dSopenharmony_cichecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */ 5202e5b6d6dSopenharmony_cistatic ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen, 5212e5b6d6dSopenharmony_ci const char *codepage, const int32_t *expectOffsets, UBool useFallback) 5222e5b6d6dSopenharmony_ci{ 5232e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5242e5b6d6dSopenharmony_ci UConverter *conv = 0; 5252e5b6d6dSopenharmony_ci UChar junkout[NEW_MAX_BUFFER]; /* FIX */ 5262e5b6d6dSopenharmony_ci int32_t junokout[NEW_MAX_BUFFER]; /* FIX */ 5272e5b6d6dSopenharmony_ci const char *src; 5282e5b6d6dSopenharmony_ci const char *realSourceEnd; 5292e5b6d6dSopenharmony_ci const char *srcLimit; 5302e5b6d6dSopenharmony_ci UChar *p; 5312e5b6d6dSopenharmony_ci UChar *targ; 5322e5b6d6dSopenharmony_ci UChar *end; 5332e5b6d6dSopenharmony_ci int32_t *offs; 5342e5b6d6dSopenharmony_ci int i; 5352e5b6d6dSopenharmony_ci UBool checkOffsets = true; 5362e5b6d6dSopenharmony_ci 5372e5b6d6dSopenharmony_ci int32_t realBufferSize; 5382e5b6d6dSopenharmony_ci UChar *realBufferEnd; 5392e5b6d6dSopenharmony_ci 5402e5b6d6dSopenharmony_ci 5412e5b6d6dSopenharmony_ci for(i=0;i<NEW_MAX_BUFFER;i++) 5422e5b6d6dSopenharmony_ci junkout[i] = 0xFFFE; 5432e5b6d6dSopenharmony_ci 5442e5b6d6dSopenharmony_ci for(i=0;i<NEW_MAX_BUFFER;i++) 5452e5b6d6dSopenharmony_ci junokout[i] = -1; 5462e5b6d6dSopenharmony_ci 5472e5b6d6dSopenharmony_ci setNuConvTestName(codepage, "TO"); 5482e5b6d6dSopenharmony_ci 5492e5b6d6dSopenharmony_ci log_verbose("\n========= %s\n", gNuConvTestName); 5502e5b6d6dSopenharmony_ci 5512e5b6d6dSopenharmony_ci conv = my_ucnv_open(codepage, &status); 5522e5b6d6dSopenharmony_ci 5532e5b6d6dSopenharmony_ci if(U_FAILURE(status)) 5542e5b6d6dSopenharmony_ci { 5552e5b6d6dSopenharmony_ci log_data_err("Couldn't open converter %s\n",gNuConvTestName); 5562e5b6d6dSopenharmony_ci return TC_FAIL; 5572e5b6d6dSopenharmony_ci } 5582e5b6d6dSopenharmony_ci if(useFallback){ 5592e5b6d6dSopenharmony_ci ucnv_setFallback(conv,useFallback); 5602e5b6d6dSopenharmony_ci } 5612e5b6d6dSopenharmony_ci log_verbose("Converter opened..\n"); 5622e5b6d6dSopenharmony_ci 5632e5b6d6dSopenharmony_ci src = (const char *)source; 5642e5b6d6dSopenharmony_ci targ = junkout; 5652e5b6d6dSopenharmony_ci offs = junokout; 5662e5b6d6dSopenharmony_ci 5672e5b6d6dSopenharmony_ci realBufferSize = UPRV_LENGTHOF(junkout); 5682e5b6d6dSopenharmony_ci realBufferEnd = junkout + realBufferSize; 5692e5b6d6dSopenharmony_ci realSourceEnd = src + sourcelen; 5702e5b6d6dSopenharmony_ci 5712e5b6d6dSopenharmony_ci if ( gOutBufferSize != realBufferSize || gInBufferSize != NEW_MAX_BUFFER ) 5722e5b6d6dSopenharmony_ci checkOffsets = false; 5732e5b6d6dSopenharmony_ci 5742e5b6d6dSopenharmony_ci do 5752e5b6d6dSopenharmony_ci { 5762e5b6d6dSopenharmony_ci end = nct_min( targ + gOutBufferSize, realBufferEnd); 5772e5b6d6dSopenharmony_ci srcLimit = nct_min(realSourceEnd, src + gInBufferSize); 5782e5b6d6dSopenharmony_ci 5792e5b6d6dSopenharmony_ci if(targ == realBufferEnd) 5802e5b6d6dSopenharmony_ci { 5812e5b6d6dSopenharmony_ci log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjet=%08lx %s",targ,gNuConvTestName); 5822e5b6d6dSopenharmony_ci return TC_FAIL; 5832e5b6d6dSopenharmony_ci } 5842e5b6d6dSopenharmony_ci log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end); 5852e5b6d6dSopenharmony_ci 5862e5b6d6dSopenharmony_ci /* oldTarg = targ; */ 5872e5b6d6dSopenharmony_ci 5882e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 5892e5b6d6dSopenharmony_ci 5902e5b6d6dSopenharmony_ci ucnv_toUnicode (conv, 5912e5b6d6dSopenharmony_ci &targ, 5922e5b6d6dSopenharmony_ci end, 5932e5b6d6dSopenharmony_ci &src, 5942e5b6d6dSopenharmony_ci srcLimit, 5952e5b6d6dSopenharmony_ci checkOffsets ? offs : NULL, 5962e5b6d6dSopenharmony_ci (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */ 5972e5b6d6dSopenharmony_ci &status); 5982e5b6d6dSopenharmony_ci 5992e5b6d6dSopenharmony_ci /* offs += (targ-oldTarg); */ 6002e5b6d6dSopenharmony_ci 6012e5b6d6dSopenharmony_ci } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */ 6022e5b6d6dSopenharmony_ci 6032e5b6d6dSopenharmony_ci if(U_FAILURE(status)) 6042e5b6d6dSopenharmony_ci { 6052e5b6d6dSopenharmony_ci log_err("Problem doing %s toUnicode, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName); 6062e5b6d6dSopenharmony_ci return TC_FAIL; 6072e5b6d6dSopenharmony_ci } 6082e5b6d6dSopenharmony_ci 6092e5b6d6dSopenharmony_ci log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", 6102e5b6d6dSopenharmony_ci sourcelen, targ-junkout); 6112e5b6d6dSopenharmony_ci if(getTestOption(VERBOSITY_OPTION)) 6122e5b6d6dSopenharmony_ci { 6132e5b6d6dSopenharmony_ci char junk[9999]; 6142e5b6d6dSopenharmony_ci char offset_str[9999]; 6152e5b6d6dSopenharmony_ci UChar *ptr; 6162e5b6d6dSopenharmony_ci 6172e5b6d6dSopenharmony_ci junk[0] = 0; 6182e5b6d6dSopenharmony_ci offset_str[0] = 0; 6192e5b6d6dSopenharmony_ci 6202e5b6d6dSopenharmony_ci for(ptr = junkout;ptr<targ;ptr++) 6212e5b6d6dSopenharmony_ci { 6222e5b6d6dSopenharmony_ci sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*ptr); 6232e5b6d6dSopenharmony_ci sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[ptr-junkout]); 6242e5b6d6dSopenharmony_ci } 6252e5b6d6dSopenharmony_ci 6262e5b6d6dSopenharmony_ci log_verbose(junk); 6272e5b6d6dSopenharmony_ci printUSeq(expect, expectlen); 6282e5b6d6dSopenharmony_ci if ( checkOffsets ) 6292e5b6d6dSopenharmony_ci { 6302e5b6d6dSopenharmony_ci log_verbose("\nOffsets:"); 6312e5b6d6dSopenharmony_ci log_verbose(offset_str); 6322e5b6d6dSopenharmony_ci } 6332e5b6d6dSopenharmony_ci log_verbose("\n"); 6342e5b6d6dSopenharmony_ci } 6352e5b6d6dSopenharmony_ci ucnv_close(conv); 6362e5b6d6dSopenharmony_ci 6372e5b6d6dSopenharmony_ci log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2); 6382e5b6d6dSopenharmony_ci 6392e5b6d6dSopenharmony_ci if (checkOffsets && (expectOffsets != 0)) 6402e5b6d6dSopenharmony_ci { 6412e5b6d6dSopenharmony_ci if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t))){ 6422e5b6d6dSopenharmony_ci log_err("did not get the expected offsets. %s\n",gNuConvTestName); 6432e5b6d6dSopenharmony_ci log_err("Got: "); 6442e5b6d6dSopenharmony_ci for(p=junkout;p<targ;p++) { 6452e5b6d6dSopenharmony_ci log_err("%d,", junokout[p-junkout]); 6462e5b6d6dSopenharmony_ci } 6472e5b6d6dSopenharmony_ci log_err("\n"); 6482e5b6d6dSopenharmony_ci log_err("Expected: "); 6492e5b6d6dSopenharmony_ci for(i=0; i<(targ-junkout); i++) { 6502e5b6d6dSopenharmony_ci log_err("%d,", expectOffsets[i]); 6512e5b6d6dSopenharmony_ci } 6522e5b6d6dSopenharmony_ci log_err("\n"); 6532e5b6d6dSopenharmony_ci log_err("output: "); 6542e5b6d6dSopenharmony_ci for(i=0; i<(targ-junkout); i++) { 6552e5b6d6dSopenharmony_ci log_err("%X,", junkout[i]); 6562e5b6d6dSopenharmony_ci } 6572e5b6d6dSopenharmony_ci log_err("\n"); 6582e5b6d6dSopenharmony_ci log_err("input: "); 6592e5b6d6dSopenharmony_ci for(i=0; i<(src-(const char *)source); i++) { 6602e5b6d6dSopenharmony_ci log_err("%X,", (unsigned char)source[i]); 6612e5b6d6dSopenharmony_ci } 6622e5b6d6dSopenharmony_ci log_err("\n"); 6632e5b6d6dSopenharmony_ci } 6642e5b6d6dSopenharmony_ci } 6652e5b6d6dSopenharmony_ci 6662e5b6d6dSopenharmony_ci if(!memcmp(junkout, expect, expectlen*2)) 6672e5b6d6dSopenharmony_ci { 6682e5b6d6dSopenharmony_ci log_verbose("Matches!\n"); 6692e5b6d6dSopenharmony_ci return TC_OK; 6702e5b6d6dSopenharmony_ci } 6712e5b6d6dSopenharmony_ci else 6722e5b6d6dSopenharmony_ci { 6732e5b6d6dSopenharmony_ci log_err("String does not match. %s\n", gNuConvTestName); 6742e5b6d6dSopenharmony_ci log_verbose("String does not match. %s\n", gNuConvTestName); 6752e5b6d6dSopenharmony_ci printf("\nGot:"); 6762e5b6d6dSopenharmony_ci printUSeqErr(junkout, expectlen); 6772e5b6d6dSopenharmony_ci printf("\nExpected:"); 6782e5b6d6dSopenharmony_ci printUSeqErr(expect, expectlen); 6792e5b6d6dSopenharmony_ci return TC_MISMATCH; 6802e5b6d6dSopenharmony_ci } 6812e5b6d6dSopenharmony_ci} 6822e5b6d6dSopenharmony_ci 6832e5b6d6dSopenharmony_ci 6842e5b6d6dSopenharmony_cistatic void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 6852e5b6d6dSopenharmony_ci{ 6862e5b6d6dSopenharmony_ci/** test chars #1 */ 6872e5b6d6dSopenharmony_ci /* 1 2 3 1Han 2Han 3Han . */ 6882e5b6d6dSopenharmony_ci static const UChar sampleText[] = 6892e5b6d6dSopenharmony_ci { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xD840, 0xDC21 }; 6902e5b6d6dSopenharmony_ci static const UChar sampleTextRoundTripUnmappable[] = 6912e5b6d6dSopenharmony_ci { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xfffd }; 6922e5b6d6dSopenharmony_ci 6932e5b6d6dSopenharmony_ci 6942e5b6d6dSopenharmony_ci static const uint8_t expectedUTF8[] = 6952e5b6d6dSopenharmony_ci { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E, 0xf0, 0xa0, 0x80, 0xa1 }; 6962e5b6d6dSopenharmony_ci static const int32_t toUTF8Offs[] = 6972e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x08, 0x08, 0x08, 0x08 }; 6982e5b6d6dSopenharmony_ci static const int32_t fmUTF8Offs[] = 6992e5b6d6dSopenharmony_ci { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d, 0x000e, 0x000e }; 7002e5b6d6dSopenharmony_ci 7012e5b6d6dSopenharmony_ci#ifdef U_ENABLE_GENERIC_ISO_2022 7022e5b6d6dSopenharmony_ci /* Same as UTF8, but with ^[%B preceding */ 7032e5b6d6dSopenharmony_ci static const const uint8_t expectedISO2022[] = 7042e5b6d6dSopenharmony_ci { 0x1b, 0x25, 0x42, 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E }; 7052e5b6d6dSopenharmony_ci static const int32_t toISO2022Offs[] = 7062e5b6d6dSopenharmony_ci { -1, -1, -1, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 7072e5b6d6dSopenharmony_ci 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07 }; /* right? */ 7082e5b6d6dSopenharmony_ci static const int32_t fmISO2022Offs[] = 7092e5b6d6dSopenharmony_ci { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x000a, 0x000d, 0x0010 }; /* is this right? */ 7102e5b6d6dSopenharmony_ci#endif 7112e5b6d6dSopenharmony_ci 7122e5b6d6dSopenharmony_ci /* 1 2 3 0, <SO> h1 h2 h3 <SI> . EBCDIC_STATEFUL */ 7132e5b6d6dSopenharmony_ci static const uint8_t expectedIBM930[] = 7142e5b6d6dSopenharmony_ci { 0xF1, 0xF2, 0xF3, 0x00, 0x0E, 0x45, 0x41, 0x45, 0x42, 0x45, 0x43, 0x0F, 0x4B, 0x0e, 0xfe, 0xfe, 0x0f }; 7152e5b6d6dSopenharmony_ci static const int32_t toIBM930Offs[] = 7162e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, -1 }; 7172e5b6d6dSopenharmony_ci static const int32_t fmIBM930Offs[] = 7182e5b6d6dSopenharmony_ci { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009, 0x000c, 0x000e }; 7192e5b6d6dSopenharmony_ci 7202e5b6d6dSopenharmony_ci /* 1 2 3 0 h1 h2 h3 . MBCS*/ 7212e5b6d6dSopenharmony_ci static const uint8_t expectedIBM943[] = 7222e5b6d6dSopenharmony_ci { 0x31, 0x32, 0x33, 0x00, 0x88, 0xea, 0x93, 0xf1, 0x8e, 0x4f, 0x2e, 0xfc, 0xfc }; 7232e5b6d6dSopenharmony_ci static const int32_t toIBM943Offs [] = 7242e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08 }; 7252e5b6d6dSopenharmony_ci static const int32_t fmIBM943Offs[] = 7262e5b6d6dSopenharmony_ci { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0006, 0x0008, 0x000a, 0x000b }; 7272e5b6d6dSopenharmony_ci 7282e5b6d6dSopenharmony_ci /* 1 2 3 0 h1 h2 h3 . DBCS*/ 7292e5b6d6dSopenharmony_ci static const uint8_t expectedIBM9027[] = 7302e5b6d6dSopenharmony_ci { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x4c, 0x41, 0x4c, 0x48, 0x4c, 0x55, 0xfe, 0xfe, 0xfe, 0xfe }; 7312e5b6d6dSopenharmony_ci static const int32_t toIBM9027Offs [] = 7322e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08 }; 7332e5b6d6dSopenharmony_ci 7342e5b6d6dSopenharmony_ci /* 1 2 3 0 <?> <?> <?> . SBCS*/ 7352e5b6d6dSopenharmony_ci static const uint8_t expectedIBM920[] = 7362e5b6d6dSopenharmony_ci { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2e, 0x1a }; 7372e5b6d6dSopenharmony_ci static const int32_t toIBM920Offs [] = 7382e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; 7392e5b6d6dSopenharmony_ci 7402e5b6d6dSopenharmony_ci /* 1 2 3 0 <?> <?> <?> . SBCS*/ 7412e5b6d6dSopenharmony_ci static const uint8_t expectedISO88593[] = 7422e5b6d6dSopenharmony_ci { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a }; 7432e5b6d6dSopenharmony_ci static const int32_t toISO88593Offs[] = 7442e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; 7452e5b6d6dSopenharmony_ci 7462e5b6d6dSopenharmony_ci /* 1 2 3 0 <?> <?> <?> . <?> LATIN_1*/ 7472e5b6d6dSopenharmony_ci static const uint8_t expectedLATIN1[] = 7482e5b6d6dSopenharmony_ci { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a }; 7492e5b6d6dSopenharmony_ci static const int32_t toLATIN1Offs[] = 7502e5b6d6dSopenharmony_ci { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; 7512e5b6d6dSopenharmony_ci 7522e5b6d6dSopenharmony_ci 7532e5b6d6dSopenharmony_ci /* etc */ 7542e5b6d6dSopenharmony_ci static const uint8_t expectedUTF16BE[] = 7552e5b6d6dSopenharmony_ci { 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x4e, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x00, 0x2e, 0xd8, 0x40, 0xdc, 0x21 }; 7562e5b6d6dSopenharmony_ci static const int32_t toUTF16BEOffs[]= 7572e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 }; 7582e5b6d6dSopenharmony_ci static const int32_t fmUTF16BEOffs[] = 7592e5b6d6dSopenharmony_ci { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 }; 7602e5b6d6dSopenharmony_ci 7612e5b6d6dSopenharmony_ci static const uint8_t expectedUTF16LE[] = 7622e5b6d6dSopenharmony_ci { 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0x2e, 0x00, 0x40, 0xd8, 0x21, 0xdc }; 7632e5b6d6dSopenharmony_ci static const int32_t toUTF16LEOffs[]= 7642e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 }; 7652e5b6d6dSopenharmony_ci static const int32_t fmUTF16LEOffs[] = 7662e5b6d6dSopenharmony_ci { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 }; 7672e5b6d6dSopenharmony_ci 7682e5b6d6dSopenharmony_ci static const uint8_t expectedUTF32BE[] = 7692e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x00, 0x31, 7702e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x32, 7712e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x33, 7722e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x00, 7732e5b6d6dSopenharmony_ci 0x00, 0x00, 0x4e, 0x00, 7742e5b6d6dSopenharmony_ci 0x00, 0x00, 0x4e, 0x8c, 7752e5b6d6dSopenharmony_ci 0x00, 0x00, 0x4e, 0x09, 7762e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x2e, 7772e5b6d6dSopenharmony_ci 0x00, 0x02, 0x00, 0x21 }; 7782e5b6d6dSopenharmony_ci static const int32_t toUTF32BEOffs[]= 7792e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 7802e5b6d6dSopenharmony_ci 0x01, 0x01, 0x01, 0x01, 7812e5b6d6dSopenharmony_ci 0x02, 0x02, 0x02, 0x02, 7822e5b6d6dSopenharmony_ci 0x03, 0x03, 0x03, 0x03, 7832e5b6d6dSopenharmony_ci 0x04, 0x04, 0x04, 0x04, 7842e5b6d6dSopenharmony_ci 0x05, 0x05, 0x05, 0x05, 7852e5b6d6dSopenharmony_ci 0x06, 0x06, 0x06, 0x06, 7862e5b6d6dSopenharmony_ci 0x07, 0x07, 0x07, 0x07, 7872e5b6d6dSopenharmony_ci 0x08, 0x08, 0x08, 0x08, 7882e5b6d6dSopenharmony_ci 0x08, 0x08, 0x08, 0x08 }; 7892e5b6d6dSopenharmony_ci static const int32_t fmUTF32BEOffs[] = 7902e5b6d6dSopenharmony_ci { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 }; 7912e5b6d6dSopenharmony_ci 7922e5b6d6dSopenharmony_ci static const uint8_t expectedUTF32LE[] = 7932e5b6d6dSopenharmony_ci { 0x31, 0x00, 0x00, 0x00, 7942e5b6d6dSopenharmony_ci 0x32, 0x00, 0x00, 0x00, 7952e5b6d6dSopenharmony_ci 0x33, 0x00, 0x00, 0x00, 7962e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x00, 7972e5b6d6dSopenharmony_ci 0x00, 0x4e, 0x00, 0x00, 7982e5b6d6dSopenharmony_ci 0x8c, 0x4e, 0x00, 0x00, 7992e5b6d6dSopenharmony_ci 0x09, 0x4e, 0x00, 0x00, 8002e5b6d6dSopenharmony_ci 0x2e, 0x00, 0x00, 0x00, 8012e5b6d6dSopenharmony_ci 0x21, 0x00, 0x02, 0x00 }; 8022e5b6d6dSopenharmony_ci static const int32_t toUTF32LEOffs[]= 8032e5b6d6dSopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 8042e5b6d6dSopenharmony_ci 0x01, 0x01, 0x01, 0x01, 8052e5b6d6dSopenharmony_ci 0x02, 0x02, 0x02, 0x02, 8062e5b6d6dSopenharmony_ci 0x03, 0x03, 0x03, 0x03, 8072e5b6d6dSopenharmony_ci 0x04, 0x04, 0x04, 0x04, 8082e5b6d6dSopenharmony_ci 0x05, 0x05, 0x05, 0x05, 8092e5b6d6dSopenharmony_ci 0x06, 0x06, 0x06, 0x06, 8102e5b6d6dSopenharmony_ci 0x07, 0x07, 0x07, 0x07, 8112e5b6d6dSopenharmony_ci 0x08, 0x08, 0x08, 0x08, 8122e5b6d6dSopenharmony_ci 0x08, 0x08, 0x08, 0x08 }; 8132e5b6d6dSopenharmony_ci static const int32_t fmUTF32LEOffs[] = 8142e5b6d6dSopenharmony_ci { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 }; 8152e5b6d6dSopenharmony_ci 8162e5b6d6dSopenharmony_ci 8172e5b6d6dSopenharmony_ci 8182e5b6d6dSopenharmony_ci 8192e5b6d6dSopenharmony_ci/** Test chars #2 **/ 8202e5b6d6dSopenharmony_ci 8212e5b6d6dSopenharmony_ci /* Sahha [health], slashed h's */ 8222e5b6d6dSopenharmony_ci static const UChar malteseUChars[] = { 0x0053, 0x0061, 0x0127, 0x0127, 0x0061 }; 8232e5b6d6dSopenharmony_ci static const uint8_t expectedMaltese913[] = { 0x53, 0x61, 0xB1, 0xB1, 0x61 }; 8242e5b6d6dSopenharmony_ci 8252e5b6d6dSopenharmony_ci /* LMBCS */ 8262e5b6d6dSopenharmony_ci static const UChar LMBCSUChars[] = { 0x0027, 0x010A, 0x0000, 0x0127, 0x2666, 0x0220 }; 8272e5b6d6dSopenharmony_ci static const uint8_t expectedLMBCS[] = { 0x27, 0x06, 0x04, 0x00, 0x01, 0x73, 0x01, 0x04, 0x14, 0x02, 0x20 }; 8282e5b6d6dSopenharmony_ci static const int32_t toLMBCSOffs[] = { 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x04 , 0x05, 0x05, 0x05 }; 8292e5b6d6dSopenharmony_ci static const int32_t fmLMBCSOffs[] = { 0x0000, 0x0001, 0x0003, 0x0004, 0x0006, 0x0008}; 8302e5b6d6dSopenharmony_ci /*********************************** START OF CODE finally *************/ 8312e5b6d6dSopenharmony_ci 8322e5b6d6dSopenharmony_ci gInBufferSize = insize; 8332e5b6d6dSopenharmony_ci gOutBufferSize = outsize; 8342e5b6d6dSopenharmony_ci 8352e5b6d6dSopenharmony_ci log_verbose("\n\n\nTesting conversions with InputBufferSize = %d, OutputBufferSize = %d\n", gInBufferSize, gOutBufferSize); 8362e5b6d6dSopenharmony_ci 8372e5b6d6dSopenharmony_ci 8382e5b6d6dSopenharmony_ci /*UTF-8*/ 8392e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8402e5b6d6dSopenharmony_ci expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs,false ); 8412e5b6d6dSopenharmony_ci 8422e5b6d6dSopenharmony_ci log_verbose("Test surrogate behaviour for UTF8\n"); 8432e5b6d6dSopenharmony_ci { 8442e5b6d6dSopenharmony_ci static const UChar testinput[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01 }; 8452e5b6d6dSopenharmony_ci static const uint8_t expectedUTF8test2[]= { 0xe2, 0x82, 0xac, 8462e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x90, 0x81, 8472e5b6d6dSopenharmony_ci 0xef, 0xbf, 0xbd 8482e5b6d6dSopenharmony_ci }; 8492e5b6d6dSopenharmony_ci static const int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3 }; 8502e5b6d6dSopenharmony_ci testConvertFromU(testinput, UPRV_LENGTHOF(testinput), 8512e5b6d6dSopenharmony_ci expectedUTF8test2, sizeof(expectedUTF8test2), "UTF8", offsets,false ); 8522e5b6d6dSopenharmony_ci 8532e5b6d6dSopenharmony_ci 8542e5b6d6dSopenharmony_ci } 8552e5b6d6dSopenharmony_ci 8562e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022) 8572e5b6d6dSopenharmony_ci /*ISO-2022*/ 8582e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8592e5b6d6dSopenharmony_ci expectedISO2022, sizeof(expectedISO2022), "ISO_2022", toISO2022Offs,false ); 8602e5b6d6dSopenharmony_ci#endif 8612e5b6d6dSopenharmony_ci 8622e5b6d6dSopenharmony_ci /*UTF16 LE*/ 8632e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8642e5b6d6dSopenharmony_ci expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs,false ); 8652e5b6d6dSopenharmony_ci /*UTF16 BE*/ 8662e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8672e5b6d6dSopenharmony_ci expectedUTF16BE, sizeof(expectedUTF16BE), "utf-16be", toUTF16BEOffs,false ); 8682e5b6d6dSopenharmony_ci /*UTF32 LE*/ 8692e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8702e5b6d6dSopenharmony_ci expectedUTF32LE, sizeof(expectedUTF32LE), "utf-32le", toUTF32LEOffs,false ); 8712e5b6d6dSopenharmony_ci /*UTF32 BE*/ 8722e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8732e5b6d6dSopenharmony_ci expectedUTF32BE, sizeof(expectedUTF32BE), "utf-32be", toUTF32BEOffs,false ); 8742e5b6d6dSopenharmony_ci 8752e5b6d6dSopenharmony_ci /*LATIN_1*/ 8762e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8772e5b6d6dSopenharmony_ci expectedLATIN1, sizeof(expectedLATIN1), "LATIN_1", toLATIN1Offs,false ); 8782e5b6d6dSopenharmony_ci 8792e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 8802e5b6d6dSopenharmony_ci /*EBCDIC_STATEFUL*/ 8812e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8822e5b6d6dSopenharmony_ci expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs,false ); 8832e5b6d6dSopenharmony_ci 8842e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8852e5b6d6dSopenharmony_ci expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,false ); 8862e5b6d6dSopenharmony_ci 8872e5b6d6dSopenharmony_ci /*MBCS*/ 8882e5b6d6dSopenharmony_ci 8892e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8902e5b6d6dSopenharmony_ci expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs,false ); 8912e5b6d6dSopenharmony_ci /*DBCS*/ 8922e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8932e5b6d6dSopenharmony_ci expectedIBM9027, sizeof(expectedIBM9027), "@ibm9027", toIBM9027Offs,false ); 8942e5b6d6dSopenharmony_ci /*SBCS*/ 8952e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8962e5b6d6dSopenharmony_ci expectedIBM920, sizeof(expectedIBM920), "ibm-920", toIBM920Offs,false ); 8972e5b6d6dSopenharmony_ci /*SBCS*/ 8982e5b6d6dSopenharmony_ci testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), 8992e5b6d6dSopenharmony_ci expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,false ); 9002e5b6d6dSopenharmony_ci#endif 9012e5b6d6dSopenharmony_ci 9022e5b6d6dSopenharmony_ci 9032e5b6d6dSopenharmony_ci/****/ 9042e5b6d6dSopenharmony_ci 9052e5b6d6dSopenharmony_ci /*UTF-8*/ 9062e5b6d6dSopenharmony_ci testConvertToU(expectedUTF8, sizeof(expectedUTF8), 9072e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf8", fmUTF8Offs,false); 9082e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022) 9092e5b6d6dSopenharmony_ci /*ISO-2022*/ 9102e5b6d6dSopenharmony_ci testConvertToU(expectedISO2022, sizeof(expectedISO2022), 9112e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "ISO_2022", fmISO2022Offs,false); 9122e5b6d6dSopenharmony_ci#endif 9132e5b6d6dSopenharmony_ci 9142e5b6d6dSopenharmony_ci /*UTF16 LE*/ 9152e5b6d6dSopenharmony_ci testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE), 9162e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf-16le", fmUTF16LEOffs,false); 9172e5b6d6dSopenharmony_ci /*UTF16 BE*/ 9182e5b6d6dSopenharmony_ci testConvertToU(expectedUTF16BE, sizeof(expectedUTF16BE), 9192e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf-16be", fmUTF16BEOffs,false); 9202e5b6d6dSopenharmony_ci /*UTF32 LE*/ 9212e5b6d6dSopenharmony_ci testConvertToU(expectedUTF32LE, sizeof(expectedUTF32LE), 9222e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf-32le", fmUTF32LEOffs,false); 9232e5b6d6dSopenharmony_ci /*UTF32 BE*/ 9242e5b6d6dSopenharmony_ci testConvertToU(expectedUTF32BE, sizeof(expectedUTF32BE), 9252e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf-32be", fmUTF32BEOffs,false); 9262e5b6d6dSopenharmony_ci 9272e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 9282e5b6d6dSopenharmony_ci /*EBCDIC_STATEFUL*/ 9292e5b6d6dSopenharmony_ci testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleTextRoundTripUnmappable, 9302e5b6d6dSopenharmony_ci UPRV_LENGTHOF(sampleTextRoundTripUnmappable), "ibm-930", fmIBM930Offs,false); 9312e5b6d6dSopenharmony_ci /*MBCS*/ 9322e5b6d6dSopenharmony_ci testConvertToU(expectedIBM943, sizeof(expectedIBM943),sampleTextRoundTripUnmappable, 9332e5b6d6dSopenharmony_ci UPRV_LENGTHOF(sampleTextRoundTripUnmappable), "ibm-943", fmIBM943Offs,false); 9342e5b6d6dSopenharmony_ci#endif 9352e5b6d6dSopenharmony_ci 9362e5b6d6dSopenharmony_ci /* Try it again to make sure it still works */ 9372e5b6d6dSopenharmony_ci testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE), 9382e5b6d6dSopenharmony_ci sampleText, UPRV_LENGTHOF(sampleText), "utf-16le", fmUTF16LEOffs,false); 9392e5b6d6dSopenharmony_ci 9402e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 9412e5b6d6dSopenharmony_ci testConvertToU(expectedMaltese913, sizeof(expectedMaltese913), 9422e5b6d6dSopenharmony_ci malteseUChars, UPRV_LENGTHOF(malteseUChars), "latin3", NULL,false); 9432e5b6d6dSopenharmony_ci 9442e5b6d6dSopenharmony_ci testConvertFromU(malteseUChars, UPRV_LENGTHOF(malteseUChars), 9452e5b6d6dSopenharmony_ci expectedMaltese913, sizeof(expectedMaltese913), "iso-8859-3", NULL,false ); 9462e5b6d6dSopenharmony_ci 9472e5b6d6dSopenharmony_ci /*LMBCS*/ 9482e5b6d6dSopenharmony_ci testConvertFromU(LMBCSUChars, UPRV_LENGTHOF(LMBCSUChars), 9492e5b6d6dSopenharmony_ci expectedLMBCS, sizeof(expectedLMBCS), "LMBCS-1", toLMBCSOffs,false ); 9502e5b6d6dSopenharmony_ci testConvertToU(expectedLMBCS, sizeof(expectedLMBCS), 9512e5b6d6dSopenharmony_ci LMBCSUChars, UPRV_LENGTHOF(LMBCSUChars), "LMBCS-1", fmLMBCSOffs,false); 9522e5b6d6dSopenharmony_ci#endif 9532e5b6d6dSopenharmony_ci 9542e5b6d6dSopenharmony_ci /* UTF-7 examples are mostly from http://www.imc.org/rfc2152 */ 9552e5b6d6dSopenharmony_ci { 9562e5b6d6dSopenharmony_ci /* encode directly set D and set O */ 9572e5b6d6dSopenharmony_ci static const uint8_t utf7[] = { 9582e5b6d6dSopenharmony_ci /* 9592e5b6d6dSopenharmony_ci Hi Mom -+Jjo--! 9602e5b6d6dSopenharmony_ci A+ImIDkQ. 9612e5b6d6dSopenharmony_ci +- 9622e5b6d6dSopenharmony_ci +ZeVnLIqe- 9632e5b6d6dSopenharmony_ci */ 9642e5b6d6dSopenharmony_ci 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21, 9652e5b6d6dSopenharmony_ci 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 9662e5b6d6dSopenharmony_ci 0x2b, 0x2d, 9672e5b6d6dSopenharmony_ci 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d 9682e5b6d6dSopenharmony_ci }; 9692e5b6d6dSopenharmony_ci static const UChar unicode[] = { 9702e5b6d6dSopenharmony_ci /* 9712e5b6d6dSopenharmony_ci Hi Mom -<WHITE SMILING FACE>-! 9722e5b6d6dSopenharmony_ci A<NOT IDENTICAL TO><ALPHA>. 9732e5b6d6dSopenharmony_ci + 9742e5b6d6dSopenharmony_ci [Japanese word "nihongo"] 9752e5b6d6dSopenharmony_ci */ 9762e5b6d6dSopenharmony_ci 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21, 9772e5b6d6dSopenharmony_ci 0x41, 0x2262, 0x0391, 0x2e, 9782e5b6d6dSopenharmony_ci 0x2b, 9792e5b6d6dSopenharmony_ci 0x65e5, 0x672c, 0x8a9e 9802e5b6d6dSopenharmony_ci }; 9812e5b6d6dSopenharmony_ci static const int32_t toUnicodeOffsets[] = { 9822e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14, 9832e5b6d6dSopenharmony_ci 15, 17, 19, 23, 9842e5b6d6dSopenharmony_ci 24, 9852e5b6d6dSopenharmony_ci 27, 29, 32 9862e5b6d6dSopenharmony_ci }; 9872e5b6d6dSopenharmony_ci static const int32_t fromUnicodeOffsets[] = { 9882e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 9892e5b6d6dSopenharmony_ci 11, 12, 12, 12, 13, 13, 13, 13, 14, 9902e5b6d6dSopenharmony_ci 15, 15, 9912e5b6d6dSopenharmony_ci 16, 16, 16, 17, 17, 17, 18, 18, 18, 18 9922e5b6d6dSopenharmony_ci }; 9932e5b6d6dSopenharmony_ci 9942e5b6d6dSopenharmony_ci /* same but escaping set O (the exclamation mark) */ 9952e5b6d6dSopenharmony_ci static const uint8_t utf7Restricted[] = { 9962e5b6d6dSopenharmony_ci /* 9972e5b6d6dSopenharmony_ci Hi Mom -+Jjo--+ACE- 9982e5b6d6dSopenharmony_ci A+ImIDkQ. 9992e5b6d6dSopenharmony_ci +- 10002e5b6d6dSopenharmony_ci +ZeVnLIqe- 10012e5b6d6dSopenharmony_ci */ 10022e5b6d6dSopenharmony_ci 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d, 10032e5b6d6dSopenharmony_ci 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 10042e5b6d6dSopenharmony_ci 0x2b, 0x2d, 10052e5b6d6dSopenharmony_ci 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d 10062e5b6d6dSopenharmony_ci }; 10072e5b6d6dSopenharmony_ci static const int32_t toUnicodeOffsetsR[] = { 10082e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15, 10092e5b6d6dSopenharmony_ci 19, 21, 23, 27, 10102e5b6d6dSopenharmony_ci 28, 10112e5b6d6dSopenharmony_ci 31, 33, 36 10122e5b6d6dSopenharmony_ci }; 10132e5b6d6dSopenharmony_ci static const int32_t fromUnicodeOffsetsR[] = { 10142e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10, 10152e5b6d6dSopenharmony_ci 11, 12, 12, 12, 13, 13, 13, 13, 14, 10162e5b6d6dSopenharmony_ci 15, 15, 10172e5b6d6dSopenharmony_ci 16, 16, 16, 17, 17, 17, 18, 18, 18, 18 10182e5b6d6dSopenharmony_ci }; 10192e5b6d6dSopenharmony_ci 10202e5b6d6dSopenharmony_ci testConvertFromU(unicode, UPRV_LENGTHOF(unicode), utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,false); 10212e5b6d6dSopenharmony_ci 10222e5b6d6dSopenharmony_ci testConvertToU(utf7, sizeof(utf7), unicode, UPRV_LENGTHOF(unicode), "UTF-7", toUnicodeOffsets,false); 10232e5b6d6dSopenharmony_ci 10242e5b6d6dSopenharmony_ci testConvertFromU(unicode, UPRV_LENGTHOF(unicode), utf7Restricted, sizeof(utf7Restricted), "UTF-7,version=1", fromUnicodeOffsetsR,false); 10252e5b6d6dSopenharmony_ci 10262e5b6d6dSopenharmony_ci testConvertToU(utf7Restricted, sizeof(utf7Restricted), unicode, UPRV_LENGTHOF(unicode), "UTF-7,version=1", toUnicodeOffsetsR,false); 10272e5b6d6dSopenharmony_ci } 10282e5b6d6dSopenharmony_ci 10292e5b6d6dSopenharmony_ci /* 10302e5b6d6dSopenharmony_ci * IMAP-mailbox-name examples are mostly from http://www.imc.org/rfc2152, 10312e5b6d6dSopenharmony_ci * modified according to RFC 2060, 10322e5b6d6dSopenharmony_ci * and supplemented with the one example in RFC 2060 itself. 10332e5b6d6dSopenharmony_ci */ 10342e5b6d6dSopenharmony_ci { 10352e5b6d6dSopenharmony_ci static const uint8_t imap[] = { 10362e5b6d6dSopenharmony_ci /* Hi Mom -&Jjo--! 10372e5b6d6dSopenharmony_ci A&ImIDkQ-. 10382e5b6d6dSopenharmony_ci &- 10392e5b6d6dSopenharmony_ci &ZeVnLIqe- 10402e5b6d6dSopenharmony_ci \ 10412e5b6d6dSopenharmony_ci ~peter 10422e5b6d6dSopenharmony_ci /mail 10432e5b6d6dSopenharmony_ci /&ZeVnLIqe- 10442e5b6d6dSopenharmony_ci /&U,BTFw- 10452e5b6d6dSopenharmony_ci */ 10462e5b6d6dSopenharmony_ci 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x26, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21, 10472e5b6d6dSopenharmony_ci 0x41, 0x26, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2d, 0x2e, 10482e5b6d6dSopenharmony_ci 0x26, 0x2d, 10492e5b6d6dSopenharmony_ci 0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d, 10502e5b6d6dSopenharmony_ci 0x5c, 10512e5b6d6dSopenharmony_ci 0x7e, 0x70, 0x65, 0x74, 0x65, 0x72, 10522e5b6d6dSopenharmony_ci 0x2f, 0x6d, 0x61, 0x69, 0x6c, 10532e5b6d6dSopenharmony_ci 0x2f, 0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d, 10542e5b6d6dSopenharmony_ci 0x2f, 0x26, 0x55, 0x2c, 0x42, 0x54, 0x46, 0x77, 0x2d 10552e5b6d6dSopenharmony_ci }; 10562e5b6d6dSopenharmony_ci static const UChar unicode[] = { 10572e5b6d6dSopenharmony_ci /* Hi Mom -<WHITE SMILING FACE>-! 10582e5b6d6dSopenharmony_ci A<NOT IDENTICAL TO><ALPHA>. 10592e5b6d6dSopenharmony_ci & 10602e5b6d6dSopenharmony_ci [Japanese word "nihongo"] 10612e5b6d6dSopenharmony_ci \ 10622e5b6d6dSopenharmony_ci ~peter 10632e5b6d6dSopenharmony_ci /mail 10642e5b6d6dSopenharmony_ci /<65e5, 672c, 8a9e> 10652e5b6d6dSopenharmony_ci /<53f0, 5317> 10662e5b6d6dSopenharmony_ci */ 10672e5b6d6dSopenharmony_ci 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21, 10682e5b6d6dSopenharmony_ci 0x41, 0x2262, 0x0391, 0x2e, 10692e5b6d6dSopenharmony_ci 0x26, 10702e5b6d6dSopenharmony_ci 0x65e5, 0x672c, 0x8a9e, 10712e5b6d6dSopenharmony_ci 0x5c, 10722e5b6d6dSopenharmony_ci 0x7e, 0x70, 0x65, 0x74, 0x65, 0x72, 10732e5b6d6dSopenharmony_ci 0x2f, 0x6d, 0x61, 0x69, 0x6c, 10742e5b6d6dSopenharmony_ci 0x2f, 0x65e5, 0x672c, 0x8a9e, 10752e5b6d6dSopenharmony_ci 0x2f, 0x53f0, 0x5317 10762e5b6d6dSopenharmony_ci }; 10772e5b6d6dSopenharmony_ci static const int32_t toUnicodeOffsets[] = { 10782e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14, 10792e5b6d6dSopenharmony_ci 15, 17, 19, 24, 10802e5b6d6dSopenharmony_ci 25, 10812e5b6d6dSopenharmony_ci 28, 30, 33, 10822e5b6d6dSopenharmony_ci 37, 10832e5b6d6dSopenharmony_ci 38, 39, 40, 41, 42, 43, 10842e5b6d6dSopenharmony_ci 44, 45, 46, 47, 48, 10852e5b6d6dSopenharmony_ci 49, 51, 53, 56, 10862e5b6d6dSopenharmony_ci 60, 62, 64 10872e5b6d6dSopenharmony_ci }; 10882e5b6d6dSopenharmony_ci static const int32_t fromUnicodeOffsets[] = { 10892e5b6d6dSopenharmony_ci 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10902e5b6d6dSopenharmony_ci 11, 12, 12, 12, 13, 13, 13, 13, 13, 14, 10912e5b6d6dSopenharmony_ci 15, 15, 10922e5b6d6dSopenharmony_ci 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 10932e5b6d6dSopenharmony_ci 19, 10942e5b6d6dSopenharmony_ci 20, 21, 22, 23, 24, 25, 10952e5b6d6dSopenharmony_ci 26, 27, 28, 29, 30, 10962e5b6d6dSopenharmony_ci 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34, 10972e5b6d6dSopenharmony_ci 35, 36, 36, 36, 37, 37, 37, 37, 37 10982e5b6d6dSopenharmony_ci }; 10992e5b6d6dSopenharmony_ci 11002e5b6d6dSopenharmony_ci testConvertFromU(unicode, UPRV_LENGTHOF(unicode), imap, sizeof(imap), "IMAP-mailbox-name", fromUnicodeOffsets,false); 11012e5b6d6dSopenharmony_ci 11022e5b6d6dSopenharmony_ci testConvertToU(imap, sizeof(imap), unicode, UPRV_LENGTHOF(unicode), "IMAP-mailbox-name", toUnicodeOffsets,false); 11032e5b6d6dSopenharmony_ci } 11042e5b6d6dSopenharmony_ci 11052e5b6d6dSopenharmony_ci /* Test UTF-8 bad data handling*/ 11062e5b6d6dSopenharmony_ci { 11072e5b6d6dSopenharmony_ci static const uint8_t utf8[]={ 11082e5b6d6dSopenharmony_ci 0x61, 11092e5b6d6dSopenharmony_ci 0xf7, 0xbf, 0xbf, 0xbf, /* > 10FFFF */ 11102e5b6d6dSopenharmony_ci 0x00, 11112e5b6d6dSopenharmony_ci 0x62, 11122e5b6d6dSopenharmony_ci 0xfb, 0xbf, 0xbf, 0xbf, 0xbf, /* > 10FFFF */ 11132e5b6d6dSopenharmony_ci 0xfb, 0xbf, 0xbf, 0xbf, 0xbf, /* > 10FFFF */ 11142e5b6d6dSopenharmony_ci 0xf4, 0x8f, 0xbf, 0xbf, /* 10FFFF */ 11152e5b6d6dSopenharmony_ci 0xdf, 0xbf, /* 7ff */ 11162e5b6d6dSopenharmony_ci 0xbf, /* truncated tail */ 11172e5b6d6dSopenharmony_ci 0xf4, 0x90, 0x80, 0x80, /* 110000 */ 11182e5b6d6dSopenharmony_ci 0x02 11192e5b6d6dSopenharmony_ci }; 11202e5b6d6dSopenharmony_ci 11212e5b6d6dSopenharmony_ci static const uint16_t utf8Expected[]={ 11222e5b6d6dSopenharmony_ci 0x0061, 11232e5b6d6dSopenharmony_ci 0xfffd, 0xfffd, 0xfffd, 0xfffd, 11242e5b6d6dSopenharmony_ci 0x0000, 11252e5b6d6dSopenharmony_ci 0x0062, 11262e5b6d6dSopenharmony_ci 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 11272e5b6d6dSopenharmony_ci 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 11282e5b6d6dSopenharmony_ci 0xdbff, 0xdfff, 11292e5b6d6dSopenharmony_ci 0x07ff, 11302e5b6d6dSopenharmony_ci 0xfffd, 11312e5b6d6dSopenharmony_ci 0xfffd, 0xfffd, 0xfffd, 0xfffd, 11322e5b6d6dSopenharmony_ci 0x0002 11332e5b6d6dSopenharmony_ci }; 11342e5b6d6dSopenharmony_ci 11352e5b6d6dSopenharmony_ci static const int32_t utf8Offsets[]={ 11362e5b6d6dSopenharmony_ci 0, 11372e5b6d6dSopenharmony_ci 1, 2, 3, 4, 11382e5b6d6dSopenharmony_ci 5, 11392e5b6d6dSopenharmony_ci 6, 11402e5b6d6dSopenharmony_ci 7, 8, 9, 10, 11, 11412e5b6d6dSopenharmony_ci 12, 13, 14, 15, 16, 11422e5b6d6dSopenharmony_ci 17, 17, 11432e5b6d6dSopenharmony_ci 21, 11442e5b6d6dSopenharmony_ci 23, 11452e5b6d6dSopenharmony_ci 24, 25, 26, 27, 11462e5b6d6dSopenharmony_ci 28 11472e5b6d6dSopenharmony_ci }; 11482e5b6d6dSopenharmony_ci testConvertToU(utf8, sizeof(utf8), 11492e5b6d6dSopenharmony_ci utf8Expected, UPRV_LENGTHOF(utf8Expected), "utf-8", utf8Offsets ,false); 11502e5b6d6dSopenharmony_ci 11512e5b6d6dSopenharmony_ci } 11522e5b6d6dSopenharmony_ci 11532e5b6d6dSopenharmony_ci /* Test UTF-32BE bad data handling*/ 11542e5b6d6dSopenharmony_ci { 11552e5b6d6dSopenharmony_ci static const uint8_t utf32[]={ 11562e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x61, 11572e5b6d6dSopenharmony_ci 0x00, 0x11, 0x00, 0x00, /* 0x110000 out of range */ 11582e5b6d6dSopenharmony_ci 0x00, 0x10, 0xff, 0xff, /* 0x10FFFF in range */ 11592e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x62, 11602e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0xff, /* 0xffffffff out of range */ 11612e5b6d6dSopenharmony_ci 0x7f, 0xff, 0xff, 0xff, /* 0x7fffffff out of range */ 11622e5b6d6dSopenharmony_ci 0x00, 0x00, 0x01, 0x62, 11632e5b6d6dSopenharmony_ci 0x00, 0x00, 0x02, 0x62 11642e5b6d6dSopenharmony_ci }; 11652e5b6d6dSopenharmony_ci static const uint16_t utf32Expected[]={ 11662e5b6d6dSopenharmony_ci 0x0061, 11672e5b6d6dSopenharmony_ci 0xfffd, /* 0x110000 out of range */ 11682e5b6d6dSopenharmony_ci 0xDBFF, /* 0x10FFFF in range */ 11692e5b6d6dSopenharmony_ci 0xDFFF, 11702e5b6d6dSopenharmony_ci 0x0062, 11712e5b6d6dSopenharmony_ci 0xfffd, /* 0xffffffff out of range */ 11722e5b6d6dSopenharmony_ci 0xfffd, /* 0x7fffffff out of range */ 11732e5b6d6dSopenharmony_ci 0x0162, 11742e5b6d6dSopenharmony_ci 0x0262 11752e5b6d6dSopenharmony_ci }; 11762e5b6d6dSopenharmony_ci static const int32_t utf32Offsets[]={ 11772e5b6d6dSopenharmony_ci 0, 4, 8, 8, 12, 16, 20, 24, 28 11782e5b6d6dSopenharmony_ci }; 11792e5b6d6dSopenharmony_ci static const uint8_t utf32ExpectedBack[]={ 11802e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x61, 11812e5b6d6dSopenharmony_ci 0x00, 0x00, 0xff, 0xfd, /* 0x110000 out of range */ 11822e5b6d6dSopenharmony_ci 0x00, 0x10, 0xff, 0xff, /* 0x10FFFF in range */ 11832e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x62, 11842e5b6d6dSopenharmony_ci 0x00, 0x00, 0xff, 0xfd, /* 0xffffffff out of range */ 11852e5b6d6dSopenharmony_ci 0x00, 0x00, 0xff, 0xfd, /* 0x7fffffff out of range */ 11862e5b6d6dSopenharmony_ci 0x00, 0x00, 0x01, 0x62, 11872e5b6d6dSopenharmony_ci 0x00, 0x00, 0x02, 0x62 11882e5b6d6dSopenharmony_ci }; 11892e5b6d6dSopenharmony_ci static const int32_t utf32OffsetsBack[]={ 11902e5b6d6dSopenharmony_ci 0,0,0,0, 11912e5b6d6dSopenharmony_ci 1,1,1,1, 11922e5b6d6dSopenharmony_ci 2,2,2,2, 11932e5b6d6dSopenharmony_ci 4,4,4,4, 11942e5b6d6dSopenharmony_ci 5,5,5,5, 11952e5b6d6dSopenharmony_ci 6,6,6,6, 11962e5b6d6dSopenharmony_ci 7,7,7,7, 11972e5b6d6dSopenharmony_ci 8,8,8,8 11982e5b6d6dSopenharmony_ci }; 11992e5b6d6dSopenharmony_ci 12002e5b6d6dSopenharmony_ci testConvertToU(utf32, sizeof(utf32), 12012e5b6d6dSopenharmony_ci utf32Expected, UPRV_LENGTHOF(utf32Expected), "utf-32be", utf32Offsets ,false); 12022e5b6d6dSopenharmony_ci testConvertFromU(utf32Expected, UPRV_LENGTHOF(utf32Expected), 12032e5b6d6dSopenharmony_ci utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32be", utf32OffsetsBack, false); 12042e5b6d6dSopenharmony_ci } 12052e5b6d6dSopenharmony_ci 12062e5b6d6dSopenharmony_ci /* Test UTF-32LE bad data handling*/ 12072e5b6d6dSopenharmony_ci { 12082e5b6d6dSopenharmony_ci static const uint8_t utf32[]={ 12092e5b6d6dSopenharmony_ci 0x61, 0x00, 0x00, 0x00, 12102e5b6d6dSopenharmony_ci 0x00, 0x00, 0x11, 0x00, /* 0x110000 out of range */ 12112e5b6d6dSopenharmony_ci 0xff, 0xff, 0x10, 0x00, /* 0x10FFFF in range */ 12122e5b6d6dSopenharmony_ci 0x62, 0x00, 0x00, 0x00, 12132e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0xff, /* 0xffffffff out of range */ 12142e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0x7f, /* 0x7fffffff out of range */ 12152e5b6d6dSopenharmony_ci 0x62, 0x01, 0x00, 0x00, 12162e5b6d6dSopenharmony_ci 0x62, 0x02, 0x00, 0x00, 12172e5b6d6dSopenharmony_ci }; 12182e5b6d6dSopenharmony_ci 12192e5b6d6dSopenharmony_ci static const uint16_t utf32Expected[]={ 12202e5b6d6dSopenharmony_ci 0x0061, 12212e5b6d6dSopenharmony_ci 0xfffd, /* 0x110000 out of range */ 12222e5b6d6dSopenharmony_ci 0xDBFF, /* 0x10FFFF in range */ 12232e5b6d6dSopenharmony_ci 0xDFFF, 12242e5b6d6dSopenharmony_ci 0x0062, 12252e5b6d6dSopenharmony_ci 0xfffd, /* 0xffffffff out of range */ 12262e5b6d6dSopenharmony_ci 0xfffd, /* 0x7fffffff out of range */ 12272e5b6d6dSopenharmony_ci 0x0162, 12282e5b6d6dSopenharmony_ci 0x0262 12292e5b6d6dSopenharmony_ci }; 12302e5b6d6dSopenharmony_ci static const int32_t utf32Offsets[]={ 12312e5b6d6dSopenharmony_ci 0, 4, 8, 8, 12, 16, 20, 24, 28 12322e5b6d6dSopenharmony_ci }; 12332e5b6d6dSopenharmony_ci static const uint8_t utf32ExpectedBack[]={ 12342e5b6d6dSopenharmony_ci 0x61, 0x00, 0x00, 0x00, 12352e5b6d6dSopenharmony_ci 0xfd, 0xff, 0x00, 0x00, /* 0x110000 out of range */ 12362e5b6d6dSopenharmony_ci 0xff, 0xff, 0x10, 0x00, /* 0x10FFFF in range */ 12372e5b6d6dSopenharmony_ci 0x62, 0x00, 0x00, 0x00, 12382e5b6d6dSopenharmony_ci 0xfd, 0xff, 0x00, 0x00, /* 0xffffffff out of range */ 12392e5b6d6dSopenharmony_ci 0xfd, 0xff, 0x00, 0x00, /* 0x7fffffff out of range */ 12402e5b6d6dSopenharmony_ci 0x62, 0x01, 0x00, 0x00, 12412e5b6d6dSopenharmony_ci 0x62, 0x02, 0x00, 0x00 12422e5b6d6dSopenharmony_ci }; 12432e5b6d6dSopenharmony_ci static const int32_t utf32OffsetsBack[]={ 12442e5b6d6dSopenharmony_ci 0,0,0,0, 12452e5b6d6dSopenharmony_ci 1,1,1,1, 12462e5b6d6dSopenharmony_ci 2,2,2,2, 12472e5b6d6dSopenharmony_ci 4,4,4,4, 12482e5b6d6dSopenharmony_ci 5,5,5,5, 12492e5b6d6dSopenharmony_ci 6,6,6,6, 12502e5b6d6dSopenharmony_ci 7,7,7,7, 12512e5b6d6dSopenharmony_ci 8,8,8,8 12522e5b6d6dSopenharmony_ci }; 12532e5b6d6dSopenharmony_ci testConvertToU(utf32, sizeof(utf32), 12542e5b6d6dSopenharmony_ci utf32Expected, UPRV_LENGTHOF(utf32Expected), "utf-32le", utf32Offsets,false ); 12552e5b6d6dSopenharmony_ci testConvertFromU(utf32Expected, UPRV_LENGTHOF(utf32Expected), 12562e5b6d6dSopenharmony_ci utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32le", utf32OffsetsBack, false); 12572e5b6d6dSopenharmony_ci } 12582e5b6d6dSopenharmony_ci} 12592e5b6d6dSopenharmony_ci 12602e5b6d6dSopenharmony_cistatic void TestCoverageMBCS(){ 12612e5b6d6dSopenharmony_ci#if 0 12622e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 12632e5b6d6dSopenharmony_ci const char *directory = loadTestData(&status); 12642e5b6d6dSopenharmony_ci char* tdpath = NULL; 12652e5b6d6dSopenharmony_ci char* saveDirectory = (char*)malloc(sizeof(char) *(strlen(u_getDataDirectory())+1)); 12662e5b6d6dSopenharmony_ci int len = strlen(directory); 12672e5b6d6dSopenharmony_ci char* index=NULL; 12682e5b6d6dSopenharmony_ci 12692e5b6d6dSopenharmony_ci tdpath = (char*) malloc(sizeof(char) * (len * 2)); 12702e5b6d6dSopenharmony_ci uprv_strcpy(saveDirectory,u_getDataDirectory()); 12712e5b6d6dSopenharmony_ci log_verbose("Retrieved data directory %s \n",saveDirectory); 12722e5b6d6dSopenharmony_ci uprv_strcpy(tdpath,directory); 12732e5b6d6dSopenharmony_ci index=strrchr(tdpath,(char)U_FILE_SEP_CHAR); 12742e5b6d6dSopenharmony_ci 12752e5b6d6dSopenharmony_ci if((unsigned int)(index-tdpath) != (strlen(tdpath)-1)){ 12762e5b6d6dSopenharmony_ci *(index+1)=0; 12772e5b6d6dSopenharmony_ci } 12782e5b6d6dSopenharmony_ci u_setDataDirectory(tdpath); 12792e5b6d6dSopenharmony_ci log_verbose("ICU data directory is set to: %s \n" ,tdpath); 12802e5b6d6dSopenharmony_ci#endif 12812e5b6d6dSopenharmony_ci 12822e5b6d6dSopenharmony_ci /*some more test to increase the code coverage in MBCS. Create an test converter from test1.ucm 12832e5b6d6dSopenharmony_ci which is test file for MBCS conversion with single-byte codepage data.*/ 12842e5b6d6dSopenharmony_ci { 12852e5b6d6dSopenharmony_ci 12862e5b6d6dSopenharmony_ci /* MBCS with single byte codepage data test1.ucm*/ 12872e5b6d6dSopenharmony_ci const UChar unicodeInput[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0x0003}; 12882e5b6d6dSopenharmony_ci const uint8_t expectedtest1[] = { 0x00, 0x05, 0xff, 0x07, 0xff,}; 12892e5b6d6dSopenharmony_ci int32_t totest1Offs[] = { 0, 1, 2, 3, 5, }; 12902e5b6d6dSopenharmony_ci 12912e5b6d6dSopenharmony_ci /*from Unicode*/ 12922e5b6d6dSopenharmony_ci testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), 12932e5b6d6dSopenharmony_ci expectedtest1, sizeof(expectedtest1), "@test1", totest1Offs,false ); 12942e5b6d6dSopenharmony_ci } 12952e5b6d6dSopenharmony_ci 12962e5b6d6dSopenharmony_ci /*some more test to increase the code coverage in MBCS. Create an test converter from test3.ucm 12972e5b6d6dSopenharmony_ci which is test file for MBCS conversion with three-byte codepage data.*/ 12982e5b6d6dSopenharmony_ci { 12992e5b6d6dSopenharmony_ci 13002e5b6d6dSopenharmony_ci /* MBCS with three byte codepage data test3.ucm*/ 13012e5b6d6dSopenharmony_ci const UChar unicodeInput[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e}; 13022e5b6d6dSopenharmony_ci const uint8_t expectedtest3[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x0b, 0x07, 0x01, 0x02, 0x0a, 0xff,}; 13032e5b6d6dSopenharmony_ci int32_t totest3Offs[] = { 0, 1, 2, 3, 3, 3, 4, 6, 6, 6, 8}; 13042e5b6d6dSopenharmony_ci 13052e5b6d6dSopenharmony_ci const uint8_t test3input[] = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x0b, 0x07, 0x01, 0x02, 0x0a, 0x01, 0x02, 0x0c,}; 13062e5b6d6dSopenharmony_ci const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd}; 13072e5b6d6dSopenharmony_ci int32_t fromtest3Offs[] = { 0, 1, 2, 3, 6, 6, 7, 7, 10 }; 13082e5b6d6dSopenharmony_ci 13092e5b6d6dSopenharmony_ci /*from Unicode*/ 13102e5b6d6dSopenharmony_ci testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), 13112e5b6d6dSopenharmony_ci expectedtest3, sizeof(expectedtest3), "@test3", totest3Offs,false ); 13122e5b6d6dSopenharmony_ci 13132e5b6d6dSopenharmony_ci /*to Unicode*/ 13142e5b6d6dSopenharmony_ci testConvertToU(test3input, sizeof(test3input), 13152e5b6d6dSopenharmony_ci expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test3", fromtest3Offs ,false); 13162e5b6d6dSopenharmony_ci 13172e5b6d6dSopenharmony_ci } 13182e5b6d6dSopenharmony_ci 13192e5b6d6dSopenharmony_ci /*some more test to increase the code coverage in MBCS. Create an test converter from test4.ucm 13202e5b6d6dSopenharmony_ci which is test file for MBCS conversion with four-byte codepage data.*/ 13212e5b6d6dSopenharmony_ci { 13222e5b6d6dSopenharmony_ci 13232e5b6d6dSopenharmony_ci /* MBCS with three byte codepage data test4.ucm*/ 13242e5b6d6dSopenharmony_ci static const UChar unicodeInput[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e}; 13252e5b6d6dSopenharmony_ci static const uint8_t expectedtest4[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x03, 0x0b, 0x07, 0x01, 0x02, 0x03, 0x0a, 0xff,}; 13262e5b6d6dSopenharmony_ci static const int32_t totest4Offs[] = { 0, 1, 2, 3, 3, 3, 3, 4, 6, 6, 6, 6, 8,}; 13272e5b6d6dSopenharmony_ci 13282e5b6d6dSopenharmony_ci static const uint8_t test4input[] = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x03, 0x0b, 0x07, 0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0c,}; 13292e5b6d6dSopenharmony_ci static const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd}; 13302e5b6d6dSopenharmony_ci static const int32_t fromtest4Offs[] = { 0, 1, 2, 3, 7, 7, 8, 8, 12,}; 13312e5b6d6dSopenharmony_ci 13322e5b6d6dSopenharmony_ci /*from Unicode*/ 13332e5b6d6dSopenharmony_ci testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), 13342e5b6d6dSopenharmony_ci expectedtest4, sizeof(expectedtest4), "@test4", totest4Offs,false ); 13352e5b6d6dSopenharmony_ci 13362e5b6d6dSopenharmony_ci /*to Unicode*/ 13372e5b6d6dSopenharmony_ci testConvertToU(test4input, sizeof(test4input), 13382e5b6d6dSopenharmony_ci expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test4", fromtest4Offs,false ); 13392e5b6d6dSopenharmony_ci 13402e5b6d6dSopenharmony_ci } 13412e5b6d6dSopenharmony_ci#if 0 13422e5b6d6dSopenharmony_ci free(tdpath); 13432e5b6d6dSopenharmony_ci /* restore the original data directory */ 13442e5b6d6dSopenharmony_ci log_verbose("Setting the data directory to %s \n", saveDirectory); 13452e5b6d6dSopenharmony_ci u_setDataDirectory(saveDirectory); 13462e5b6d6dSopenharmony_ci free(saveDirectory); 13472e5b6d6dSopenharmony_ci#endif 13482e5b6d6dSopenharmony_ci 13492e5b6d6dSopenharmony_ci} 13502e5b6d6dSopenharmony_ci 13512e5b6d6dSopenharmony_cistatic void TestConverterType(const char *convName, UConverterType convType) { 13522e5b6d6dSopenharmony_ci UConverter* myConverter; 13532e5b6d6dSopenharmony_ci UErrorCode err = U_ZERO_ERROR; 13542e5b6d6dSopenharmony_ci 13552e5b6d6dSopenharmony_ci myConverter = my_ucnv_open(convName, &err); 13562e5b6d6dSopenharmony_ci 13572e5b6d6dSopenharmony_ci if (U_FAILURE(err)) { 13582e5b6d6dSopenharmony_ci log_data_err("Failed to create an %s converter\n", convName); 13592e5b6d6dSopenharmony_ci return; 13602e5b6d6dSopenharmony_ci } 13612e5b6d6dSopenharmony_ci else 13622e5b6d6dSopenharmony_ci { 13632e5b6d6dSopenharmony_ci if (ucnv_getType(myConverter)!=convType) { 13642e5b6d6dSopenharmony_ci log_err("ucnv_getType Failed for %s. Got enum value 0x%X\n", 13652e5b6d6dSopenharmony_ci convName, convType); 13662e5b6d6dSopenharmony_ci } 13672e5b6d6dSopenharmony_ci else { 13682e5b6d6dSopenharmony_ci log_verbose("ucnv_getType %s ok\n", convName); 13692e5b6d6dSopenharmony_ci } 13702e5b6d6dSopenharmony_ci } 13712e5b6d6dSopenharmony_ci ucnv_close(myConverter); 13722e5b6d6dSopenharmony_ci} 13732e5b6d6dSopenharmony_ci 13742e5b6d6dSopenharmony_cistatic void TestConverterTypesAndStarters() 13752e5b6d6dSopenharmony_ci{ 13762e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 13772e5b6d6dSopenharmony_ci UConverter* myConverter; 13782e5b6d6dSopenharmony_ci UErrorCode err = U_ZERO_ERROR; 13792e5b6d6dSopenharmony_ci UBool mystarters[256]; 13802e5b6d6dSopenharmony_ci 13812e5b6d6dSopenharmony_ci/* const UBool expectedKSCstarters[256] = { 13822e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13832e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13842e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13852e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13862e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13872e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13882e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13892e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13902e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13912e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13922e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13932e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13942e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13952e5b6d6dSopenharmony_ci false, false, false, false, false, false, false, false, false, false, 13962e5b6d6dSopenharmony_ci false, false, false, true, true, true, true, true, true, true, 13972e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 13982e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 13992e5b6d6dSopenharmony_ci true, true, true, false, false, true, true, true, true, true, 14002e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14012e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14022e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14032e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14042e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14052e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14062e5b6d6dSopenharmony_ci true, true, true, true, true, true, true, true, true, true, 14072e5b6d6dSopenharmony_ci true, true, true, true, true, true};*/ 14082e5b6d6dSopenharmony_ci 14092e5b6d6dSopenharmony_ci 14102e5b6d6dSopenharmony_ci log_verbose("Testing KSC, ibm-930, ibm-878 for starters and their conversion types."); 14112e5b6d6dSopenharmony_ci 14122e5b6d6dSopenharmony_ci myConverter = ucnv_open("ksc", &err); 14132e5b6d6dSopenharmony_ci if (U_FAILURE(err)) { 14142e5b6d6dSopenharmony_ci log_data_err("Failed to create an ibm-ksc converter\n"); 14152e5b6d6dSopenharmony_ci return; 14162e5b6d6dSopenharmony_ci } 14172e5b6d6dSopenharmony_ci else 14182e5b6d6dSopenharmony_ci { 14192e5b6d6dSopenharmony_ci if (ucnv_getType(myConverter)!=UCNV_MBCS) 14202e5b6d6dSopenharmony_ci log_err("ucnv_getType Failed for ibm-949\n"); 14212e5b6d6dSopenharmony_ci else 14222e5b6d6dSopenharmony_ci log_verbose("ucnv_getType ibm-949 ok\n"); 14232e5b6d6dSopenharmony_ci 14242e5b6d6dSopenharmony_ci if(myConverter!=NULL) 14252e5b6d6dSopenharmony_ci ucnv_getStarters(myConverter, mystarters, &err); 14262e5b6d6dSopenharmony_ci 14272e5b6d6dSopenharmony_ci /*if (memcmp(expectedKSCstarters, mystarters, sizeof(expectedKSCstarters))) 14282e5b6d6dSopenharmony_ci log_err("Failed ucnv_getStarters for ksc\n"); 14292e5b6d6dSopenharmony_ci else 14302e5b6d6dSopenharmony_ci log_verbose("ucnv_getStarters ok\n");*/ 14312e5b6d6dSopenharmony_ci 14322e5b6d6dSopenharmony_ci } 14332e5b6d6dSopenharmony_ci ucnv_close(myConverter); 14342e5b6d6dSopenharmony_ci 14352e5b6d6dSopenharmony_ci TestConverterType("ibm-930", UCNV_EBCDIC_STATEFUL); 14362e5b6d6dSopenharmony_ci TestConverterType("ibm-878", UCNV_SBCS); 14372e5b6d6dSopenharmony_ci#endif 14382e5b6d6dSopenharmony_ci 14392e5b6d6dSopenharmony_ci TestConverterType("iso-8859-1", UCNV_LATIN_1); 14402e5b6d6dSopenharmony_ci 14412e5b6d6dSopenharmony_ci TestConverterType("ibm-1208", UCNV_UTF8); 14422e5b6d6dSopenharmony_ci 14432e5b6d6dSopenharmony_ci TestConverterType("utf-8", UCNV_UTF8); 14442e5b6d6dSopenharmony_ci TestConverterType("UTF-16BE", UCNV_UTF16_BigEndian); 14452e5b6d6dSopenharmony_ci TestConverterType("UTF-16LE", UCNV_UTF16_LittleEndian); 14462e5b6d6dSopenharmony_ci TestConverterType("UTF-32BE", UCNV_UTF32_BigEndian); 14472e5b6d6dSopenharmony_ci TestConverterType("UTF-32LE", UCNV_UTF32_LittleEndian); 14482e5b6d6dSopenharmony_ci 14492e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 14502e5b6d6dSopenharmony_ci 14512e5b6d6dSopenharmony_ci#if defined(U_ENABLE_GENERIC_ISO_2022) 14522e5b6d6dSopenharmony_ci TestConverterType("iso-2022", UCNV_ISO_2022); 14532e5b6d6dSopenharmony_ci#endif 14542e5b6d6dSopenharmony_ci 14552e5b6d6dSopenharmony_ci TestConverterType("hz", UCNV_HZ); 14562e5b6d6dSopenharmony_ci#endif 14572e5b6d6dSopenharmony_ci 14582e5b6d6dSopenharmony_ci TestConverterType("scsu", UCNV_SCSU); 14592e5b6d6dSopenharmony_ci 14602e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 14612e5b6d6dSopenharmony_ci TestConverterType("x-iscii-de", UCNV_ISCII); 14622e5b6d6dSopenharmony_ci#endif 14632e5b6d6dSopenharmony_ci 14642e5b6d6dSopenharmony_ci TestConverterType("ascii", UCNV_US_ASCII); 14652e5b6d6dSopenharmony_ci TestConverterType("utf-7", UCNV_UTF7); 14662e5b6d6dSopenharmony_ci TestConverterType("IMAP-mailbox-name", UCNV_IMAP_MAILBOX); 14672e5b6d6dSopenharmony_ci TestConverterType("bocu-1", UCNV_BOCU1); 14682e5b6d6dSopenharmony_ci} 14692e5b6d6dSopenharmony_ci 14702e5b6d6dSopenharmony_cistatic void 14712e5b6d6dSopenharmony_ciTestAmbiguousConverter(UConverter *cnv) { 14722e5b6d6dSopenharmony_ci static const char inBytes[3]={ 0x61, 0x5B, 0x5c }; 14732e5b6d6dSopenharmony_ci UChar outUnicode[20]={ 0, 0, 0, 0 }; 14742e5b6d6dSopenharmony_ci 14752e5b6d6dSopenharmony_ci const char *s; 14762e5b6d6dSopenharmony_ci UChar *u; 14772e5b6d6dSopenharmony_ci UErrorCode errorCode; 14782e5b6d6dSopenharmony_ci UBool isAmbiguous; 14792e5b6d6dSopenharmony_ci 14802e5b6d6dSopenharmony_ci /* try to convert an 'a', a square bracket and a US-ASCII backslash */ 14812e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 14822e5b6d6dSopenharmony_ci s=inBytes; 14832e5b6d6dSopenharmony_ci u=outUnicode; 14842e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &u, u+20, &s, s+3, NULL, true, &errorCode); 14852e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 14862e5b6d6dSopenharmony_ci /* we do not care about general failures in this test; the input may just not be mappable */ 14872e5b6d6dSopenharmony_ci return; 14882e5b6d6dSopenharmony_ci } 14892e5b6d6dSopenharmony_ci 14902e5b6d6dSopenharmony_ci if(outUnicode[0]!=0x61 || outUnicode[1]!=0x5B || outUnicode[2]==0xfffd) { 14912e5b6d6dSopenharmony_ci /* not a close ASCII-family encoding, or 0x5c is unassigned/illegal: this test is not applicable */ 14922e5b6d6dSopenharmony_ci /* There are some encodings that are partially ASCII based, 14932e5b6d6dSopenharmony_ci like the ISO-7 and GSM series of codepages, which we ignore. */ 14942e5b6d6dSopenharmony_ci return; 14952e5b6d6dSopenharmony_ci } 14962e5b6d6dSopenharmony_ci 14972e5b6d6dSopenharmony_ci isAmbiguous=ucnv_isAmbiguous(cnv); 14982e5b6d6dSopenharmony_ci 14992e5b6d6dSopenharmony_ci /* check that outUnicode[1]!=0x5c is exactly the same as ucnv_isAmbiguous() */ 15002e5b6d6dSopenharmony_ci if((outUnicode[2]!=0x5c)!=isAmbiguous) { 15012e5b6d6dSopenharmony_ci log_err("error: converter \"%s\" needs a backslash fix: %d but ucnv_isAmbiguous()==%d\n", 15022e5b6d6dSopenharmony_ci ucnv_getName(cnv, &errorCode), outUnicode[2]!=0x5c, isAmbiguous); 15032e5b6d6dSopenharmony_ci return; 15042e5b6d6dSopenharmony_ci } 15052e5b6d6dSopenharmony_ci 15062e5b6d6dSopenharmony_ci if(outUnicode[2]!=0x5c) { 15072e5b6d6dSopenharmony_ci /* needs fixup, fix it */ 15082e5b6d6dSopenharmony_ci ucnv_fixFileSeparator(cnv, outUnicode, (int32_t)(u-outUnicode)); 15092e5b6d6dSopenharmony_ci if(outUnicode[2]!=0x5c) { 15102e5b6d6dSopenharmony_ci /* the fix failed */ 15112e5b6d6dSopenharmony_ci log_err("error: ucnv_fixFileSeparator(%s) failed\n", ucnv_getName(cnv, &errorCode)); 15122e5b6d6dSopenharmony_ci return; 15132e5b6d6dSopenharmony_ci } 15142e5b6d6dSopenharmony_ci } 15152e5b6d6dSopenharmony_ci} 15162e5b6d6dSopenharmony_ci 15172e5b6d6dSopenharmony_cistatic void TestAmbiguous() 15182e5b6d6dSopenharmony_ci{ 15192e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 15202e5b6d6dSopenharmony_ci UConverter *ascii_cnv = 0, *sjis_cnv = 0, *cnv; 15212e5b6d6dSopenharmony_ci static const char target[] = { 15222e5b6d6dSopenharmony_ci /* "\\usr\\local\\share\\data\\icutest.txt" */ 15232e5b6d6dSopenharmony_ci 0x5c, 0x75, 0x73, 0x72, 15242e5b6d6dSopenharmony_ci 0x5c, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 15252e5b6d6dSopenharmony_ci 0x5c, 0x73, 0x68, 0x61, 0x72, 0x65, 15262e5b6d6dSopenharmony_ci 0x5c, 0x64, 0x61, 0x74, 0x61, 15272e5b6d6dSopenharmony_ci 0x5c, 0x69, 0x63, 0x75, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74, 15282e5b6d6dSopenharmony_ci 0 15292e5b6d6dSopenharmony_ci }; 15302e5b6d6dSopenharmony_ci UChar asciiResult[200], sjisResult[200]; 15312e5b6d6dSopenharmony_ci int32_t /*asciiLength = 0,*/ sjisLength = 0, i; 15322e5b6d6dSopenharmony_ci const char *name; 15332e5b6d6dSopenharmony_ci 15342e5b6d6dSopenharmony_ci /* enumerate all converters */ 15352e5b6d6dSopenharmony_ci status=U_ZERO_ERROR; 15362e5b6d6dSopenharmony_ci for(i=0; (name=ucnv_getAvailableName(i))!=NULL; ++i) { 15372e5b6d6dSopenharmony_ci cnv=ucnv_open(name, &status); 15382e5b6d6dSopenharmony_ci if(U_SUCCESS(status)) { 15392e5b6d6dSopenharmony_ci TestAmbiguousConverter(cnv); 15402e5b6d6dSopenharmony_ci ucnv_close(cnv); 15412e5b6d6dSopenharmony_ci } else { 15422e5b6d6dSopenharmony_ci log_err("error: unable to open available converter \"%s\"\n", name); 15432e5b6d6dSopenharmony_ci status=U_ZERO_ERROR; 15442e5b6d6dSopenharmony_ci } 15452e5b6d6dSopenharmony_ci } 15462e5b6d6dSopenharmony_ci 15472e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 15482e5b6d6dSopenharmony_ci sjis_cnv = ucnv_open("ibm-943", &status); 15492e5b6d6dSopenharmony_ci if (U_FAILURE(status)) 15502e5b6d6dSopenharmony_ci { 15512e5b6d6dSopenharmony_ci log_data_err("Failed to create a SJIS converter\n"); 15522e5b6d6dSopenharmony_ci return; 15532e5b6d6dSopenharmony_ci } 15542e5b6d6dSopenharmony_ci ascii_cnv = ucnv_open("LATIN-1", &status); 15552e5b6d6dSopenharmony_ci if (U_FAILURE(status)) 15562e5b6d6dSopenharmony_ci { 15572e5b6d6dSopenharmony_ci log_data_err("Failed to create a LATIN-1 converter\n"); 15582e5b6d6dSopenharmony_ci ucnv_close(sjis_cnv); 15592e5b6d6dSopenharmony_ci return; 15602e5b6d6dSopenharmony_ci } 15612e5b6d6dSopenharmony_ci /* convert target from SJIS to Unicode */ 15622e5b6d6dSopenharmony_ci sjisLength = ucnv_toUChars(sjis_cnv, sjisResult, UPRV_LENGTHOF(sjisResult), target, (int32_t)strlen(target), &status); 15632e5b6d6dSopenharmony_ci if (U_FAILURE(status)) 15642e5b6d6dSopenharmony_ci { 15652e5b6d6dSopenharmony_ci log_err("Failed to convert the SJIS string.\n"); 15662e5b6d6dSopenharmony_ci ucnv_close(sjis_cnv); 15672e5b6d6dSopenharmony_ci ucnv_close(ascii_cnv); 15682e5b6d6dSopenharmony_ci return; 15692e5b6d6dSopenharmony_ci } 15702e5b6d6dSopenharmony_ci /* convert target from Latin-1 to Unicode */ 15712e5b6d6dSopenharmony_ci /*asciiLength =*/ ucnv_toUChars(ascii_cnv, asciiResult, UPRV_LENGTHOF(asciiResult), target, (int32_t)strlen(target), &status); 15722e5b6d6dSopenharmony_ci if (U_FAILURE(status)) 15732e5b6d6dSopenharmony_ci { 15742e5b6d6dSopenharmony_ci log_err("Failed to convert the Latin-1 string.\n"); 15752e5b6d6dSopenharmony_ci ucnv_close(sjis_cnv); 15762e5b6d6dSopenharmony_ci ucnv_close(ascii_cnv); 15772e5b6d6dSopenharmony_ci return; 15782e5b6d6dSopenharmony_ci } 15792e5b6d6dSopenharmony_ci if (!ucnv_isAmbiguous(sjis_cnv)) 15802e5b6d6dSopenharmony_ci { 15812e5b6d6dSopenharmony_ci log_err("SJIS converter should contain ambiguous character mappings.\n"); 15822e5b6d6dSopenharmony_ci ucnv_close(sjis_cnv); 15832e5b6d6dSopenharmony_ci ucnv_close(ascii_cnv); 15842e5b6d6dSopenharmony_ci return; 15852e5b6d6dSopenharmony_ci } 15862e5b6d6dSopenharmony_ci if (u_strcmp(sjisResult, asciiResult) == 0) 15872e5b6d6dSopenharmony_ci { 15882e5b6d6dSopenharmony_ci log_err("File separators for SJIS don't need to be fixed.\n"); 15892e5b6d6dSopenharmony_ci } 15902e5b6d6dSopenharmony_ci ucnv_fixFileSeparator(sjis_cnv, sjisResult, sjisLength); 15912e5b6d6dSopenharmony_ci if (u_strcmp(sjisResult, asciiResult) != 0) 15922e5b6d6dSopenharmony_ci { 15932e5b6d6dSopenharmony_ci log_err("Fixing file separator for SJIS failed.\n"); 15942e5b6d6dSopenharmony_ci } 15952e5b6d6dSopenharmony_ci ucnv_close(sjis_cnv); 15962e5b6d6dSopenharmony_ci ucnv_close(ascii_cnv); 15972e5b6d6dSopenharmony_ci#endif 15982e5b6d6dSopenharmony_ci} 15992e5b6d6dSopenharmony_ci 16002e5b6d6dSopenharmony_cistatic void 16012e5b6d6dSopenharmony_ciTestSignatureDetection(){ 16022e5b6d6dSopenharmony_ci /* with null terminated strings */ 16032e5b6d6dSopenharmony_ci { 16042e5b6d6dSopenharmony_ci static const char* data[] = { 16052e5b6d6dSopenharmony_ci "\xFE\xFF\x00\x00", /* UTF-16BE */ 16062e5b6d6dSopenharmony_ci "\xFF\xFE\x00\x00", /* UTF-16LE */ 16072e5b6d6dSopenharmony_ci "\xEF\xBB\xBF\x00", /* UTF-8 */ 16082e5b6d6dSopenharmony_ci "\x0E\xFE\xFF\x00", /* SCSU */ 16092e5b6d6dSopenharmony_ci 16102e5b6d6dSopenharmony_ci "\xFE\xFF", /* UTF-16BE */ 16112e5b6d6dSopenharmony_ci "\xFF\xFE", /* UTF-16LE */ 16122e5b6d6dSopenharmony_ci "\xEF\xBB\xBF", /* UTF-8 */ 16132e5b6d6dSopenharmony_ci "\x0E\xFE\xFF", /* SCSU */ 16142e5b6d6dSopenharmony_ci 16152e5b6d6dSopenharmony_ci "\xFE\xFF\x41\x42", /* UTF-16BE */ 16162e5b6d6dSopenharmony_ci "\xFF\xFE\x41\x41", /* UTF-16LE */ 16172e5b6d6dSopenharmony_ci "\xEF\xBB\xBF\x41", /* UTF-8 */ 16182e5b6d6dSopenharmony_ci "\x0E\xFE\xFF\x41", /* SCSU */ 16192e5b6d6dSopenharmony_ci 16202e5b6d6dSopenharmony_ci "\x2B\x2F\x76\x38\x2D", /* UTF-7 */ 16212e5b6d6dSopenharmony_ci "\x2B\x2F\x76\x38\x41", /* UTF-7 */ 16222e5b6d6dSopenharmony_ci "\x2B\x2F\x76\x39\x41", /* UTF-7 */ 16232e5b6d6dSopenharmony_ci "\x2B\x2F\x76\x2B\x41", /* UTF-7 */ 16242e5b6d6dSopenharmony_ci "\x2B\x2F\x76\x2F\x41", /* UTF-7 */ 16252e5b6d6dSopenharmony_ci 16262e5b6d6dSopenharmony_ci "\xDD\x73\x66\x73" /* UTF-EBCDIC */ 16272e5b6d6dSopenharmony_ci }; 16282e5b6d6dSopenharmony_ci static const char* expected[] = { 16292e5b6d6dSopenharmony_ci "UTF-16BE", 16302e5b6d6dSopenharmony_ci "UTF-16LE", 16312e5b6d6dSopenharmony_ci "UTF-8", 16322e5b6d6dSopenharmony_ci "SCSU", 16332e5b6d6dSopenharmony_ci 16342e5b6d6dSopenharmony_ci "UTF-16BE", 16352e5b6d6dSopenharmony_ci "UTF-16LE", 16362e5b6d6dSopenharmony_ci "UTF-8", 16372e5b6d6dSopenharmony_ci "SCSU", 16382e5b6d6dSopenharmony_ci 16392e5b6d6dSopenharmony_ci "UTF-16BE", 16402e5b6d6dSopenharmony_ci "UTF-16LE", 16412e5b6d6dSopenharmony_ci "UTF-8", 16422e5b6d6dSopenharmony_ci "SCSU", 16432e5b6d6dSopenharmony_ci 16442e5b6d6dSopenharmony_ci "UTF-7", 16452e5b6d6dSopenharmony_ci "UTF-7", 16462e5b6d6dSopenharmony_ci "UTF-7", 16472e5b6d6dSopenharmony_ci "UTF-7", 16482e5b6d6dSopenharmony_ci "UTF-7", 16492e5b6d6dSopenharmony_ci "UTF-EBCDIC" 16502e5b6d6dSopenharmony_ci }; 16512e5b6d6dSopenharmony_ci static const int32_t expectedLength[] ={ 16522e5b6d6dSopenharmony_ci 2, 16532e5b6d6dSopenharmony_ci 2, 16542e5b6d6dSopenharmony_ci 3, 16552e5b6d6dSopenharmony_ci 3, 16562e5b6d6dSopenharmony_ci 16572e5b6d6dSopenharmony_ci 2, 16582e5b6d6dSopenharmony_ci 2, 16592e5b6d6dSopenharmony_ci 3, 16602e5b6d6dSopenharmony_ci 3, 16612e5b6d6dSopenharmony_ci 16622e5b6d6dSopenharmony_ci 2, 16632e5b6d6dSopenharmony_ci 2, 16642e5b6d6dSopenharmony_ci 3, 16652e5b6d6dSopenharmony_ci 3, 16662e5b6d6dSopenharmony_ci 16672e5b6d6dSopenharmony_ci 5, 16682e5b6d6dSopenharmony_ci 4, 16692e5b6d6dSopenharmony_ci 4, 16702e5b6d6dSopenharmony_ci 4, 16712e5b6d6dSopenharmony_ci 4, 16722e5b6d6dSopenharmony_ci 4 16732e5b6d6dSopenharmony_ci }; 16742e5b6d6dSopenharmony_ci int i=0; 16752e5b6d6dSopenharmony_ci UErrorCode err; 16762e5b6d6dSopenharmony_ci int32_t signatureLength = -1; 16772e5b6d6dSopenharmony_ci const char* source = NULL; 16782e5b6d6dSopenharmony_ci const char* enc = NULL; 16792e5b6d6dSopenharmony_ci for( ; i<UPRV_LENGTHOF(data); i++){ 16802e5b6d6dSopenharmony_ci err = U_ZERO_ERROR; 16812e5b6d6dSopenharmony_ci source = data[i]; 16822e5b6d6dSopenharmony_ci enc = ucnv_detectUnicodeSignature(source, -1 , &signatureLength, &err); 16832e5b6d6dSopenharmony_ci if(U_FAILURE(err)){ 16842e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err)); 16852e5b6d6dSopenharmony_ci continue; 16862e5b6d6dSopenharmony_ci } 16872e5b6d6dSopenharmony_ci if(enc == NULL || strcmp(enc,expected[i]) !=0){ 16882e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc); 16892e5b6d6dSopenharmony_ci continue; 16902e5b6d6dSopenharmony_ci } 16912e5b6d6dSopenharmony_ci if(signatureLength != expectedLength[i]){ 16922e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]); 16932e5b6d6dSopenharmony_ci } 16942e5b6d6dSopenharmony_ci } 16952e5b6d6dSopenharmony_ci } 16962e5b6d6dSopenharmony_ci { 16972e5b6d6dSopenharmony_ci static const char* data[] = { 16982e5b6d6dSopenharmony_ci "\xFE\xFF\x00", /* UTF-16BE */ 16992e5b6d6dSopenharmony_ci "\xFF\xFE\x00", /* UTF-16LE */ 17002e5b6d6dSopenharmony_ci "\xEF\xBB\xBF\x00", /* UTF-8 */ 17012e5b6d6dSopenharmony_ci "\x0E\xFE\xFF\x00", /* SCSU */ 17022e5b6d6dSopenharmony_ci "\x00\x00\xFE\xFF", /* UTF-32BE */ 17032e5b6d6dSopenharmony_ci "\xFF\xFE\x00\x00", /* UTF-32LE */ 17042e5b6d6dSopenharmony_ci "\xFE\xFF", /* UTF-16BE */ 17052e5b6d6dSopenharmony_ci "\xFF\xFE", /* UTF-16LE */ 17062e5b6d6dSopenharmony_ci "\xEF\xBB\xBF", /* UTF-8 */ 17072e5b6d6dSopenharmony_ci "\x0E\xFE\xFF", /* SCSU */ 17082e5b6d6dSopenharmony_ci "\x00\x00\xFE\xFF", /* UTF-32BE */ 17092e5b6d6dSopenharmony_ci "\xFF\xFE\x00\x00", /* UTF-32LE */ 17102e5b6d6dSopenharmony_ci "\xFE\xFF\x41\x42", /* UTF-16BE */ 17112e5b6d6dSopenharmony_ci "\xFF\xFE\x41\x41", /* UTF-16LE */ 17122e5b6d6dSopenharmony_ci "\xEF\xBB\xBF\x41", /* UTF-8 */ 17132e5b6d6dSopenharmony_ci "\x0E\xFE\xFF\x41", /* SCSU */ 17142e5b6d6dSopenharmony_ci "\x00\x00\xFE\xFF\x41", /* UTF-32BE */ 17152e5b6d6dSopenharmony_ci "\xFF\xFE\x00\x00\x42", /* UTF-32LE */ 17162e5b6d6dSopenharmony_ci "\xFB\xEE\x28", /* BOCU-1 */ 17172e5b6d6dSopenharmony_ci "\xFF\x41\x42" /* NULL */ 17182e5b6d6dSopenharmony_ci }; 17192e5b6d6dSopenharmony_ci static const int len[] = { 17202e5b6d6dSopenharmony_ci 3, 17212e5b6d6dSopenharmony_ci 3, 17222e5b6d6dSopenharmony_ci 4, 17232e5b6d6dSopenharmony_ci 4, 17242e5b6d6dSopenharmony_ci 4, 17252e5b6d6dSopenharmony_ci 4, 17262e5b6d6dSopenharmony_ci 2, 17272e5b6d6dSopenharmony_ci 2, 17282e5b6d6dSopenharmony_ci 3, 17292e5b6d6dSopenharmony_ci 3, 17302e5b6d6dSopenharmony_ci 4, 17312e5b6d6dSopenharmony_ci 4, 17322e5b6d6dSopenharmony_ci 4, 17332e5b6d6dSopenharmony_ci 4, 17342e5b6d6dSopenharmony_ci 4, 17352e5b6d6dSopenharmony_ci 4, 17362e5b6d6dSopenharmony_ci 5, 17372e5b6d6dSopenharmony_ci 5, 17382e5b6d6dSopenharmony_ci 3, 17392e5b6d6dSopenharmony_ci 3 17402e5b6d6dSopenharmony_ci }; 17412e5b6d6dSopenharmony_ci 17422e5b6d6dSopenharmony_ci static const char* expected[] = { 17432e5b6d6dSopenharmony_ci "UTF-16BE", 17442e5b6d6dSopenharmony_ci "UTF-16LE", 17452e5b6d6dSopenharmony_ci "UTF-8", 17462e5b6d6dSopenharmony_ci "SCSU", 17472e5b6d6dSopenharmony_ci "UTF-32BE", 17482e5b6d6dSopenharmony_ci "UTF-32LE", 17492e5b6d6dSopenharmony_ci "UTF-16BE", 17502e5b6d6dSopenharmony_ci "UTF-16LE", 17512e5b6d6dSopenharmony_ci "UTF-8", 17522e5b6d6dSopenharmony_ci "SCSU", 17532e5b6d6dSopenharmony_ci "UTF-32BE", 17542e5b6d6dSopenharmony_ci "UTF-32LE", 17552e5b6d6dSopenharmony_ci "UTF-16BE", 17562e5b6d6dSopenharmony_ci "UTF-16LE", 17572e5b6d6dSopenharmony_ci "UTF-8", 17582e5b6d6dSopenharmony_ci "SCSU", 17592e5b6d6dSopenharmony_ci "UTF-32BE", 17602e5b6d6dSopenharmony_ci "UTF-32LE", 17612e5b6d6dSopenharmony_ci "BOCU-1", 17622e5b6d6dSopenharmony_ci NULL 17632e5b6d6dSopenharmony_ci }; 17642e5b6d6dSopenharmony_ci static const int32_t expectedLength[] ={ 17652e5b6d6dSopenharmony_ci 2, 17662e5b6d6dSopenharmony_ci 2, 17672e5b6d6dSopenharmony_ci 3, 17682e5b6d6dSopenharmony_ci 3, 17692e5b6d6dSopenharmony_ci 4, 17702e5b6d6dSopenharmony_ci 4, 17712e5b6d6dSopenharmony_ci 2, 17722e5b6d6dSopenharmony_ci 2, 17732e5b6d6dSopenharmony_ci 3, 17742e5b6d6dSopenharmony_ci 3, 17752e5b6d6dSopenharmony_ci 4, 17762e5b6d6dSopenharmony_ci 4, 17772e5b6d6dSopenharmony_ci 2, 17782e5b6d6dSopenharmony_ci 2, 17792e5b6d6dSopenharmony_ci 3, 17802e5b6d6dSopenharmony_ci 3, 17812e5b6d6dSopenharmony_ci 4, 17822e5b6d6dSopenharmony_ci 4, 17832e5b6d6dSopenharmony_ci 3, 17842e5b6d6dSopenharmony_ci 0 17852e5b6d6dSopenharmony_ci }; 17862e5b6d6dSopenharmony_ci int i=0; 17872e5b6d6dSopenharmony_ci UErrorCode err; 17882e5b6d6dSopenharmony_ci int32_t signatureLength = -1; 17892e5b6d6dSopenharmony_ci int32_t sourceLength=-1; 17902e5b6d6dSopenharmony_ci const char* source = NULL; 17912e5b6d6dSopenharmony_ci const char* enc = NULL; 17922e5b6d6dSopenharmony_ci for( ; i<UPRV_LENGTHOF(data); i++){ 17932e5b6d6dSopenharmony_ci err = U_ZERO_ERROR; 17942e5b6d6dSopenharmony_ci source = data[i]; 17952e5b6d6dSopenharmony_ci sourceLength = len[i]; 17962e5b6d6dSopenharmony_ci enc = ucnv_detectUnicodeSignature(source, sourceLength , &signatureLength, &err); 17972e5b6d6dSopenharmony_ci if(U_FAILURE(err)){ 17982e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err)); 17992e5b6d6dSopenharmony_ci continue; 18002e5b6d6dSopenharmony_ci } 18012e5b6d6dSopenharmony_ci if(enc == NULL || strcmp(enc,expected[i]) !=0){ 18022e5b6d6dSopenharmony_ci if(expected[i] !=NULL){ 18032e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc); 18042e5b6d6dSopenharmony_ci continue; 18052e5b6d6dSopenharmony_ci } 18062e5b6d6dSopenharmony_ci } 18072e5b6d6dSopenharmony_ci if(signatureLength != expectedLength[i]){ 18082e5b6d6dSopenharmony_ci log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]); 18092e5b6d6dSopenharmony_ci } 18102e5b6d6dSopenharmony_ci } 18112e5b6d6dSopenharmony_ci } 18122e5b6d6dSopenharmony_ci} 18132e5b6d6dSopenharmony_ci 18142e5b6d6dSopenharmony_cistatic void TestUTF7() { 18152e5b6d6dSopenharmony_ci /* test input */ 18162e5b6d6dSopenharmony_ci static const uint8_t in[]={ 18172e5b6d6dSopenharmony_ci /* H - +Jjo- - ! +- +2AHcAQ */ 18182e5b6d6dSopenharmony_ci 0x48, 18192e5b6d6dSopenharmony_ci 0x2d, 18202e5b6d6dSopenharmony_ci 0x2b, 0x4a, 0x6a, 0x6f, 18212e5b6d6dSopenharmony_ci 0x2d, 0x2d, 18222e5b6d6dSopenharmony_ci 0x21, 18232e5b6d6dSopenharmony_ci 0x2b, 0x2d, 18242e5b6d6dSopenharmony_ci 0x2b, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51 18252e5b6d6dSopenharmony_ci }; 18262e5b6d6dSopenharmony_ci 18272e5b6d6dSopenharmony_ci /* expected test results */ 18282e5b6d6dSopenharmony_ci static const int32_t results[]={ 18292e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 18302e5b6d6dSopenharmony_ci 1, 0x48, 18312e5b6d6dSopenharmony_ci 1, 0x2d, 18322e5b6d6dSopenharmony_ci 4, 0x263a, /* <WHITE SMILING FACE> */ 18332e5b6d6dSopenharmony_ci 2, 0x2d, 18342e5b6d6dSopenharmony_ci 1, 0x21, 18352e5b6d6dSopenharmony_ci 2, 0x2b, 18362e5b6d6dSopenharmony_ci 7, 0x10401 18372e5b6d6dSopenharmony_ci }; 18382e5b6d6dSopenharmony_ci 18392e5b6d6dSopenharmony_ci const char *cnvName; 18402e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 18412e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 18422e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-7", &errorCode); 18432e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 18442e5b6d6dSopenharmony_ci log_data_err("Unable to open a UTF-7 converter: %s\n", u_errorName(errorCode)); 18452e5b6d6dSopenharmony_ci return; 18462e5b6d6dSopenharmony_ci } 18472e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-7"); 18482e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 18492e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 18502e5b6d6dSopenharmony_ci cnvName = ucnv_getName(cnv, &errorCode); 18512e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "UTF-7") != 0) { 18522e5b6d6dSopenharmony_ci log_err("UTF-7 converter is called %s: %s\n", cnvName, u_errorName(errorCode)); 18532e5b6d6dSopenharmony_ci } 18542e5b6d6dSopenharmony_ci ucnv_close(cnv); 18552e5b6d6dSopenharmony_ci} 18562e5b6d6dSopenharmony_ci 18572e5b6d6dSopenharmony_cistatic void TestIMAP() { 18582e5b6d6dSopenharmony_ci /* test input */ 18592e5b6d6dSopenharmony_ci static const uint8_t in[]={ 18602e5b6d6dSopenharmony_ci /* H - &Jjo- - ! &- &2AHcAQ- \ */ 18612e5b6d6dSopenharmony_ci 0x48, 18622e5b6d6dSopenharmony_ci 0x2d, 18632e5b6d6dSopenharmony_ci 0x26, 0x4a, 0x6a, 0x6f, 18642e5b6d6dSopenharmony_ci 0x2d, 0x2d, 18652e5b6d6dSopenharmony_ci 0x21, 18662e5b6d6dSopenharmony_ci 0x26, 0x2d, 18672e5b6d6dSopenharmony_ci 0x26, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51, 0x2d 18682e5b6d6dSopenharmony_ci }; 18692e5b6d6dSopenharmony_ci 18702e5b6d6dSopenharmony_ci /* expected test results */ 18712e5b6d6dSopenharmony_ci static const int32_t results[]={ 18722e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 18732e5b6d6dSopenharmony_ci 1, 0x48, 18742e5b6d6dSopenharmony_ci 1, 0x2d, 18752e5b6d6dSopenharmony_ci 4, 0x263a, /* <WHITE SMILING FACE> */ 18762e5b6d6dSopenharmony_ci 2, 0x2d, 18772e5b6d6dSopenharmony_ci 1, 0x21, 18782e5b6d6dSopenharmony_ci 2, 0x26, 18792e5b6d6dSopenharmony_ci 7, 0x10401 18802e5b6d6dSopenharmony_ci }; 18812e5b6d6dSopenharmony_ci 18822e5b6d6dSopenharmony_ci const char *cnvName; 18832e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 18842e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 18852e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("IMAP-mailbox-name", &errorCode); 18862e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 18872e5b6d6dSopenharmony_ci log_data_err("Unable to open a IMAP-mailbox-name converter: %s\n", u_errorName(errorCode)); 18882e5b6d6dSopenharmony_ci return; 18892e5b6d6dSopenharmony_ci } 18902e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "IMAP-mailbox-name"); 18912e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 18922e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 18932e5b6d6dSopenharmony_ci cnvName = ucnv_getName(cnv, &errorCode); 18942e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "IMAP-mailbox-name") != 0) { 18952e5b6d6dSopenharmony_ci log_err("IMAP-mailbox-name converter is called %s: %s\n", cnvName, u_errorName(errorCode)); 18962e5b6d6dSopenharmony_ci } 18972e5b6d6dSopenharmony_ci ucnv_close(cnv); 18982e5b6d6dSopenharmony_ci} 18992e5b6d6dSopenharmony_ci 19002e5b6d6dSopenharmony_cistatic void TestUTF8() { 19012e5b6d6dSopenharmony_ci /* test input */ 19022e5b6d6dSopenharmony_ci static const uint8_t in[]={ 19032e5b6d6dSopenharmony_ci 0x61, 19042e5b6d6dSopenharmony_ci 0xc2, 0x80, 19052e5b6d6dSopenharmony_ci 0xe0, 0xa0, 0x80, 19062e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x80, 0x80, 19072e5b6d6dSopenharmony_ci 0xf4, 0x84, 0x8c, 0xa1, 19082e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x90, 0x81 19092e5b6d6dSopenharmony_ci }; 19102e5b6d6dSopenharmony_ci 19112e5b6d6dSopenharmony_ci /* expected test results */ 19122e5b6d6dSopenharmony_ci static const int32_t results[]={ 19132e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 19142e5b6d6dSopenharmony_ci 1, 0x61, 19152e5b6d6dSopenharmony_ci 2, 0x80, 19162e5b6d6dSopenharmony_ci 3, 0x800, 19172e5b6d6dSopenharmony_ci 4, 0x10000, 19182e5b6d6dSopenharmony_ci 4, 0x104321, 19192e5b6d6dSopenharmony_ci 4, 0x10401 19202e5b6d6dSopenharmony_ci }; 19212e5b6d6dSopenharmony_ci 19222e5b6d6dSopenharmony_ci /* error test input */ 19232e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 19242e5b6d6dSopenharmony_ci 0x61, 19252e5b6d6dSopenharmony_ci 0xc0, 0x80, /* illegal non-shortest form */ 19262e5b6d6dSopenharmony_ci 0xe0, 0x80, 0x80, /* illegal non-shortest form */ 19272e5b6d6dSopenharmony_ci 0xf0, 0x80, 0x80, 0x80, /* illegal non-shortest form */ 19282e5b6d6dSopenharmony_ci 0xc0, 0xc0, /* illegal trail byte */ 19292e5b6d6dSopenharmony_ci 0xf4, 0x90, 0x80, 0x80, /* 0x110000 out of range */ 19302e5b6d6dSopenharmony_ci 0xf8, 0x80, 0x80, 0x80, 0x80, /* too long */ 19312e5b6d6dSopenharmony_ci 0xfe, /* illegal byte altogether */ 19322e5b6d6dSopenharmony_ci 0x62 19332e5b6d6dSopenharmony_ci }; 19342e5b6d6dSopenharmony_ci 19352e5b6d6dSopenharmony_ci /* expected error test results */ 19362e5b6d6dSopenharmony_ci static const int32_t results2[]={ 19372e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 19382e5b6d6dSopenharmony_ci 1, 0x61, 19392e5b6d6dSopenharmony_ci 22, 0x62 19402e5b6d6dSopenharmony_ci }; 19412e5b6d6dSopenharmony_ci 19422e5b6d6dSopenharmony_ci UConverterToUCallback cb; 19432e5b6d6dSopenharmony_ci const void *p; 19442e5b6d6dSopenharmony_ci 19452e5b6d6dSopenharmony_ci const char *source=(const char *)in,*limit=(const char *)in+sizeof(in); 19462e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 19472e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-8", &errorCode); 19482e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 19492e5b6d6dSopenharmony_ci log_err("Unable to open a UTF-8 converter: %s\n", u_errorName(errorCode)); 19502e5b6d6dSopenharmony_ci return; 19512e5b6d6dSopenharmony_ci } 19522e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-8"); 19532e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 19542e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 19552e5b6d6dSopenharmony_ci 19562e5b6d6dSopenharmony_ci /* test error behavior with a skip callback */ 19572e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode); 19582e5b6d6dSopenharmony_ci source=(const char *)in2; 19592e5b6d6dSopenharmony_ci limit=(const char *)(in2+sizeof(in2)); 19602e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "UTF-8"); 19612e5b6d6dSopenharmony_ci 19622e5b6d6dSopenharmony_ci ucnv_close(cnv); 19632e5b6d6dSopenharmony_ci} 19642e5b6d6dSopenharmony_ci 19652e5b6d6dSopenharmony_cistatic void TestCESU8() { 19662e5b6d6dSopenharmony_ci /* test input */ 19672e5b6d6dSopenharmony_ci static const uint8_t in[]={ 19682e5b6d6dSopenharmony_ci 0x61, 19692e5b6d6dSopenharmony_ci 0xc2, 0x80, 19702e5b6d6dSopenharmony_ci 0xe0, 0xa0, 0x80, 19712e5b6d6dSopenharmony_ci 0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80, 19722e5b6d6dSopenharmony_ci 0xed, 0xb0, 0x81, 0xed, 0xa0, 0x82, 19732e5b6d6dSopenharmony_ci 0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf, 19742e5b6d6dSopenharmony_ci 0xef, 0xbf, 0xbc 19752e5b6d6dSopenharmony_ci }; 19762e5b6d6dSopenharmony_ci 19772e5b6d6dSopenharmony_ci /* expected test results */ 19782e5b6d6dSopenharmony_ci static const int32_t results[]={ 19792e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 19802e5b6d6dSopenharmony_ci 1, 0x61, 19812e5b6d6dSopenharmony_ci 2, 0x80, 19822e5b6d6dSopenharmony_ci 3, 0x800, 19832e5b6d6dSopenharmony_ci 6, 0x10000, 19842e5b6d6dSopenharmony_ci 3, 0xdc01, 19852e5b6d6dSopenharmony_ci -1,0xd802, /* may read 3 or 6 bytes */ 19862e5b6d6dSopenharmony_ci -1,0x10ffff,/* may read 0 or 3 bytes */ 19872e5b6d6dSopenharmony_ci 3, 0xfffc 19882e5b6d6dSopenharmony_ci }; 19892e5b6d6dSopenharmony_ci 19902e5b6d6dSopenharmony_ci /* error test input */ 19912e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 19922e5b6d6dSopenharmony_ci 0x61, 19932e5b6d6dSopenharmony_ci 0xc0, 0x80, /* illegal non-shortest form */ 19942e5b6d6dSopenharmony_ci 0xe0, 0x80, 0x80, /* illegal non-shortest form */ 19952e5b6d6dSopenharmony_ci 0xf0, 0x80, 0x80, 0x80, /* illegal non-shortest form */ 19962e5b6d6dSopenharmony_ci 0xc0, 0xc0, /* illegal trail byte */ 19972e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x80, 0x80, /* illegal 4-byte supplementary code point */ 19982e5b6d6dSopenharmony_ci 0xf4, 0x84, 0x8c, 0xa1, /* illegal 4-byte supplementary code point */ 19992e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x90, 0x81, /* illegal 4-byte supplementary code point */ 20002e5b6d6dSopenharmony_ci 0xf4, 0x90, 0x80, 0x80, /* 0x110000 out of range */ 20012e5b6d6dSopenharmony_ci 0xf8, 0x80, 0x80, 0x80, 0x80, /* too long */ 20022e5b6d6dSopenharmony_ci 0xfe, /* illegal byte altogether */ 20032e5b6d6dSopenharmony_ci 0x62 20042e5b6d6dSopenharmony_ci }; 20052e5b6d6dSopenharmony_ci 20062e5b6d6dSopenharmony_ci /* expected error test results */ 20072e5b6d6dSopenharmony_ci static const int32_t results2[]={ 20082e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 20092e5b6d6dSopenharmony_ci 1, 0x61, 20102e5b6d6dSopenharmony_ci 34, 0x62 20112e5b6d6dSopenharmony_ci }; 20122e5b6d6dSopenharmony_ci 20132e5b6d6dSopenharmony_ci UConverterToUCallback cb; 20142e5b6d6dSopenharmony_ci const void *p; 20152e5b6d6dSopenharmony_ci 20162e5b6d6dSopenharmony_ci const char *source=(const char *)in,*limit=(const char *)in+sizeof(in); 20172e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 20182e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("CESU-8", &errorCode); 20192e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 20202e5b6d6dSopenharmony_ci log_data_err("Unable to open a CESU-8 converter: %s\n", u_errorName(errorCode)); 20212e5b6d6dSopenharmony_ci return; 20222e5b6d6dSopenharmony_ci } 20232e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "CESU-8"); 20242e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 20252e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 20262e5b6d6dSopenharmony_ci 20272e5b6d6dSopenharmony_ci /* test error behavior with a skip callback */ 20282e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode); 20292e5b6d6dSopenharmony_ci source=(const char *)in2; 20302e5b6d6dSopenharmony_ci limit=(const char *)(in2+sizeof(in2)); 20312e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "CESU-8"); 20322e5b6d6dSopenharmony_ci 20332e5b6d6dSopenharmony_ci ucnv_close(cnv); 20342e5b6d6dSopenharmony_ci} 20352e5b6d6dSopenharmony_ci 20362e5b6d6dSopenharmony_cistatic void TestUTF16() { 20372e5b6d6dSopenharmony_ci /* test input */ 20382e5b6d6dSopenharmony_ci static const uint8_t in1[]={ 20392e5b6d6dSopenharmony_ci 0xfe, 0xff, 0x4e, 0x00, 0xfe, 0xff 20402e5b6d6dSopenharmony_ci }; 20412e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 20422e5b6d6dSopenharmony_ci 0xff, 0xfe, 0x4e, 0x00, 0xfe, 0xff 20432e5b6d6dSopenharmony_ci }; 20442e5b6d6dSopenharmony_ci static const uint8_t in3[]={ 20452e5b6d6dSopenharmony_ci 0xfe, 0xfe, 0x4e, 0x00, 0xfe, 0xff, 0xd8, 0x40, 0xdc, 0x01 20462e5b6d6dSopenharmony_ci }; 20472e5b6d6dSopenharmony_ci 20482e5b6d6dSopenharmony_ci /* expected test results */ 20492e5b6d6dSopenharmony_ci static const int32_t results1[]={ 20502e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 20512e5b6d6dSopenharmony_ci 4, 0x4e00, 20522e5b6d6dSopenharmony_ci 2, 0xfeff 20532e5b6d6dSopenharmony_ci }; 20542e5b6d6dSopenharmony_ci static const int32_t results2[]={ 20552e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 20562e5b6d6dSopenharmony_ci 4, 0x004e, 20572e5b6d6dSopenharmony_ci 2, 0xfffe 20582e5b6d6dSopenharmony_ci }; 20592e5b6d6dSopenharmony_ci static const int32_t results3[]={ 20602e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 20612e5b6d6dSopenharmony_ci 2, 0xfefe, 20622e5b6d6dSopenharmony_ci 2, 0x4e00, 20632e5b6d6dSopenharmony_ci 2, 0xfeff, 20642e5b6d6dSopenharmony_ci 4, 0x20001 20652e5b6d6dSopenharmony_ci }; 20662e5b6d6dSopenharmony_ci 20672e5b6d6dSopenharmony_ci const char *source, *limit; 20682e5b6d6dSopenharmony_ci 20692e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 20702e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-16", &errorCode); 20712e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 20722e5b6d6dSopenharmony_ci log_err("Unable to open a UTF-16 converter: %s\n", u_errorName(errorCode)); 20732e5b6d6dSopenharmony_ci return; 20742e5b6d6dSopenharmony_ci } 20752e5b6d6dSopenharmony_ci 20762e5b6d6dSopenharmony_ci source=(const char *)in1, limit=(const char *)in1+sizeof(in1); 20772e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results1, "UTF-16"); 20782e5b6d6dSopenharmony_ci 20792e5b6d6dSopenharmony_ci source=(const char *)in2, limit=(const char *)in2+sizeof(in2); 20802e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 20812e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "UTF-16"); 20822e5b6d6dSopenharmony_ci 20832e5b6d6dSopenharmony_ci source=(const char *)in3, limit=(const char *)in3+sizeof(in3); 20842e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 20852e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results3, "UTF-16"); 20862e5b6d6dSopenharmony_ci 20872e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 20882e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 20892e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 20902e5b6d6dSopenharmony_ci 20912e5b6d6dSopenharmony_ci ucnv_close(cnv); 20922e5b6d6dSopenharmony_ci} 20932e5b6d6dSopenharmony_ci 20942e5b6d6dSopenharmony_cistatic void TestUTF16BE() { 20952e5b6d6dSopenharmony_ci /* test input */ 20962e5b6d6dSopenharmony_ci static const uint8_t in[]={ 20972e5b6d6dSopenharmony_ci 0x00, 0x61, 20982e5b6d6dSopenharmony_ci 0x00, 0xc0, 20992e5b6d6dSopenharmony_ci 0x00, 0x31, 21002e5b6d6dSopenharmony_ci 0x00, 0xf4, 21012e5b6d6dSopenharmony_ci 0xce, 0xfe, 21022e5b6d6dSopenharmony_ci 0xd8, 0x01, 0xdc, 0x01 21032e5b6d6dSopenharmony_ci }; 21042e5b6d6dSopenharmony_ci 21052e5b6d6dSopenharmony_ci /* expected test results */ 21062e5b6d6dSopenharmony_ci static const int32_t results[]={ 21072e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 21082e5b6d6dSopenharmony_ci 2, 0x61, 21092e5b6d6dSopenharmony_ci 2, 0xc0, 21102e5b6d6dSopenharmony_ci 2, 0x31, 21112e5b6d6dSopenharmony_ci 2, 0xf4, 21122e5b6d6dSopenharmony_ci 2, 0xcefe, 21132e5b6d6dSopenharmony_ci 4, 0x10401 21142e5b6d6dSopenharmony_ci }; 21152e5b6d6dSopenharmony_ci 21162e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 21172e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 21182e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("utf-16be", &errorCode); 21192e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 21202e5b6d6dSopenharmony_ci log_err("Unable to open a UTF16-BE converter: %s\n", u_errorName(errorCode)); 21212e5b6d6dSopenharmony_ci return; 21222e5b6d6dSopenharmony_ci } 21232e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-16BE"); 21242e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 21252e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 21262e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 21272e5b6d6dSopenharmony_ci { 21282e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x61}; 21292e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 21302e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character"); 21312e5b6d6dSopenharmony_ci } 21322e5b6d6dSopenharmony_ci#if 0 21332e5b6d6dSopenharmony_ci /* 21342e5b6d6dSopenharmony_ci * Test disabled because currently the UTF-16BE/LE converters are supposed 21352e5b6d6dSopenharmony_ci * to not set errors for unpaired surrogates. 21362e5b6d6dSopenharmony_ci * This may change with 21372e5b6d6dSopenharmony_ci * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32 21382e5b6d6dSopenharmony_ci */ 21392e5b6d6dSopenharmony_ci 21402e5b6d6dSopenharmony_ci /*Test for the condition where there is a surrogate pair*/ 21412e5b6d6dSopenharmony_ci { 21422e5b6d6dSopenharmony_ci const uint8_t source2[]={0xd8, 0x01}; 21432e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character"); 21442e5b6d6dSopenharmony_ci } 21452e5b6d6dSopenharmony_ci#endif 21462e5b6d6dSopenharmony_ci ucnv_close(cnv); 21472e5b6d6dSopenharmony_ci} 21482e5b6d6dSopenharmony_ci 21492e5b6d6dSopenharmony_cistatic void 21502e5b6d6dSopenharmony_ciTestUTF16LE() { 21512e5b6d6dSopenharmony_ci /* test input */ 21522e5b6d6dSopenharmony_ci static const uint8_t in[]={ 21532e5b6d6dSopenharmony_ci 0x61, 0x00, 21542e5b6d6dSopenharmony_ci 0x31, 0x00, 21552e5b6d6dSopenharmony_ci 0x4e, 0x2e, 21562e5b6d6dSopenharmony_ci 0x4e, 0x00, 21572e5b6d6dSopenharmony_ci 0x01, 0xd8, 0x01, 0xdc 21582e5b6d6dSopenharmony_ci }; 21592e5b6d6dSopenharmony_ci 21602e5b6d6dSopenharmony_ci /* expected test results */ 21612e5b6d6dSopenharmony_ci static const int32_t results[]={ 21622e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 21632e5b6d6dSopenharmony_ci 2, 0x61, 21642e5b6d6dSopenharmony_ci 2, 0x31, 21652e5b6d6dSopenharmony_ci 2, 0x2e4e, 21662e5b6d6dSopenharmony_ci 2, 0x4e, 21672e5b6d6dSopenharmony_ci 4, 0x10401 21682e5b6d6dSopenharmony_ci }; 21692e5b6d6dSopenharmony_ci 21702e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 21712e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 21722e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("utf-16le", &errorCode); 21732e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 21742e5b6d6dSopenharmony_ci log_err("Unable to open a UTF16-LE converter: %s\n", u_errorName(errorCode)); 21752e5b6d6dSopenharmony_ci return; 21762e5b6d6dSopenharmony_ci } 21772e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-16LE"); 21782e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 21792e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 21802e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 21812e5b6d6dSopenharmony_ci { 21822e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x61}; 21832e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 21842e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character"); 21852e5b6d6dSopenharmony_ci } 21862e5b6d6dSopenharmony_ci#if 0 21872e5b6d6dSopenharmony_ci /* 21882e5b6d6dSopenharmony_ci * Test disabled because currently the UTF-16BE/LE converters are supposed 21892e5b6d6dSopenharmony_ci * to not set errors for unpaired surrogates. 21902e5b6d6dSopenharmony_ci * This may change with 21912e5b6d6dSopenharmony_ci * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32 21922e5b6d6dSopenharmony_ci */ 21932e5b6d6dSopenharmony_ci 21942e5b6d6dSopenharmony_ci /*Test for the condition where there is a surrogate character*/ 21952e5b6d6dSopenharmony_ci { 21962e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x01, 0xd8}; 21972e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character"); 21982e5b6d6dSopenharmony_ci } 21992e5b6d6dSopenharmony_ci#endif 22002e5b6d6dSopenharmony_ci 22012e5b6d6dSopenharmony_ci ucnv_close(cnv); 22022e5b6d6dSopenharmony_ci} 22032e5b6d6dSopenharmony_ci 22042e5b6d6dSopenharmony_cistatic void TestUTF32() { 22052e5b6d6dSopenharmony_ci /* test input */ 22062e5b6d6dSopenharmony_ci static const uint8_t in1[]={ 22072e5b6d6dSopenharmony_ci 0x00, 0x00, 0xfe, 0xff, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff 22082e5b6d6dSopenharmony_ci }; 22092e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 22102e5b6d6dSopenharmony_ci 0xff, 0xfe, 0x00, 0x00, 0x00, 0x10, 0x0f, 0x00, 0xfe, 0xff, 0x00, 0x00 22112e5b6d6dSopenharmony_ci }; 22122e5b6d6dSopenharmony_ci static const uint8_t in3[]={ 22132e5b6d6dSopenharmony_ci 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x00, 0xd8, 0x40, 0x00, 0x00, 0xdc, 0x01 22142e5b6d6dSopenharmony_ci }; 22152e5b6d6dSopenharmony_ci 22162e5b6d6dSopenharmony_ci /* expected test results */ 22172e5b6d6dSopenharmony_ci static const int32_t results1[]={ 22182e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 22192e5b6d6dSopenharmony_ci 8, 0x100f00, 22202e5b6d6dSopenharmony_ci 4, 0xfeff 22212e5b6d6dSopenharmony_ci }; 22222e5b6d6dSopenharmony_ci static const int32_t results2[]={ 22232e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 22242e5b6d6dSopenharmony_ci 8, 0x0f1000, 22252e5b6d6dSopenharmony_ci 4, 0xfffe 22262e5b6d6dSopenharmony_ci }; 22272e5b6d6dSopenharmony_ci static const int32_t results3[]={ 22282e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 22292e5b6d6dSopenharmony_ci 4, 0xfefe, 22302e5b6d6dSopenharmony_ci 4, 0x100f00, 22312e5b6d6dSopenharmony_ci 4, 0xfffd, /* unmatched surrogate */ 22322e5b6d6dSopenharmony_ci 4, 0xfffd /* unmatched surrogate */ 22332e5b6d6dSopenharmony_ci }; 22342e5b6d6dSopenharmony_ci 22352e5b6d6dSopenharmony_ci const char *source, *limit; 22362e5b6d6dSopenharmony_ci 22372e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 22382e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-32", &errorCode); 22392e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 22402e5b6d6dSopenharmony_ci log_data_err("Unable to open a UTF-32 converter: %s\n", u_errorName(errorCode)); 22412e5b6d6dSopenharmony_ci return; 22422e5b6d6dSopenharmony_ci } 22432e5b6d6dSopenharmony_ci 22442e5b6d6dSopenharmony_ci source=(const char *)in1, limit=(const char *)in1+sizeof(in1); 22452e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results1, "UTF-32"); 22462e5b6d6dSopenharmony_ci 22472e5b6d6dSopenharmony_ci source=(const char *)in2, limit=(const char *)in2+sizeof(in2); 22482e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 22492e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "UTF-32"); 22502e5b6d6dSopenharmony_ci 22512e5b6d6dSopenharmony_ci source=(const char *)in3, limit=(const char *)in3+sizeof(in3); 22522e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 22532e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results3, "UTF-32"); 22542e5b6d6dSopenharmony_ci 22552e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 22562e5b6d6dSopenharmony_ci ucnv_resetToUnicode(cnv); 22572e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 22582e5b6d6dSopenharmony_ci 22592e5b6d6dSopenharmony_ci ucnv_close(cnv); 22602e5b6d6dSopenharmony_ci} 22612e5b6d6dSopenharmony_ci 22622e5b6d6dSopenharmony_cistatic void 22632e5b6d6dSopenharmony_ciTestUTF32BE() { 22642e5b6d6dSopenharmony_ci /* test input */ 22652e5b6d6dSopenharmony_ci static const uint8_t in[]={ 22662e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x61, 22672e5b6d6dSopenharmony_ci 0x00, 0x00, 0x30, 0x61, 22682e5b6d6dSopenharmony_ci 0x00, 0x00, 0xdc, 0x00, 22692e5b6d6dSopenharmony_ci 0x00, 0x00, 0xd8, 0x00, 22702e5b6d6dSopenharmony_ci 0x00, 0x00, 0xdf, 0xff, 22712e5b6d6dSopenharmony_ci 0x00, 0x00, 0xff, 0xfe, 22722e5b6d6dSopenharmony_ci 0x00, 0x10, 0xab, 0xcd, 22732e5b6d6dSopenharmony_ci 0x00, 0x10, 0xff, 0xff 22742e5b6d6dSopenharmony_ci }; 22752e5b6d6dSopenharmony_ci 22762e5b6d6dSopenharmony_ci /* expected test results */ 22772e5b6d6dSopenharmony_ci static const int32_t results[]={ 22782e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 22792e5b6d6dSopenharmony_ci 4, 0x61, 22802e5b6d6dSopenharmony_ci 4, 0x3061, 22812e5b6d6dSopenharmony_ci 4, 0xfffd, 22822e5b6d6dSopenharmony_ci 4, 0xfffd, 22832e5b6d6dSopenharmony_ci 4, 0xfffd, 22842e5b6d6dSopenharmony_ci 4, 0xfffe, 22852e5b6d6dSopenharmony_ci 4, 0x10abcd, 22862e5b6d6dSopenharmony_ci 4, 0x10ffff 22872e5b6d6dSopenharmony_ci }; 22882e5b6d6dSopenharmony_ci 22892e5b6d6dSopenharmony_ci /* error test input */ 22902e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 22912e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x61, 22922e5b6d6dSopenharmony_ci 0x00, 0x11, 0x00, 0x00, /* 0x110000 out of range */ 22932e5b6d6dSopenharmony_ci 0x00, 0x00, 0x00, 0x62, 22942e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0xff, /* 0xffffffff out of range */ 22952e5b6d6dSopenharmony_ci 0x7f, 0xff, 0xff, 0xff, /* 0x7fffffff out of range */ 22962e5b6d6dSopenharmony_ci 0x00, 0x00, 0x01, 0x62, 22972e5b6d6dSopenharmony_ci 0x00, 0x00, 0x02, 0x62 22982e5b6d6dSopenharmony_ci }; 22992e5b6d6dSopenharmony_ci 23002e5b6d6dSopenharmony_ci /* expected error test results */ 23012e5b6d6dSopenharmony_ci static const int32_t results2[]={ 23022e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 23032e5b6d6dSopenharmony_ci 4, 0x61, 23042e5b6d6dSopenharmony_ci 8, 0x62, 23052e5b6d6dSopenharmony_ci 12, 0x162, 23062e5b6d6dSopenharmony_ci 4, 0x262 23072e5b6d6dSopenharmony_ci }; 23082e5b6d6dSopenharmony_ci 23092e5b6d6dSopenharmony_ci UConverterToUCallback cb; 23102e5b6d6dSopenharmony_ci const void *p; 23112e5b6d6dSopenharmony_ci 23122e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 23132e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 23142e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-32BE", &errorCode); 23152e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 23162e5b6d6dSopenharmony_ci log_data_err("Unable to open a UTF-32BE converter: %s\n", u_errorName(errorCode)); 23172e5b6d6dSopenharmony_ci return; 23182e5b6d6dSopenharmony_ci } 23192e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-32BE"); 23202e5b6d6dSopenharmony_ci 23212e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 23222e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 23232e5b6d6dSopenharmony_ci 23242e5b6d6dSopenharmony_ci /* test error behavior with a skip callback */ 23252e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode); 23262e5b6d6dSopenharmony_ci source=(const char *)in2; 23272e5b6d6dSopenharmony_ci limit=(const char *)(in2+sizeof(in2)); 23282e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "UTF-32BE"); 23292e5b6d6dSopenharmony_ci 23302e5b6d6dSopenharmony_ci ucnv_close(cnv); 23312e5b6d6dSopenharmony_ci} 23322e5b6d6dSopenharmony_ci 23332e5b6d6dSopenharmony_cistatic void 23342e5b6d6dSopenharmony_ciTestUTF32LE() { 23352e5b6d6dSopenharmony_ci /* test input */ 23362e5b6d6dSopenharmony_ci static const uint8_t in[]={ 23372e5b6d6dSopenharmony_ci 0x61, 0x00, 0x00, 0x00, 23382e5b6d6dSopenharmony_ci 0x61, 0x30, 0x00, 0x00, 23392e5b6d6dSopenharmony_ci 0x00, 0xdc, 0x00, 0x00, 23402e5b6d6dSopenharmony_ci 0x00, 0xd8, 0x00, 0x00, 23412e5b6d6dSopenharmony_ci 0xff, 0xdf, 0x00, 0x00, 23422e5b6d6dSopenharmony_ci 0xfe, 0xff, 0x00, 0x00, 23432e5b6d6dSopenharmony_ci 0xcd, 0xab, 0x10, 0x00, 23442e5b6d6dSopenharmony_ci 0xff, 0xff, 0x10, 0x00 23452e5b6d6dSopenharmony_ci }; 23462e5b6d6dSopenharmony_ci 23472e5b6d6dSopenharmony_ci /* expected test results */ 23482e5b6d6dSopenharmony_ci static const int32_t results[]={ 23492e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 23502e5b6d6dSopenharmony_ci 4, 0x61, 23512e5b6d6dSopenharmony_ci 4, 0x3061, 23522e5b6d6dSopenharmony_ci 4, 0xfffd, 23532e5b6d6dSopenharmony_ci 4, 0xfffd, 23542e5b6d6dSopenharmony_ci 4, 0xfffd, 23552e5b6d6dSopenharmony_ci 4, 0xfffe, 23562e5b6d6dSopenharmony_ci 4, 0x10abcd, 23572e5b6d6dSopenharmony_ci 4, 0x10ffff 23582e5b6d6dSopenharmony_ci }; 23592e5b6d6dSopenharmony_ci 23602e5b6d6dSopenharmony_ci /* error test input */ 23612e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 23622e5b6d6dSopenharmony_ci 0x61, 0x00, 0x00, 0x00, 23632e5b6d6dSopenharmony_ci 0x00, 0x00, 0x11, 0x00, /* 0x110000 out of range */ 23642e5b6d6dSopenharmony_ci 0x62, 0x00, 0x00, 0x00, 23652e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0xff, /* 0xffffffff out of range */ 23662e5b6d6dSopenharmony_ci 0xff, 0xff, 0xff, 0x7f, /* 0x7fffffff out of range */ 23672e5b6d6dSopenharmony_ci 0x62, 0x01, 0x00, 0x00, 23682e5b6d6dSopenharmony_ci 0x62, 0x02, 0x00, 0x00, 23692e5b6d6dSopenharmony_ci }; 23702e5b6d6dSopenharmony_ci 23712e5b6d6dSopenharmony_ci /* expected error test results */ 23722e5b6d6dSopenharmony_ci static const int32_t results2[]={ 23732e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 23742e5b6d6dSopenharmony_ci 4, 0x61, 23752e5b6d6dSopenharmony_ci 8, 0x62, 23762e5b6d6dSopenharmony_ci 12, 0x162, 23772e5b6d6dSopenharmony_ci 4, 0x262, 23782e5b6d6dSopenharmony_ci }; 23792e5b6d6dSopenharmony_ci 23802e5b6d6dSopenharmony_ci UConverterToUCallback cb; 23812e5b6d6dSopenharmony_ci const void *p; 23822e5b6d6dSopenharmony_ci 23832e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 23842e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 23852e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("UTF-32LE", &errorCode); 23862e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 23872e5b6d6dSopenharmony_ci log_data_err("Unable to open a UTF-32LE converter: %s\n", u_errorName(errorCode)); 23882e5b6d6dSopenharmony_ci return; 23892e5b6d6dSopenharmony_ci } 23902e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "UTF-32LE"); 23912e5b6d6dSopenharmony_ci 23922e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 23932e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 23942e5b6d6dSopenharmony_ci 23952e5b6d6dSopenharmony_ci /* test error behavior with a skip callback */ 23962e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode); 23972e5b6d6dSopenharmony_ci source=(const char *)in2; 23982e5b6d6dSopenharmony_ci limit=(const char *)(in2+sizeof(in2)); 23992e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results2, "UTF-32LE"); 24002e5b6d6dSopenharmony_ci 24012e5b6d6dSopenharmony_ci ucnv_close(cnv); 24022e5b6d6dSopenharmony_ci} 24032e5b6d6dSopenharmony_ci 24042e5b6d6dSopenharmony_cistatic void 24052e5b6d6dSopenharmony_ciTestLATIN1() { 24062e5b6d6dSopenharmony_ci /* test input */ 24072e5b6d6dSopenharmony_ci static const uint8_t in[]={ 24082e5b6d6dSopenharmony_ci 0x61, 24092e5b6d6dSopenharmony_ci 0x31, 24102e5b6d6dSopenharmony_ci 0x32, 24112e5b6d6dSopenharmony_ci 0xc0, 24122e5b6d6dSopenharmony_ci 0xf0, 24132e5b6d6dSopenharmony_ci 0xf4, 24142e5b6d6dSopenharmony_ci }; 24152e5b6d6dSopenharmony_ci 24162e5b6d6dSopenharmony_ci /* expected test results */ 24172e5b6d6dSopenharmony_ci static const int32_t results[]={ 24182e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 24192e5b6d6dSopenharmony_ci 1, 0x61, 24202e5b6d6dSopenharmony_ci 1, 0x31, 24212e5b6d6dSopenharmony_ci 1, 0x32, 24222e5b6d6dSopenharmony_ci 1, 0xc0, 24232e5b6d6dSopenharmony_ci 1, 0xf0, 24242e5b6d6dSopenharmony_ci 1, 0xf4, 24252e5b6d6dSopenharmony_ci }; 24262e5b6d6dSopenharmony_ci static const uint16_t in1[] = { 24272e5b6d6dSopenharmony_ci 0x08, 0x00, 0x1b, 0x4c, 0xea, 0x16, 0xca, 0xd3, 0x94, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 24282e5b6d6dSopenharmony_ci 0xc4, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 0xc4, 0x16, 0xca, 0xd3, 0x94, 0x08, 0x02, 0x0f, 24292e5b6d6dSopenharmony_ci 0x53, 0x4a, 0x4e, 0x16, 0x7d, 0x00, 0x30, 0x82, 0x52, 0x4d, 0x30, 0x6b, 0x6d, 0x41, 0x88, 0x4c, 24302e5b6d6dSopenharmony_ci 0xe5, 0x97, 0x9f, 0x08, 0x0c, 0x16, 0xca, 0xd3, 0x94, 0x15, 0xae, 0x0e, 0x6b, 0x4c, 0x08, 0x0d, 24312e5b6d6dSopenharmony_ci 0x8c, 0xb4, 0xa3, 0x9f, 0xca, 0x99, 0xcb, 0x8b, 0xc2, 0x97, 0xcc, 0xaa, 0x84, 0x08, 0x02, 0x0e, 24322e5b6d6dSopenharmony_ci 0x7c, 0x73, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x93, 0xd3, 0xb4, 0xc5, 0xdc, 0x9f, 0x0e, 0x79, 0x3e, 24332e5b6d6dSopenharmony_ci 0x06, 0xae, 0xb1, 0x9d, 0x93, 0xd3, 0x08, 0x0c, 0xbe, 0xa3, 0x8f, 0x08, 0x88, 0xbe, 0xa3, 0x8d, 24342e5b6d6dSopenharmony_ci 0xd3, 0xa8, 0xa3, 0x97, 0xc5, 0x17, 0x89, 0x08, 0x0d, 0x15, 0xd2, 0x08, 0x01, 0x93, 0xc8, 0xaa, 24352e5b6d6dSopenharmony_ci 0x8f, 0x0e, 0x61, 0x1b, 0x99, 0xcb, 0x0e, 0x4e, 0xba, 0x9f, 0xa1, 0xae, 0x93, 0xa8, 0xa0, 0x08, 24362e5b6d6dSopenharmony_ci 0x02, 0x08, 0x0c, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x0f, 0x4f, 0xe1, 0x80, 0x05, 0xec, 0x60, 0x8d, 24372e5b6d6dSopenharmony_ci 0xea, 0x06, 0xd3, 0xe6, 0x0f, 0x8a, 0x00, 0x30, 0x44, 0x65, 0xb9, 0xe4, 0xfe, 0xe7, 0xc2, 0x06, 24382e5b6d6dSopenharmony_ci 0xcb, 0x82 24392e5b6d6dSopenharmony_ci }; 24402e5b6d6dSopenharmony_ci static const uint8_t out1[] = { 24412e5b6d6dSopenharmony_ci 0x08, 0x00, 0x1b, 0x4c, 0xea, 0x16, 0xca, 0xd3, 0x94, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 24422e5b6d6dSopenharmony_ci 0xc4, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 0xc4, 0x16, 0xca, 0xd3, 0x94, 0x08, 0x02, 0x0f, 24432e5b6d6dSopenharmony_ci 0x53, 0x4a, 0x4e, 0x16, 0x7d, 0x00, 0x30, 0x82, 0x52, 0x4d, 0x30, 0x6b, 0x6d, 0x41, 0x88, 0x4c, 24442e5b6d6dSopenharmony_ci 0xe5, 0x97, 0x9f, 0x08, 0x0c, 0x16, 0xca, 0xd3, 0x94, 0x15, 0xae, 0x0e, 0x6b, 0x4c, 0x08, 0x0d, 24452e5b6d6dSopenharmony_ci 0x8c, 0xb4, 0xa3, 0x9f, 0xca, 0x99, 0xcb, 0x8b, 0xc2, 0x97, 0xcc, 0xaa, 0x84, 0x08, 0x02, 0x0e, 24462e5b6d6dSopenharmony_ci 0x7c, 0x73, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x93, 0xd3, 0xb4, 0xc5, 0xdc, 0x9f, 0x0e, 0x79, 0x3e, 24472e5b6d6dSopenharmony_ci 0x06, 0xae, 0xb1, 0x9d, 0x93, 0xd3, 0x08, 0x0c, 0xbe, 0xa3, 0x8f, 0x08, 0x88, 0xbe, 0xa3, 0x8d, 24482e5b6d6dSopenharmony_ci 0xd3, 0xa8, 0xa3, 0x97, 0xc5, 0x17, 0x89, 0x08, 0x0d, 0x15, 0xd2, 0x08, 0x01, 0x93, 0xc8, 0xaa, 24492e5b6d6dSopenharmony_ci 0x8f, 0x0e, 0x61, 0x1b, 0x99, 0xcb, 0x0e, 0x4e, 0xba, 0x9f, 0xa1, 0xae, 0x93, 0xa8, 0xa0, 0x08, 24502e5b6d6dSopenharmony_ci 0x02, 0x08, 0x0c, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x0f, 0x4f, 0xe1, 0x80, 0x05, 0xec, 0x60, 0x8d, 24512e5b6d6dSopenharmony_ci 0xea, 0x06, 0xd3, 0xe6, 0x0f, 0x8a, 0x00, 0x30, 0x44, 0x65, 0xb9, 0xe4, 0xfe, 0xe7, 0xc2, 0x06, 24522e5b6d6dSopenharmony_ci 0xcb, 0x82 24532e5b6d6dSopenharmony_ci }; 24542e5b6d6dSopenharmony_ci static const uint16_t in2[]={ 24552e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x29, 0x47, 0x0E, 0x23, 0x21, 0x23, 0x22, 0x23, 24562e5b6d6dSopenharmony_ci 0x23, 0x23, 0x24, 0x23, 0x25, 0x23, 0x26, 0x23, 0x27, 0x23, 24572e5b6d6dSopenharmony_ci 0x28, 0x23, 0x29, 0x23, 0x2A, 0x23, 0x2B, 0x0F, 0x2F, 0x2A, 24582e5b6d6dSopenharmony_ci 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 0x31, 0x20, 0x2A, 0x2F, 24592e5b6d6dSopenharmony_ci 0x0D, 0x0A, 0x1B, 0x24, 0x2A, 0x48, 0x1B, 0x4E, 0x22, 0x21, 24602e5b6d6dSopenharmony_ci 0x1B, 0x4E, 0x22, 0x22, 0x1B, 0x4E, 0x22, 0x23, 0x1B, 0x4E, 24612e5b6d6dSopenharmony_ci 0x22, 0x24, 0x1B, 0x4E, 0x22, 0x25, 0x0F, 0x2F, 0x2A, 0x70, 24622e5b6d6dSopenharmony_ci 0x6C, 0x61, 0x6E, 0x65, 0x32, 0x2A, 0x2F, 0x20, 0x0D, 0x0A, 24632e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x2B, 0x49, 0x1B, 0x4F, 0x22, 0x44, 0x1B, 0x4F, 24642e5b6d6dSopenharmony_ci 0x22, 0x45, 0x1B, 0x4F, 0x22, 0x46, 0x1B, 0x4F, 0x22, 0x47, 24652e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x48, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 24662e5b6d6dSopenharmony_ci 0x6E, 0x65, 0x20, 0x33, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 24672e5b6d6dSopenharmony_ci 0x24, 0x2B, 0x4A, 0x1B, 0x4F, 0x21, 0x44, 0x1B, 0x4F, 0x21, 24682e5b6d6dSopenharmony_ci 0x45, 0x1B, 0x4F, 0x22, 0x6A, 0x1B, 0x4F, 0x22, 0x6B, 0x1B, 24692e5b6d6dSopenharmony_ci 0x4F, 0x22, 0x6C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 24702e5b6d6dSopenharmony_ci 0x65, 0x20, 0x34, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 24712e5b6d6dSopenharmony_ci 0x2B, 0x4B, 0x1B, 0x4F, 0x21, 0x74, 0x1B, 0x4F, 0x22, 0x50, 24722e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x51, 0x1B, 0x4F, 0x23, 0x37, 0x1B, 0x4F, 24732e5b6d6dSopenharmony_ci 0x22, 0x5C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 24742e5b6d6dSopenharmony_ci 0x65, 0x20, 0x35, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 24752e5b6d6dSopenharmony_ci 0x2B, 0x4C, 0x1B, 0x4F, 0x21, 0x23, 0x1B, 0x4F, 0x22, 0x2C, 24762e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x23, 0x4E, 0x1B, 0x4F, 0x21, 0x6E, 0x1B, 0x4F, 24772e5b6d6dSopenharmony_ci 0x23, 0x71, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 24782e5b6d6dSopenharmony_ci 0x20, 0x36, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 0x2B, 24792e5b6d6dSopenharmony_ci 0x4D, 0x1B, 0x4F, 0x22, 0x71, 0x1B, 0x4F, 0x21, 0x4E, 0x1B, 24802e5b6d6dSopenharmony_ci 0x4F, 0x21, 0x6A, 0x1B, 0x4F, 0x23, 0x3A, 0x1B, 0x4F, 0x23, 24812e5b6d6dSopenharmony_ci 0x6F, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 24822e5b6d6dSopenharmony_ci 0x37, 0x20, 0x2A, 0x2F, 24832e5b6d6dSopenharmony_ci }; 24842e5b6d6dSopenharmony_ci static const unsigned char out2[]={ 24852e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x29, 0x47, 0x0E, 0x23, 0x21, 0x23, 0x22, 0x23, 24862e5b6d6dSopenharmony_ci 0x23, 0x23, 0x24, 0x23, 0x25, 0x23, 0x26, 0x23, 0x27, 0x23, 24872e5b6d6dSopenharmony_ci 0x28, 0x23, 0x29, 0x23, 0x2A, 0x23, 0x2B, 0x0F, 0x2F, 0x2A, 24882e5b6d6dSopenharmony_ci 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 0x31, 0x20, 0x2A, 0x2F, 24892e5b6d6dSopenharmony_ci 0x0D, 0x0A, 0x1B, 0x24, 0x2A, 0x48, 0x1B, 0x4E, 0x22, 0x21, 24902e5b6d6dSopenharmony_ci 0x1B, 0x4E, 0x22, 0x22, 0x1B, 0x4E, 0x22, 0x23, 0x1B, 0x4E, 24912e5b6d6dSopenharmony_ci 0x22, 0x24, 0x1B, 0x4E, 0x22, 0x25, 0x0F, 0x2F, 0x2A, 0x70, 24922e5b6d6dSopenharmony_ci 0x6C, 0x61, 0x6E, 0x65, 0x32, 0x2A, 0x2F, 0x20, 0x0D, 0x0A, 24932e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x2B, 0x49, 0x1B, 0x4F, 0x22, 0x44, 0x1B, 0x4F, 24942e5b6d6dSopenharmony_ci 0x22, 0x45, 0x1B, 0x4F, 0x22, 0x46, 0x1B, 0x4F, 0x22, 0x47, 24952e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x48, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 24962e5b6d6dSopenharmony_ci 0x6E, 0x65, 0x20, 0x33, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 24972e5b6d6dSopenharmony_ci 0x24, 0x2B, 0x4A, 0x1B, 0x4F, 0x21, 0x44, 0x1B, 0x4F, 0x21, 24982e5b6d6dSopenharmony_ci 0x45, 0x1B, 0x4F, 0x22, 0x6A, 0x1B, 0x4F, 0x22, 0x6B, 0x1B, 24992e5b6d6dSopenharmony_ci 0x4F, 0x22, 0x6C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 25002e5b6d6dSopenharmony_ci 0x65, 0x20, 0x34, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 25012e5b6d6dSopenharmony_ci 0x2B, 0x4B, 0x1B, 0x4F, 0x21, 0x74, 0x1B, 0x4F, 0x22, 0x50, 25022e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x51, 0x1B, 0x4F, 0x23, 0x37, 0x1B, 0x4F, 25032e5b6d6dSopenharmony_ci 0x22, 0x5C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 25042e5b6d6dSopenharmony_ci 0x65, 0x20, 0x35, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 25052e5b6d6dSopenharmony_ci 0x2B, 0x4C, 0x1B, 0x4F, 0x21, 0x23, 0x1B, 0x4F, 0x22, 0x2C, 25062e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x23, 0x4E, 0x1B, 0x4F, 0x21, 0x6E, 0x1B, 0x4F, 25072e5b6d6dSopenharmony_ci 0x23, 0x71, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 25082e5b6d6dSopenharmony_ci 0x20, 0x36, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 0x2B, 25092e5b6d6dSopenharmony_ci 0x4D, 0x1B, 0x4F, 0x22, 0x71, 0x1B, 0x4F, 0x21, 0x4E, 0x1B, 25102e5b6d6dSopenharmony_ci 0x4F, 0x21, 0x6A, 0x1B, 0x4F, 0x23, 0x3A, 0x1B, 0x4F, 0x23, 25112e5b6d6dSopenharmony_ci 0x6F, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 25122e5b6d6dSopenharmony_ci 0x37, 0x20, 0x2A, 0x2F, 25132e5b6d6dSopenharmony_ci }; 25142e5b6d6dSopenharmony_ci const char *source=(const char *)in; 25152e5b6d6dSopenharmony_ci const char *limit=(const char *)in+sizeof(in); 25162e5b6d6dSopenharmony_ci 25172e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 25182e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("LATIN_1", &errorCode); 25192e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 25202e5b6d6dSopenharmony_ci log_data_err("Unable to open a LATIN_1 converter: %s\n", u_errorName(errorCode)); 25212e5b6d6dSopenharmony_ci return; 25222e5b6d6dSopenharmony_ci } 25232e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "LATIN_1"); 25242e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 25252e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 25262e5b6d6dSopenharmony_ci TestConv((uint16_t*)in1,sizeof(in1)/2,"LATIN_1","LATIN-1",(char*)out1,sizeof(out1)); 25272e5b6d6dSopenharmony_ci TestConv((uint16_t*)in2,sizeof(in2)/2,"ASCII","ASCII",(char*)out2,sizeof(out2)); 25282e5b6d6dSopenharmony_ci 25292e5b6d6dSopenharmony_ci ucnv_close(cnv); 25302e5b6d6dSopenharmony_ci} 25312e5b6d6dSopenharmony_ci 25322e5b6d6dSopenharmony_cistatic void 25332e5b6d6dSopenharmony_ciTestSBCS() { 25342e5b6d6dSopenharmony_ci /* test input */ 25352e5b6d6dSopenharmony_ci static const uint8_t in[]={ 0x61, 0xc0, 0x80, 0xe0, 0xf0, 0xf4}; 25362e5b6d6dSopenharmony_ci /* expected test results */ 25372e5b6d6dSopenharmony_ci static const int32_t results[]={ 25382e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 25392e5b6d6dSopenharmony_ci 1, 0x61, 25402e5b6d6dSopenharmony_ci 1, 0xbf, 25412e5b6d6dSopenharmony_ci 1, 0xc4, 25422e5b6d6dSopenharmony_ci 1, 0x2021, 25432e5b6d6dSopenharmony_ci 1, 0xf8ff, 25442e5b6d6dSopenharmony_ci 1, 0x00d9 25452e5b6d6dSopenharmony_ci }; 25462e5b6d6dSopenharmony_ci 25472e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 25482e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 25492e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("x-mac-turkish", &errorCode); 25502e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 25512e5b6d6dSopenharmony_ci log_data_err("Unable to open a SBCS(x-mac-turkish) converter: %s\n", u_errorName(errorCode)); 25522e5b6d6dSopenharmony_ci return; 25532e5b6d6dSopenharmony_ci } 25542e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "SBCS(x-mac-turkish)"); 25552e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 25562e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 25572e5b6d6dSopenharmony_ci /*Test for Illegal character */ /* 25582e5b6d6dSopenharmony_ci { 25592e5b6d6dSopenharmony_ci static const uint8_t input1[]={ 0xA1 }; 25602e5b6d6dSopenharmony_ci const char* illegalsource=(const char*)input1; 25612e5b6d6dSopenharmony_ci TestNextUCharError(cnv, illegalsource, illegalsource+sizeof(illegalsource), U_INVALID_CHAR_FOUND, "source has a illegal character"); 25622e5b6d6dSopenharmony_ci } 25632e5b6d6dSopenharmony_ci */ 25642e5b6d6dSopenharmony_ci ucnv_close(cnv); 25652e5b6d6dSopenharmony_ci} 25662e5b6d6dSopenharmony_ci 25672e5b6d6dSopenharmony_cistatic void 25682e5b6d6dSopenharmony_ciTestDBCS() { 25692e5b6d6dSopenharmony_ci /* test input */ 25702e5b6d6dSopenharmony_ci static const uint8_t in[]={ 25712e5b6d6dSopenharmony_ci 0x44, 0x6a, 25722e5b6d6dSopenharmony_ci 0xc4, 0x9c, 25732e5b6d6dSopenharmony_ci 0x7a, 0x74, 25742e5b6d6dSopenharmony_ci 0x46, 0xab, 25752e5b6d6dSopenharmony_ci 0x42, 0x5b, 25762e5b6d6dSopenharmony_ci 25772e5b6d6dSopenharmony_ci }; 25782e5b6d6dSopenharmony_ci 25792e5b6d6dSopenharmony_ci /* expected test results */ 25802e5b6d6dSopenharmony_ci static const int32_t results[]={ 25812e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 25822e5b6d6dSopenharmony_ci 2, 0x00a7, 25832e5b6d6dSopenharmony_ci 2, 0xe1d2, 25842e5b6d6dSopenharmony_ci 2, 0x6962, 25852e5b6d6dSopenharmony_ci 2, 0xf842, 25862e5b6d6dSopenharmony_ci 2, 0xffe5, 25872e5b6d6dSopenharmony_ci }; 25882e5b6d6dSopenharmony_ci 25892e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 25902e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 25912e5b6d6dSopenharmony_ci 25922e5b6d6dSopenharmony_ci UConverter *cnv=my_ucnv_open("@ibm9027", &errorCode); 25932e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 25942e5b6d6dSopenharmony_ci log_data_err("Unable to open a DBCS(@ibm9027) converter: %s\n", u_errorName(errorCode)); 25952e5b6d6dSopenharmony_ci return; 25962e5b6d6dSopenharmony_ci } 25972e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "DBCS(@ibm9027)"); 25982e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 25992e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 26002e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 26012e5b6d6dSopenharmony_ci { 26022e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x1a, 0x1b}; 26032e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character"); 26042e5b6d6dSopenharmony_ci } 26052e5b6d6dSopenharmony_ci /*Test for the condition where we have a truncated char*/ 26062e5b6d6dSopenharmony_ci { 26072e5b6d6dSopenharmony_ci static const uint8_t source1[]={0xc4}; 26082e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 26092e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated"); 26102e5b6d6dSopenharmony_ci } 26112e5b6d6dSopenharmony_ci ucnv_close(cnv); 26122e5b6d6dSopenharmony_ci} 26132e5b6d6dSopenharmony_ci 26142e5b6d6dSopenharmony_cistatic void 26152e5b6d6dSopenharmony_ciTestMBCS() { 26162e5b6d6dSopenharmony_ci /* test input */ 26172e5b6d6dSopenharmony_ci static const uint8_t in[]={ 26182e5b6d6dSopenharmony_ci 0x01, 26192e5b6d6dSopenharmony_ci 0xa6, 0xa3, 26202e5b6d6dSopenharmony_ci 0x00, 26212e5b6d6dSopenharmony_ci 0xa6, 0xa1, 26222e5b6d6dSopenharmony_ci 0x08, 26232e5b6d6dSopenharmony_ci 0xc2, 0x76, 26242e5b6d6dSopenharmony_ci 0xc2, 0x78, 26252e5b6d6dSopenharmony_ci 26262e5b6d6dSopenharmony_ci }; 26272e5b6d6dSopenharmony_ci 26282e5b6d6dSopenharmony_ci /* expected test results */ 26292e5b6d6dSopenharmony_ci static const int32_t results[]={ 26302e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 26312e5b6d6dSopenharmony_ci 1, 0x0001, 26322e5b6d6dSopenharmony_ci 2, 0x250c, 26332e5b6d6dSopenharmony_ci 1, 0x0000, 26342e5b6d6dSopenharmony_ci 2, 0x2500, 26352e5b6d6dSopenharmony_ci 1, 0x0008, 26362e5b6d6dSopenharmony_ci 2, 0xd60c, 26372e5b6d6dSopenharmony_ci 2, 0xd60e, 26382e5b6d6dSopenharmony_ci }; 26392e5b6d6dSopenharmony_ci 26402e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 26412e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 26422e5b6d6dSopenharmony_ci 26432e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("ibm-1363", &errorCode); 26442e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 26452e5b6d6dSopenharmony_ci log_data_err("Unable to open a MBCS(ibm-1363) converter: %s\n", u_errorName(errorCode)); 26462e5b6d6dSopenharmony_ci return; 26472e5b6d6dSopenharmony_ci } 26482e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "MBCS(ibm-1363)"); 26492e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 26502e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 26512e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 26522e5b6d6dSopenharmony_ci { 26532e5b6d6dSopenharmony_ci static const uint8_t source2[]={0xa1, 0x80}; 26542e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character"); 26552e5b6d6dSopenharmony_ci } 26562e5b6d6dSopenharmony_ci /*Test for the condition where we have a truncated char*/ 26572e5b6d6dSopenharmony_ci { 26582e5b6d6dSopenharmony_ci static const uint8_t source1[]={0xc4}; 26592e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 26602e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated"); 26612e5b6d6dSopenharmony_ci } 26622e5b6d6dSopenharmony_ci ucnv_close(cnv); 26632e5b6d6dSopenharmony_ci 26642e5b6d6dSopenharmony_ci} 26652e5b6d6dSopenharmony_ci 26662e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO 26672e5b6d6dSopenharmony_cistatic void 26682e5b6d6dSopenharmony_ciTestICCRunout() { 26692e5b6d6dSopenharmony_ci/* { "ibm-1363", :bin{ a2aea2 }, "\u00a1\u001a", :intvector{ 0, 2 }, :int{1}, :int{0}, "\", "?", :bin{""} } */ 26702e5b6d6dSopenharmony_ci 26712e5b6d6dSopenharmony_ci const char *cnvName = "ibm-1363"; 26722e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 26732e5b6d6dSopenharmony_ci const char sourceData[] = { (char)0xa2, (char)0xae, (char)0xa2 }; 26742e5b6d6dSopenharmony_ci /* UChar expectUData[] = { 0x00a1, 0x001a }; */ 26752e5b6d6dSopenharmony_ci const char *source = sourceData; 26762e5b6d6dSopenharmony_ci const char *sourceLim = sourceData+sizeof(sourceData); 26772e5b6d6dSopenharmony_ci UChar c1, c2, c3; 26782e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open(cnvName, &status); 26792e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 26802e5b6d6dSopenharmony_ci log_data_err("Unable to open %s converter: %s\n", cnvName, u_errorName(status)); 26812e5b6d6dSopenharmony_ci return; 26822e5b6d6dSopenharmony_ci } 26832e5b6d6dSopenharmony_ci 26842e5b6d6dSopenharmony_ci#if 0 26852e5b6d6dSopenharmony_ci { 26862e5b6d6dSopenharmony_ci UChar targetBuf[256]; 26872e5b6d6dSopenharmony_ci UChar *target = targetBuf; 26882e5b6d6dSopenharmony_ci UChar *targetLim = target+256; 26892e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &target, targetLim, &source, sourceLim, NULL, true, &status); 26902e5b6d6dSopenharmony_ci 26912e5b6d6dSopenharmony_ci log_info("After convert: target@%d, source@%d, status%s\n", 26922e5b6d6dSopenharmony_ci target-targetBuf, source-sourceData, u_errorName(status)); 26932e5b6d6dSopenharmony_ci 26942e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 26952e5b6d6dSopenharmony_ci log_err("Failed to convert: %s\n", u_errorName(status)); 26962e5b6d6dSopenharmony_ci } else { 26972e5b6d6dSopenharmony_ci 26982e5b6d6dSopenharmony_ci } 26992e5b6d6dSopenharmony_ci } 27002e5b6d6dSopenharmony_ci#endif 27012e5b6d6dSopenharmony_ci 27022e5b6d6dSopenharmony_ci c1=ucnv_getNextUChar(cnv, &source, sourceLim, &status); 27032e5b6d6dSopenharmony_ci log_verbose("c1: U+%04X, source@%d, status %s\n", c1, source-sourceData, u_errorName(status)); 27042e5b6d6dSopenharmony_ci 27052e5b6d6dSopenharmony_ci c2=ucnv_getNextUChar(cnv, &source, sourceLim, &status); 27062e5b6d6dSopenharmony_ci log_verbose("c2: U+%04X, source@%d, status %s\n", c2, source-sourceData, u_errorName(status)); 27072e5b6d6dSopenharmony_ci 27082e5b6d6dSopenharmony_ci c3=ucnv_getNextUChar(cnv, &source, sourceLim, &status); 27092e5b6d6dSopenharmony_ci log_verbose("c3: U+%04X, source@%d, status %s\n", c3, source-sourceData, u_errorName(status)); 27102e5b6d6dSopenharmony_ci 27112e5b6d6dSopenharmony_ci if(status==U_INDEX_OUTOFBOUNDS_ERROR && c3==0xFFFF) { 27122e5b6d6dSopenharmony_ci log_verbose("OK\n"); 27132e5b6d6dSopenharmony_ci } else { 27142e5b6d6dSopenharmony_ci log_err("FAIL: c3 was not FFFF or err was not U_INDEXOUTOFBOUNDS_ERROR\n"); 27152e5b6d6dSopenharmony_ci } 27162e5b6d6dSopenharmony_ci 27172e5b6d6dSopenharmony_ci ucnv_close(cnv); 27182e5b6d6dSopenharmony_ci 27192e5b6d6dSopenharmony_ci} 27202e5b6d6dSopenharmony_ci#endif 27212e5b6d6dSopenharmony_ci 27222e5b6d6dSopenharmony_ci#ifdef U_ENABLE_GENERIC_ISO_2022 27232e5b6d6dSopenharmony_ci 27242e5b6d6dSopenharmony_cistatic void 27252e5b6d6dSopenharmony_ciTestISO_2022() { 27262e5b6d6dSopenharmony_ci /* test input */ 27272e5b6d6dSopenharmony_ci static const uint8_t in[]={ 27282e5b6d6dSopenharmony_ci 0x1b, 0x25, 0x42, 27292e5b6d6dSopenharmony_ci 0x31, 27302e5b6d6dSopenharmony_ci 0x32, 27312e5b6d6dSopenharmony_ci 0x61, 27322e5b6d6dSopenharmony_ci 0xc2, 0x80, 27332e5b6d6dSopenharmony_ci 0xe0, 0xa0, 0x80, 27342e5b6d6dSopenharmony_ci 0xf0, 0x90, 0x80, 0x80 27352e5b6d6dSopenharmony_ci }; 27362e5b6d6dSopenharmony_ci 27372e5b6d6dSopenharmony_ci 27382e5b6d6dSopenharmony_ci 27392e5b6d6dSopenharmony_ci /* expected test results */ 27402e5b6d6dSopenharmony_ci static const int32_t results[]={ 27412e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 27422e5b6d6dSopenharmony_ci 4, 0x0031, /* 4 bytes including the escape sequence */ 27432e5b6d6dSopenharmony_ci 1, 0x0032, 27442e5b6d6dSopenharmony_ci 1, 0x61, 27452e5b6d6dSopenharmony_ci 2, 0x80, 27462e5b6d6dSopenharmony_ci 3, 0x800, 27472e5b6d6dSopenharmony_ci 4, 0x10000 27482e5b6d6dSopenharmony_ci }; 27492e5b6d6dSopenharmony_ci 27502e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 27512e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 27522e5b6d6dSopenharmony_ci UConverter *cnv; 27532e5b6d6dSopenharmony_ci 27542e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022", &errorCode); 27552e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 27562e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 27572e5b6d6dSopenharmony_ci return; 27582e5b6d6dSopenharmony_ci } 27592e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "ISO_2022"); 27602e5b6d6dSopenharmony_ci 27612e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 27622e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source-1, U_ILLEGAL_ARGUMENT_ERROR, "sourceLimit < source"); 27632e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 27642e5b6d6dSopenharmony_ci /*Test for the condition where we have a truncated char*/ 27652e5b6d6dSopenharmony_ci { 27662e5b6d6dSopenharmony_ci static const uint8_t source1[]={0xc4}; 27672e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 27682e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated"); 27692e5b6d6dSopenharmony_ci } 27702e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 27712e5b6d6dSopenharmony_ci { 27722e5b6d6dSopenharmony_ci static const uint8_t source2[]={0xa1, 0x01}; 27732e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_CHAR_FOUND, "an invalid character"); 27742e5b6d6dSopenharmony_ci } 27752e5b6d6dSopenharmony_ci ucnv_close(cnv); 27762e5b6d6dSopenharmony_ci} 27772e5b6d6dSopenharmony_ci 27782e5b6d6dSopenharmony_ci#endif 27792e5b6d6dSopenharmony_ci 27802e5b6d6dSopenharmony_cistatic void 27812e5b6d6dSopenharmony_ciTestSmallTargetBuffer(const uint16_t* source, const UChar* sourceLimit,UConverter* cnv){ 27822e5b6d6dSopenharmony_ci const UChar* uSource; 27832e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 27842e5b6d6dSopenharmony_ci const char* cSource; 27852e5b6d6dSopenharmony_ci const char* cSourceLimit; 27862e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 27872e5b6d6dSopenharmony_ci UChar *uTarget; 27882e5b6d6dSopenharmony_ci char *cTarget; 27892e5b6d6dSopenharmony_ci const char *cTargetLimit; 27902e5b6d6dSopenharmony_ci char *cBuf; 27912e5b6d6dSopenharmony_ci UChar *uBuf; /*,*test;*/ 27922e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 27932e5b6d6dSopenharmony_ci int len=0; 27942e5b6d6dSopenharmony_ci int i=2; 27952e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 27962e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 27972e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 10); 27982e5b6d6dSopenharmony_ci ucnv_reset(cnv); 27992e5b6d6dSopenharmony_ci for(;--i>0; ){ 28002e5b6d6dSopenharmony_ci uSource = (UChar*) source; 28012e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)sourceLimit; 28022e5b6d6dSopenharmony_ci cTarget = cBuf; 28032e5b6d6dSopenharmony_ci uTarget = uBuf; 28042e5b6d6dSopenharmony_ci cSource = cBuf; 28052e5b6d6dSopenharmony_ci cTargetLimit = cBuf; 28062e5b6d6dSopenharmony_ci uTargetLimit = uBuf; 28072e5b6d6dSopenharmony_ci 28082e5b6d6dSopenharmony_ci do{ 28092e5b6d6dSopenharmony_ci 28102e5b6d6dSopenharmony_ci cTargetLimit = cTargetLimit+ i; 28112e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,NULL,false, &errorCode); 28122e5b6d6dSopenharmony_ci if(errorCode==U_BUFFER_OVERFLOW_ERROR){ 28132e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 28142e5b6d6dSopenharmony_ci continue; 28152e5b6d6dSopenharmony_ci } 28162e5b6d6dSopenharmony_ci 28172e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 28182e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 28192e5b6d6dSopenharmony_ci return; 28202e5b6d6dSopenharmony_ci } 28212e5b6d6dSopenharmony_ci 28222e5b6d6dSopenharmony_ci }while (uSource<uSourceLimit); 28232e5b6d6dSopenharmony_ci 28242e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 28252e5b6d6dSopenharmony_ci do{ 28262e5b6d6dSopenharmony_ci uTargetLimit=uTargetLimit+i; 28272e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,NULL,false,&errorCode); 28282e5b6d6dSopenharmony_ci if(errorCode==U_BUFFER_OVERFLOW_ERROR){ 28292e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 28302e5b6d6dSopenharmony_ci continue; 28312e5b6d6dSopenharmony_ci } 28322e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 28332e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 28342e5b6d6dSopenharmony_ci return; 28352e5b6d6dSopenharmony_ci } 28362e5b6d6dSopenharmony_ci }while(cSource<cSourceLimit); 28372e5b6d6dSopenharmony_ci 28382e5b6d6dSopenharmony_ci uSource = source; 28392e5b6d6dSopenharmony_ci /*test =uBuf;*/ 28402e5b6d6dSopenharmony_ci for(len=0;len<(int)(source - sourceLimit);len++){ 28412e5b6d6dSopenharmony_ci if(uBuf[len]!=uSource[len]){ 28422e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",uSource[len],(int)uBuf[len]) ; 28432e5b6d6dSopenharmony_ci } 28442e5b6d6dSopenharmony_ci } 28452e5b6d6dSopenharmony_ci } 28462e5b6d6dSopenharmony_ci free(uBuf); 28472e5b6d6dSopenharmony_ci free(cBuf); 28482e5b6d6dSopenharmony_ci} 28492e5b6d6dSopenharmony_ci/* Test for Jitterbug 778 */ 28502e5b6d6dSopenharmony_cistatic void TestToAndFromUChars(const uint16_t* source, const UChar* sourceLimit,UConverter* cnv){ 28512e5b6d6dSopenharmony_ci const UChar* uSource; 28522e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 28532e5b6d6dSopenharmony_ci const char* cSource; 28542e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 28552e5b6d6dSopenharmony_ci UChar *uTarget; 28562e5b6d6dSopenharmony_ci char *cTarget; 28572e5b6d6dSopenharmony_ci const char *cTargetLimit; 28582e5b6d6dSopenharmony_ci char *cBuf; 28592e5b6d6dSopenharmony_ci UChar *uBuf,*test; 28602e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 28612e5b6d6dSopenharmony_ci int numCharsInTarget=0; 28622e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 28632e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 28642e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 28652e5b6d6dSopenharmony_ci uSource = source; 28662e5b6d6dSopenharmony_ci uSourceLimit=sourceLimit; 28672e5b6d6dSopenharmony_ci cTarget = cBuf; 28682e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 28692e5b6d6dSopenharmony_ci uTarget = uBuf; 28702e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 28712e5b6d6dSopenharmony_ci ucnv_reset(cnv); 28722e5b6d6dSopenharmony_ci numCharsInTarget=ucnv_fromUChars(cnv, cTarget, (int32_t)(cTargetLimit-cTarget), uSource, (int32_t)(uSourceLimit-uSource), &errorCode); 28732e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 28742e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 28752e5b6d6dSopenharmony_ci return; 28762e5b6d6dSopenharmony_ci } 28772e5b6d6dSopenharmony_ci cSource = cBuf; 28782e5b6d6dSopenharmony_ci test =uBuf; 28792e5b6d6dSopenharmony_ci ucnv_toUChars(cnv,uTarget,(int32_t)(uTargetLimit-uTarget),cSource,numCharsInTarget,&errorCode); 28802e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 28812e5b6d6dSopenharmony_ci log_err("ucnv_toUChars conversion failed, reason %s\n", u_errorName(errorCode)); 28822e5b6d6dSopenharmony_ci return; 28832e5b6d6dSopenharmony_ci } 28842e5b6d6dSopenharmony_ci uSource = source; 28852e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 28862e5b6d6dSopenharmony_ci if(*test!=*uSource){ 28872e5b6d6dSopenharmony_ci 28882e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 28892e5b6d6dSopenharmony_ci } 28902e5b6d6dSopenharmony_ci uSource++; 28912e5b6d6dSopenharmony_ci test++; 28922e5b6d6dSopenharmony_ci } 28932e5b6d6dSopenharmony_ci free(uBuf); 28942e5b6d6dSopenharmony_ci free(cBuf); 28952e5b6d6dSopenharmony_ci} 28962e5b6d6dSopenharmony_ci 28972e5b6d6dSopenharmony_cistatic void TestSmallSourceBuffer(const uint16_t* source, const UChar* sourceLimit,UConverter* cnv){ 28982e5b6d6dSopenharmony_ci const UChar* uSource; 28992e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 29002e5b6d6dSopenharmony_ci const char* cSource; 29012e5b6d6dSopenharmony_ci const char* cSourceLimit; 29022e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 29032e5b6d6dSopenharmony_ci UChar *uTarget; 29042e5b6d6dSopenharmony_ci char *cTarget; 29052e5b6d6dSopenharmony_ci const char *cTargetLimit; 29062e5b6d6dSopenharmony_ci char *cBuf; 29072e5b6d6dSopenharmony_ci UChar *uBuf; /*,*test;*/ 29082e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 29092e5b6d6dSopenharmony_ci int len=0; 29102e5b6d6dSopenharmony_ci int i=2; 29112e5b6d6dSopenharmony_ci const UChar *temp = sourceLimit; 29122e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 29132e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 29142e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 10); 29152e5b6d6dSopenharmony_ci 29162e5b6d6dSopenharmony_ci ucnv_reset(cnv); 29172e5b6d6dSopenharmony_ci for(;--i>0;){ 29182e5b6d6dSopenharmony_ci uSource = (UChar*) source; 29192e5b6d6dSopenharmony_ci cTarget = cBuf; 29202e5b6d6dSopenharmony_ci uTarget = uBuf; 29212e5b6d6dSopenharmony_ci cSource = cBuf; 29222e5b6d6dSopenharmony_ci cTargetLimit = cBuf; 29232e5b6d6dSopenharmony_ci uTargetLimit = uBuf+uBufSize*5; 29242e5b6d6dSopenharmony_ci cTargetLimit = cTargetLimit+uBufSize*10; 29252e5b6d6dSopenharmony_ci uSourceLimit=uSource; 29262e5b6d6dSopenharmony_ci do{ 29272e5b6d6dSopenharmony_ci 29282e5b6d6dSopenharmony_ci if (uSourceLimit < sourceLimit) { 29292e5b6d6dSopenharmony_ci uSourceLimit = uSourceLimit+1; 29302e5b6d6dSopenharmony_ci } 29312e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,NULL,false, &errorCode); 29322e5b6d6dSopenharmony_ci if(errorCode==U_BUFFER_OVERFLOW_ERROR){ 29332e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 29342e5b6d6dSopenharmony_ci continue; 29352e5b6d6dSopenharmony_ci } 29362e5b6d6dSopenharmony_ci 29372e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 29382e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 29392e5b6d6dSopenharmony_ci return; 29402e5b6d6dSopenharmony_ci } 29412e5b6d6dSopenharmony_ci 29422e5b6d6dSopenharmony_ci }while (uSource<temp); 29432e5b6d6dSopenharmony_ci 29442e5b6d6dSopenharmony_ci cSourceLimit =cBuf; 29452e5b6d6dSopenharmony_ci do{ 29462e5b6d6dSopenharmony_ci if (cSourceLimit < cBuf + (cTarget - cBuf)) { 29472e5b6d6dSopenharmony_ci cSourceLimit = cSourceLimit+1; 29482e5b6d6dSopenharmony_ci } 29492e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,NULL,false,&errorCode); 29502e5b6d6dSopenharmony_ci if(errorCode==U_BUFFER_OVERFLOW_ERROR){ 29512e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 29522e5b6d6dSopenharmony_ci continue; 29532e5b6d6dSopenharmony_ci } 29542e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 29552e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 29562e5b6d6dSopenharmony_ci return; 29572e5b6d6dSopenharmony_ci } 29582e5b6d6dSopenharmony_ci }while(cSource<cTarget); 29592e5b6d6dSopenharmony_ci 29602e5b6d6dSopenharmony_ci uSource = source; 29612e5b6d6dSopenharmony_ci /*test =uBuf;*/ 29622e5b6d6dSopenharmony_ci for(;len<(int)(source - sourceLimit);len++){ 29632e5b6d6dSopenharmony_ci if(uBuf[len]!=uSource[len]){ 29642e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",uSource[len],(int)uBuf[len]) ; 29652e5b6d6dSopenharmony_ci } 29662e5b6d6dSopenharmony_ci } 29672e5b6d6dSopenharmony_ci } 29682e5b6d6dSopenharmony_ci free(uBuf); 29692e5b6d6dSopenharmony_ci free(cBuf); 29702e5b6d6dSopenharmony_ci} 29712e5b6d6dSopenharmony_cistatic void 29722e5b6d6dSopenharmony_ciTestGetNextUChar2022(UConverter* cnv, const char* source, const char* limit, 29732e5b6d6dSopenharmony_ci const uint16_t results[], const char* message){ 29742e5b6d6dSopenharmony_ci/* const char* s0; */ 29752e5b6d6dSopenharmony_ci const char* s=(char*)source; 29762e5b6d6dSopenharmony_ci const uint16_t *r=results; 29772e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 29782e5b6d6dSopenharmony_ci uint32_t c,exC; 29792e5b6d6dSopenharmony_ci ucnv_reset(cnv); 29802e5b6d6dSopenharmony_ci while(s<limit) { 29812e5b6d6dSopenharmony_ci /* s0=s; */ 29822e5b6d6dSopenharmony_ci c=ucnv_getNextUChar(cnv, &s, limit, &errorCode); 29832e5b6d6dSopenharmony_ci if(errorCode==U_INDEX_OUTOFBOUNDS_ERROR) { 29842e5b6d6dSopenharmony_ci break; /* no more significant input */ 29852e5b6d6dSopenharmony_ci } else if(U_FAILURE(errorCode)) { 29862e5b6d6dSopenharmony_ci log_err("%s ucnv_getNextUChar() failed: %s\n", message, u_errorName(errorCode)); 29872e5b6d6dSopenharmony_ci break; 29882e5b6d6dSopenharmony_ci } else { 29892e5b6d6dSopenharmony_ci if(U16_IS_LEAD(*r)){ 29902e5b6d6dSopenharmony_ci int i =0, len = 2; 29912e5b6d6dSopenharmony_ci U16_NEXT(r, i, len, exC); 29922e5b6d6dSopenharmony_ci r++; 29932e5b6d6dSopenharmony_ci }else{ 29942e5b6d6dSopenharmony_ci exC = *r; 29952e5b6d6dSopenharmony_ci } 29962e5b6d6dSopenharmony_ci if(c!=(uint32_t)(exC)) 29972e5b6d6dSopenharmony_ci log_err("%s ucnv_getNextUChar() Expected: \\u%04X Got: \\u%04X \n",message,(uint32_t) (*r),c); 29982e5b6d6dSopenharmony_ci } 29992e5b6d6dSopenharmony_ci r++; 30002e5b6d6dSopenharmony_ci } 30012e5b6d6dSopenharmony_ci} 30022e5b6d6dSopenharmony_ci 30032e5b6d6dSopenharmony_cistatic int TestJitterbug930(const char* enc){ 30042e5b6d6dSopenharmony_ci UErrorCode err = U_ZERO_ERROR; 30052e5b6d6dSopenharmony_ci UConverter*converter; 30062e5b6d6dSopenharmony_ci char out[80]; 30072e5b6d6dSopenharmony_ci char*target = out; 30082e5b6d6dSopenharmony_ci UChar in[4]; 30092e5b6d6dSopenharmony_ci const UChar*source = in; 30102e5b6d6dSopenharmony_ci int32_t off[80]; 30112e5b6d6dSopenharmony_ci int32_t* offsets = off; 30122e5b6d6dSopenharmony_ci int numOffWritten=0; 30132e5b6d6dSopenharmony_ci UBool flush = 0; 30142e5b6d6dSopenharmony_ci converter = my_ucnv_open(enc, &err); 30152e5b6d6dSopenharmony_ci 30162e5b6d6dSopenharmony_ci in[0] = 0x41; /* 0x4E00;*/ 30172e5b6d6dSopenharmony_ci in[1] = 0x4E01; 30182e5b6d6dSopenharmony_ci in[2] = 0x4E02; 30192e5b6d6dSopenharmony_ci in[3] = 0x4E03; 30202e5b6d6dSopenharmony_ci 30212e5b6d6dSopenharmony_ci memset(off, '*', sizeof(off)); 30222e5b6d6dSopenharmony_ci 30232e5b6d6dSopenharmony_ci ucnv_fromUnicode (converter, 30242e5b6d6dSopenharmony_ci &target, 30252e5b6d6dSopenharmony_ci target+2, 30262e5b6d6dSopenharmony_ci &source, 30272e5b6d6dSopenharmony_ci source+3, 30282e5b6d6dSopenharmony_ci offsets, 30292e5b6d6dSopenharmony_ci flush, 30302e5b6d6dSopenharmony_ci &err); 30312e5b6d6dSopenharmony_ci 30322e5b6d6dSopenharmony_ci /* writes three bytes into the output buffer: 41 1B 24 30332e5b6d6dSopenharmony_ci * but offsets contains 0 1 1 30342e5b6d6dSopenharmony_ci */ 30352e5b6d6dSopenharmony_ci while(*offsets< off[10]){ 30362e5b6d6dSopenharmony_ci numOffWritten++; 30372e5b6d6dSopenharmony_ci offsets++; 30382e5b6d6dSopenharmony_ci } 30392e5b6d6dSopenharmony_ci log_verbose("Testing Jitterbug 930 for encoding %s",enc); 30402e5b6d6dSopenharmony_ci if(numOffWritten!= (int)(target-out)){ 30412e5b6d6dSopenharmony_ci log_err("Jitterbug 930 test for enc: %s failed. Expected: %i Got: %i",enc, (int)(target-out),numOffWritten); 30422e5b6d6dSopenharmony_ci } 30432e5b6d6dSopenharmony_ci 30442e5b6d6dSopenharmony_ci err = U_ZERO_ERROR; 30452e5b6d6dSopenharmony_ci 30462e5b6d6dSopenharmony_ci memset(off,'*' , sizeof(off)); 30472e5b6d6dSopenharmony_ci 30482e5b6d6dSopenharmony_ci flush = 1; 30492e5b6d6dSopenharmony_ci offsets=off; 30502e5b6d6dSopenharmony_ci ucnv_fromUnicode (converter, 30512e5b6d6dSopenharmony_ci &target, 30522e5b6d6dSopenharmony_ci target+4, 30532e5b6d6dSopenharmony_ci &source, 30542e5b6d6dSopenharmony_ci source, 30552e5b6d6dSopenharmony_ci offsets, 30562e5b6d6dSopenharmony_ci flush, 30572e5b6d6dSopenharmony_ci &err); 30582e5b6d6dSopenharmony_ci numOffWritten=0; 30592e5b6d6dSopenharmony_ci while(*offsets< off[10]){ 30602e5b6d6dSopenharmony_ci numOffWritten++; 30612e5b6d6dSopenharmony_ci if(*offsets!= -1){ 30622e5b6d6dSopenharmony_ci log_err("Jitterbug 930 test for enc: %s failed. Expected: %i Got: %i",enc,-1,*offsets) ; 30632e5b6d6dSopenharmony_ci } 30642e5b6d6dSopenharmony_ci offsets++; 30652e5b6d6dSopenharmony_ci } 30662e5b6d6dSopenharmony_ci 30672e5b6d6dSopenharmony_ci /* writes 42 43 7A into output buffer, 30682e5b6d6dSopenharmony_ci * offsets contains -1 -1 -1 30692e5b6d6dSopenharmony_ci */ 30702e5b6d6dSopenharmony_ci ucnv_close(converter); 30712e5b6d6dSopenharmony_ci return 0; 30722e5b6d6dSopenharmony_ci} 30732e5b6d6dSopenharmony_ci 30742e5b6d6dSopenharmony_cistatic void 30752e5b6d6dSopenharmony_ciTestHZ() { 30762e5b6d6dSopenharmony_ci /* test input */ 30772e5b6d6dSopenharmony_ci static const uint16_t in[]={ 30782e5b6d6dSopenharmony_ci 0x3000, 0x3001, 0x3002, 0x00B7, 0x02C9, 0x02C7, 0x00A8, 0x3003, 0x3005, 0x2014, 30792e5b6d6dSopenharmony_ci 0xFF5E, 0x2016, 0x2026, 0x007E, 0x997C, 0x70B3, 0x75C5, 0x5E76, 0x73BB, 0x83E0, 30802e5b6d6dSopenharmony_ci 0x64AD, 0x62E8, 0x94B5, 0x000A, 0x6CE2, 0x535A, 0x52C3, 0x640F, 0x94C2, 0x7B94, 30812e5b6d6dSopenharmony_ci 0x4F2F, 0x5E1B, 0x8236, 0x000A, 0x8116, 0x818A, 0x6E24, 0x6CCA, 0x9A73, 0x6355, 30822e5b6d6dSopenharmony_ci 0x535C, 0x54FA, 0x8865, 0x000A, 0x57E0, 0x4E0D, 0x5E03, 0x6B65, 0x7C3F, 0x90E8, 30832e5b6d6dSopenharmony_ci 0x6016, 0x248F, 0x2490, 0x000A, 0x2491, 0x2492, 0x2493, 0x2494, 0x2495, 0x2496, 30842e5b6d6dSopenharmony_ci 0x2497, 0x2498, 0x2499, 0x000A, 0x249A, 0x249B, 0x2474, 0x2475, 0x2476, 0x2477, 30852e5b6d6dSopenharmony_ci 0x2478, 0x2479, 0x247A, 0x000A, 0x247B, 0x247C, 0x247D, 0x247E, 0x247F, 0x2480, 30862e5b6d6dSopenharmony_ci 0x2481, 0x2482, 0x2483, 0x000A, 0x0041, 0x0043, 0x0044, 0x0045, 0x0046, 0x007E, 30872e5b6d6dSopenharmony_ci 0x0048, 0x0049, 0x004A, 0x000A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 30882e5b6d6dSopenharmony_ci 0x0051, 0x0052, 0x0053, 0x000A, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 30892e5b6d6dSopenharmony_ci 0x005A, 0x005B, 0x005C, 0x000A 30902e5b6d6dSopenharmony_ci }; 30912e5b6d6dSopenharmony_ci const UChar* uSource; 30922e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 30932e5b6d6dSopenharmony_ci const char* cSource; 30942e5b6d6dSopenharmony_ci const char* cSourceLimit; 30952e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 30962e5b6d6dSopenharmony_ci UChar *uTarget; 30972e5b6d6dSopenharmony_ci char *cTarget; 30982e5b6d6dSopenharmony_ci const char *cTargetLimit; 30992e5b6d6dSopenharmony_ci char *cBuf = NULL; 31002e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 31012e5b6d6dSopenharmony_ci UChar *test; 31022e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 31032e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 31042e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 31052e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 31062e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 31072e5b6d6dSopenharmony_ci cnv=ucnv_open("HZ", &errorCode); 31082e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 31092e5b6d6dSopenharmony_ci log_data_err("Unable to open HZ converter: %s\n", u_errorName(errorCode)); 31102e5b6d6dSopenharmony_ci goto cleanup; 31112e5b6d6dSopenharmony_ci } 31122e5b6d6dSopenharmony_ci 31132e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 31142e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 31152e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 31162e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 31172e5b6d6dSopenharmony_ci cTarget = cBuf; 31182e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 31192e5b6d6dSopenharmony_ci uTarget = uBuf; 31202e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 31212e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 31222e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 31232e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 31242e5b6d6dSopenharmony_ci goto cleanup; 31252e5b6d6dSopenharmony_ci } 31262e5b6d6dSopenharmony_ci cSource = cBuf; 31272e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 31282e5b6d6dSopenharmony_ci test =uBuf; 31292e5b6d6dSopenharmony_ci myOff=offsets; 31302e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 31312e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 31322e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 31332e5b6d6dSopenharmony_ci goto cleanup; 31342e5b6d6dSopenharmony_ci } 31352e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 31362e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 31372e5b6d6dSopenharmony_ci if(*test!=*uSource){ 31382e5b6d6dSopenharmony_ci 31392e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 31402e5b6d6dSopenharmony_ci } 31412e5b6d6dSopenharmony_ci uSource++; 31422e5b6d6dSopenharmony_ci test++; 31432e5b6d6dSopenharmony_ci } 31442e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, "HZ encoding"); 31452e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 31462e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 31472e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 31482e5b6d6dSopenharmony_ci TestJitterbug930("csISO2022JP"); 31492e5b6d6dSopenharmony_ci 31502e5b6d6dSopenharmony_cicleanup: 31512e5b6d6dSopenharmony_ci ucnv_close(cnv); 31522e5b6d6dSopenharmony_ci free(offsets); 31532e5b6d6dSopenharmony_ci free(uBuf); 31542e5b6d6dSopenharmony_ci free(cBuf); 31552e5b6d6dSopenharmony_ci} 31562e5b6d6dSopenharmony_ci 31572e5b6d6dSopenharmony_cistatic void 31582e5b6d6dSopenharmony_ciTestISCII(){ 31592e5b6d6dSopenharmony_ci /* test input */ 31602e5b6d6dSopenharmony_ci static const uint16_t in[]={ 31612e5b6d6dSopenharmony_ci /* test full range of Devanagari */ 31622e5b6d6dSopenharmony_ci 0x0901,0x0902,0x0903,0x0905,0x0906,0x0907,0x0908,0x0909,0x090A, 31632e5b6d6dSopenharmony_ci 0x090B,0x090E,0x090F,0x0910,0x090D,0x0912,0x0913,0x0914,0x0911, 31642e5b6d6dSopenharmony_ci 0x0915,0x0916,0x0917,0x0918,0x0919,0x091A,0x091B,0x091C,0x091D, 31652e5b6d6dSopenharmony_ci 0x091E,0x091F,0x0920,0x0921,0x0922,0x0923,0x0924,0x0925,0x0926, 31662e5b6d6dSopenharmony_ci 0x0927,0x0928,0x0929,0x092A,0x092B,0x092C,0x092D,0x092E,0x092F, 31672e5b6d6dSopenharmony_ci 0x095F,0x0930,0x0931,0x0932,0x0933,0x0934,0x0935,0x0936,0x0937, 31682e5b6d6dSopenharmony_ci 0x0938,0x0939,0x200D,0x093E,0x093F,0x0940,0x0941,0x0942,0x0943, 31692e5b6d6dSopenharmony_ci 0x0946,0x0947,0x0948,0x0945,0x094A,0x094B,0x094C,0x0949,0x094D, 31702e5b6d6dSopenharmony_ci 0x093d,0x0966,0x0967,0x0968,0x0969,0x096A,0x096B,0x096C, 31712e5b6d6dSopenharmony_ci 0x096D,0x096E,0x096F, 31722e5b6d6dSopenharmony_ci /* test Soft halant*/ 31732e5b6d6dSopenharmony_ci 0x0915,0x094d, 0x200D, 31742e5b6d6dSopenharmony_ci /* test explicit halant */ 31752e5b6d6dSopenharmony_ci 0x0915,0x094d, 0x200c, 31762e5b6d6dSopenharmony_ci /* test double danda */ 31772e5b6d6dSopenharmony_ci 0x965, 31782e5b6d6dSopenharmony_ci /* test ASCII */ 31792e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x29, 0x47, 0x0E, 0x23, 0x21, 0x23, 0x22, 0x23, 31802e5b6d6dSopenharmony_ci 0x23, 0x23, 0x24, 0x23, 0x25, 0x23, 0x26, 0x23, 0x27, 0x23, 31812e5b6d6dSopenharmony_ci 0x28, 0x23, 0x29, 0x23, 0x2A, 0x23, 0x2B, 0x0F, 0x2F, 0x2A, 31822e5b6d6dSopenharmony_ci /* tests from Lotus */ 31832e5b6d6dSopenharmony_ci 0x0061,0x0915,0x000D,0x000A,0x0996,0x0043, 31842e5b6d6dSopenharmony_ci 0x0930,0x094D,0x200D, 31852e5b6d6dSopenharmony_ci 0x0901,0x000D,0x000A,0x0905,0x0985,0x0043, 31862e5b6d6dSopenharmony_ci 0x0915,0x0921,0x002B,0x095F, 31872e5b6d6dSopenharmony_ci /* tamil range */ 31882e5b6d6dSopenharmony_ci 0x0B86, 0xB87, 0xB88, 31892e5b6d6dSopenharmony_ci /* telugu range */ 31902e5b6d6dSopenharmony_ci 0x0C05, 0x0C02, 0x0C03,0x0c31, 31912e5b6d6dSopenharmony_ci /* kannada range */ 31922e5b6d6dSopenharmony_ci 0x0C85, 0xC82, 0x0C83, 31932e5b6d6dSopenharmony_ci /* test Abbr sign and Anudatta */ 31942e5b6d6dSopenharmony_ci 0x0970, 0x952, 31952e5b6d6dSopenharmony_ci /* 0x0958, 31962e5b6d6dSopenharmony_ci 0x0959, 31972e5b6d6dSopenharmony_ci 0x095A, 31982e5b6d6dSopenharmony_ci 0x095B, 31992e5b6d6dSopenharmony_ci 0x095C, 32002e5b6d6dSopenharmony_ci 0x095D, 32012e5b6d6dSopenharmony_ci 0x095E, 32022e5b6d6dSopenharmony_ci 0x095F,*/ 32032e5b6d6dSopenharmony_ci 0x0960 /* Vocallic RRI 0xAB, 0xE9*/, 32042e5b6d6dSopenharmony_ci 0x0944 /* Vowel Sign Vocallic RRI 0xDF, 0xE9 */, 32052e5b6d6dSopenharmony_ci 0x090C , 32062e5b6d6dSopenharmony_ci 0x0962, 32072e5b6d6dSopenharmony_ci 0x0961 /* Vocallic LL 0xa6, 0xE9 */, 32082e5b6d6dSopenharmony_ci 0x0963 /* Vowel Sign Vocallic LL 0xdb, 0xE9, */, 32092e5b6d6dSopenharmony_ci 0x0950 /* OM Symbol 0xa1, 0xE9,*/, 32102e5b6d6dSopenharmony_ci 0x093D /* Avagraha 0xEA, 0xE9*/, 32112e5b6d6dSopenharmony_ci 0x0958, 32122e5b6d6dSopenharmony_ci 0x0959, 32132e5b6d6dSopenharmony_ci 0x095A, 32142e5b6d6dSopenharmony_ci 0x095B, 32152e5b6d6dSopenharmony_ci 0x095C, 32162e5b6d6dSopenharmony_ci 0x095D, 32172e5b6d6dSopenharmony_ci 0x095E, 32182e5b6d6dSopenharmony_ci 0x0020, 0x094D, 0x0930, 0x0000, 0x00A0 32192e5b6d6dSopenharmony_ci }; 32202e5b6d6dSopenharmony_ci static const unsigned char byteArr[]={ 32212e5b6d6dSopenharmony_ci 32222e5b6d6dSopenharmony_ci 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9, 32232e5b6d6dSopenharmony_ci 0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2, 32242e5b6d6dSopenharmony_ci 0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb, 32252e5b6d6dSopenharmony_ci 0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4, 32262e5b6d6dSopenharmony_ci 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd, 32272e5b6d6dSopenharmony_ci 0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, 32282e5b6d6dSopenharmony_ci 0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, 32292e5b6d6dSopenharmony_ci 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8, 32302e5b6d6dSopenharmony_ci 0xea,0xe9,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 32312e5b6d6dSopenharmony_ci 0xf8,0xf9,0xfa, 32322e5b6d6dSopenharmony_ci /* test soft halant */ 32332e5b6d6dSopenharmony_ci 0xb3, 0xE8, 0xE9, 32342e5b6d6dSopenharmony_ci /* test explicit halant */ 32352e5b6d6dSopenharmony_ci 0xb3, 0xE8, 0xE8, 32362e5b6d6dSopenharmony_ci /* test double danda */ 32372e5b6d6dSopenharmony_ci 0xea, 0xea, 32382e5b6d6dSopenharmony_ci /* test ASCII */ 32392e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x29, 0x47, 0x0E, 0x23, 0x21, 0x23, 0x22, 0x23, 32402e5b6d6dSopenharmony_ci 0x23, 0x23, 0x24, 0x23, 0x25, 0x23, 0x26, 0x23, 0x27, 0x23, 32412e5b6d6dSopenharmony_ci 0x28, 0x23, 0x29, 0x23, 0x2A, 0x23, 0x2B, 0x0F, 0x2F, 0x2A, 32422e5b6d6dSopenharmony_ci /* test ATR code */ 32432e5b6d6dSopenharmony_ci 32442e5b6d6dSopenharmony_ci /* tests from Lotus */ 32452e5b6d6dSopenharmony_ci 0x61,0xEF,0x42,0xEF,0x30,0xB3,0x0D,0x0A,0xEF,0x43,0xB4,0x43, 32462e5b6d6dSopenharmony_ci 0xEF,0x42,0xCF,0xE8,0xD9, 32472e5b6d6dSopenharmony_ci 0xEF,0x42,0xA1,0x0D,0x0A,0xEF,0x42,0xA4,0xEF,0x43,0xA4,0x43, 32482e5b6d6dSopenharmony_ci 0xEF,0x42,0xB3,0xBF,0x2B,0xEF,0x42,0xCE, 32492e5b6d6dSopenharmony_ci /* tamil range */ 32502e5b6d6dSopenharmony_ci 0xEF, 0x44, 0xa5, 0xa6, 0xa7, 32512e5b6d6dSopenharmony_ci /* telugu range */ 32522e5b6d6dSopenharmony_ci 0xEF, 0x45,0xa4, 0xa2, 0xa3,0xd0, 32532e5b6d6dSopenharmony_ci /* kannada range */ 32542e5b6d6dSopenharmony_ci 0xEF, 0x48,0xa4, 0xa2, 0xa3, 32552e5b6d6dSopenharmony_ci /* anudatta and abbreviation sign */ 32562e5b6d6dSopenharmony_ci 0xEF, 0x42, 0xF0, 0xBF, 0xF0, 0xB8, 32572e5b6d6dSopenharmony_ci 32582e5b6d6dSopenharmony_ci 32592e5b6d6dSopenharmony_ci 0xAA, 0xE9,/* RI + NUKTA 0x0960*/ 32602e5b6d6dSopenharmony_ci 32612e5b6d6dSopenharmony_ci 0xDF, 0xE9,/* Vowel sign RI + NUKTA 0x0944*/ 32622e5b6d6dSopenharmony_ci 32632e5b6d6dSopenharmony_ci 0xa6, 0xE9,/* Vowel I + NUKTA 0x090C*/ 32642e5b6d6dSopenharmony_ci 32652e5b6d6dSopenharmony_ci 0xdb, 0xE9,/* Vowel sign I + Nukta 0x0962*/ 32662e5b6d6dSopenharmony_ci 32672e5b6d6dSopenharmony_ci 0xa7, 0xE9,/* Vowel II + NUKTA 0x0961*/ 32682e5b6d6dSopenharmony_ci 32692e5b6d6dSopenharmony_ci 0xdc, 0xE9,/* Vowel sign II + Nukta 0x0963*/ 32702e5b6d6dSopenharmony_ci 32712e5b6d6dSopenharmony_ci 0xa1, 0xE9,/* chandrabindu + Nukta 0x0950*/ 32722e5b6d6dSopenharmony_ci 32732e5b6d6dSopenharmony_ci 0xEA, 0xE9, /* Danda + Nukta 0x093D*/ 32742e5b6d6dSopenharmony_ci 32752e5b6d6dSopenharmony_ci 0xB3, 0xE9, /* Ka + NUKTA */ 32762e5b6d6dSopenharmony_ci 32772e5b6d6dSopenharmony_ci 0xB4, 0xE9, /* Kha + NUKTA */ 32782e5b6d6dSopenharmony_ci 32792e5b6d6dSopenharmony_ci 0xB5, 0xE9, /* Ga + NUKTA */ 32802e5b6d6dSopenharmony_ci 32812e5b6d6dSopenharmony_ci 0xBA, 0xE9, 32822e5b6d6dSopenharmony_ci 32832e5b6d6dSopenharmony_ci 0xBF, 0xE9, 32842e5b6d6dSopenharmony_ci 32852e5b6d6dSopenharmony_ci 0xC0, 0xE9, 32862e5b6d6dSopenharmony_ci 32872e5b6d6dSopenharmony_ci 0xC9, 0xE9, 32882e5b6d6dSopenharmony_ci /* INV halant RA */ 32892e5b6d6dSopenharmony_ci 0xD9, 0xE8, 0xCF, 32902e5b6d6dSopenharmony_ci 0x00, 0x00A0, 32912e5b6d6dSopenharmony_ci /* just consume unhandled codepoints */ 32922e5b6d6dSopenharmony_ci 0xEF, 0x30, 32932e5b6d6dSopenharmony_ci 32942e5b6d6dSopenharmony_ci }; 32952e5b6d6dSopenharmony_ci testConvertToU(byteArr,(sizeof(byteArr)),in,UPRV_LENGTHOF(in),"x-iscii-de",NULL,true); 32962e5b6d6dSopenharmony_ci TestConv(in,(sizeof(in)/2),"ISCII,version=0","hindi", (char *)byteArr,sizeof(byteArr)); 32972e5b6d6dSopenharmony_ci 32982e5b6d6dSopenharmony_ci} 32992e5b6d6dSopenharmony_ci 33002e5b6d6dSopenharmony_cistatic void 33012e5b6d6dSopenharmony_ciTestISO_2022_JP() { 33022e5b6d6dSopenharmony_ci /* test input */ 33032e5b6d6dSopenharmony_ci static const uint16_t in[]={ 33042e5b6d6dSopenharmony_ci 0x0041,/*0x00E9,*/0x3000, 0x3001, 0x3002, 0x0020, 0x000D, 0x000A, 33052e5b6d6dSopenharmony_ci 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 33062e5b6d6dSopenharmony_ci 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 33072e5b6d6dSopenharmony_ci 0x3005, 0x3006, 0x3007, 0x30FC, 0x2015, 0x2010, 0xFF0F, 0x005C, 0x000D, 0x000A, 33082e5b6d6dSopenharmony_ci 0x3013, 0x2018, 0x2026, 0x2025, 0x2018, 0x2019, 0x201C, 0x000D, 0x000A, 33092e5b6d6dSopenharmony_ci 0x201D, 0x3014, 0x000D, 0x000A, 33102e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 33112e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 33122e5b6d6dSopenharmony_ci }; 33132e5b6d6dSopenharmony_ci const UChar* uSource; 33142e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 33152e5b6d6dSopenharmony_ci const char* cSource; 33162e5b6d6dSopenharmony_ci const char* cSourceLimit; 33172e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 33182e5b6d6dSopenharmony_ci UChar *uTarget; 33192e5b6d6dSopenharmony_ci char *cTarget; 33202e5b6d6dSopenharmony_ci const char *cTargetLimit; 33212e5b6d6dSopenharmony_ci char *cBuf = NULL; 33222e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 33232e5b6d6dSopenharmony_ci UChar *test; 33242e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 33252e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 33262e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 33272e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 33282e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 33292e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022_JP_1", &errorCode); 33302e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 33312e5b6d6dSopenharmony_ci log_data_err("Unable to open an ISO_2022_JP_1 converter: %s\n", u_errorName(errorCode)); 33322e5b6d6dSopenharmony_ci goto cleanup; 33332e5b6d6dSopenharmony_ci } 33342e5b6d6dSopenharmony_ci 33352e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 33362e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 33372e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 33382e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 33392e5b6d6dSopenharmony_ci cTarget = cBuf; 33402e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 33412e5b6d6dSopenharmony_ci uTarget = uBuf; 33422e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 33432e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 33442e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 33452e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 33462e5b6d6dSopenharmony_ci goto cleanup; 33472e5b6d6dSopenharmony_ci } 33482e5b6d6dSopenharmony_ci cSource = cBuf; 33492e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 33502e5b6d6dSopenharmony_ci test =uBuf; 33512e5b6d6dSopenharmony_ci myOff=offsets; 33522e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 33532e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 33542e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 33552e5b6d6dSopenharmony_ci goto cleanup; 33562e5b6d6dSopenharmony_ci } 33572e5b6d6dSopenharmony_ci 33582e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 33592e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 33602e5b6d6dSopenharmony_ci if(*test!=*uSource){ 33612e5b6d6dSopenharmony_ci 33622e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 33632e5b6d6dSopenharmony_ci } 33642e5b6d6dSopenharmony_ci uSource++; 33652e5b6d6dSopenharmony_ci test++; 33662e5b6d6dSopenharmony_ci } 33672e5b6d6dSopenharmony_ci 33682e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 33692e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 33702e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, "ISO-2022-JP encoding"); 33712e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 33722e5b6d6dSopenharmony_ci TestJitterbug930("csISO2022JP"); 33732e5b6d6dSopenharmony_ci 33742e5b6d6dSopenharmony_cicleanup: 33752e5b6d6dSopenharmony_ci ucnv_close(cnv); 33762e5b6d6dSopenharmony_ci free(uBuf); 33772e5b6d6dSopenharmony_ci free(cBuf); 33782e5b6d6dSopenharmony_ci free(offsets); 33792e5b6d6dSopenharmony_ci} 33802e5b6d6dSopenharmony_ci 33812e5b6d6dSopenharmony_cistatic void TestConv(const uint16_t in[],int len, const char* conv, const char* lang, char byteArr[],int byteArrLen){ 33822e5b6d6dSopenharmony_ci const UChar* uSource; 33832e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 33842e5b6d6dSopenharmony_ci const char* cSource; 33852e5b6d6dSopenharmony_ci const char* cSourceLimit; 33862e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 33872e5b6d6dSopenharmony_ci UChar *uTarget; 33882e5b6d6dSopenharmony_ci char *cTarget; 33892e5b6d6dSopenharmony_ci const char *cTargetLimit; 33902e5b6d6dSopenharmony_ci char *cBuf; 33912e5b6d6dSopenharmony_ci UChar *uBuf,*test; 33922e5b6d6dSopenharmony_ci int32_t uBufSize = 120*10; 33932e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 33942e5b6d6dSopenharmony_ci UConverter *cnv; 33952e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) ); 33962e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 33972e5b6d6dSopenharmony_ci cnv=my_ucnv_open(conv, &errorCode); 33982e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 33992e5b6d6dSopenharmony_ci log_data_err("Unable to open a %s converter: %s\n", conv, u_errorName(errorCode)); 34002e5b6d6dSopenharmony_ci return; 34012e5b6d6dSopenharmony_ci } 34022e5b6d6dSopenharmony_ci 34032e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)); 34042e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char)); 34052e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 34062e5b6d6dSopenharmony_ci uSourceLimit=uSource+len; 34072e5b6d6dSopenharmony_ci cTarget = cBuf; 34082e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize; 34092e5b6d6dSopenharmony_ci uTarget = uBuf; 34102e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize; 34112e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 34122e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 34132e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 34142e5b6d6dSopenharmony_ci return; 34152e5b6d6dSopenharmony_ci } 34162e5b6d6dSopenharmony_ci /*log_verbose("length of compressed string for language %s using %s:%i \n",conv,lang,(cTarget-cBuf));*/ 34172e5b6d6dSopenharmony_ci cSource = cBuf; 34182e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 34192e5b6d6dSopenharmony_ci test =uBuf; 34202e5b6d6dSopenharmony_ci myOff=offsets; 34212e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 34222e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 34232e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed, reason: %s\n", u_errorName(errorCode)); 34242e5b6d6dSopenharmony_ci return; 34252e5b6d6dSopenharmony_ci } 34262e5b6d6dSopenharmony_ci 34272e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 34282e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 34292e5b6d6dSopenharmony_ci if(*test!=*uSource){ 34302e5b6d6dSopenharmony_ci log_err("for codepage %s : Expected : \\u%04X \t Got: \\u%04X\n",conv,*uSource,(int)*test) ; 34312e5b6d6dSopenharmony_ci } 34322e5b6d6dSopenharmony_ci uSource++; 34332e5b6d6dSopenharmony_ci test++; 34342e5b6d6dSopenharmony_ci } 34352e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)&in[len],cnv); 34362e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)&in[len],cnv); 34372e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, conv); 34382e5b6d6dSopenharmony_ci if(byteArr && byteArrLen!=0){ 34392e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, byteArr, (byteArr+byteArrLen), in, lang); 34402e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)&in[len],cnv); 34412e5b6d6dSopenharmony_ci { 34422e5b6d6dSopenharmony_ci cSource = byteArr; 34432e5b6d6dSopenharmony_ci cSourceLimit = cSource+byteArrLen; 34442e5b6d6dSopenharmony_ci test=uBuf; 34452e5b6d6dSopenharmony_ci myOff = offsets; 34462e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 34472e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 34482e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 34492e5b6d6dSopenharmony_ci return; 34502e5b6d6dSopenharmony_ci } 34512e5b6d6dSopenharmony_ci 34522e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 34532e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 34542e5b6d6dSopenharmony_ci if(*test!=*uSource){ 34552e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 34562e5b6d6dSopenharmony_ci } 34572e5b6d6dSopenharmony_ci uSource++; 34582e5b6d6dSopenharmony_ci test++; 34592e5b6d6dSopenharmony_ci } 34602e5b6d6dSopenharmony_ci } 34612e5b6d6dSopenharmony_ci } 34622e5b6d6dSopenharmony_ci 34632e5b6d6dSopenharmony_ci ucnv_close(cnv); 34642e5b6d6dSopenharmony_ci free(uBuf); 34652e5b6d6dSopenharmony_ci free(cBuf); 34662e5b6d6dSopenharmony_ci free(offsets); 34672e5b6d6dSopenharmony_ci} 34682e5b6d6dSopenharmony_cistatic UChar U_CALLCONV 34692e5b6d6dSopenharmony_ci_charAt(int32_t offset, void *context) { 34702e5b6d6dSopenharmony_ci return ((char*)context)[offset]; 34712e5b6d6dSopenharmony_ci} 34722e5b6d6dSopenharmony_ci 34732e5b6d6dSopenharmony_cistatic int32_t 34742e5b6d6dSopenharmony_ciunescape(UChar* dst, int32_t dstLen,const char* src,int32_t srcLen,UErrorCode *status){ 34752e5b6d6dSopenharmony_ci int32_t srcIndex=0; 34762e5b6d6dSopenharmony_ci int32_t dstIndex=0; 34772e5b6d6dSopenharmony_ci if(U_FAILURE(*status)){ 34782e5b6d6dSopenharmony_ci return 0; 34792e5b6d6dSopenharmony_ci } 34802e5b6d6dSopenharmony_ci if((dst==NULL && dstLen>0) || (src==NULL ) || dstLen < -1 || srcLen <-1 ){ 34812e5b6d6dSopenharmony_ci *status = U_ILLEGAL_ARGUMENT_ERROR; 34822e5b6d6dSopenharmony_ci return 0; 34832e5b6d6dSopenharmony_ci } 34842e5b6d6dSopenharmony_ci if(srcLen==-1){ 34852e5b6d6dSopenharmony_ci srcLen = (int32_t)uprv_strlen(src); 34862e5b6d6dSopenharmony_ci } 34872e5b6d6dSopenharmony_ci 34882e5b6d6dSopenharmony_ci for (; srcIndex<srcLen; ) { 34892e5b6d6dSopenharmony_ci UChar32 c = src[srcIndex++]; 34902e5b6d6dSopenharmony_ci if (c == 0x005C /*'\\'*/) { 34912e5b6d6dSopenharmony_ci c = u_unescapeAt(_charAt,&srcIndex,srcLen,(void*)src); /* advances i*/ 34922e5b6d6dSopenharmony_ci if (c == (UChar32)0xFFFFFFFF) { 34932e5b6d6dSopenharmony_ci *status=U_INVALID_CHAR_FOUND; /* return empty string */ 34942e5b6d6dSopenharmony_ci break; /* invalid escape sequence */ 34952e5b6d6dSopenharmony_ci } 34962e5b6d6dSopenharmony_ci } 34972e5b6d6dSopenharmony_ci if(dstIndex < dstLen){ 34982e5b6d6dSopenharmony_ci if(c>0xFFFF){ 34992e5b6d6dSopenharmony_ci dst[dstIndex++] = U16_LEAD(c); 35002e5b6d6dSopenharmony_ci if(dstIndex<dstLen){ 35012e5b6d6dSopenharmony_ci dst[dstIndex]=U16_TRAIL(c); 35022e5b6d6dSopenharmony_ci }else{ 35032e5b6d6dSopenharmony_ci *status=U_BUFFER_OVERFLOW_ERROR; 35042e5b6d6dSopenharmony_ci } 35052e5b6d6dSopenharmony_ci }else{ 35062e5b6d6dSopenharmony_ci dst[dstIndex]=(UChar)c; 35072e5b6d6dSopenharmony_ci } 35082e5b6d6dSopenharmony_ci 35092e5b6d6dSopenharmony_ci }else{ 35102e5b6d6dSopenharmony_ci *status = U_BUFFER_OVERFLOW_ERROR; 35112e5b6d6dSopenharmony_ci } 35122e5b6d6dSopenharmony_ci dstIndex++; /* for preflighting */ 35132e5b6d6dSopenharmony_ci } 35142e5b6d6dSopenharmony_ci return dstIndex; 35152e5b6d6dSopenharmony_ci} 35162e5b6d6dSopenharmony_ci 35172e5b6d6dSopenharmony_cistatic void 35182e5b6d6dSopenharmony_ciTestFullRoundtrip(const char* cp){ 35192e5b6d6dSopenharmony_ci UChar usource[10] ={0}; 35202e5b6d6dSopenharmony_ci UChar nsrc[10] = {0}; 35212e5b6d6dSopenharmony_ci uint32_t i=1; 35222e5b6d6dSopenharmony_ci int len=0, ulen; 35232e5b6d6dSopenharmony_ci nsrc[0]=0x0061; 35242e5b6d6dSopenharmony_ci /* Test codepoint 0 */ 35252e5b6d6dSopenharmony_ci TestConv(usource,1,cp,"",NULL,0); 35262e5b6d6dSopenharmony_ci TestConv(usource,2,cp,"",NULL,0); 35272e5b6d6dSopenharmony_ci nsrc[2]=0x5555; 35282e5b6d6dSopenharmony_ci TestConv(nsrc,3,cp,"",NULL,0); 35292e5b6d6dSopenharmony_ci 35302e5b6d6dSopenharmony_ci for(;i<=0x10FFFF;i++){ 35312e5b6d6dSopenharmony_ci if(i==0xD800){ 35322e5b6d6dSopenharmony_ci i=0xDFFF; 35332e5b6d6dSopenharmony_ci continue; 35342e5b6d6dSopenharmony_ci } 35352e5b6d6dSopenharmony_ci if(i<=0xFFFF){ 35362e5b6d6dSopenharmony_ci usource[0] =(UChar) i; 35372e5b6d6dSopenharmony_ci len=1; 35382e5b6d6dSopenharmony_ci }else{ 35392e5b6d6dSopenharmony_ci usource[0]=U16_LEAD(i); 35402e5b6d6dSopenharmony_ci usource[1]=U16_TRAIL(i); 35412e5b6d6dSopenharmony_ci len=2; 35422e5b6d6dSopenharmony_ci } 35432e5b6d6dSopenharmony_ci ulen=len; 35442e5b6d6dSopenharmony_ci if(i==0x80) { 35452e5b6d6dSopenharmony_ci usource[2]=0; 35462e5b6d6dSopenharmony_ci } 35472e5b6d6dSopenharmony_ci /* Test only single code points */ 35482e5b6d6dSopenharmony_ci TestConv(usource,ulen,cp,"",NULL,0); 35492e5b6d6dSopenharmony_ci /* Test codepoint repeated twice */ 35502e5b6d6dSopenharmony_ci usource[ulen]=usource[0]; 35512e5b6d6dSopenharmony_ci usource[ulen+1]=usource[1]; 35522e5b6d6dSopenharmony_ci ulen+=len; 35532e5b6d6dSopenharmony_ci TestConv(usource,ulen,cp,"",NULL,0); 35542e5b6d6dSopenharmony_ci /* Test codepoint repeated 3 times */ 35552e5b6d6dSopenharmony_ci usource[ulen]=usource[0]; 35562e5b6d6dSopenharmony_ci usource[ulen+1]=usource[1]; 35572e5b6d6dSopenharmony_ci ulen+=len; 35582e5b6d6dSopenharmony_ci TestConv(usource,ulen,cp,"",NULL,0); 35592e5b6d6dSopenharmony_ci /* Test codepoint in between 2 codepoints */ 35602e5b6d6dSopenharmony_ci nsrc[1]=usource[0]; 35612e5b6d6dSopenharmony_ci nsrc[2]=usource[1]; 35622e5b6d6dSopenharmony_ci nsrc[len+1]=0x5555; 35632e5b6d6dSopenharmony_ci TestConv(nsrc,len+2,cp,"",NULL,0); 35642e5b6d6dSopenharmony_ci uprv_memset(usource,0,sizeof(UChar)*10); 35652e5b6d6dSopenharmony_ci } 35662e5b6d6dSopenharmony_ci} 35672e5b6d6dSopenharmony_ci 35682e5b6d6dSopenharmony_cistatic void 35692e5b6d6dSopenharmony_ciTestRoundTrippingAllUTF(void){ 35702e5b6d6dSopenharmony_ci if(!getTestOption(QUICK_OPTION)){ 35712e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for BOCU-1\n"); 35722e5b6d6dSopenharmony_ci TestFullRoundtrip("BOCU-1"); 35732e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for SCSU\n"); 35742e5b6d6dSopenharmony_ci TestFullRoundtrip("SCSU"); 35752e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-8\n"); 35762e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-8"); 35772e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for CESU-8\n"); 35782e5b6d6dSopenharmony_ci TestFullRoundtrip("CESU-8"); 35792e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-16BE\n"); 35802e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-16BE"); 35812e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-16LE\n"); 35822e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-16LE"); 35832e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-16\n"); 35842e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-16"); 35852e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-32BE\n"); 35862e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-32BE"); 35872e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-32LE\n"); 35882e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-32LE"); 35892e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-32\n"); 35902e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-32"); 35912e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-7\n"); 35922e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-7"); 35932e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for UTF-7\n"); 35942e5b6d6dSopenharmony_ci TestFullRoundtrip("UTF-7,version=1"); 35952e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for IMAP-mailbox-name\n"); 35962e5b6d6dSopenharmony_ci TestFullRoundtrip("IMAP-mailbox-name"); 35972e5b6d6dSopenharmony_ci /* 35982e5b6d6dSopenharmony_ci * 35992e5b6d6dSopenharmony_ci * With the update to GB18030 2005 (Ticket #8274), this test will fail because the 2005 version of 36002e5b6d6dSopenharmony_ci * GB18030 contains mappings to actual Unicode codepoints (which were previously mapped to PUA). 36012e5b6d6dSopenharmony_ci * The old mappings remain as fallbacks. 36022e5b6d6dSopenharmony_ci * This test may be reintroduced at a later time. 36032e5b6d6dSopenharmony_ci * 36042e5b6d6dSopenharmony_ci * 110118 - mow 36052e5b6d6dSopenharmony_ci */ 36062e5b6d6dSopenharmony_ci /* 36072e5b6d6dSopenharmony_ci log_verbose("Running exhaustive round trip test for GB18030\n"); 36082e5b6d6dSopenharmony_ci TestFullRoundtrip("GB18030"); 36092e5b6d6dSopenharmony_ci */ 36102e5b6d6dSopenharmony_ci } 36112e5b6d6dSopenharmony_ci} 36122e5b6d6dSopenharmony_ci 36132e5b6d6dSopenharmony_cistatic void 36142e5b6d6dSopenharmony_ciTestSCSU() { 36152e5b6d6dSopenharmony_ci 36162e5b6d6dSopenharmony_ci static const uint16_t germanUTF16[]={ 36172e5b6d6dSopenharmony_ci 0x00d6, 0x006c, 0x0020, 0x0066, 0x006c, 0x0069, 0x0065, 0x00df, 0x0074 36182e5b6d6dSopenharmony_ci }; 36192e5b6d6dSopenharmony_ci 36202e5b6d6dSopenharmony_ci static const uint8_t germanSCSU[]={ 36212e5b6d6dSopenharmony_ci 0xd6, 0x6c, 0x20, 0x66, 0x6c, 0x69, 0x65, 0xdf, 0x74 36222e5b6d6dSopenharmony_ci }; 36232e5b6d6dSopenharmony_ci 36242e5b6d6dSopenharmony_ci static const uint16_t russianUTF16[]={ 36252e5b6d6dSopenharmony_ci 0x041c, 0x043e, 0x0441, 0x043a, 0x0432, 0x0430 36262e5b6d6dSopenharmony_ci }; 36272e5b6d6dSopenharmony_ci 36282e5b6d6dSopenharmony_ci static const uint8_t russianSCSU[]={ 36292e5b6d6dSopenharmony_ci 0x12, 0x9c, 0xbe, 0xc1, 0xba, 0xb2, 0xb0 36302e5b6d6dSopenharmony_ci }; 36312e5b6d6dSopenharmony_ci 36322e5b6d6dSopenharmony_ci static const uint16_t japaneseUTF16[]={ 36332e5b6d6dSopenharmony_ci 0x3000, 0x266a, 0x30ea, 0x30f3, 0x30b4, 0x53ef, 0x611b, 36342e5b6d6dSopenharmony_ci 0x3044, 0x3084, 0x53ef, 0x611b, 0x3044, 0x3084, 0x30ea, 0x30f3, 36352e5b6d6dSopenharmony_ci 0x30b4, 0x3002, 0x534a, 0x4e16, 0x7d00, 0x3082, 0x524d, 0x306b, 36362e5b6d6dSopenharmony_ci 0x6d41, 0x884c, 0x3057, 0x305f, 0x300c, 0x30ea, 0x30f3, 0x30b4, 36372e5b6d6dSopenharmony_ci 0x306e, 0x6b4c, 0x300d, 0x304c, 0x3074, 0x3063, 0x305f, 0x308a, 36382e5b6d6dSopenharmony_ci 0x3059, 0x308b, 0x304b, 0x3082, 0x3057, 0x308c, 0x306a, 0x3044, 36392e5b6d6dSopenharmony_ci 0x3002, 0x7c73, 0x30a2, 0x30c3, 0x30d7, 0x30eb, 0x30b3, 0x30f3, 36402e5b6d6dSopenharmony_ci 0x30d4, 0x30e5, 0x30fc, 0x30bf, 0x793e, 0x306e, 0x30d1, 0x30bd, 36412e5b6d6dSopenharmony_ci 0x30b3, 0x30f3, 0x300c, 0x30de, 0x30c3, 0x30af, 0xff08, 0x30de, 36422e5b6d6dSopenharmony_ci 0x30c3, 0x30ad, 0x30f3, 0x30c8, 0x30c3, 0x30b7, 0x30e5, 0xff09, 36432e5b6d6dSopenharmony_ci 0x300d, 0x3092, 0x3001, 0x3053, 0x3088, 0x306a, 0x304f, 0x611b, 36442e5b6d6dSopenharmony_ci 0x3059, 0x308b, 0x4eba, 0x305f, 0x3061, 0x306e, 0x3053, 0x3068, 36452e5b6d6dSopenharmony_ci 0x3060, 0x3002, 0x300c, 0x30a2, 0x30c3, 0x30d7, 0x30eb, 0x4fe1, 36462e5b6d6dSopenharmony_ci 0x8005, 0x300d, 0x306a, 0x3093, 0x3066, 0x8a00, 0x3044, 0x65b9, 36472e5b6d6dSopenharmony_ci 0x307e, 0x3067, 0x3042, 0x308b, 0x3002 36482e5b6d6dSopenharmony_ci }; 36492e5b6d6dSopenharmony_ci 36502e5b6d6dSopenharmony_ci /* SCSUEncoder produces a slightly longer result (179B vs. 178B) because of one different choice: 36512e5b6d6dSopenharmony_ci it uses an SQn once where a longer look-ahead could have shown that SCn is more efficient */ 36522e5b6d6dSopenharmony_ci static const uint8_t japaneseSCSU[]={ 36532e5b6d6dSopenharmony_ci 0x08, 0x00, 0x1b, 0x4c, 0xea, 0x16, 0xca, 0xd3, 0x94, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 36542e5b6d6dSopenharmony_ci 0xc4, 0x0f, 0x53, 0xef, 0x61, 0x1b, 0xe5, 0x84, 0xc4, 0x16, 0xca, 0xd3, 0x94, 0x08, 0x02, 0x0f, 36552e5b6d6dSopenharmony_ci 0x53, 0x4a, 0x4e, 0x16, 0x7d, 0x00, 0x30, 0x82, 0x52, 0x4d, 0x30, 0x6b, 0x6d, 0x41, 0x88, 0x4c, 36562e5b6d6dSopenharmony_ci 0xe5, 0x97, 0x9f, 0x08, 0x0c, 0x16, 0xca, 0xd3, 0x94, 0x15, 0xae, 0x0e, 0x6b, 0x4c, 0x08, 0x0d, 36572e5b6d6dSopenharmony_ci 0x8c, 0xb4, 0xa3, 0x9f, 0xca, 0x99, 0xcb, 0x8b, 0xc2, 0x97, 0xcc, 0xaa, 0x84, 0x08, 0x02, 0x0e, 36582e5b6d6dSopenharmony_ci 0x7c, 0x73, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x93, 0xd3, 0xb4, 0xc5, 0xdc, 0x9f, 0x0e, 0x79, 0x3e, 36592e5b6d6dSopenharmony_ci 0x06, 0xae, 0xb1, 0x9d, 0x93, 0xd3, 0x08, 0x0c, 0xbe, 0xa3, 0x8f, 0x08, 0x88, 0xbe, 0xa3, 0x8d, 36602e5b6d6dSopenharmony_ci 0xd3, 0xa8, 0xa3, 0x97, 0xc5, 0x17, 0x89, 0x08, 0x0d, 0x15, 0xd2, 0x08, 0x01, 0x93, 0xc8, 0xaa, 36612e5b6d6dSopenharmony_ci 0x8f, 0x0e, 0x61, 0x1b, 0x99, 0xcb, 0x0e, 0x4e, 0xba, 0x9f, 0xa1, 0xae, 0x93, 0xa8, 0xa0, 0x08, 36622e5b6d6dSopenharmony_ci 0x02, 0x08, 0x0c, 0xe2, 0x16, 0xa3, 0xb7, 0xcb, 0x0f, 0x4f, 0xe1, 0x80, 0x05, 0xec, 0x60, 0x8d, 36632e5b6d6dSopenharmony_ci 0xea, 0x06, 0xd3, 0xe6, 0x0f, 0x8a, 0x00, 0x30, 0x44, 0x65, 0xb9, 0xe4, 0xfe, 0xe7, 0xc2, 0x06, 36642e5b6d6dSopenharmony_ci 0xcb, 0x82 36652e5b6d6dSopenharmony_ci }; 36662e5b6d6dSopenharmony_ci 36672e5b6d6dSopenharmony_ci static const uint16_t allFeaturesUTF16[]={ 36682e5b6d6dSopenharmony_ci 0x0041, 0x00df, 0x0401, 0x015f, 0x00df, 0x01df, 0xf000, 0xdbff, 36692e5b6d6dSopenharmony_ci 0xdfff, 0x000d, 0x000a, 0x0041, 0x00df, 0x0401, 0x015f, 0x00df, 36702e5b6d6dSopenharmony_ci 0x01df, 0xf000, 0xdbff, 0xdfff 36712e5b6d6dSopenharmony_ci }; 36722e5b6d6dSopenharmony_ci 36732e5b6d6dSopenharmony_ci /* see comment at japaneseSCSU: the same kind of different choice yields a slightly shorter 36742e5b6d6dSopenharmony_ci * result here (34B vs. 35B) 36752e5b6d6dSopenharmony_ci */ 36762e5b6d6dSopenharmony_ci static const uint8_t allFeaturesSCSU[]={ 36772e5b6d6dSopenharmony_ci 0x41, 0xdf, 0x12, 0x81, 0x03, 0x5f, 0x10, 0xdf, 0x1b, 0x03, 36782e5b6d6dSopenharmony_ci 0xdf, 0x1c, 0x88, 0x80, 0x0b, 0xbf, 0xff, 0xff, 0x0d, 0x0a, 36792e5b6d6dSopenharmony_ci 0x41, 0x10, 0xdf, 0x12, 0x81, 0x03, 0x5f, 0x10, 0xdf, 0x13, 36802e5b6d6dSopenharmony_ci 0xdf, 0x14, 0x80, 0x15, 0xff 36812e5b6d6dSopenharmony_ci }; 36822e5b6d6dSopenharmony_ci static const uint16_t monkeyIn[]={ 36832e5b6d6dSopenharmony_ci 0x00A8, 0x3003, 0x3005, 0x2015, 0xFF5E, 0x2016, 0x2026, 0x2018, 0x000D, 0x000A, 36842e5b6d6dSopenharmony_ci 0x2019, 0x201C, 0x201D, 0x3014, 0x3015, 0x3008, 0x3009, 0x300A, 0x000D, 0x000A, 36852e5b6d6dSopenharmony_ci 0x300B, 0x300C, 0x300D, 0x300E, 0x300F, 0x3016, 0x3017, 0x3010, 0x000D, 0x000A, 36862e5b6d6dSopenharmony_ci 0x3011, 0x00B1, 0x00D7, 0x00F7, 0x2236, 0x2227, 0x7FC1, 0x8956, 0x000D, 0x000A, 36872e5b6d6dSopenharmony_ci 0x9D2C, 0x9D0E, 0x9EC4, 0x5CA1, 0x6C96, 0x837B, 0x5104, 0x5C4B, 0x000D, 0x000A, 36882e5b6d6dSopenharmony_ci 0x61B6, 0x81C6, 0x6876, 0x7261, 0x4E59, 0x4FFA, 0x5378, 0x57F7, 0x000D, 0x000A, 36892e5b6d6dSopenharmony_ci 0x57F4, 0x57F9, 0x57FA, 0x57FC, 0x5800, 0x5802, 0x5805, 0x5806, 0x000D, 0x000A, 36902e5b6d6dSopenharmony_ci 0x580A, 0x581E, 0x6BB5, 0x6BB7, 0x6BBA, 0x6BBC, 0x9CE2, 0x977C, 0x000D, 0x000A, 36912e5b6d6dSopenharmony_ci 0x6BBF, 0x6BC1, 0x6BC5, 0x6BC6, 0x6BCB, 0x6BCD, 0x6BCF, 0x6BD2, 0x000D, 0x000A, 36922e5b6d6dSopenharmony_ci 0x6BD3, 0x6BD4, 0x6BD6, 0x6BD7, 0x6BD8, 0x6BDB, 0x6BEB, 0x6BEC, 0x000D, 0x000A, 36932e5b6d6dSopenharmony_ci 0x6C05, 0x6C08, 0x6C0F, 0x6C11, 0x6C13, 0x6C23, 0x6C34, 0x0041, 0x000D, 0x000A, 36942e5b6d6dSopenharmony_ci 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 36952e5b6d6dSopenharmony_ci 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 36962e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 36972e5b6d6dSopenharmony_ci 0x005B, 0x9792, 0x9CCC, 0x9CCD, 0x9CCE, 0x9CCF, 0x9CD0, 0x9CD3, 0x000D, 0x000A, 36982e5b6d6dSopenharmony_ci 0x9CD4, 0x9CD5, 0x9CD7, 0x9CD8, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 36992e5b6d6dSopenharmony_ci 0x9785, 0x9791, 0x00BD, 0x0390, 0x0385, 0x0386, 0x0388, 0x0389, 0x000D, 0x000A, 37002e5b6d6dSopenharmony_ci 0x038E, 0x038F, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x000D, 0x000A, 37012e5b6d6dSopenharmony_ci 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x038A, 0x038C, 0x039C, 0x000D, 0x000A, 37022e5b6d6dSopenharmony_ci /* test non-BMP code points */ 37032e5b6d6dSopenharmony_ci 0xD869, 0xDE99, 0xD869, 0xDE9C, 0xD869, 0xDE9D, 0xD869, 0xDE9E, 0xD869, 0xDE9F, 37042e5b6d6dSopenharmony_ci 0xD869, 0xDEA0, 0xD869, 0xDEA5, 0xD869, 0xDEA6, 0xD869, 0xDEA7, 0xD869, 0xDEA8, 37052e5b6d6dSopenharmony_ci 0xD869, 0xDEAB, 0xD869, 0xDEAC, 0xD869, 0xDEAD, 0xD869, 0xDEAE, 0xD869, 0xDEAF, 37062e5b6d6dSopenharmony_ci 0xD869, 0xDEB0, 0xD869, 0xDEB1, 0xD869, 0xDEB3, 0xD869, 0xDEB5, 0xD869, 0xDEB6, 37072e5b6d6dSopenharmony_ci 0xD869, 0xDEB7, 0xD869, 0xDEB8, 0xD869, 0xDEB9, 0xD869, 0xDEBA, 0xD869, 0xDEBB, 37082e5b6d6dSopenharmony_ci 0xD869, 0xDEBC, 0xD869, 0xDEBD, 0xD869, 0xDEBE, 0xD869, 0xDEBF, 0xD869, 0xDEC0, 37092e5b6d6dSopenharmony_ci 0xD869, 0xDEC1, 0xD869, 0xDEC2, 0xD869, 0xDEC3, 0xD869, 0xDEC4, 0xD869, 0xDEC8, 37102e5b6d6dSopenharmony_ci 0xD869, 0xDECA, 0xD869, 0xDECB, 0xD869, 0xDECD, 0xD869, 0xDECE, 0xD869, 0xDECF, 37112e5b6d6dSopenharmony_ci 0xD869, 0xDED0, 0xD869, 0xDED1, 0xD869, 0xDED2, 0xD869, 0xDED3, 0xD869, 0xDED4, 37122e5b6d6dSopenharmony_ci 0xD869, 0xDED5, 0xD800, 0xDC00, 0xD800, 0xDC00, 0xD800, 0xDC00, 0xDBFF, 0xDFFF, 37132e5b6d6dSopenharmony_ci 0xDBFF, 0xDFFF, 0xDBFF, 0xDFFF, 37142e5b6d6dSopenharmony_ci 37152e5b6d6dSopenharmony_ci 37162e5b6d6dSopenharmony_ci 0x4DB3, 0x4DB4, 0x4DB5, 0x4E00, 0x4E00, 0x4E01, 0x4E02, 0x4E03, 0x000D, 0x000A, 37172e5b6d6dSopenharmony_ci 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x33E0, 0x33E6, 0x000D, 0x000A, 37182e5b6d6dSopenharmony_ci 0x4E05, 0x4E07, 0x4E04, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x000D, 0x000A, 37192e5b6d6dSopenharmony_ci 0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A, 37202e5b6d6dSopenharmony_ci 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A, 37212e5b6d6dSopenharmony_ci }; 37222e5b6d6dSopenharmony_ci static const char *fTestCases [] = { 37232e5b6d6dSopenharmony_ci "\\ud800\\udc00", /* smallest surrogate*/ 37242e5b6d6dSopenharmony_ci "\\ud8ff\\udcff", 37252e5b6d6dSopenharmony_ci "\\udBff\\udFff", /* largest surrogate pair*/ 37262e5b6d6dSopenharmony_ci "\\ud834\\udc00", 37272e5b6d6dSopenharmony_ci "\\U0010FFFF", 37282e5b6d6dSopenharmony_ci "Hello \\u9292 \\u9192 World!", 37292e5b6d6dSopenharmony_ci "Hell\\u0429o \\u9292 \\u9192 W\\u00e4rld!", 37302e5b6d6dSopenharmony_ci "Hell\\u0429o \\u9292 \\u9292W\\u00e4rld!", 37312e5b6d6dSopenharmony_ci 37322e5b6d6dSopenharmony_ci "\\u0648\\u06c8", /* catch missing reset*/ 37332e5b6d6dSopenharmony_ci "\\u0648\\u06c8", 37342e5b6d6dSopenharmony_ci 37352e5b6d6dSopenharmony_ci "\\u4444\\uE001", /* lowest quotable*/ 37362e5b6d6dSopenharmony_ci "\\u4444\\uf2FF", /* highest quotable*/ 37372e5b6d6dSopenharmony_ci "\\u4444\\uf188\\u4444", 37382e5b6d6dSopenharmony_ci "\\u4444\\uf188\\uf288", 37392e5b6d6dSopenharmony_ci "\\u4444\\uf188abc\\u0429\\uf288", 37402e5b6d6dSopenharmony_ci "\\u9292\\u2222", 37412e5b6d6dSopenharmony_ci "Hell\\u0429\\u04230o \\u9292 \\u9292W\\u00e4\\u0192rld!", 37422e5b6d6dSopenharmony_ci "Hell\\u0429o \\u9292 \\u9292W\\u00e4rld!", 37432e5b6d6dSopenharmony_ci "Hello World!123456", 37442e5b6d6dSopenharmony_ci "Hello W\\u0081\\u011f\\u0082!", /* Latin 1 run*/ 37452e5b6d6dSopenharmony_ci 37462e5b6d6dSopenharmony_ci "abc\\u0301\\u0302", /* uses SQn for u301 u302*/ 37472e5b6d6dSopenharmony_ci "abc\\u4411d", /* uses SQU*/ 37482e5b6d6dSopenharmony_ci "abc\\u4411\\u4412d",/* uses SCU*/ 37492e5b6d6dSopenharmony_ci "abc\\u0401\\u0402\\u047f\\u00a5\\u0405", /* uses SQn for ua5*/ 37502e5b6d6dSopenharmony_ci "\\u9191\\u9191\\u3041\\u9191\\u3041\\u3041\\u3000", /* SJIS like data*/ 37512e5b6d6dSopenharmony_ci "\\u9292\\u2222", 37522e5b6d6dSopenharmony_ci "\\u9191\\u9191\\u3041\\u9191\\u3041\\u3041\\u3000", 37532e5b6d6dSopenharmony_ci "\\u9999\\u3051\\u300c\\u9999\\u9999\\u3060\\u9999\\u3065\\u3065\\u3065\\u300c", 37542e5b6d6dSopenharmony_ci "\\u3000\\u266a\\u30ea\\u30f3\\u30b4\\u53ef\\u611b\\u3044\\u3084\\u53ef\\u611b\\u3044\\u3084\\u30ea\\u30f3\\u30b4\\u3002", 37552e5b6d6dSopenharmony_ci 37562e5b6d6dSopenharmony_ci "", /* empty input*/ 37572e5b6d6dSopenharmony_ci "\\u0000", /* smallest BMP character*/ 37582e5b6d6dSopenharmony_ci "\\uFFFF", /* largest BMP character*/ 37592e5b6d6dSopenharmony_ci 37602e5b6d6dSopenharmony_ci /* regression tests*/ 37612e5b6d6dSopenharmony_ci "\\u6441\\ub413\\ua733\\uf8fe\\ueedb\\u587f\\u195f\\u4899\\uf23d\\u49fd\\u0aac\\u5792\\ufc22\\ufc3c\\ufc46\\u00aa", 37622e5b6d6dSopenharmony_ci "\\u00df\\u01df\\uf000\\udbff\\udfff\\u000d\n\\u0041\\u00df\\u0401\\u015f\\u00df\\u01df\\uf000\\udbff\\udfff", 37632e5b6d6dSopenharmony_ci "\\u30f9\\u8321\\u05e5\\u181c\\ud72b\\u2019\\u99c9\\u2f2f\\uc10c\\u82e1\\u2c4d\\u1ebc\\u6013\\u66dc\\ubbde\\u94a5\\u4726\\u74af\\u3083\\u55b9\\u000c", 37642e5b6d6dSopenharmony_ci "\\u0041\\u00df\\u0401\\u015f", 37652e5b6d6dSopenharmony_ci "\\u9066\\u2123abc", 37662e5b6d6dSopenharmony_ci "\\ud266\\u43d7\\u\\ue386\\uc9c0\\u4a6b\\u9222\\u901f\\u7410\\ua63f\\u539b\\u9596\\u482e\\u9d47\\ucfe4\\u7b71\\uc280\\uf26a\\u982f\\u862a\\u4edd\\uf513\\ufda6\\u869d\\u2ee0\\ua216\\u3ff6\\u3c70\\u89c0\\u9576\\ud5ec\\ubfda\\u6cca\\u5bb3\\ubcea\\u554c\\u914e\\ufa4a\\uede3\\u2990\\ud2f5\\u2729\\u5141\\u0f26\\uccd8\\u5413\\ud196\\ubbe2\\u51b9\\u9b48\\u0dc8\\u2195\\u21a2\\u21e9\\u00e4\\u9d92\\u0bc0\\u06c5", 37672e5b6d6dSopenharmony_ci "\\uf95b\\u2458\\u2468\\u0e20\\uf51b\\ue36e\\ubfc1\\u0080\\u02dd\\uf1b5\\u0cf3\\u6059\\u7489", 37682e5b6d6dSopenharmony_ci }; 37692e5b6d6dSopenharmony_ci int i=0; 37702e5b6d6dSopenharmony_ci for(;i<UPRV_LENGTHOF(fTestCases);i++){ 37712e5b6d6dSopenharmony_ci const char* cSrc = fTestCases[i]; 37722e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 37732e5b6d6dSopenharmony_ci int32_t cSrcLen,srcLen; 37742e5b6d6dSopenharmony_ci UChar* src; 37752e5b6d6dSopenharmony_ci /* UConverter* cnv = ucnv_open("SCSU",&status); */ 37762e5b6d6dSopenharmony_ci cSrcLen = srcLen = (int32_t)uprv_strlen(fTestCases[i]); 37772e5b6d6dSopenharmony_ci src = (UChar*) malloc((sizeof(UChar) * srcLen) + sizeof(UChar)); 37782e5b6d6dSopenharmony_ci srcLen=unescape(src,srcLen,cSrc,cSrcLen,&status); 37792e5b6d6dSopenharmony_ci log_verbose("Testing roundtrip for src: %s at index :%d\n",cSrc,i); 37802e5b6d6dSopenharmony_ci TestConv(src,srcLen,"SCSU","Coverage",NULL,0); 37812e5b6d6dSopenharmony_ci free(src); 37822e5b6d6dSopenharmony_ci } 37832e5b6d6dSopenharmony_ci TestConv(allFeaturesUTF16,(sizeof(allFeaturesUTF16)/2),"SCSU","all features", (char *)allFeaturesSCSU,sizeof(allFeaturesSCSU)); 37842e5b6d6dSopenharmony_ci TestConv(allFeaturesUTF16,(sizeof(allFeaturesUTF16)/2),"SCSU","all features",(char *)allFeaturesSCSU,sizeof(allFeaturesSCSU)); 37852e5b6d6dSopenharmony_ci TestConv(japaneseUTF16,(sizeof(japaneseUTF16)/2),"SCSU","japaneese",(char *)japaneseSCSU,sizeof(japaneseSCSU)); 37862e5b6d6dSopenharmony_ci TestConv(japaneseUTF16,(sizeof(japaneseUTF16)/2),"SCSU,locale=ja","japaneese",(char *)japaneseSCSU,sizeof(japaneseSCSU)); 37872e5b6d6dSopenharmony_ci TestConv(germanUTF16,(sizeof(germanUTF16)/2),"SCSU","german",(char *)germanSCSU,sizeof(germanSCSU)); 37882e5b6d6dSopenharmony_ci TestConv(russianUTF16,(sizeof(russianUTF16)/2), "SCSU","russian",(char *)russianSCSU,sizeof(russianSCSU)); 37892e5b6d6dSopenharmony_ci TestConv(monkeyIn,(sizeof(monkeyIn)/2),"SCSU","monkey",NULL,0); 37902e5b6d6dSopenharmony_ci} 37912e5b6d6dSopenharmony_ci 37922e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 37932e5b6d6dSopenharmony_cistatic void TestJitterbug2346(){ 37942e5b6d6dSopenharmony_ci char source[] = { 0x1b,0x24,0x42,0x3d,0x45,0x1b,0x28,0x4a,0x0d,0x0a, 37952e5b6d6dSopenharmony_ci 0x1b,0x24,0x42,0x3d,0x45,0x1b,0x28,0x4a,0x0d,0x0a}; 37962e5b6d6dSopenharmony_ci uint16_t expected[] = {0x91CD,0x000D,0x000A,0x91CD,0x000D,0x000A}; 37972e5b6d6dSopenharmony_ci 37982e5b6d6dSopenharmony_ci UChar uTarget[500]={'\0'}; 37992e5b6d6dSopenharmony_ci UChar* utarget=uTarget; 38002e5b6d6dSopenharmony_ci UChar* utargetLimit=uTarget+sizeof(uTarget)/2; 38012e5b6d6dSopenharmony_ci 38022e5b6d6dSopenharmony_ci char cTarget[500]={'\0'}; 38032e5b6d6dSopenharmony_ci char* ctarget=cTarget; 38042e5b6d6dSopenharmony_ci char* ctargetLimit=cTarget+sizeof(cTarget); 38052e5b6d6dSopenharmony_ci const char* csource=source; 38062e5b6d6dSopenharmony_ci UChar* temp = expected; 38072e5b6d6dSopenharmony_ci UErrorCode err=U_ZERO_ERROR; 38082e5b6d6dSopenharmony_ci 38092e5b6d6dSopenharmony_ci UConverter* conv =ucnv_open("ISO_2022_JP",&err); 38102e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 38112e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(err)); 38122e5b6d6dSopenharmony_ci return; 38132e5b6d6dSopenharmony_ci } 38142e5b6d6dSopenharmony_ci ucnv_toUnicode(conv,&utarget,utargetLimit,&csource,csource+sizeof(source),NULL,true,&err); 38152e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 38162e5b6d6dSopenharmony_ci log_err("ISO_2022_JP to Unicode conversion failed: %s\n", u_errorName(err)); 38172e5b6d6dSopenharmony_ci return; 38182e5b6d6dSopenharmony_ci } 38192e5b6d6dSopenharmony_ci utargetLimit=utarget; 38202e5b6d6dSopenharmony_ci utarget = uTarget; 38212e5b6d6dSopenharmony_ci while(utarget<utargetLimit){ 38222e5b6d6dSopenharmony_ci if(*temp!=*utarget){ 38232e5b6d6dSopenharmony_ci 38242e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*utarget,(int)*temp) ; 38252e5b6d6dSopenharmony_ci } 38262e5b6d6dSopenharmony_ci utarget++; 38272e5b6d6dSopenharmony_ci temp++; 38282e5b6d6dSopenharmony_ci } 38292e5b6d6dSopenharmony_ci ucnv_fromUnicode(conv,&ctarget,ctargetLimit,(const UChar**)&utarget,utargetLimit,NULL,true,&err); 38302e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 38312e5b6d6dSopenharmony_ci log_err("ISO_2022_JP from Unicode conversion failed: %s\n", u_errorName(err)); 38322e5b6d6dSopenharmony_ci return; 38332e5b6d6dSopenharmony_ci } 38342e5b6d6dSopenharmony_ci ctargetLimit=ctarget; 38352e5b6d6dSopenharmony_ci ctarget =cTarget; 38362e5b6d6dSopenharmony_ci ucnv_close(conv); 38372e5b6d6dSopenharmony_ci 38382e5b6d6dSopenharmony_ci 38392e5b6d6dSopenharmony_ci} 38402e5b6d6dSopenharmony_ci 38412e5b6d6dSopenharmony_cistatic void 38422e5b6d6dSopenharmony_ciTestISO_2022_JP_1() { 38432e5b6d6dSopenharmony_ci /* test input */ 38442e5b6d6dSopenharmony_ci static const uint16_t in[]={ 38452e5b6d6dSopenharmony_ci 0x3000, 0x3001, 0x3002, 0x0020, 0xFF0E, 0x30FB, 0xFF1A, 0xFF1B, 0x000D, 0x000A, 38462e5b6d6dSopenharmony_ci 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 38472e5b6d6dSopenharmony_ci 0x52C8, 0x52CC, 0x52CF, 0x52D1, 0x52D4, 0x52D6, 0x52DB, 0x52DC, 0x000D, 0x000A, 38482e5b6d6dSopenharmony_ci 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 38492e5b6d6dSopenharmony_ci 0x3005, 0x3006, 0x3007, 0x30FC, 0x2015, 0x2010, 0xFF0F, 0x005C, 0x000D, 0x000A, 38502e5b6d6dSopenharmony_ci 0x3013, 0x2018, 0x2026, 0x2025, 0x2018, 0x2019, 0x201C, 0x000D, 0x000A, 38512e5b6d6dSopenharmony_ci 0x201D, 0x000D, 0x000A, 38522e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 38532e5b6d6dSopenharmony_ci 0x4F94, 0x4F97, 0x52BA, 0x52BB, 0x52BD, 0x52C0, 0x52C4, 0x52C6, 0x000D, 0x000A, 38542e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 38552e5b6d6dSopenharmony_ci 0x4F78, 0x4F79, 0x4F7A, 0x4F7D, 0x4F7E, 0x4F81, 0x4F82, 0x4F84, 0x000D, 0x000A, 38562e5b6d6dSopenharmony_ci 0x4F85, 0x4F89, 0x4F8A, 0x4F8C, 0x4F8E, 0x4F90, 0x4F92, 0x4F93, 0x000D, 0x000A, 38572e5b6d6dSopenharmony_ci 0x52E1, 0x52E5, 0x52E8, 0x52E9, 0x000D, 0x000A 38582e5b6d6dSopenharmony_ci }; 38592e5b6d6dSopenharmony_ci const UChar* uSource; 38602e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 38612e5b6d6dSopenharmony_ci const char* cSource; 38622e5b6d6dSopenharmony_ci const char* cSourceLimit; 38632e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 38642e5b6d6dSopenharmony_ci UChar *uTarget; 38652e5b6d6dSopenharmony_ci char *cTarget; 38662e5b6d6dSopenharmony_ci const char *cTargetLimit; 38672e5b6d6dSopenharmony_ci char *cBuf; 38682e5b6d6dSopenharmony_ci UChar *uBuf,*test; 38692e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 38702e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 38712e5b6d6dSopenharmony_ci UConverter *cnv; 38722e5b6d6dSopenharmony_ci 38732e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022_JP_1", &errorCode); 38742e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 38752e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 38762e5b6d6dSopenharmony_ci return; 38772e5b6d6dSopenharmony_ci } 38782e5b6d6dSopenharmony_ci 38792e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 38802e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 38812e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 38822e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 38832e5b6d6dSopenharmony_ci cTarget = cBuf; 38842e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 38852e5b6d6dSopenharmony_ci uTarget = uBuf; 38862e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 38872e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,NULL,true, &errorCode); 38882e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 38892e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 38902e5b6d6dSopenharmony_ci return; 38912e5b6d6dSopenharmony_ci } 38922e5b6d6dSopenharmony_ci cSource = cBuf; 38932e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 38942e5b6d6dSopenharmony_ci test =uBuf; 38952e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,NULL,true,&errorCode); 38962e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 38972e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 38982e5b6d6dSopenharmony_ci return; 38992e5b6d6dSopenharmony_ci } 39002e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 39012e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 39022e5b6d6dSopenharmony_ci if(*test!=*uSource){ 39032e5b6d6dSopenharmony_ci 39042e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 39052e5b6d6dSopenharmony_ci } 39062e5b6d6dSopenharmony_ci uSource++; 39072e5b6d6dSopenharmony_ci test++; 39082e5b6d6dSopenharmony_ci } 39092e5b6d6dSopenharmony_ci /*ucnv_close(cnv); 39102e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022,locale=jp,version=1", &errorCode);*/ 39112e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 39122e5b6d6dSopenharmony_ci ucnv_reset(cnv); 39132e5b6d6dSopenharmony_ci { 39142e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x0e,0x24,0x053}; 39152e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-JP-1]"); 39162e5b6d6dSopenharmony_ci } 39172e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 39182e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 39192e5b6d6dSopenharmony_ci ucnv_close(cnv); 39202e5b6d6dSopenharmony_ci free(uBuf); 39212e5b6d6dSopenharmony_ci free(cBuf); 39222e5b6d6dSopenharmony_ci} 39232e5b6d6dSopenharmony_ci 39242e5b6d6dSopenharmony_cistatic void 39252e5b6d6dSopenharmony_ciTestISO_2022_JP_2() { 39262e5b6d6dSopenharmony_ci /* test input */ 39272e5b6d6dSopenharmony_ci static const uint16_t in[]={ 39282e5b6d6dSopenharmony_ci 0x00A8, 0x3003, 0x3005, 0x2015, 0xFF5E, 0x2016, 0x2026, 0x2018, 0x000D, 0x000A, 39292e5b6d6dSopenharmony_ci 0x2019, 0x201C, 0x201D, 0x3014, 0x3015, 0x3008, 0x3009, 0x300A, 0x000D, 0x000A, 39302e5b6d6dSopenharmony_ci 0x300B, 0x300C, 0x300D, 0x300E, 0x300F, 0x3016, 0x3017, 0x3010, 0x000D, 0x000A, 39312e5b6d6dSopenharmony_ci 0x3011, 0x00B1, 0x00D7, 0x00F7, 0x2236, 0x2227, 0x7FC1, 0x8956, 0x000D, 0x000A, 39322e5b6d6dSopenharmony_ci 0x9D2C, 0x9D0E, 0x9EC4, 0x5CA1, 0x6C96, 0x837B, 0x5104, 0x5C4B, 0x000D, 0x000A, 39332e5b6d6dSopenharmony_ci 0x61B6, 0x81C6, 0x6876, 0x7261, 0x4E59, 0x4FFA, 0x5378, 0x57F7, 0x000D, 0x000A, 39342e5b6d6dSopenharmony_ci 0x57F4, 0x57F9, 0x57FA, 0x57FC, 0x5800, 0x5802, 0x5805, 0x5806, 0x000D, 0x000A, 39352e5b6d6dSopenharmony_ci 0x580A, 0x581E, 0x6BB5, 0x6BB7, 0x6BBA, 0x6BBC, 0x9CE2, 0x977C, 0x000D, 0x000A, 39362e5b6d6dSopenharmony_ci 0x6BBF, 0x6BC1, 0x6BC5, 0x6BC6, 0x6BCB, 0x6BCD, 0x6BCF, 0x6BD2, 0x000D, 0x000A, 39372e5b6d6dSopenharmony_ci 0x6BD3, 0x6BD4, 0x6BD6, 0x6BD7, 0x6BD8, 0x6BDB, 0x6BEB, 0x6BEC, 0x000D, 0x000A, 39382e5b6d6dSopenharmony_ci 0x6C05, 0x6C08, 0x6C0F, 0x6C11, 0x6C13, 0x6C23, 0x6C34, 0x0041, 0x000D, 0x000A, 39392e5b6d6dSopenharmony_ci 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 39402e5b6d6dSopenharmony_ci 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 39412e5b6d6dSopenharmony_ci 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 39422e5b6d6dSopenharmony_ci 0x005B, 0x9792, 0x9CCC, 0x9CCD, 0x9CCE, 0x9CCF, 0x9CD0, 0x9CD3, 0x000D, 0x000A, 39432e5b6d6dSopenharmony_ci 0x9CD4, 0x9CD5, 0x9CD7, 0x9CD8, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 39442e5b6d6dSopenharmony_ci 0x9785, 0x9791, 0x00BD, 0x0390, 0x0385, 0x0386, 0x0388, 0x0389, 0x000D, 0x000A, 39452e5b6d6dSopenharmony_ci 0x038E, 0x038F, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x000D, 0x000A, 39462e5b6d6dSopenharmony_ci 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x038A, 0x038C, 0x039C, 0x000D, 0x000A 39472e5b6d6dSopenharmony_ci }; 39482e5b6d6dSopenharmony_ci const UChar* uSource; 39492e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 39502e5b6d6dSopenharmony_ci const char* cSource; 39512e5b6d6dSopenharmony_ci const char* cSourceLimit; 39522e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 39532e5b6d6dSopenharmony_ci UChar *uTarget; 39542e5b6d6dSopenharmony_ci char *cTarget; 39552e5b6d6dSopenharmony_ci const char *cTargetLimit; 39562e5b6d6dSopenharmony_ci char *cBuf = NULL; 39572e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 39582e5b6d6dSopenharmony_ci UChar *test; 39592e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 39602e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 39612e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 39622e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 39632e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 39642e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022_JP_2", &errorCode); 39652e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 39662e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 39672e5b6d6dSopenharmony_ci goto cleanup; 39682e5b6d6dSopenharmony_ci } 39692e5b6d6dSopenharmony_ci 39702e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 39712e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 39722e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 39732e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 39742e5b6d6dSopenharmony_ci cTarget = cBuf; 39752e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 39762e5b6d6dSopenharmony_ci uTarget = uBuf; 39772e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 39782e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 39792e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 39802e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 39812e5b6d6dSopenharmony_ci goto cleanup; 39822e5b6d6dSopenharmony_ci } 39832e5b6d6dSopenharmony_ci cSource = cBuf; 39842e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 39852e5b6d6dSopenharmony_ci test =uBuf; 39862e5b6d6dSopenharmony_ci myOff=offsets; 39872e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 39882e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 39892e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 39902e5b6d6dSopenharmony_ci goto cleanup; 39912e5b6d6dSopenharmony_ci } 39922e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 39932e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 39942e5b6d6dSopenharmony_ci if(*test!=*uSource){ 39952e5b6d6dSopenharmony_ci 39962e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 39972e5b6d6dSopenharmony_ci } 39982e5b6d6dSopenharmony_ci uSource++; 39992e5b6d6dSopenharmony_ci test++; 40002e5b6d6dSopenharmony_ci } 40012e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40022e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40032e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40042e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 40052e5b6d6dSopenharmony_ci ucnv_reset(cnv); 40062e5b6d6dSopenharmony_ci { 40072e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x0e,0x24,0x053}; 40082e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-JP-2]"); 40092e5b6d6dSopenharmony_ci } 40102e5b6d6dSopenharmony_ci 40112e5b6d6dSopenharmony_cicleanup: 40122e5b6d6dSopenharmony_ci ucnv_close(cnv); 40132e5b6d6dSopenharmony_ci free(uBuf); 40142e5b6d6dSopenharmony_ci free(cBuf); 40152e5b6d6dSopenharmony_ci free(offsets); 40162e5b6d6dSopenharmony_ci} 40172e5b6d6dSopenharmony_ci 40182e5b6d6dSopenharmony_cistatic void 40192e5b6d6dSopenharmony_ciTestISO_2022_KR() { 40202e5b6d6dSopenharmony_ci /* test input */ 40212e5b6d6dSopenharmony_ci static const uint16_t in[]={ 40222e5b6d6dSopenharmony_ci 0x9F4B,0x9F4E,0x9F52,0x9F5F,0x9F61,0x9F67,0x9F6A,0x000A,0x000D 40232e5b6d6dSopenharmony_ci ,0x9F6C,0x9F77,0x9F8D,0x9F90,0x9F95,0x9F9C,0xAC00,0xAC01,0xAC04 40242e5b6d6dSopenharmony_ci ,0xAC07,0xAC08,0xAC09,0x0025,0x0026,0x0027,0x000A,0x000D,0x0028,0x0029 40252e5b6d6dSopenharmony_ci ,0x002A,0x002B,0x002C,0x002D,0x002E,0x53C3,0x53C8,0x53C9,0x53CA,0x53CB 40262e5b6d6dSopenharmony_ci ,0x53CD,0x53D4,0x53D6,0x53D7,0x53DB,0x000A,0x000D,0x53E1,0x53E2 40272e5b6d6dSopenharmony_ci ,0x53E3,0x53E4,0x000A,0x000D}; 40282e5b6d6dSopenharmony_ci const UChar* uSource; 40292e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 40302e5b6d6dSopenharmony_ci const char* cSource; 40312e5b6d6dSopenharmony_ci const char* cSourceLimit; 40322e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 40332e5b6d6dSopenharmony_ci UChar *uTarget; 40342e5b6d6dSopenharmony_ci char *cTarget; 40352e5b6d6dSopenharmony_ci const char *cTargetLimit; 40362e5b6d6dSopenharmony_ci char *cBuf = NULL; 40372e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 40382e5b6d6dSopenharmony_ci UChar *test; 40392e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 40402e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 40412e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 40422e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 40432e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 40442e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022,locale=kr", &errorCode); 40452e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 40462e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 40472e5b6d6dSopenharmony_ci goto cleanup; 40482e5b6d6dSopenharmony_ci } 40492e5b6d6dSopenharmony_ci 40502e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 40512e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 40522e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 40532e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 40542e5b6d6dSopenharmony_ci cTarget = cBuf; 40552e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 40562e5b6d6dSopenharmony_ci uTarget = uBuf; 40572e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 40582e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 40592e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 40602e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 40612e5b6d6dSopenharmony_ci goto cleanup; 40622e5b6d6dSopenharmony_ci } 40632e5b6d6dSopenharmony_ci cSource = cBuf; 40642e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 40652e5b6d6dSopenharmony_ci test =uBuf; 40662e5b6d6dSopenharmony_ci myOff=offsets; 40672e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 40682e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 40692e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 40702e5b6d6dSopenharmony_ci goto cleanup; 40712e5b6d6dSopenharmony_ci } 40722e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 40732e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 40742e5b6d6dSopenharmony_ci if(*test!=*uSource){ 40752e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,*test) ; 40762e5b6d6dSopenharmony_ci } 40772e5b6d6dSopenharmony_ci uSource++; 40782e5b6d6dSopenharmony_ci test++; 40792e5b6d6dSopenharmony_ci } 40802e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, "ISO-2022-KR encoding"); 40812e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40822e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40832e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 40842e5b6d6dSopenharmony_ci TestJitterbug930("csISO2022KR"); 40852e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 40862e5b6d6dSopenharmony_ci ucnv_reset(cnv); 40872e5b6d6dSopenharmony_ci { 40882e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x1b,0x24,0x053}; 40892e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 40902e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]"); 40912e5b6d6dSopenharmony_ci } 40922e5b6d6dSopenharmony_ci 40932e5b6d6dSopenharmony_cicleanup: 40942e5b6d6dSopenharmony_ci ucnv_close(cnv); 40952e5b6d6dSopenharmony_ci free(uBuf); 40962e5b6d6dSopenharmony_ci free(cBuf); 40972e5b6d6dSopenharmony_ci free(offsets); 40982e5b6d6dSopenharmony_ci} 40992e5b6d6dSopenharmony_ci 41002e5b6d6dSopenharmony_cistatic void 41012e5b6d6dSopenharmony_ciTestISO_2022_KR_1() { 41022e5b6d6dSopenharmony_ci /* test input */ 41032e5b6d6dSopenharmony_ci static const uint16_t in[]={ 41042e5b6d6dSopenharmony_ci 0x9F4B,0x9F4E,0x9F52,0x9F5F,0x9F61,0x9F67,0x9F6A,0x000A,0x000D 41052e5b6d6dSopenharmony_ci ,0x9F6C,0x9F77,0x9F8D,0x9F90,0x9F95,0x9F9C,0xAC00,0xAC01,0xAC04 41062e5b6d6dSopenharmony_ci ,0xAC07,0xAC08,0xAC09,0x0025,0x0026,0x0027,0x000A,0x000D,0x0028,0x0029 41072e5b6d6dSopenharmony_ci ,0x002A,0x002B,0x002C,0x002D,0x002E,0x53C3,0x53C8,0x53C9,0x53CA,0x53CB 41082e5b6d6dSopenharmony_ci ,0x53CD,0x53D4,0x53D6,0x53D7,0x53DB,0x000A,0x000D,0x53E1,0x53E2 41092e5b6d6dSopenharmony_ci ,0x53E3,0x53E4,0x000A,0x000D}; 41102e5b6d6dSopenharmony_ci const UChar* uSource; 41112e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 41122e5b6d6dSopenharmony_ci const char* cSource; 41132e5b6d6dSopenharmony_ci const char* cSourceLimit; 41142e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 41152e5b6d6dSopenharmony_ci UChar *uTarget; 41162e5b6d6dSopenharmony_ci char *cTarget; 41172e5b6d6dSopenharmony_ci const char *cTargetLimit; 41182e5b6d6dSopenharmony_ci char *cBuf = NULL; 41192e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 41202e5b6d6dSopenharmony_ci UChar *test; 41212e5b6d6dSopenharmony_ci int32_t uBufSize = 120; 41222e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 41232e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 41242e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 41252e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 41262e5b6d6dSopenharmony_ci cnv=ucnv_open("ibm-25546", &errorCode); 41272e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 41282e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 41292e5b6d6dSopenharmony_ci goto cleanup; 41302e5b6d6dSopenharmony_ci } 41312e5b6d6dSopenharmony_ci 41322e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 41332e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 5); 41342e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 41352e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 41362e5b6d6dSopenharmony_ci cTarget = cBuf; 41372e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 41382e5b6d6dSopenharmony_ci uTarget = uBuf; 41392e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 41402e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 41412e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 41422e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 41432e5b6d6dSopenharmony_ci goto cleanup; 41442e5b6d6dSopenharmony_ci } 41452e5b6d6dSopenharmony_ci cSource = cBuf; 41462e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 41472e5b6d6dSopenharmony_ci test =uBuf; 41482e5b6d6dSopenharmony_ci myOff=offsets; 41492e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 41502e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 41512e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 41522e5b6d6dSopenharmony_ci goto cleanup; 41532e5b6d6dSopenharmony_ci } 41542e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 41552e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 41562e5b6d6dSopenharmony_ci if(*test!=*uSource){ 41572e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,*test) ; 41582e5b6d6dSopenharmony_ci } 41592e5b6d6dSopenharmony_ci uSource++; 41602e5b6d6dSopenharmony_ci test++; 41612e5b6d6dSopenharmony_ci } 41622e5b6d6dSopenharmony_ci ucnv_reset(cnv); 41632e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, "ISO-2022-KR encoding"); 41642e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 41652e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 41662e5b6d6dSopenharmony_ci ucnv_reset(cnv); 41672e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 41682e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 41692e5b6d6dSopenharmony_ci ucnv_reset(cnv); 41702e5b6d6dSopenharmony_ci { 41712e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x1b,0x24,0x053}; 41722e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 41732e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]"); 41742e5b6d6dSopenharmony_ci } 41752e5b6d6dSopenharmony_ci 41762e5b6d6dSopenharmony_cicleanup: 41772e5b6d6dSopenharmony_ci ucnv_close(cnv); 41782e5b6d6dSopenharmony_ci free(uBuf); 41792e5b6d6dSopenharmony_ci free(cBuf); 41802e5b6d6dSopenharmony_ci free(offsets); 41812e5b6d6dSopenharmony_ci} 41822e5b6d6dSopenharmony_ci 41832e5b6d6dSopenharmony_cistatic void TestJitterbug2411(){ 41842e5b6d6dSopenharmony_ci static const char* source = "\x1b\x24\x29\x43\x6b\x6b\x6e\x6e\x6a\x68\x70\x6f\x69\x75\x79\x71\x77\x65\x68\x67\x0A" 41852e5b6d6dSopenharmony_ci "\x1b\x24\x29\x43\x6a\x61\x73\x64\x66\x6a\x61\x73\x64\x66\x68\x6f\x69\x75\x79\x1b\x24\x29\x43"; 41862e5b6d6dSopenharmony_ci UConverter* kr=NULL, *kr1=NULL; 41872e5b6d6dSopenharmony_ci UErrorCode errorCode = U_ZERO_ERROR; 41882e5b6d6dSopenharmony_ci UChar tgt[100]={'\0'}; 41892e5b6d6dSopenharmony_ci UChar* target = tgt; 41902e5b6d6dSopenharmony_ci UChar* targetLimit = target+100; 41912e5b6d6dSopenharmony_ci kr=ucnv_open("iso-2022-kr", &errorCode); 41922e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 41932e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022-kr converter: %s\n", u_errorName(errorCode)); 41942e5b6d6dSopenharmony_ci return; 41952e5b6d6dSopenharmony_ci } 41962e5b6d6dSopenharmony_ci ucnv_toUnicode(kr,&target,targetLimit,&source,source+uprv_strlen(source),NULL,true,&errorCode); 41972e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 41982e5b6d6dSopenharmony_ci log_err("iso-2022-kr cannot handle multiple escape sequences : %s\n", u_errorName(errorCode)); 41992e5b6d6dSopenharmony_ci return; 42002e5b6d6dSopenharmony_ci } 42012e5b6d6dSopenharmony_ci kr1 = ucnv_open("ibm-25546", &errorCode); 42022e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 42032e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022-kr_1 converter: %s\n", u_errorName(errorCode)); 42042e5b6d6dSopenharmony_ci return; 42052e5b6d6dSopenharmony_ci } 42062e5b6d6dSopenharmony_ci target = tgt; 42072e5b6d6dSopenharmony_ci targetLimit = target+100; 42082e5b6d6dSopenharmony_ci ucnv_toUnicode(kr,&target,targetLimit,&source,source+uprv_strlen(source),NULL,true,&errorCode); 42092e5b6d6dSopenharmony_ci 42102e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 42112e5b6d6dSopenharmony_ci log_err("iso-2022-kr_1 cannot handle multiple escape sequences : %s\n", u_errorName(errorCode)); 42122e5b6d6dSopenharmony_ci return; 42132e5b6d6dSopenharmony_ci } 42142e5b6d6dSopenharmony_ci 42152e5b6d6dSopenharmony_ci ucnv_close(kr); 42162e5b6d6dSopenharmony_ci ucnv_close(kr1); 42172e5b6d6dSopenharmony_ci 42182e5b6d6dSopenharmony_ci} 42192e5b6d6dSopenharmony_ci 42202e5b6d6dSopenharmony_cistatic void 42212e5b6d6dSopenharmony_ciTestJIS(){ 42222e5b6d6dSopenharmony_ci /* From Unicode moved to testdata/conversion.txt */ 42232e5b6d6dSopenharmony_ci /*To Unicode*/ 42242e5b6d6dSopenharmony_ci { 42252e5b6d6dSopenharmony_ci static const uint8_t sampleTextJIS[] = { 42262e5b6d6dSopenharmony_ci 0x1b,0x28,0x48,0x41,0x42, /*jis-Roman*/ 42272e5b6d6dSopenharmony_ci 0x1b,0x28,0x49,0x41,0x42, /*Katakana Set*/ 42282e5b6d6dSopenharmony_ci 0x1b,0x26,0x40,0x1b,0x24,0x42,0x21,0x21 /*recognize and ignore <esc>&@*/ 42292e5b6d6dSopenharmony_ci }; 42302e5b6d6dSopenharmony_ci static const uint16_t expectedISO2022JIS[] = { 42312e5b6d6dSopenharmony_ci 0x0041, 0x0042, 42322e5b6d6dSopenharmony_ci 0xFF81, 0xFF82, 42332e5b6d6dSopenharmony_ci 0x3000 42342e5b6d6dSopenharmony_ci }; 42352e5b6d6dSopenharmony_ci static const int32_t toISO2022JISOffs[]={ 42362e5b6d6dSopenharmony_ci 3,4, 42372e5b6d6dSopenharmony_ci 8,9, 42382e5b6d6dSopenharmony_ci 16 42392e5b6d6dSopenharmony_ci }; 42402e5b6d6dSopenharmony_ci 42412e5b6d6dSopenharmony_ci static const uint8_t sampleTextJIS7[] = { 42422e5b6d6dSopenharmony_ci 0x1b,0x28,0x48,0x41,0x42, /*JIS7-Roman*/ 42432e5b6d6dSopenharmony_ci 0x1b,0x28,0x49,0x41,0x42, /*Katakana Set*/ 42442e5b6d6dSopenharmony_ci 0x1b,0x24,0x42,0x21,0x21, 42452e5b6d6dSopenharmony_ci 0x0e,0x41,0x42,0x0f, /*Test Katakana set with SI and SO */ 42462e5b6d6dSopenharmony_ci 0x21,0x22, 42472e5b6d6dSopenharmony_ci 0x1b,0x26,0x40,0x1b,0x24,0x42,0x21,0x21 /*recognize and ignore <esc>&@*/ 42482e5b6d6dSopenharmony_ci }; 42492e5b6d6dSopenharmony_ci static const uint16_t expectedISO2022JIS7[] = { 42502e5b6d6dSopenharmony_ci 0x0041, 0x0042, 42512e5b6d6dSopenharmony_ci 0xFF81, 0xFF82, 42522e5b6d6dSopenharmony_ci 0x3000, 42532e5b6d6dSopenharmony_ci 0xFF81, 0xFF82, 42542e5b6d6dSopenharmony_ci 0x3001, 42552e5b6d6dSopenharmony_ci 0x3000 42562e5b6d6dSopenharmony_ci }; 42572e5b6d6dSopenharmony_ci static const int32_t toISO2022JIS7Offs[]={ 42582e5b6d6dSopenharmony_ci 3,4, 42592e5b6d6dSopenharmony_ci 8,9, 42602e5b6d6dSopenharmony_ci 13,16, 42612e5b6d6dSopenharmony_ci 17, 42622e5b6d6dSopenharmony_ci 19,27 42632e5b6d6dSopenharmony_ci }; 42642e5b6d6dSopenharmony_ci static const uint8_t sampleTextJIS8[] = { 42652e5b6d6dSopenharmony_ci 0x1b,0x28,0x48,0x41,0x42, /*JIS8-Roman*/ 42662e5b6d6dSopenharmony_ci 0xa1,0xc8,0xd9,/*Katakana Set*/ 42672e5b6d6dSopenharmony_ci 0x1b,0x28,0x42, 42682e5b6d6dSopenharmony_ci 0x41,0x42, 42692e5b6d6dSopenharmony_ci 0xb1,0xc3, /*Katakana Set*/ 42702e5b6d6dSopenharmony_ci 0x1b,0x24,0x42,0x21,0x21 42712e5b6d6dSopenharmony_ci }; 42722e5b6d6dSopenharmony_ci static const uint16_t expectedISO2022JIS8[] = { 42732e5b6d6dSopenharmony_ci 0x0041, 0x0042, 42742e5b6d6dSopenharmony_ci 0xff61, 0xff88, 0xff99, 42752e5b6d6dSopenharmony_ci 0x0041, 0x0042, 42762e5b6d6dSopenharmony_ci 0xff71, 0xff83, 42772e5b6d6dSopenharmony_ci 0x3000 42782e5b6d6dSopenharmony_ci }; 42792e5b6d6dSopenharmony_ci static const int32_t toISO2022JIS8Offs[]={ 42802e5b6d6dSopenharmony_ci 3, 4, 5, 6, 42812e5b6d6dSopenharmony_ci 7, 11, 12, 13, 42822e5b6d6dSopenharmony_ci 14, 18, 42832e5b6d6dSopenharmony_ci }; 42842e5b6d6dSopenharmony_ci 42852e5b6d6dSopenharmony_ci testConvertToU(sampleTextJIS,sizeof(sampleTextJIS),expectedISO2022JIS, 42862e5b6d6dSopenharmony_ci UPRV_LENGTHOF(expectedISO2022JIS),"JIS", toISO2022JISOffs,true); 42872e5b6d6dSopenharmony_ci testConvertToU(sampleTextJIS7,sizeof(sampleTextJIS7),expectedISO2022JIS7, 42882e5b6d6dSopenharmony_ci UPRV_LENGTHOF(expectedISO2022JIS7),"JIS7", toISO2022JIS7Offs,true); 42892e5b6d6dSopenharmony_ci testConvertToU(sampleTextJIS8,sizeof(sampleTextJIS8),expectedISO2022JIS8, 42902e5b6d6dSopenharmony_ci UPRV_LENGTHOF(expectedISO2022JIS8),"JIS8", toISO2022JIS8Offs,true); 42912e5b6d6dSopenharmony_ci } 42922e5b6d6dSopenharmony_ci 42932e5b6d6dSopenharmony_ci} 42942e5b6d6dSopenharmony_ci 42952e5b6d6dSopenharmony_ci 42962e5b6d6dSopenharmony_ci#if 0 42972e5b6d6dSopenharmony_ci ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 42982e5b6d6dSopenharmony_ci 42992e5b6d6dSopenharmony_cistatic void TestJitterbug915(){ 43002e5b6d6dSopenharmony_ci/* tests for roundtripping of the below sequence 43012e5b6d6dSopenharmony_ci\x1b$)G\x0E#!#"###$#%#&#'#(#)#*#+ / *plane 1 * / 43022e5b6d6dSopenharmony_ci\x1b$*H\x1bN"!\x1bN""\x1bN"#\x1bN"$\x1bN"% / *plane 2 * / 43032e5b6d6dSopenharmony_ci\x1b$+I\x1bO"D\x1bO"E\x1bO"F\x1bO"G\x1bO"H / *plane 3 * / 43042e5b6d6dSopenharmony_ci\x1b$+J\x1bO!D\x1bO!E\x1bO"j\x1bO"k\x1bO"l / *plane 4 * / 43052e5b6d6dSopenharmony_ci\x1b$+K\x1bO!t\x1bO"P\x1bO"Q\x1bO#7\x1bO"\ / *plane 5 * / 43062e5b6d6dSopenharmony_ci\x1b$+L\x1bO!#\x1bO",\x1bO#N\x1bO!n\x1bO#q / *plane 6 * / 43072e5b6d6dSopenharmony_ci\x1b$+M\x1bO"q\x1bO!N\x1bO!j\x1bO#:\x1bO#o / *plane 7 * / 43082e5b6d6dSopenharmony_ci*/ 43092e5b6d6dSopenharmony_ci static const char cSource[]={ 43102e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x29, 0x47, 0x0E, 0x23, 0x21, 0x23, 0x22, 0x23, 43112e5b6d6dSopenharmony_ci 0x23, 0x23, 0x24, 0x23, 0x25, 0x23, 0x26, 0x23, 0x27, 0x23, 43122e5b6d6dSopenharmony_ci 0x28, 0x23, 0x29, 0x23, 0x2A, 0x23, 0x2B, 0x0F, 0x2F, 0x2A, 43132e5b6d6dSopenharmony_ci 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 0x31, 0x20, 0x2A, 0x2F, 43142e5b6d6dSopenharmony_ci 0x0D, 0x0A, 0x1B, 0x24, 0x2A, 0x48, 0x1B, 0x4E, 0x22, 0x21, 43152e5b6d6dSopenharmony_ci 0x1B, 0x4E, 0x22, 0x22, 0x1B, 0x4E, 0x22, 0x23, 0x1B, 0x4E, 43162e5b6d6dSopenharmony_ci 0x22, 0x24, 0x1B, 0x4E, 0x22, 0x25, 0x2F, 0x2A, 0x70, 43172e5b6d6dSopenharmony_ci 0x6C, 0x61, 0x6E, 0x65, 0x32, 0x2A, 0x2F, 0x20, 0x0D, 0x0A, 43182e5b6d6dSopenharmony_ci 0x1B, 0x24, 0x2B, 0x49, 0x1B, 0x4F, 0x22, 0x44, 0x1B, 0x4F, 43192e5b6d6dSopenharmony_ci 0x22, 0x45, 0x1B, 0x4F, 0x22, 0x46, 0x1B, 0x4F, 0x22, 0x47, 43202e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x48, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 43212e5b6d6dSopenharmony_ci 0x6E, 0x65, 0x20, 0x33, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 43222e5b6d6dSopenharmony_ci 0x24, 0x2B, 0x4A, 0x1B, 0x4F, 0x21, 0x44, 0x1B, 0x4F, 0x21, 43232e5b6d6dSopenharmony_ci 0x45, 0x1B, 0x4F, 0x22, 0x6A, 0x1B, 0x4F, 0x22, 0x6B, 0x1B, 43242e5b6d6dSopenharmony_ci 0x4F, 0x22, 0x6C, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 43252e5b6d6dSopenharmony_ci 0x65, 0x20, 0x34, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 43262e5b6d6dSopenharmony_ci 0x2B, 0x4B, 0x1B, 0x4F, 0x21, 0x74, 0x1B, 0x4F, 0x22, 0x50, 43272e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x22, 0x51, 0x1B, 0x4F, 0x23, 0x37, 0x1B, 0x4F, 43282e5b6d6dSopenharmony_ci 0x22, 0x5C, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 43292e5b6d6dSopenharmony_ci 0x65, 0x20, 0x35, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 43302e5b6d6dSopenharmony_ci 0x2B, 0x4C, 0x1B, 0x4F, 0x21, 0x23, 0x1B, 0x4F, 0x22, 0x2C, 43312e5b6d6dSopenharmony_ci 0x1B, 0x4F, 0x23, 0x4E, 0x1B, 0x4F, 0x21, 0x6E, 0x1B, 0x4F, 43322e5b6d6dSopenharmony_ci 0x23, 0x71, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 43332e5b6d6dSopenharmony_ci 0x20, 0x36, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 0x2B, 43342e5b6d6dSopenharmony_ci 0x4D, 0x1B, 0x4F, 0x22, 0x71, 0x1B, 0x4F, 0x21, 0x4E, 0x1B, 43352e5b6d6dSopenharmony_ci 0x4F, 0x21, 0x6A, 0x1B, 0x4F, 0x23, 0x3A, 0x1B, 0x4F, 0x23, 43362e5b6d6dSopenharmony_ci 0x6F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 43372e5b6d6dSopenharmony_ci 0x37, 0x20, 0x2A, 0x2F 43382e5b6d6dSopenharmony_ci }; 43392e5b6d6dSopenharmony_ci UChar uTarget[500]={'\0'}; 43402e5b6d6dSopenharmony_ci UChar* utarget=uTarget; 43412e5b6d6dSopenharmony_ci UChar* utargetLimit=uTarget+sizeof(uTarget)/2; 43422e5b6d6dSopenharmony_ci 43432e5b6d6dSopenharmony_ci char cTarget[500]={'\0'}; 43442e5b6d6dSopenharmony_ci char* ctarget=cTarget; 43452e5b6d6dSopenharmony_ci char* ctargetLimit=cTarget+sizeof(cTarget); 43462e5b6d6dSopenharmony_ci const char* csource=cSource; 43472e5b6d6dSopenharmony_ci const char* tempSrc = cSource; 43482e5b6d6dSopenharmony_ci UErrorCode err=U_ZERO_ERROR; 43492e5b6d6dSopenharmony_ci 43502e5b6d6dSopenharmony_ci UConverter* conv =ucnv_open("ISO_2022_CN_EXT",&err); 43512e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 43522e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(err)); 43532e5b6d6dSopenharmony_ci return; 43542e5b6d6dSopenharmony_ci } 43552e5b6d6dSopenharmony_ci ucnv_toUnicode(conv,&utarget,utargetLimit,&csource,csource+sizeof(cSource),NULL,true,&err); 43562e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 43572e5b6d6dSopenharmony_ci log_err("iso-2022-CN to Unicode conversion failed: %s\n", u_errorName(err)); 43582e5b6d6dSopenharmony_ci return; 43592e5b6d6dSopenharmony_ci } 43602e5b6d6dSopenharmony_ci utargetLimit=utarget; 43612e5b6d6dSopenharmony_ci utarget = uTarget; 43622e5b6d6dSopenharmony_ci ucnv_fromUnicode(conv,&ctarget,ctargetLimit,(const UChar**)&utarget,utargetLimit,NULL,true,&err); 43632e5b6d6dSopenharmony_ci if(U_FAILURE(err)) { 43642e5b6d6dSopenharmony_ci log_err("iso-2022-CN from Unicode conversion failed: %s\n", u_errorName(err)); 43652e5b6d6dSopenharmony_ci return; 43662e5b6d6dSopenharmony_ci } 43672e5b6d6dSopenharmony_ci ctargetLimit=ctarget; 43682e5b6d6dSopenharmony_ci ctarget =cTarget; 43692e5b6d6dSopenharmony_ci while(ctarget<ctargetLimit){ 43702e5b6d6dSopenharmony_ci if(*ctarget != *tempSrc){ 43712e5b6d6dSopenharmony_ci log_err("j915[%d] Expected : \\x%02X \t Got: \\x%02X\n", (int)(ctarget-cTarget), *ctarget,(int)*tempSrc) ; 43722e5b6d6dSopenharmony_ci } 43732e5b6d6dSopenharmony_ci ++ctarget; 43742e5b6d6dSopenharmony_ci ++tempSrc; 43752e5b6d6dSopenharmony_ci } 43762e5b6d6dSopenharmony_ci 43772e5b6d6dSopenharmony_ci ucnv_close(conv); 43782e5b6d6dSopenharmony_ci} 43792e5b6d6dSopenharmony_ci 43802e5b6d6dSopenharmony_cistatic void 43812e5b6d6dSopenharmony_ciTestISO_2022_CN_EXT() { 43822e5b6d6dSopenharmony_ci /* test input */ 43832e5b6d6dSopenharmony_ci static const uint16_t in[]={ 43842e5b6d6dSopenharmony_ci /* test Non-BMP code points */ 43852e5b6d6dSopenharmony_ci 0xD869, 0xDE99, 0xD869, 0xDE9C, 0xD869, 0xDE9D, 0xD869, 0xDE9E, 0xD869, 0xDE9F, 43862e5b6d6dSopenharmony_ci 0xD869, 0xDEA0, 0xD869, 0xDEA5, 0xD869, 0xDEA6, 0xD869, 0xDEA7, 0xD869, 0xDEA8, 43872e5b6d6dSopenharmony_ci 0xD869, 0xDEAB, 0xD869, 0xDEAC, 0xD869, 0xDEAD, 0xD869, 0xDEAE, 0xD869, 0xDEAF, 43882e5b6d6dSopenharmony_ci 0xD869, 0xDEB0, 0xD869, 0xDEB1, 0xD869, 0xDEB3, 0xD869, 0xDEB5, 0xD869, 0xDEB6, 43892e5b6d6dSopenharmony_ci 0xD869, 0xDEB7, 0xD869, 0xDEB8, 0xD869, 0xDEB9, 0xD869, 0xDEBA, 0xD869, 0xDEBB, 43902e5b6d6dSopenharmony_ci 0xD869, 0xDEBC, 0xD869, 0xDEBD, 0xD869, 0xDEBE, 0xD869, 0xDEBF, 0xD869, 0xDEC0, 43912e5b6d6dSopenharmony_ci 0xD869, 0xDEC1, 0xD869, 0xDEC2, 0xD869, 0xDEC3, 0xD869, 0xDEC4, 0xD869, 0xDEC8, 43922e5b6d6dSopenharmony_ci 0xD869, 0xDECA, 0xD869, 0xDECB, 0xD869, 0xDECD, 0xD869, 0xDECE, 0xD869, 0xDECF, 43932e5b6d6dSopenharmony_ci 0xD869, 0xDED0, 0xD869, 0xDED1, 0xD869, 0xDED2, 0xD869, 0xDED3, 0xD869, 0xDED4, 43942e5b6d6dSopenharmony_ci 0xD869, 0xDED5, 43952e5b6d6dSopenharmony_ci 43962e5b6d6dSopenharmony_ci 0x4DB3, 0x4DB4, 0x4DB5, 0x4E00, 0x4E00, 0x4E01, 0x4E02, 0x4E03, 0x000D, 0x000A, 43972e5b6d6dSopenharmony_ci 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x33E0, 0x33E6, 0x000D, 0x000A, 43982e5b6d6dSopenharmony_ci 0x4E05, 0x4E07, 0x4E04, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x000D, 0x000A, 43992e5b6d6dSopenharmony_ci 0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A, 44002e5b6d6dSopenharmony_ci 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A, 44012e5b6d6dSopenharmony_ci 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0x6332, 0x63B0, 0x643F, 0x000D, 0x000A, 44022e5b6d6dSopenharmony_ci 0x64D8, 0x8004, 0x6BEA, 0x6BF3, 0x6BFD, 0x6BF5, 0x6BF9, 0x6C05, 0x000D, 0x000A, 44032e5b6d6dSopenharmony_ci 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x000D, 0x000A, 44042e5b6d6dSopenharmony_ci 0x6C07, 0x6C06, 0x6C0D, 0x6C15, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 44052e5b6d6dSopenharmony_ci 0x9CE2, 0x977C, 0x9785, 0x9791, 0x9792, 0x9794, 0x97AF, 0x97AB, 0x000D, 0x000A, 44062e5b6d6dSopenharmony_ci 0x97A3, 0x97B2, 0x97B4, 0x9AB1, 0x9AB0, 0x9AB7, 0x9E58, 0x9AB6, 0x000D, 0x000A, 44072e5b6d6dSopenharmony_ci 0x9ABA, 0x9ABC, 0x9AC1, 0x9AC0, 0x9AC5, 0x9AC2, 0x9ACB, 0x9ACC, 0x000D, 0x000A, 44082e5b6d6dSopenharmony_ci 0x9AD1, 0x9B45, 0x9B43, 0x9B47, 0x9B49, 0x9B48, 0x9B4D, 0x9B51, 0x000D, 0x000A, 44092e5b6d6dSopenharmony_ci 0x98E8, 0x990D, 0x992E, 0x9955, 0x9954, 0x9ADF, 0x3443, 0x3444, 0x000D, 0x000A, 44102e5b6d6dSopenharmony_ci 0x3445, 0x3449, 0x344A, 0x344B, 0x60F2, 0x60F3, 0x60F4, 0x60F5, 0x000D, 0x000A, 44112e5b6d6dSopenharmony_ci 0x60F6, 0x60F7, 0x60F8, 0x60F9, 0x60FA, 0x60FB, 0x60FC, 0x60FD, 0x000D, 0x000A, 44122e5b6d6dSopenharmony_ci 0x60FE, 0x60FF, 0x6100, 0x6101, 0x6102, 0x0041, 0x0042, 0x0043, 0x000D, 0x000A, 44132e5b6d6dSopenharmony_ci 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x000D, 0x000A, 44142e5b6d6dSopenharmony_ci 44152e5b6d6dSopenharmony_ci 0x33E7, 0x33E8, 0x33E9, 0x33EA, 0x000D, 0x000A 44162e5b6d6dSopenharmony_ci 44172e5b6d6dSopenharmony_ci }; 44182e5b6d6dSopenharmony_ci 44192e5b6d6dSopenharmony_ci const UChar* uSource; 44202e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 44212e5b6d6dSopenharmony_ci const char* cSource; 44222e5b6d6dSopenharmony_ci const char* cSourceLimit; 44232e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 44242e5b6d6dSopenharmony_ci UChar *uTarget; 44252e5b6d6dSopenharmony_ci char *cTarget; 44262e5b6d6dSopenharmony_ci const char *cTargetLimit; 44272e5b6d6dSopenharmony_ci char *cBuf = NULL; 44282e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 44292e5b6d6dSopenharmony_ci UChar *test; 44302e5b6d6dSopenharmony_ci int32_t uBufSize = 180; 44312e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 44322e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 44332e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 44342e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 44352e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022,locale=cn,version=1", &errorCode); 44362e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 44372e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 44382e5b6d6dSopenharmony_ci goto cleanup; 44392e5b6d6dSopenharmony_ci } 44402e5b6d6dSopenharmony_ci 44412e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 44422e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 10); 44432e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 44442e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 44452e5b6d6dSopenharmony_ci cTarget = cBuf; 44462e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 44472e5b6d6dSopenharmony_ci uTarget = uBuf; 44482e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 44492e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 44502e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 44512e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 44522e5b6d6dSopenharmony_ci goto cleanup; 44532e5b6d6dSopenharmony_ci } 44542e5b6d6dSopenharmony_ci cSource = cBuf; 44552e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 44562e5b6d6dSopenharmony_ci test =uBuf; 44572e5b6d6dSopenharmony_ci myOff=offsets; 44582e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 44592e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 44602e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 44612e5b6d6dSopenharmony_ci goto cleanup; 44622e5b6d6dSopenharmony_ci } 44632e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 44642e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 44652e5b6d6dSopenharmony_ci if(*test!=*uSource){ 44662e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 44672e5b6d6dSopenharmony_ci } 44682e5b6d6dSopenharmony_ci else{ 44692e5b6d6dSopenharmony_ci log_verbose(" Got: \\u%04X\n",(int)*test) ; 44702e5b6d6dSopenharmony_ci } 44712e5b6d6dSopenharmony_ci uSource++; 44722e5b6d6dSopenharmony_ci test++; 44732e5b6d6dSopenharmony_ci } 44742e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 44752e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 44762e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 44772e5b6d6dSopenharmony_ci ucnv_reset(cnv); 44782e5b6d6dSopenharmony_ci { 44792e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x0e,0x24,0x053}; 44802e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN-EXT]"); 44812e5b6d6dSopenharmony_ci } 44822e5b6d6dSopenharmony_ci 44832e5b6d6dSopenharmony_cicleanup: 44842e5b6d6dSopenharmony_ci ucnv_close(cnv); 44852e5b6d6dSopenharmony_ci free(uBuf); 44862e5b6d6dSopenharmony_ci free(cBuf); 44872e5b6d6dSopenharmony_ci free(offsets); 44882e5b6d6dSopenharmony_ci} 44892e5b6d6dSopenharmony_ci#endif 44902e5b6d6dSopenharmony_ci 44912e5b6d6dSopenharmony_cistatic void 44922e5b6d6dSopenharmony_ciTestISO_2022_CN() { 44932e5b6d6dSopenharmony_ci /* test input */ 44942e5b6d6dSopenharmony_ci static const uint16_t in[]={ 44952e5b6d6dSopenharmony_ci /* jitterbug 951 */ 44962e5b6d6dSopenharmony_ci 0xFF2D, 0xFF49, 0xFF58, 0xFF45, 0xFF44, 0x0020, 0xFF43, 0xFF48, 0xFF41, 0xFF52, 44972e5b6d6dSopenharmony_ci 0x0020, 0xFF06, 0x0020, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0xFF15, 0xFF16, 0xFF17, 44982e5b6d6dSopenharmony_ci 0xFF18, 0xFF19, 0xFF10, 0x0020, 0xFF4E, 0xFF55, 0xFF4D, 0xFF42, 0xFF45, 0xFF52, 44992e5b6d6dSopenharmony_ci 0x0020, 0xFF54, 0xFF45, 0xFF53, 0xFF54, 0x0020, 0xFF4C, 0xFF49, 0xFF4E, 0xFF45, 45002e5b6d6dSopenharmony_ci 0x0020, 0x0045, 0x004e, 0x0044, 45012e5b6d6dSopenharmony_ci /**/ 45022e5b6d6dSopenharmony_ci 0x4E00, 0x4E00, 0x4E01, 0x4E03, 0x60F6, 0x60F7, 0x60F8, 0x60FB, 0x000D, 0x000A, 45032e5b6d6dSopenharmony_ci 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x60FB, 0x60FC, 0x000D, 0x000A, 45042e5b6d6dSopenharmony_ci 0x4E07, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x0042, 0x0043, 0x000D, 0x000A, 45052e5b6d6dSopenharmony_ci 0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A, 45062e5b6d6dSopenharmony_ci 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A, 45072e5b6d6dSopenharmony_ci 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0x6332, 0x63B0, 0x643F, 0x000D, 0x000A, 45082e5b6d6dSopenharmony_ci 0x64D8, 0x8004, 0x6BEA, 0x6BF3, 0x6BFD, 0x6BF5, 0x6BF9, 0x6C05, 0x000D, 0x000A, 45092e5b6d6dSopenharmony_ci 0x6C07, 0x6C06, 0x6C0D, 0x6C15, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 45102e5b6d6dSopenharmony_ci 0x9CE2, 0x977C, 0x9785, 0x9791, 0x9792, 0x9794, 0x97AF, 0x97AB, 0x000D, 0x000A, 45112e5b6d6dSopenharmony_ci 0x97A3, 0x97B2, 0x97B4, 0x9AB1, 0x9AB0, 0x9AB7, 0x9E58, 0x9AB6, 0x000D, 0x000A, 45122e5b6d6dSopenharmony_ci 0x9ABA, 0x9ABC, 0x9AC1, 0x9AC0, 0x9AC5, 0x9AC2, 0x9ACB, 0x9ACC, 0x000D, 0x000A, 45132e5b6d6dSopenharmony_ci 0x9AD1, 0x9B45, 0x9B43, 0x9B47, 0x9B49, 0x9B48, 0x9B4D, 0x9B51, 0x000D, 0x000A, 45142e5b6d6dSopenharmony_ci 0x98E8, 0x990D, 0x992E, 0x9955, 0x9954, 0x9ADF, 0x60FE, 0x60FF, 0x000D, 0x000A, 45152e5b6d6dSopenharmony_ci 0x60F2, 0x60F3, 0x60F4, 0x60F5, 0x000D, 0x000A, 0x60F9, 0x60FA, 0x000D, 0x000A, 45162e5b6d6dSopenharmony_ci 0x6100, 0x6101, 0x0041, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x000D, 0x000A, 45172e5b6d6dSopenharmony_ci 0x247D, 0x247E, 0x247F, 0x2480, 0x2481, 0x2482, 0x2483, 0x2484, 0x2485, 0x2486, 45182e5b6d6dSopenharmony_ci 0x2487, 0x2460, 0x2461, 0xFF20, 0xFF21, 0xFF22, 0x0049, 0x004A, 0x000D, 0x000A, 45192e5b6d6dSopenharmony_ci 45202e5b6d6dSopenharmony_ci }; 45212e5b6d6dSopenharmony_ci const UChar* uSource; 45222e5b6d6dSopenharmony_ci const UChar* uSourceLimit; 45232e5b6d6dSopenharmony_ci const char* cSource; 45242e5b6d6dSopenharmony_ci const char* cSourceLimit; 45252e5b6d6dSopenharmony_ci UChar *uTargetLimit =NULL; 45262e5b6d6dSopenharmony_ci UChar *uTarget; 45272e5b6d6dSopenharmony_ci char *cTarget; 45282e5b6d6dSopenharmony_ci const char *cTargetLimit; 45292e5b6d6dSopenharmony_ci char *cBuf = NULL; 45302e5b6d6dSopenharmony_ci UChar *uBuf = NULL; 45312e5b6d6dSopenharmony_ci UChar *test; 45322e5b6d6dSopenharmony_ci int32_t uBufSize = 180; 45332e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 45342e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 45352e5b6d6dSopenharmony_ci int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) * 5); 45362e5b6d6dSopenharmony_ci int32_t* myOff= offsets; 45372e5b6d6dSopenharmony_ci cnv=ucnv_open("ISO_2022,locale=cn,version=0", &errorCode); 45382e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 45392e5b6d6dSopenharmony_ci log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode)); 45402e5b6d6dSopenharmony_ci goto cleanup; 45412e5b6d6dSopenharmony_ci } 45422e5b6d6dSopenharmony_ci 45432e5b6d6dSopenharmony_ci uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); 45442e5b6d6dSopenharmony_ci cBuf =(char*)malloc(uBufSize * sizeof(char) * 10); 45452e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 45462e5b6d6dSopenharmony_ci uSourceLimit=(const UChar*)in + UPRV_LENGTHOF(in); 45472e5b6d6dSopenharmony_ci cTarget = cBuf; 45482e5b6d6dSopenharmony_ci cTargetLimit = cBuf +uBufSize*5; 45492e5b6d6dSopenharmony_ci uTarget = uBuf; 45502e5b6d6dSopenharmony_ci uTargetLimit = uBuf+ uBufSize*5; 45512e5b6d6dSopenharmony_ci ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,myOff,true, &errorCode); 45522e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 45532e5b6d6dSopenharmony_ci log_err("ucnv_fromUnicode conversion failed reason %s\n", u_errorName(errorCode)); 45542e5b6d6dSopenharmony_ci goto cleanup; 45552e5b6d6dSopenharmony_ci } 45562e5b6d6dSopenharmony_ci cSource = cBuf; 45572e5b6d6dSopenharmony_ci cSourceLimit =cTarget; 45582e5b6d6dSopenharmony_ci test =uBuf; 45592e5b6d6dSopenharmony_ci myOff=offsets; 45602e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,myOff,true,&errorCode); 45612e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)){ 45622e5b6d6dSopenharmony_ci log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); 45632e5b6d6dSopenharmony_ci goto cleanup; 45642e5b6d6dSopenharmony_ci } 45652e5b6d6dSopenharmony_ci uSource = (const UChar*)in; 45662e5b6d6dSopenharmony_ci while(uSource<uSourceLimit){ 45672e5b6d6dSopenharmony_ci if(*test!=*uSource){ 45682e5b6d6dSopenharmony_ci log_err("Expected : \\u%04X \t Got: \\u%04X\n",*uSource,(int)*test) ; 45692e5b6d6dSopenharmony_ci } 45702e5b6d6dSopenharmony_ci else{ 45712e5b6d6dSopenharmony_ci log_verbose(" Got: \\u%04X\n",(int)*test) ; 45722e5b6d6dSopenharmony_ci } 45732e5b6d6dSopenharmony_ci uSource++; 45742e5b6d6dSopenharmony_ci test++; 45752e5b6d6dSopenharmony_ci } 45762e5b6d6dSopenharmony_ci TestGetNextUChar2022(cnv, cBuf, cTarget, in, "ISO-2022-CN encoding"); 45772e5b6d6dSopenharmony_ci TestSmallTargetBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 45782e5b6d6dSopenharmony_ci TestSmallSourceBuffer(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 45792e5b6d6dSopenharmony_ci TestToAndFromUChars(in,(const UChar*)in + UPRV_LENGTHOF(in),cnv); 45802e5b6d6dSopenharmony_ci TestJitterbug930("csISO2022CN"); 45812e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 45822e5b6d6dSopenharmony_ci ucnv_reset(cnv); 45832e5b6d6dSopenharmony_ci { 45842e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x0e,0x24,0x053}; 45852e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN]"); 45862e5b6d6dSopenharmony_ci } 45872e5b6d6dSopenharmony_ci 45882e5b6d6dSopenharmony_cicleanup: 45892e5b6d6dSopenharmony_ci ucnv_close(cnv); 45902e5b6d6dSopenharmony_ci free(uBuf); 45912e5b6d6dSopenharmony_ci free(cBuf); 45922e5b6d6dSopenharmony_ci free(offsets); 45932e5b6d6dSopenharmony_ci} 45942e5b6d6dSopenharmony_ci 45952e5b6d6dSopenharmony_ci/* Tests for empty segments in ISO-2022-JP/KR/CN, HZ, check that UConverterCallbackReason is UCNV_IRREGULAR */ 45962e5b6d6dSopenharmony_citypedef struct { 45972e5b6d6dSopenharmony_ci const char * converterName; 45982e5b6d6dSopenharmony_ci const char * inputText; 45992e5b6d6dSopenharmony_ci int inputTextLength; 46002e5b6d6dSopenharmony_ci} EmptySegmentTest; 46012e5b6d6dSopenharmony_ci 46022e5b6d6dSopenharmony_ci/* Callback for TestJitterbug6175, should only get called for empty segment errors */ 46032e5b6d6dSopenharmony_cistatic void UCNV_TO_U_CALLBACK_EMPTYSEGMENT( const void *context, UConverterToUnicodeArgs *toArgs, const char* codeUnits, 46042e5b6d6dSopenharmony_ci int32_t length, UConverterCallbackReason reason, UErrorCode * err ) { 46052e5b6d6dSopenharmony_ci // suppress compiler warnings about unused variables 46062e5b6d6dSopenharmony_ci (void)context; 46072e5b6d6dSopenharmony_ci (void)codeUnits; 46082e5b6d6dSopenharmony_ci (void)length; 46092e5b6d6dSopenharmony_ci if (reason > UCNV_IRREGULAR) { 46102e5b6d6dSopenharmony_ci return; 46112e5b6d6dSopenharmony_ci } 46122e5b6d6dSopenharmony_ci if (reason != UCNV_IRREGULAR) { 46132e5b6d6dSopenharmony_ci log_err("toUnicode callback invoked for empty segment but reason is not UCNV_IRREGULAR\n"); 46142e5b6d6dSopenharmony_ci } 46152e5b6d6dSopenharmony_ci /* Standard stuff below from UCNV_TO_U_CALLBACK_SUBSTITUTE */ 46162e5b6d6dSopenharmony_ci *err = U_ZERO_ERROR; 46172e5b6d6dSopenharmony_ci ucnv_cbToUWriteSub(toArgs,0,err); 46182e5b6d6dSopenharmony_ci} 46192e5b6d6dSopenharmony_ci 46202e5b6d6dSopenharmony_cienum { kEmptySegmentToUCharsMax = 64 }; 46212e5b6d6dSopenharmony_cistatic void TestJitterbug6175(void) { 46222e5b6d6dSopenharmony_ci static const char iso2022jp_a[] = { 0x61, 0x62, 0x1B,0x24,0x42, 0x1B,0x28,0x42, 0x63, 0x64, 0x0D, 0x0A }; 46232e5b6d6dSopenharmony_ci static const char iso2022kr_a[] = { 0x1B,0x24,0x29,0x43, 0x61, 0x0E, 0x0F, 0x62, 0x0D, 0x0A }; 46242e5b6d6dSopenharmony_ci static const char iso2022cn_a[] = { 0x61, 0x1B,0x24,0x29,0x41, 0x62, 0x0E, 0x0F, 0x1B,0x24,0x2A,0x48, 0x1B,0x4E, 0x6A,0x65, 0x63, 0x0D, 0x0A }; 46252e5b6d6dSopenharmony_ci static const char iso2022cn_b[] = { 0x61, 0x1B,0x24,0x29,0x41, 0x62, 0x0E, 0x1B,0x24,0x29,0x47, 0x68,0x64, 0x0F, 0x63, 0x0D, 0x0A }; 46262e5b6d6dSopenharmony_ci static const char hzGB2312_a[] = { 0x61, 0x62, 0x7E,0x7B, 0x7E,0x7D, 0x63, 0x64 }; 46272e5b6d6dSopenharmony_ci static const EmptySegmentTest emptySegmentTests[] = { 46282e5b6d6dSopenharmony_ci /* converterName inputText inputTextLength */ 46292e5b6d6dSopenharmony_ci { "ISO-2022-JP", iso2022jp_a, sizeof(iso2022jp_a) }, 46302e5b6d6dSopenharmony_ci { "ISO-2022-KR", iso2022kr_a, sizeof(iso2022kr_a) }, 46312e5b6d6dSopenharmony_ci { "ISO-2022-CN", iso2022cn_a, sizeof(iso2022cn_a) }, 46322e5b6d6dSopenharmony_ci { "ISO-2022-CN", iso2022cn_b, sizeof(iso2022cn_b) }, 46332e5b6d6dSopenharmony_ci { "HZ-GB-2312", hzGB2312_a, sizeof(hzGB2312_a) }, 46342e5b6d6dSopenharmony_ci /* terminator: */ 46352e5b6d6dSopenharmony_ci { NULL, NULL, 0, } 46362e5b6d6dSopenharmony_ci }; 46372e5b6d6dSopenharmony_ci const EmptySegmentTest * testPtr; 46382e5b6d6dSopenharmony_ci for (testPtr = emptySegmentTests; testPtr->converterName != NULL; ++testPtr) { 46392e5b6d6dSopenharmony_ci UErrorCode err = U_ZERO_ERROR; 46402e5b6d6dSopenharmony_ci UConverter * cnv = ucnv_open(testPtr->converterName, &err); 46412e5b6d6dSopenharmony_ci if (U_FAILURE(err)) { 46422e5b6d6dSopenharmony_ci log_data_err("Unable to open %s converter: %s\n", testPtr->converterName, u_errorName(err)); 46432e5b6d6dSopenharmony_ci return; 46442e5b6d6dSopenharmony_ci } 46452e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_EMPTYSEGMENT, NULL, NULL, NULL, &err); 46462e5b6d6dSopenharmony_ci if (U_FAILURE(err)) { 46472e5b6d6dSopenharmony_ci log_data_err("Unable to setToUCallBack for %s converter: %s\n", testPtr->converterName, u_errorName(err)); 46482e5b6d6dSopenharmony_ci ucnv_close(cnv); 46492e5b6d6dSopenharmony_ci return; 46502e5b6d6dSopenharmony_ci } 46512e5b6d6dSopenharmony_ci { 46522e5b6d6dSopenharmony_ci UChar toUChars[kEmptySegmentToUCharsMax]; 46532e5b6d6dSopenharmony_ci UChar * toUCharsPtr = toUChars; 46542e5b6d6dSopenharmony_ci const UChar * toUCharsLimit = toUCharsPtr + kEmptySegmentToUCharsMax; 46552e5b6d6dSopenharmony_ci const char * inCharsPtr = testPtr->inputText; 46562e5b6d6dSopenharmony_ci const char * inCharsLimit = inCharsPtr + testPtr->inputTextLength; 46572e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &toUCharsPtr, toUCharsLimit, &inCharsPtr, inCharsLimit, NULL, true, &err); 46582e5b6d6dSopenharmony_ci } 46592e5b6d6dSopenharmony_ci ucnv_close(cnv); 46602e5b6d6dSopenharmony_ci } 46612e5b6d6dSopenharmony_ci} 46622e5b6d6dSopenharmony_ci 46632e5b6d6dSopenharmony_cistatic void 46642e5b6d6dSopenharmony_ciTestEBCDIC_STATEFUL() { 46652e5b6d6dSopenharmony_ci /* test input */ 46662e5b6d6dSopenharmony_ci static const uint8_t in[]={ 46672e5b6d6dSopenharmony_ci 0x61, 46682e5b6d6dSopenharmony_ci 0x1a, 46692e5b6d6dSopenharmony_ci 0x0f, 0x4b, 46702e5b6d6dSopenharmony_ci 0x42, 46712e5b6d6dSopenharmony_ci 0x40, 46722e5b6d6dSopenharmony_ci 0x36, 46732e5b6d6dSopenharmony_ci }; 46742e5b6d6dSopenharmony_ci 46752e5b6d6dSopenharmony_ci /* expected test results */ 46762e5b6d6dSopenharmony_ci static const int32_t results[]={ 46772e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 46782e5b6d6dSopenharmony_ci 1, 0x002f, 46792e5b6d6dSopenharmony_ci 1, 0x0092, 46802e5b6d6dSopenharmony_ci 2, 0x002e, 46812e5b6d6dSopenharmony_ci 1, 0xff62, 46822e5b6d6dSopenharmony_ci 1, 0x0020, 46832e5b6d6dSopenharmony_ci 1, 0x0096, 46842e5b6d6dSopenharmony_ci 46852e5b6d6dSopenharmony_ci }; 46862e5b6d6dSopenharmony_ci static const uint8_t in2[]={ 46872e5b6d6dSopenharmony_ci 0x0f, 46882e5b6d6dSopenharmony_ci 0xa1, 46892e5b6d6dSopenharmony_ci 0x01 46902e5b6d6dSopenharmony_ci }; 46912e5b6d6dSopenharmony_ci 46922e5b6d6dSopenharmony_ci /* expected test results */ 46932e5b6d6dSopenharmony_ci static const int32_t results2[]={ 46942e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 46952e5b6d6dSopenharmony_ci 2, 0x203E, 46962e5b6d6dSopenharmony_ci 1, 0x0001, 46972e5b6d6dSopenharmony_ci }; 46982e5b6d6dSopenharmony_ci 46992e5b6d6dSopenharmony_ci const char *source=(const char *)in, *limit=(const char *)in+sizeof(in); 47002e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 47012e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("ibm-930", &errorCode); 47022e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 47032e5b6d6dSopenharmony_ci log_data_err("Unable to open a EBCDIC_STATEFUL(ibm-930) converter: %s\n", u_errorName(errorCode)); 47042e5b6d6dSopenharmony_ci return; 47052e5b6d6dSopenharmony_ci } 47062e5b6d6dSopenharmony_ci TestNextUChar(cnv, source, limit, results, "EBCDIC_STATEFUL(ibm-930)"); 47072e5b6d6dSopenharmony_ci ucnv_reset(cnv); 47082e5b6d6dSopenharmony_ci /* Test the condition when source >= sourceLimit */ 47092e5b6d6dSopenharmony_ci TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source"); 47102e5b6d6dSopenharmony_ci ucnv_reset(cnv); 47112e5b6d6dSopenharmony_ci /*Test for the condition where source > sourcelimit after consuming the shift character */ 47122e5b6d6dSopenharmony_ci { 47132e5b6d6dSopenharmony_ci static const uint8_t source1[]={0x0f}; 47142e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_INDEX_OUTOFBOUNDS_ERROR, "a character is truncated"); 47152e5b6d6dSopenharmony_ci } 47162e5b6d6dSopenharmony_ci /*Test for the condition where there is an invalid character*/ 47172e5b6d6dSopenharmony_ci ucnv_reset(cnv); 47182e5b6d6dSopenharmony_ci { 47192e5b6d6dSopenharmony_ci static const uint8_t source2[]={0x0e, 0x7F, 0xFF}; 47202e5b6d6dSopenharmony_ci TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character [EBCDIC STATEFUL]"); 47212e5b6d6dSopenharmony_ci } 47222e5b6d6dSopenharmony_ci ucnv_reset(cnv); 47232e5b6d6dSopenharmony_ci source=(const char*)in2; 47242e5b6d6dSopenharmony_ci limit=(const char*)in2+sizeof(in2); 47252e5b6d6dSopenharmony_ci TestNextUChar(cnv,source,limit,results2,"EBCDIC_STATEFUL(ibm-930),seq#2"); 47262e5b6d6dSopenharmony_ci ucnv_close(cnv); 47272e5b6d6dSopenharmony_ci 47282e5b6d6dSopenharmony_ci} 47292e5b6d6dSopenharmony_ci 47302e5b6d6dSopenharmony_cistatic void 47312e5b6d6dSopenharmony_ciTestGB18030() { 47322e5b6d6dSopenharmony_ci /* test input */ 47332e5b6d6dSopenharmony_ci static const uint8_t in[]={ 47342e5b6d6dSopenharmony_ci 0x24, 47352e5b6d6dSopenharmony_ci 0x7f, 47362e5b6d6dSopenharmony_ci 0x81, 0x30, 0x81, 0x30, 47372e5b6d6dSopenharmony_ci 0xa8, 0xbf, 47382e5b6d6dSopenharmony_ci 0xa2, 0xe3, 47392e5b6d6dSopenharmony_ci 0xd2, 0xbb, 47402e5b6d6dSopenharmony_ci 0x82, 0x35, 0x8f, 0x33, 47412e5b6d6dSopenharmony_ci 0x84, 0x31, 0xa4, 0x39, 47422e5b6d6dSopenharmony_ci 0x90, 0x30, 0x81, 0x30, 47432e5b6d6dSopenharmony_ci 0xe3, 0x32, 0x9a, 0x35 47442e5b6d6dSopenharmony_ci#if 0 47452e5b6d6dSopenharmony_ci /* 47462e5b6d6dSopenharmony_ci * Feature removed markus 2000-oct-26 47472e5b6d6dSopenharmony_ci * Only some codepages must match surrogate pairs into supplementary code points - 47482e5b6d6dSopenharmony_ci * see javadoc for ucnv_getNextUChar() and implementation notes in ucnvmbcs.c . 47492e5b6d6dSopenharmony_ci * GB 18030 provides direct encodings for supplementary code points, therefore 47502e5b6d6dSopenharmony_ci * it must not combine two single-encoded surrogates into one code point. 47512e5b6d6dSopenharmony_ci */ 47522e5b6d6dSopenharmony_ci 0x83, 0x36, 0xc8, 0x30, 0x83, 0x37, 0xb0, 0x34 /* separately encoded surrogates */ 47532e5b6d6dSopenharmony_ci#endif 47542e5b6d6dSopenharmony_ci }; 47552e5b6d6dSopenharmony_ci 47562e5b6d6dSopenharmony_ci /* expected test results */ 47572e5b6d6dSopenharmony_ci static const int32_t results[]={ 47582e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 47592e5b6d6dSopenharmony_ci 1, 0x24, 47602e5b6d6dSopenharmony_ci 1, 0x7f, 47612e5b6d6dSopenharmony_ci 4, 0x80, 47622e5b6d6dSopenharmony_ci 2, 0x1f9, 47632e5b6d6dSopenharmony_ci 2, 0x20ac, 47642e5b6d6dSopenharmony_ci 2, 0x4e00, 47652e5b6d6dSopenharmony_ci 4, 0x9fa6, 47662e5b6d6dSopenharmony_ci 4, 0xffff, 47672e5b6d6dSopenharmony_ci 4, 0x10000, 47682e5b6d6dSopenharmony_ci 4, 0x10ffff 47692e5b6d6dSopenharmony_ci#if 0 47702e5b6d6dSopenharmony_ci /* Feature removed. See comment above. */ 47712e5b6d6dSopenharmony_ci 8, 0x10000 47722e5b6d6dSopenharmony_ci#endif 47732e5b6d6dSopenharmony_ci }; 47742e5b6d6dSopenharmony_ci 47752e5b6d6dSopenharmony_ci/* const char *source=(const char *)in,*limit=(const char *)in+sizeof(in); */ 47762e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 47772e5b6d6dSopenharmony_ci UConverter *cnv=ucnv_open("gb18030", &errorCode); 47782e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 47792e5b6d6dSopenharmony_ci log_data_err("Unable to open a gb18030 converter: %s\n", u_errorName(errorCode)); 47802e5b6d6dSopenharmony_ci return; 47812e5b6d6dSopenharmony_ci } 47822e5b6d6dSopenharmony_ci TestNextUChar(cnv, (const char *)in, (const char *)in+sizeof(in), results, "gb18030"); 47832e5b6d6dSopenharmony_ci ucnv_close(cnv); 47842e5b6d6dSopenharmony_ci} 47852e5b6d6dSopenharmony_ci 47862e5b6d6dSopenharmony_cistatic void 47872e5b6d6dSopenharmony_ciTestLMBCS() { 47882e5b6d6dSopenharmony_ci /* LMBCS-1 string */ 47892e5b6d6dSopenharmony_ci static const uint8_t pszLMBCS[]={ 47902e5b6d6dSopenharmony_ci 0x61, 47912e5b6d6dSopenharmony_ci 0x01, 0x29, 47922e5b6d6dSopenharmony_ci 0x81, 47932e5b6d6dSopenharmony_ci 0xA0, 47942e5b6d6dSopenharmony_ci 0x0F, 0x27, 47952e5b6d6dSopenharmony_ci 0x0F, 0x91, 47962e5b6d6dSopenharmony_ci 0x14, 0x0a, 0x74, 47972e5b6d6dSopenharmony_ci 0x14, 0xF6, 0x02, 47982e5b6d6dSopenharmony_ci 0x14, 0xd8, 0x4d, 0x14, 0xdc, 0x56, /* UTF-16 surrogate pair */ 47992e5b6d6dSopenharmony_ci 0x10, 0x88, 0xA0, 48002e5b6d6dSopenharmony_ci }; 48012e5b6d6dSopenharmony_ci 48022e5b6d6dSopenharmony_ci /* Unicode UChar32 equivalents */ 48032e5b6d6dSopenharmony_ci static const UChar32 pszUnicode32[]={ 48042e5b6d6dSopenharmony_ci /* code point */ 48052e5b6d6dSopenharmony_ci 0x00000061, 48062e5b6d6dSopenharmony_ci 0x00002013, 48072e5b6d6dSopenharmony_ci 0x000000FC, 48082e5b6d6dSopenharmony_ci 0x000000E1, 48092e5b6d6dSopenharmony_ci 0x00000007, 48102e5b6d6dSopenharmony_ci 0x00000091, 48112e5b6d6dSopenharmony_ci 0x00000a74, 48122e5b6d6dSopenharmony_ci 0x00000200, 48132e5b6d6dSopenharmony_ci 0x00023456, /* code point for surrogate pair */ 48142e5b6d6dSopenharmony_ci 0x00005516 48152e5b6d6dSopenharmony_ci }; 48162e5b6d6dSopenharmony_ci 48172e5b6d6dSopenharmony_ci/* Unicode UChar equivalents */ 48182e5b6d6dSopenharmony_ci static const UChar pszUnicode[]={ 48192e5b6d6dSopenharmony_ci /* code point */ 48202e5b6d6dSopenharmony_ci 0x0061, 48212e5b6d6dSopenharmony_ci 0x2013, 48222e5b6d6dSopenharmony_ci 0x00FC, 48232e5b6d6dSopenharmony_ci 0x00E1, 48242e5b6d6dSopenharmony_ci 0x0007, 48252e5b6d6dSopenharmony_ci 0x0091, 48262e5b6d6dSopenharmony_ci 0x0a74, 48272e5b6d6dSopenharmony_ci 0x0200, 48282e5b6d6dSopenharmony_ci 0xD84D, /* low surrogate */ 48292e5b6d6dSopenharmony_ci 0xDC56, /* high surrogate */ 48302e5b6d6dSopenharmony_ci 0x5516 48312e5b6d6dSopenharmony_ci }; 48322e5b6d6dSopenharmony_ci 48332e5b6d6dSopenharmony_ci/* expected test results */ 48342e5b6d6dSopenharmony_ci static const int offsets32[]={ 48352e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 48362e5b6d6dSopenharmony_ci 0, 48372e5b6d6dSopenharmony_ci 1, 48382e5b6d6dSopenharmony_ci 3, 48392e5b6d6dSopenharmony_ci 4, 48402e5b6d6dSopenharmony_ci 5, 48412e5b6d6dSopenharmony_ci 7, 48422e5b6d6dSopenharmony_ci 9, 48432e5b6d6dSopenharmony_ci 12, 48442e5b6d6dSopenharmony_ci 15, 48452e5b6d6dSopenharmony_ci 21, 48462e5b6d6dSopenharmony_ci 24 48472e5b6d6dSopenharmony_ci }; 48482e5b6d6dSopenharmony_ci 48492e5b6d6dSopenharmony_ci/* expected test results */ 48502e5b6d6dSopenharmony_ci static const int offsets[]={ 48512e5b6d6dSopenharmony_ci /* number of bytes read, code point */ 48522e5b6d6dSopenharmony_ci 0, 48532e5b6d6dSopenharmony_ci 1, 48542e5b6d6dSopenharmony_ci 3, 48552e5b6d6dSopenharmony_ci 4, 48562e5b6d6dSopenharmony_ci 5, 48572e5b6d6dSopenharmony_ci 7, 48582e5b6d6dSopenharmony_ci 9, 48592e5b6d6dSopenharmony_ci 12, 48602e5b6d6dSopenharmony_ci 15, 48612e5b6d6dSopenharmony_ci 18, 48622e5b6d6dSopenharmony_ci 21, 48632e5b6d6dSopenharmony_ci 24 48642e5b6d6dSopenharmony_ci }; 48652e5b6d6dSopenharmony_ci 48662e5b6d6dSopenharmony_ci 48672e5b6d6dSopenharmony_ci UConverter *cnv; 48682e5b6d6dSopenharmony_ci 48692e5b6d6dSopenharmony_ci#define NAME_LMBCS_1 "LMBCS-1" 48702e5b6d6dSopenharmony_ci#define NAME_LMBCS_2 "LMBCS-2" 48712e5b6d6dSopenharmony_ci 48722e5b6d6dSopenharmony_ci 48732e5b6d6dSopenharmony_ci /* Some basic open/close/property tests on some LMBCS converters */ 48742e5b6d6dSopenharmony_ci { 48752e5b6d6dSopenharmony_ci 48762e5b6d6dSopenharmony_ci char expected_subchars[] = {0x3F}; /* ANSI Question Mark */ 48772e5b6d6dSopenharmony_ci char new_subchars [] = {0x7F}; /* subst char used by SmartSuite..*/ 48782e5b6d6dSopenharmony_ci char get_subchars [1]; 48792e5b6d6dSopenharmony_ci const char * get_name; 48802e5b6d6dSopenharmony_ci UConverter *cnv1; 48812e5b6d6dSopenharmony_ci UConverter *cnv2; 48822e5b6d6dSopenharmony_ci 48832e5b6d6dSopenharmony_ci int8_t len = sizeof(get_subchars); 48842e5b6d6dSopenharmony_ci 48852e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 48862e5b6d6dSopenharmony_ci 48872e5b6d6dSopenharmony_ci /* Open */ 48882e5b6d6dSopenharmony_ci cnv1=ucnv_open(NAME_LMBCS_1, &errorCode); 48892e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 48902e5b6d6dSopenharmony_ci log_data_err("Unable to open a LMBCS-1 converter: %s\n", u_errorName(errorCode)); 48912e5b6d6dSopenharmony_ci return; 48922e5b6d6dSopenharmony_ci } 48932e5b6d6dSopenharmony_ci cnv2=ucnv_open(NAME_LMBCS_2, &errorCode); 48942e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 48952e5b6d6dSopenharmony_ci log_data_err("Unable to open a LMBCS-2 converter: %s\n", u_errorName(errorCode)); 48962e5b6d6dSopenharmony_ci return; 48972e5b6d6dSopenharmony_ci } 48982e5b6d6dSopenharmony_ci 48992e5b6d6dSopenharmony_ci /* Name */ 49002e5b6d6dSopenharmony_ci get_name = ucnv_getName (cnv1, &errorCode); 49012e5b6d6dSopenharmony_ci if (strcmp(NAME_LMBCS_1,get_name)){ 49022e5b6d6dSopenharmony_ci log_err("Unexpected converter name: %s\n", get_name); 49032e5b6d6dSopenharmony_ci } 49042e5b6d6dSopenharmony_ci get_name = ucnv_getName (cnv2, &errorCode); 49052e5b6d6dSopenharmony_ci if (strcmp(NAME_LMBCS_2,get_name)){ 49062e5b6d6dSopenharmony_ci log_err("Unexpected converter name: %s\n", get_name); 49072e5b6d6dSopenharmony_ci } 49082e5b6d6dSopenharmony_ci 49092e5b6d6dSopenharmony_ci /* substitution chars */ 49102e5b6d6dSopenharmony_ci ucnv_getSubstChars (cnv1, get_subchars, &len, &errorCode); 49112e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 49122e5b6d6dSopenharmony_ci log_err("Failure on get subst chars: %s\n", u_errorName(errorCode)); 49132e5b6d6dSopenharmony_ci } 49142e5b6d6dSopenharmony_ci if (len!=1){ 49152e5b6d6dSopenharmony_ci log_err("Unexpected length of sub chars\n"); 49162e5b6d6dSopenharmony_ci } 49172e5b6d6dSopenharmony_ci if (get_subchars[0] != expected_subchars[0]){ 49182e5b6d6dSopenharmony_ci log_err("Unexpected value of sub chars\n"); 49192e5b6d6dSopenharmony_ci } 49202e5b6d6dSopenharmony_ci ucnv_setSubstChars (cnv2,new_subchars, len, &errorCode); 49212e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 49222e5b6d6dSopenharmony_ci log_err("Failure on set subst chars: %s\n", u_errorName(errorCode)); 49232e5b6d6dSopenharmony_ci } 49242e5b6d6dSopenharmony_ci ucnv_getSubstChars (cnv2, get_subchars, &len, &errorCode); 49252e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 49262e5b6d6dSopenharmony_ci log_err("Failure on get subst chars: %s\n", u_errorName(errorCode)); 49272e5b6d6dSopenharmony_ci } 49282e5b6d6dSopenharmony_ci if (len!=1){ 49292e5b6d6dSopenharmony_ci log_err("Unexpected length of sub chars\n"); 49302e5b6d6dSopenharmony_ci } 49312e5b6d6dSopenharmony_ci if (get_subchars[0] != new_subchars[0]){ 49322e5b6d6dSopenharmony_ci log_err("Unexpected value of sub chars\n"); 49332e5b6d6dSopenharmony_ci } 49342e5b6d6dSopenharmony_ci ucnv_close(cnv1); 49352e5b6d6dSopenharmony_ci ucnv_close(cnv2); 49362e5b6d6dSopenharmony_ci 49372e5b6d6dSopenharmony_ci } 49382e5b6d6dSopenharmony_ci 49392e5b6d6dSopenharmony_ci /* LMBCS to Unicode - offsets */ 49402e5b6d6dSopenharmony_ci { 49412e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 49422e5b6d6dSopenharmony_ci 49432e5b6d6dSopenharmony_ci const char * pSource = (const char *)pszLMBCS; 49442e5b6d6dSopenharmony_ci const char * sourceLimit = (const char *)pszLMBCS + sizeof(pszLMBCS); 49452e5b6d6dSopenharmony_ci 49462e5b6d6dSopenharmony_ci UChar Out [sizeof(pszUnicode) + 1]; 49472e5b6d6dSopenharmony_ci UChar * pOut = Out; 49482e5b6d6dSopenharmony_ci UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode); 49492e5b6d6dSopenharmony_ci 49502e5b6d6dSopenharmony_ci int32_t off [sizeof(offsets)]; 49512e5b6d6dSopenharmony_ci 49522e5b6d6dSopenharmony_ci /* last 'offset' in expected results is just the final size. 49532e5b6d6dSopenharmony_ci (Makes other tests easier). Compensate here: */ 49542e5b6d6dSopenharmony_ci 49552e5b6d6dSopenharmony_ci off[UPRV_LENGTHOF(offsets)-1] = sizeof(pszLMBCS); 49562e5b6d6dSopenharmony_ci 49572e5b6d6dSopenharmony_ci 49582e5b6d6dSopenharmony_ci 49592e5b6d6dSopenharmony_ci cnv=ucnv_open("lmbcs", &errorCode); /* use generic name for LMBCS-1 */ 49602e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 49612e5b6d6dSopenharmony_ci log_data_err("Unable to open a LMBCS converter: %s\n", u_errorName(errorCode)); 49622e5b6d6dSopenharmony_ci return; 49632e5b6d6dSopenharmony_ci } 49642e5b6d6dSopenharmony_ci 49652e5b6d6dSopenharmony_ci 49662e5b6d6dSopenharmony_ci 49672e5b6d6dSopenharmony_ci ucnv_toUnicode (cnv, 49682e5b6d6dSopenharmony_ci &pOut, 49692e5b6d6dSopenharmony_ci OutLimit, 49702e5b6d6dSopenharmony_ci &pSource, 49712e5b6d6dSopenharmony_ci sourceLimit, 49722e5b6d6dSopenharmony_ci off, 49732e5b6d6dSopenharmony_ci true, 49742e5b6d6dSopenharmony_ci &errorCode); 49752e5b6d6dSopenharmony_ci 49762e5b6d6dSopenharmony_ci 49772e5b6d6dSopenharmony_ci if (memcmp(off,offsets,sizeof(offsets))) 49782e5b6d6dSopenharmony_ci { 49792e5b6d6dSopenharmony_ci log_err("LMBCS->Uni: Calculated offsets do not match expected results\n"); 49802e5b6d6dSopenharmony_ci } 49812e5b6d6dSopenharmony_ci if (memcmp(Out,pszUnicode,sizeof(pszUnicode))) 49822e5b6d6dSopenharmony_ci { 49832e5b6d6dSopenharmony_ci log_err("LMBCS->Uni: Calculated codepoints do not match expected results\n"); 49842e5b6d6dSopenharmony_ci } 49852e5b6d6dSopenharmony_ci ucnv_close(cnv); 49862e5b6d6dSopenharmony_ci } 49872e5b6d6dSopenharmony_ci { 49882e5b6d6dSopenharmony_ci /* LMBCS to Unicode - getNextUChar */ 49892e5b6d6dSopenharmony_ci const char * sourceStart; 49902e5b6d6dSopenharmony_ci const char *source=(const char *)pszLMBCS; 49912e5b6d6dSopenharmony_ci const char *limit=(const char *)pszLMBCS+sizeof(pszLMBCS); 49922e5b6d6dSopenharmony_ci const UChar32 *results= pszUnicode32; 49932e5b6d6dSopenharmony_ci const int *off = offsets32; 49942e5b6d6dSopenharmony_ci 49952e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 49962e5b6d6dSopenharmony_ci UChar32 uniChar; 49972e5b6d6dSopenharmony_ci 49982e5b6d6dSopenharmony_ci cnv=ucnv_open("LMBCS-1", &errorCode); 49992e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 50002e5b6d6dSopenharmony_ci log_data_err("Unable to open a LMBCS-1 converter: %s\n", u_errorName(errorCode)); 50012e5b6d6dSopenharmony_ci return; 50022e5b6d6dSopenharmony_ci } 50032e5b6d6dSopenharmony_ci else 50042e5b6d6dSopenharmony_ci { 50052e5b6d6dSopenharmony_ci 50062e5b6d6dSopenharmony_ci while(source<limit) { 50072e5b6d6dSopenharmony_ci sourceStart=source; 50082e5b6d6dSopenharmony_ci uniChar=ucnv_getNextUChar(cnv, &source, source + (off[1] - off[0]), &errorCode); 50092e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 50102e5b6d6dSopenharmony_ci log_err("LMBCS-1 ucnv_getNextUChar() failed: %s\n", u_errorName(errorCode)); 50112e5b6d6dSopenharmony_ci break; 50122e5b6d6dSopenharmony_ci } else if(source-sourceStart != off[1] - off[0] || uniChar != *results) { 50132e5b6d6dSopenharmony_ci log_err("LMBCS-1 ucnv_getNextUChar() result %lx from %d bytes, should have been %lx from %d bytes.\n", 50142e5b6d6dSopenharmony_ci uniChar, (source-sourceStart), *results, *off); 50152e5b6d6dSopenharmony_ci break; 50162e5b6d6dSopenharmony_ci } 50172e5b6d6dSopenharmony_ci results++; 50182e5b6d6dSopenharmony_ci off++; 50192e5b6d6dSopenharmony_ci } 50202e5b6d6dSopenharmony_ci } 50212e5b6d6dSopenharmony_ci ucnv_close(cnv); 50222e5b6d6dSopenharmony_ci } 50232e5b6d6dSopenharmony_ci { /* test locale & optimization group operations: Unicode to LMBCS */ 50242e5b6d6dSopenharmony_ci 50252e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 50262e5b6d6dSopenharmony_ci UConverter *cnv16he = ucnv_open("LMBCS-16,locale=he", &errorCode); 50272e5b6d6dSopenharmony_ci UConverter *cnv16jp = ucnv_open("LMBCS-16,locale=ja_JP", &errorCode); 50282e5b6d6dSopenharmony_ci UConverter *cnv01us = ucnv_open("LMBCS-1,locale=us_EN", &errorCode); 50292e5b6d6dSopenharmony_ci UChar uniString [] = {0x0192}; /* Latin Small letter f with hook */ 50302e5b6d6dSopenharmony_ci const UChar * pUniOut = uniString; 50312e5b6d6dSopenharmony_ci UChar * pUniIn = uniString; 50322e5b6d6dSopenharmony_ci uint8_t lmbcsString [4]; 50332e5b6d6dSopenharmony_ci const char * pLMBCSOut = (const char *)lmbcsString; 50342e5b6d6dSopenharmony_ci char * pLMBCSIn = (char *)lmbcsString; 50352e5b6d6dSopenharmony_ci 50362e5b6d6dSopenharmony_ci /* 0192 (hook) converts to both group 3 & group 1. input locale should differentiate */ 50372e5b6d6dSopenharmony_ci ucnv_fromUnicode (cnv16he, 50382e5b6d6dSopenharmony_ci &pLMBCSIn, (pLMBCSIn + UPRV_LENGTHOF(lmbcsString)), 50392e5b6d6dSopenharmony_ci &pUniOut, pUniOut + UPRV_LENGTHOF(uniString), 50402e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50412e5b6d6dSopenharmony_ci 50422e5b6d6dSopenharmony_ci if (lmbcsString[0] != 0x3 || lmbcsString[1] != 0x83) 50432e5b6d6dSopenharmony_ci { 50442e5b6d6dSopenharmony_ci log_err("LMBCS-16,locale=he gives unexpected translation\n"); 50452e5b6d6dSopenharmony_ci } 50462e5b6d6dSopenharmony_ci 50472e5b6d6dSopenharmony_ci pLMBCSIn= (char *)lmbcsString; 50482e5b6d6dSopenharmony_ci pUniOut = uniString; 50492e5b6d6dSopenharmony_ci ucnv_fromUnicode (cnv01us, 50502e5b6d6dSopenharmony_ci &pLMBCSIn, (const char *)(lmbcsString + UPRV_LENGTHOF(lmbcsString)), 50512e5b6d6dSopenharmony_ci &pUniOut, pUniOut + UPRV_LENGTHOF(uniString), 50522e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50532e5b6d6dSopenharmony_ci 50542e5b6d6dSopenharmony_ci if (lmbcsString[0] != 0x9F) 50552e5b6d6dSopenharmony_ci { 50562e5b6d6dSopenharmony_ci log_err("LMBCS-1,locale=US gives unexpected translation\n"); 50572e5b6d6dSopenharmony_ci } 50582e5b6d6dSopenharmony_ci 50592e5b6d6dSopenharmony_ci /* single byte char from mbcs char set */ 50602e5b6d6dSopenharmony_ci lmbcsString[0] = 0xAE; /* 1/2 width katakana letter small Yo */ 50612e5b6d6dSopenharmony_ci pLMBCSOut = (const char *)lmbcsString; 50622e5b6d6dSopenharmony_ci pUniIn = uniString; 50632e5b6d6dSopenharmony_ci ucnv_toUnicode (cnv16jp, 50642e5b6d6dSopenharmony_ci &pUniIn, pUniIn + 1, 50652e5b6d6dSopenharmony_ci &pLMBCSOut, (pLMBCSOut + 1), 50662e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50672e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || pLMBCSOut != (const char *)lmbcsString+1 || pUniIn != uniString+1 || uniString[0] != 0xFF6E) 50682e5b6d6dSopenharmony_ci { 50692e5b6d6dSopenharmony_ci log_err("Unexpected results from LMBCS-16 single byte char\n"); 50702e5b6d6dSopenharmony_ci } 50712e5b6d6dSopenharmony_ci /* convert to group 1: should be 3 bytes */ 50722e5b6d6dSopenharmony_ci pLMBCSIn = (char *)lmbcsString; 50732e5b6d6dSopenharmony_ci pUniOut = uniString; 50742e5b6d6dSopenharmony_ci ucnv_fromUnicode (cnv01us, 50752e5b6d6dSopenharmony_ci &pLMBCSIn, (const char *)(pLMBCSIn + 3), 50762e5b6d6dSopenharmony_ci &pUniOut, pUniOut + 1, 50772e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50782e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || pLMBCSIn != (const char *)lmbcsString+3 || pUniOut != uniString+1 50792e5b6d6dSopenharmony_ci || lmbcsString[0] != 0x10 || lmbcsString[1] != 0x10 || lmbcsString[2] != 0xAE) 50802e5b6d6dSopenharmony_ci { 50812e5b6d6dSopenharmony_ci log_err("Unexpected results to LMBCS-1 single byte mbcs char\n"); 50822e5b6d6dSopenharmony_ci } 50832e5b6d6dSopenharmony_ci pLMBCSOut = (const char *)lmbcsString; 50842e5b6d6dSopenharmony_ci pUniIn = uniString; 50852e5b6d6dSopenharmony_ci ucnv_toUnicode (cnv01us, 50862e5b6d6dSopenharmony_ci &pUniIn, pUniIn + 1, 50872e5b6d6dSopenharmony_ci &pLMBCSOut, (const char *)(pLMBCSOut + 3), 50882e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50892e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || pLMBCSOut != (const char *)lmbcsString+3 || pUniIn != uniString+1 || uniString[0] != 0xFF6E) 50902e5b6d6dSopenharmony_ci { 50912e5b6d6dSopenharmony_ci log_err("Unexpected results from LMBCS-1 single byte mbcs char\n"); 50922e5b6d6dSopenharmony_ci } 50932e5b6d6dSopenharmony_ci pLMBCSIn = (char *)lmbcsString; 50942e5b6d6dSopenharmony_ci pUniOut = uniString; 50952e5b6d6dSopenharmony_ci ucnv_fromUnicode (cnv16jp, 50962e5b6d6dSopenharmony_ci &pLMBCSIn, (const char *)(pLMBCSIn + 1), 50972e5b6d6dSopenharmony_ci &pUniOut, pUniOut + 1, 50982e5b6d6dSopenharmony_ci NULL, 1, &errorCode); 50992e5b6d6dSopenharmony_ci if (U_FAILURE(errorCode) || pLMBCSIn != (const char *)lmbcsString+1 || pUniOut != uniString+1 || lmbcsString[0] != 0xAE) 51002e5b6d6dSopenharmony_ci { 51012e5b6d6dSopenharmony_ci log_err("Unexpected results to LMBCS-16 single byte mbcs char\n"); 51022e5b6d6dSopenharmony_ci } 51032e5b6d6dSopenharmony_ci ucnv_close(cnv16he); 51042e5b6d6dSopenharmony_ci ucnv_close(cnv16jp); 51052e5b6d6dSopenharmony_ci ucnv_close(cnv01us); 51062e5b6d6dSopenharmony_ci } 51072e5b6d6dSopenharmony_ci { 51082e5b6d6dSopenharmony_ci /* Small source buffer testing, LMBCS -> Unicode */ 51092e5b6d6dSopenharmony_ci 51102e5b6d6dSopenharmony_ci UErrorCode errorCode=U_ZERO_ERROR; 51112e5b6d6dSopenharmony_ci 51122e5b6d6dSopenharmony_ci const char * pSource = (const char *)pszLMBCS; 51132e5b6d6dSopenharmony_ci const char * sourceLimit = (const char *)pszLMBCS + sizeof(pszLMBCS); 51142e5b6d6dSopenharmony_ci int codepointCount = 0; 51152e5b6d6dSopenharmony_ci 51162e5b6d6dSopenharmony_ci UChar Out [sizeof(pszUnicode) + 1]; 51172e5b6d6dSopenharmony_ci UChar * pOut = Out; 51182e5b6d6dSopenharmony_ci UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode); 51192e5b6d6dSopenharmony_ci 51202e5b6d6dSopenharmony_ci 51212e5b6d6dSopenharmony_ci cnv = ucnv_open(NAME_LMBCS_1, &errorCode); 51222e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 51232e5b6d6dSopenharmony_ci log_err("Unable to open a LMBCS-1 converter: %s\n", u_errorName(errorCode)); 51242e5b6d6dSopenharmony_ci return; 51252e5b6d6dSopenharmony_ci } 51262e5b6d6dSopenharmony_ci 51272e5b6d6dSopenharmony_ci 51282e5b6d6dSopenharmony_ci while ((pSource < sourceLimit) && U_SUCCESS (errorCode)) 51292e5b6d6dSopenharmony_ci { 51302e5b6d6dSopenharmony_ci ucnv_toUnicode (cnv, 51312e5b6d6dSopenharmony_ci &pOut, 51322e5b6d6dSopenharmony_ci OutLimit, 51332e5b6d6dSopenharmony_ci &pSource, 51342e5b6d6dSopenharmony_ci (pSource+1), /* claim that this is a 1- byte buffer */ 51352e5b6d6dSopenharmony_ci NULL, 51362e5b6d6dSopenharmony_ci false, /* false means there might be more chars in the next buffer */ 51372e5b6d6dSopenharmony_ci &errorCode); 51382e5b6d6dSopenharmony_ci 51392e5b6d6dSopenharmony_ci if (U_SUCCESS (errorCode)) 51402e5b6d6dSopenharmony_ci { 51412e5b6d6dSopenharmony_ci if ((pSource - (const char *)pszLMBCS) == offsets [codepointCount+1]) 51422e5b6d6dSopenharmony_ci { 51432e5b6d6dSopenharmony_ci /* we are on to the next code point: check value */ 51442e5b6d6dSopenharmony_ci 51452e5b6d6dSopenharmony_ci if (Out[0] != pszUnicode[codepointCount]){ 51462e5b6d6dSopenharmony_ci log_err("LMBCS->Uni result %lx should have been %lx \n", 51472e5b6d6dSopenharmony_ci Out[0], pszUnicode[codepointCount]); 51482e5b6d6dSopenharmony_ci } 51492e5b6d6dSopenharmony_ci 51502e5b6d6dSopenharmony_ci pOut = Out; /* reset for accumulating next code point */ 51512e5b6d6dSopenharmony_ci codepointCount++; 51522e5b6d6dSopenharmony_ci } 51532e5b6d6dSopenharmony_ci } 51542e5b6d6dSopenharmony_ci else 51552e5b6d6dSopenharmony_ci { 51562e5b6d6dSopenharmony_ci log_err("Unexpected Error on toUnicode: %s\n", u_errorName(errorCode)); 51572e5b6d6dSopenharmony_ci } 51582e5b6d6dSopenharmony_ci } 51592e5b6d6dSopenharmony_ci { 51602e5b6d6dSopenharmony_ci /* limits & surrogate error testing */ 51612e5b6d6dSopenharmony_ci char LIn [sizeof(pszLMBCS)]; 51622e5b6d6dSopenharmony_ci const char * pLIn = LIn; 51632e5b6d6dSopenharmony_ci 51642e5b6d6dSopenharmony_ci char LOut [sizeof(pszLMBCS)]; 51652e5b6d6dSopenharmony_ci char * pLOut = LOut; 51662e5b6d6dSopenharmony_ci 51672e5b6d6dSopenharmony_ci UChar UOut [sizeof(pszUnicode)]; 51682e5b6d6dSopenharmony_ci UChar * pUOut = UOut; 51692e5b6d6dSopenharmony_ci 51702e5b6d6dSopenharmony_ci UChar UIn [sizeof(pszUnicode)]; 51712e5b6d6dSopenharmony_ci const UChar * pUIn = UIn; 51722e5b6d6dSopenharmony_ci 51732e5b6d6dSopenharmony_ci int32_t off [sizeof(offsets)]; 51742e5b6d6dSopenharmony_ci UChar32 uniChar; 51752e5b6d6dSopenharmony_ci 51762e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 51772e5b6d6dSopenharmony_ci 51782e5b6d6dSopenharmony_ci /* negative source request should always return U_ILLEGAL_ARGUMENT_ERROR */ 51792e5b6d6dSopenharmony_ci pUIn++; 51802e5b6d6dSopenharmony_ci ucnv_fromUnicode(cnv, &pLOut, pLOut+1, &pUIn, pUIn-1, off, false, &errorCode); 51812e5b6d6dSopenharmony_ci if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) 51822e5b6d6dSopenharmony_ci { 51832e5b6d6dSopenharmony_ci log_err("Unexpected Error on negative source request to ucnv_fromUnicode: %s\n", u_errorName(errorCode)); 51842e5b6d6dSopenharmony_ci } 51852e5b6d6dSopenharmony_ci pUIn--; 51862e5b6d6dSopenharmony_ci 51872e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 51882e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+1,(const char **)&pLIn,(const char *)(pLIn-1),off,false, &errorCode); 51892e5b6d6dSopenharmony_ci if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) 51902e5b6d6dSopenharmony_ci { 51912e5b6d6dSopenharmony_ci log_err("Unexpected Error on negative source request to ucnv_toUnicode: %s\n", u_errorName(errorCode)); 51922e5b6d6dSopenharmony_ci } 51932e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 51942e5b6d6dSopenharmony_ci 51952e5b6d6dSopenharmony_ci uniChar = ucnv_getNextUChar(cnv, (const char **)&pLIn, (const char *)(pLIn-1), &errorCode); 51962e5b6d6dSopenharmony_ci if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) 51972e5b6d6dSopenharmony_ci { 51982e5b6d6dSopenharmony_ci log_err("Unexpected Error on negative source request to ucnv_getNextUChar: %s\n", u_errorName(errorCode)); 51992e5b6d6dSopenharmony_ci } 52002e5b6d6dSopenharmony_ci errorCode=U_ZERO_ERROR; 52012e5b6d6dSopenharmony_ci 52022e5b6d6dSopenharmony_ci /* 0 byte source request - no error, no pointer movement */ 52032e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+1,(const char **)&pLIn,(const char *)pLIn,off,false, &errorCode); 52042e5b6d6dSopenharmony_ci ucnv_fromUnicode(cnv, &pLOut,pLOut+1,&pUIn,pUIn,off,false, &errorCode); 52052e5b6d6dSopenharmony_ci if(U_FAILURE(errorCode)) { 52062e5b6d6dSopenharmony_ci log_err("0 byte source request: unexpected error: %s\n", u_errorName(errorCode)); 52072e5b6d6dSopenharmony_ci } 52082e5b6d6dSopenharmony_ci if ((pUOut != UOut) || (pUIn != UIn) || (pLOut != LOut) || (pLIn != LIn)) 52092e5b6d6dSopenharmony_ci { 52102e5b6d6dSopenharmony_ci log_err("Unexpected pointer move in 0 byte source request \n"); 52112e5b6d6dSopenharmony_ci } 52122e5b6d6dSopenharmony_ci /*0 byte source request - GetNextUChar : error & value == fffe or ffff */ 52132e5b6d6dSopenharmony_ci uniChar = ucnv_getNextUChar(cnv, (const char **)&pLIn, (const char *)pLIn, &errorCode); 52142e5b6d6dSopenharmony_ci if (errorCode != U_INDEX_OUTOFBOUNDS_ERROR) 52152e5b6d6dSopenharmony_ci { 52162e5b6d6dSopenharmony_ci log_err("Unexpected Error on 0-byte source request to ucnv_getnextUChar: %s\n", u_errorName(errorCode)); 52172e5b6d6dSopenharmony_ci } 52182e5b6d6dSopenharmony_ci if (((uint32_t)uniChar - 0xfffe) > 1) /* not 0xfffe<=uniChar<=0xffff */ 52192e5b6d6dSopenharmony_ci { 52202e5b6d6dSopenharmony_ci log_err("Unexpected value on 0-byte source request to ucnv_getnextUChar \n"); 52212e5b6d6dSopenharmony_ci } 52222e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 52232e5b6d6dSopenharmony_ci 52242e5b6d6dSopenharmony_ci /* running out of target room : U_BUFFER_OVERFLOW_ERROR */ 52252e5b6d6dSopenharmony_ci 52262e5b6d6dSopenharmony_ci pUIn = pszUnicode; 52272e5b6d6dSopenharmony_ci ucnv_fromUnicode(cnv, &pLOut,pLOut+offsets[4],&pUIn,pUIn+UPRV_LENGTHOF(pszUnicode),off,false, &errorCode); 52282e5b6d6dSopenharmony_ci if (errorCode != U_BUFFER_OVERFLOW_ERROR || pLOut != LOut + offsets[4] || pUIn != pszUnicode+4 ) 52292e5b6d6dSopenharmony_ci { 52302e5b6d6dSopenharmony_ci log_err("Unexpected results on out of target room to ucnv_fromUnicode\n"); 52312e5b6d6dSopenharmony_ci } 52322e5b6d6dSopenharmony_ci 52332e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 52342e5b6d6dSopenharmony_ci 52352e5b6d6dSopenharmony_ci pLIn = (const char *)pszLMBCS; 52362e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+4,&pLIn,(pLIn+sizeof(pszLMBCS)),off,false, &errorCode); 52372e5b6d6dSopenharmony_ci if (errorCode != U_BUFFER_OVERFLOW_ERROR || pUOut != UOut + 4 || pLIn != (const char *)pszLMBCS+offsets[4]) 52382e5b6d6dSopenharmony_ci { 52392e5b6d6dSopenharmony_ci log_err("Unexpected results on out of target room to ucnv_toUnicode\n"); 52402e5b6d6dSopenharmony_ci } 52412e5b6d6dSopenharmony_ci 52422e5b6d6dSopenharmony_ci /* unpaired or chopped LMBCS surrogates */ 52432e5b6d6dSopenharmony_ci 52442e5b6d6dSopenharmony_ci /* OK high surrogate, Low surrogate is chopped */ 52452e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 52462e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 52472e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 52482e5b6d6dSopenharmony_ci LIn [3] = (char)0x14; 52492e5b6d6dSopenharmony_ci LIn [4] = (char)0xDC; 52502e5b6d6dSopenharmony_ci pLIn = LIn; 52512e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 52522e5b6d6dSopenharmony_ci pUOut = UOut; 52532e5b6d6dSopenharmony_ci 52542e5b6d6dSopenharmony_ci ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); 52552e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,true, &errorCode); 52562e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5) 52572e5b6d6dSopenharmony_ci { 52582e5b6d6dSopenharmony_ci log_err("Unexpected results on chopped low surrogate\n"); 52592e5b6d6dSopenharmony_ci } 52602e5b6d6dSopenharmony_ci 52612e5b6d6dSopenharmony_ci /* chopped at surrogate boundary */ 52622e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 52632e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 52642e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 52652e5b6d6dSopenharmony_ci pLIn = LIn; 52662e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 52672e5b6d6dSopenharmony_ci pUOut = UOut; 52682e5b6d6dSopenharmony_ci 52692e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+3),off,true, &errorCode); 52702e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || U_FAILURE(errorCode) || pUOut != UOut + 1 || pLIn != LIn + 3) 52712e5b6d6dSopenharmony_ci { 52722e5b6d6dSopenharmony_ci log_err("Unexpected results on chopped at surrogate boundary \n"); 52732e5b6d6dSopenharmony_ci } 52742e5b6d6dSopenharmony_ci 52752e5b6d6dSopenharmony_ci /* unpaired surrogate plus valid Unichar */ 52762e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 52772e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 52782e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 52792e5b6d6dSopenharmony_ci LIn [3] = (char)0x14; 52802e5b6d6dSopenharmony_ci LIn [4] = (char)0xC9; 52812e5b6d6dSopenharmony_ci LIn [5] = (char)0xD0; 52822e5b6d6dSopenharmony_ci pLIn = LIn; 52832e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 52842e5b6d6dSopenharmony_ci pUOut = UOut; 52852e5b6d6dSopenharmony_ci 52862e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+6),off,true, &errorCode); 52872e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || UOut[1] != 0xC9D0 || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 6) 52882e5b6d6dSopenharmony_ci { 52892e5b6d6dSopenharmony_ci log_err("Unexpected results after unpaired surrogate plus valid Unichar \n"); 52902e5b6d6dSopenharmony_ci } 52912e5b6d6dSopenharmony_ci 52922e5b6d6dSopenharmony_ci /* unpaired surrogate plus chopped Unichar */ 52932e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 52942e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 52952e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 52962e5b6d6dSopenharmony_ci LIn [3] = (char)0x14; 52972e5b6d6dSopenharmony_ci LIn [4] = (char)0xC9; 52982e5b6d6dSopenharmony_ci 52992e5b6d6dSopenharmony_ci pLIn = LIn; 53002e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 53012e5b6d6dSopenharmony_ci pUOut = UOut; 53022e5b6d6dSopenharmony_ci 53032e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,true, &errorCode); 53042e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5) 53052e5b6d6dSopenharmony_ci { 53062e5b6d6dSopenharmony_ci log_err("Unexpected results after unpaired surrogate plus chopped Unichar \n"); 53072e5b6d6dSopenharmony_ci } 53082e5b6d6dSopenharmony_ci 53092e5b6d6dSopenharmony_ci /* unpaired surrogate plus valid non-Unichar */ 53102e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 53112e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 53122e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 53132e5b6d6dSopenharmony_ci LIn [3] = (char)0x0F; 53142e5b6d6dSopenharmony_ci LIn [4] = (char)0x3B; 53152e5b6d6dSopenharmony_ci 53162e5b6d6dSopenharmony_ci pLIn = LIn; 53172e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 53182e5b6d6dSopenharmony_ci pUOut = UOut; 53192e5b6d6dSopenharmony_ci 53202e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,true, &errorCode); 53212e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || UOut[1] != 0x1B || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 5) 53222e5b6d6dSopenharmony_ci { 53232e5b6d6dSopenharmony_ci log_err("Unexpected results after unpaired surrogate plus valid non-Unichar\n"); 53242e5b6d6dSopenharmony_ci } 53252e5b6d6dSopenharmony_ci 53262e5b6d6dSopenharmony_ci /* unpaired surrogate plus chopped non-Unichar */ 53272e5b6d6dSopenharmony_ci LIn [0] = (char)0x14; 53282e5b6d6dSopenharmony_ci LIn [1] = (char)0xD8; 53292e5b6d6dSopenharmony_ci LIn [2] = (char)0x01; 53302e5b6d6dSopenharmony_ci LIn [3] = (char)0x0F; 53312e5b6d6dSopenharmony_ci 53322e5b6d6dSopenharmony_ci pLIn = LIn; 53332e5b6d6dSopenharmony_ci errorCode = U_ZERO_ERROR; 53342e5b6d6dSopenharmony_ci pUOut = UOut; 53352e5b6d6dSopenharmony_ci 53362e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+4),off,true, &errorCode); 53372e5b6d6dSopenharmony_ci 53382e5b6d6dSopenharmony_ci if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 4) 53392e5b6d6dSopenharmony_ci { 53402e5b6d6dSopenharmony_ci log_err("Unexpected results after unpaired surrogate plus chopped non-Unichar\n"); 53412e5b6d6dSopenharmony_ci } 53422e5b6d6dSopenharmony_ci } 53432e5b6d6dSopenharmony_ci } 53442e5b6d6dSopenharmony_ci ucnv_close(cnv); /* final cleanup */ 53452e5b6d6dSopenharmony_ci} 53462e5b6d6dSopenharmony_ci 53472e5b6d6dSopenharmony_ci 53482e5b6d6dSopenharmony_cistatic void TestJitterbug255() 53492e5b6d6dSopenharmony_ci{ 53502e5b6d6dSopenharmony_ci static const uint8_t testBytes[] = { 0x95, 0xcf, 0x8a, 0xb7, 0x0d, 0x0a, 0x00 }; 53512e5b6d6dSopenharmony_ci const char *testBuffer = (const char *)testBytes; 53522e5b6d6dSopenharmony_ci const char *testEnd = (const char *)testBytes + sizeof(testBytes); 53532e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 53542e5b6d6dSopenharmony_ci /*UChar32 result;*/ 53552e5b6d6dSopenharmony_ci UConverter *cnv = 0; 53562e5b6d6dSopenharmony_ci 53572e5b6d6dSopenharmony_ci cnv = ucnv_open("shift-jis", &status); 53582e5b6d6dSopenharmony_ci if (U_FAILURE(status) || cnv == 0) { 53592e5b6d6dSopenharmony_ci log_data_err("Failed to open the converter for SJIS.\n"); 53602e5b6d6dSopenharmony_ci return; 53612e5b6d6dSopenharmony_ci } 53622e5b6d6dSopenharmony_ci while (testBuffer != testEnd) 53632e5b6d6dSopenharmony_ci { 53642e5b6d6dSopenharmony_ci /*result = */ucnv_getNextUChar (cnv, &testBuffer, testEnd , &status); 53652e5b6d6dSopenharmony_ci if (U_FAILURE(status)) 53662e5b6d6dSopenharmony_ci { 53672e5b6d6dSopenharmony_ci log_err("Failed to convert the next UChar for SJIS.\n"); 53682e5b6d6dSopenharmony_ci break; 53692e5b6d6dSopenharmony_ci } 53702e5b6d6dSopenharmony_ci } 53712e5b6d6dSopenharmony_ci ucnv_close(cnv); 53722e5b6d6dSopenharmony_ci} 53732e5b6d6dSopenharmony_ci 53742e5b6d6dSopenharmony_cistatic void TestEBCDICUS4XML() 53752e5b6d6dSopenharmony_ci{ 53762e5b6d6dSopenharmony_ci UChar unicodes_x[] = {0x0000, 0x0000, 0x0000, 0x0000}; 53772e5b6d6dSopenharmony_ci static const UChar toUnicodeMaps_x[] = {0x000A, 0x000A, 0x000D, 0x0000}; 53782e5b6d6dSopenharmony_ci static const char fromUnicodeMaps_x[] = {0x25, 0x25, 0x0D, 0x00}; 53792e5b6d6dSopenharmony_ci static const char newLines_x[] = {0x25, 0x15, 0x0D, 0x00}; 53802e5b6d6dSopenharmony_ci char target_x[] = {0x00, 0x00, 0x00, 0x00}; 53812e5b6d6dSopenharmony_ci UChar *unicodes = unicodes_x; 53822e5b6d6dSopenharmony_ci const UChar *toUnicodeMaps = toUnicodeMaps_x; 53832e5b6d6dSopenharmony_ci char *target = target_x; 53842e5b6d6dSopenharmony_ci const char* fromUnicodeMaps = fromUnicodeMaps_x, *newLines = newLines_x; 53852e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 53862e5b6d6dSopenharmony_ci UConverter *cnv = 0; 53872e5b6d6dSopenharmony_ci 53882e5b6d6dSopenharmony_ci cnv = ucnv_open("ebcdic-xml-us", &status); 53892e5b6d6dSopenharmony_ci if (U_FAILURE(status) || cnv == 0) { 53902e5b6d6dSopenharmony_ci log_data_err("Failed to open the converter for EBCDIC-XML-US.\n"); 53912e5b6d6dSopenharmony_ci return; 53922e5b6d6dSopenharmony_ci } 53932e5b6d6dSopenharmony_ci ucnv_toUnicode(cnv, &unicodes, unicodes+3, (const char**)&newLines, newLines+3, NULL, true, &status); 53942e5b6d6dSopenharmony_ci if (U_FAILURE(status) || memcmp(unicodes_x, toUnicodeMaps, sizeof(UChar)*3) != 0) { 53952e5b6d6dSopenharmony_ci log_err("To Unicode conversion failed in EBCDICUS4XML test. %s\n", 53962e5b6d6dSopenharmony_ci u_errorName(status)); 53972e5b6d6dSopenharmony_ci printUSeqErr(unicodes_x, 3); 53982e5b6d6dSopenharmony_ci printUSeqErr(toUnicodeMaps, 3); 53992e5b6d6dSopenharmony_ci } 54002e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 54012e5b6d6dSopenharmony_ci ucnv_fromUnicode(cnv, &target, target+3, (const UChar**)&toUnicodeMaps, toUnicodeMaps+3, NULL, true, &status); 54022e5b6d6dSopenharmony_ci if (U_FAILURE(status) || memcmp(target_x, fromUnicodeMaps, sizeof(char)*3) != 0) { 54032e5b6d6dSopenharmony_ci log_err("From Unicode conversion failed in EBCDICUS4XML test. %s\n", 54042e5b6d6dSopenharmony_ci u_errorName(status)); 54052e5b6d6dSopenharmony_ci printSeqErr((const unsigned char*)target_x, 3); 54062e5b6d6dSopenharmony_ci printSeqErr((const unsigned char*)fromUnicodeMaps, 3); 54072e5b6d6dSopenharmony_ci } 54082e5b6d6dSopenharmony_ci ucnv_close(cnv); 54092e5b6d6dSopenharmony_ci} 54102e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_LEGACY_COLLATION */ 54112e5b6d6dSopenharmony_ci 54122e5b6d6dSopenharmony_ci#if !UCONFIG_NO_COLLATION 54132e5b6d6dSopenharmony_ci 54142e5b6d6dSopenharmony_cistatic void TestJitterbug981(){ 54152e5b6d6dSopenharmony_ci const UChar* rules; 54162e5b6d6dSopenharmony_ci int32_t rules_length, target_cap, bytes_needed, buff_size; 54172e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 54182e5b6d6dSopenharmony_ci UConverter *utf8cnv; 54192e5b6d6dSopenharmony_ci UCollator* myCollator; 54202e5b6d6dSopenharmony_ci char *buff; 54212e5b6d6dSopenharmony_ci int numNeeded=0; 54222e5b6d6dSopenharmony_ci utf8cnv = ucnv_open ("utf8", &status); 54232e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 54242e5b6d6dSopenharmony_ci log_err("Could not open UTF-8 converter. Error: %s\n", u_errorName(status)); 54252e5b6d6dSopenharmony_ci return; 54262e5b6d6dSopenharmony_ci } 54272e5b6d6dSopenharmony_ci myCollator = ucol_open("zh", &status); 54282e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 54292e5b6d6dSopenharmony_ci log_data_err("Could not open collator for zh locale. Error: %s\n", u_errorName(status)); 54302e5b6d6dSopenharmony_ci ucnv_close(utf8cnv); 54312e5b6d6dSopenharmony_ci return; 54322e5b6d6dSopenharmony_ci } 54332e5b6d6dSopenharmony_ci 54342e5b6d6dSopenharmony_ci rules = ucol_getRules(myCollator, &rules_length); 54352e5b6d6dSopenharmony_ci if(rules_length == 0) { 54362e5b6d6dSopenharmony_ci log_data_err("missing zh tailoring rule string\n"); 54372e5b6d6dSopenharmony_ci ucol_close(myCollator); 54382e5b6d6dSopenharmony_ci ucnv_close(utf8cnv); 54392e5b6d6dSopenharmony_ci return; 54402e5b6d6dSopenharmony_ci } 54412e5b6d6dSopenharmony_ci buff_size = rules_length * ucnv_getMaxCharSize(utf8cnv); 54422e5b6d6dSopenharmony_ci buff = malloc(buff_size); 54432e5b6d6dSopenharmony_ci 54442e5b6d6dSopenharmony_ci target_cap = 0; 54452e5b6d6dSopenharmony_ci do { 54462e5b6d6dSopenharmony_ci ucnv_reset(utf8cnv); 54472e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 54482e5b6d6dSopenharmony_ci if(target_cap >= buff_size) { 54492e5b6d6dSopenharmony_ci log_err("wanted %d bytes, only %d available\n", target_cap, buff_size); 54502e5b6d6dSopenharmony_ci break; 54512e5b6d6dSopenharmony_ci } 54522e5b6d6dSopenharmony_ci bytes_needed = ucnv_fromUChars(utf8cnv, buff, target_cap, 54532e5b6d6dSopenharmony_ci rules, rules_length, &status); 54542e5b6d6dSopenharmony_ci target_cap = (bytes_needed > target_cap) ? bytes_needed : target_cap +1; 54552e5b6d6dSopenharmony_ci if(numNeeded!=0 && numNeeded!= bytes_needed){ 54562e5b6d6dSopenharmony_ci log_err("ucnv_fromUChars returns different values for required capacity in pre-flight and conversion modes"); 54572e5b6d6dSopenharmony_ci break; 54582e5b6d6dSopenharmony_ci } 54592e5b6d6dSopenharmony_ci numNeeded = bytes_needed; 54602e5b6d6dSopenharmony_ci } while (status == U_BUFFER_OVERFLOW_ERROR); 54612e5b6d6dSopenharmony_ci ucol_close(myCollator); 54622e5b6d6dSopenharmony_ci ucnv_close(utf8cnv); 54632e5b6d6dSopenharmony_ci free(buff); 54642e5b6d6dSopenharmony_ci} 54652e5b6d6dSopenharmony_ci 54662e5b6d6dSopenharmony_ci#endif 54672e5b6d6dSopenharmony_ci 54682e5b6d6dSopenharmony_ci#if !UCONFIG_NO_LEGACY_CONVERSION 54692e5b6d6dSopenharmony_cistatic void TestJitterbug1293(){ 54702e5b6d6dSopenharmony_ci static const UChar src[] = {0x30DE, 0x30A4, 0x5E83, 0x544A, 0x30BF, 0x30A4, 0x30D7,0x000}; 54712e5b6d6dSopenharmony_ci char target[256]; 54722e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 54732e5b6d6dSopenharmony_ci UConverter* conv=NULL; 54742e5b6d6dSopenharmony_ci int32_t target_cap, bytes_needed, numNeeded = 0; 54752e5b6d6dSopenharmony_ci conv = ucnv_open("shift-jis",&status); 54762e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 54772e5b6d6dSopenharmony_ci log_data_err("Could not open Shift-Jis converter. Error: %s", u_errorName(status)); 54782e5b6d6dSopenharmony_ci return; 54792e5b6d6dSopenharmony_ci } 54802e5b6d6dSopenharmony_ci 54812e5b6d6dSopenharmony_ci do{ 54822e5b6d6dSopenharmony_ci target_cap =0; 54832e5b6d6dSopenharmony_ci bytes_needed = ucnv_fromUChars(conv,target,256,src,u_strlen(src),&status); 54842e5b6d6dSopenharmony_ci target_cap = (bytes_needed > target_cap) ? bytes_needed : target_cap +1; 54852e5b6d6dSopenharmony_ci if(numNeeded!=0 && numNeeded!= bytes_needed){ 54862e5b6d6dSopenharmony_ci log_err("ucnv_fromUChars returns different values for required capacity in pre-flight and conversion modes"); 54872e5b6d6dSopenharmony_ci } 54882e5b6d6dSopenharmony_ci numNeeded = bytes_needed; 54892e5b6d6dSopenharmony_ci } while (status == U_BUFFER_OVERFLOW_ERROR); 54902e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 54912e5b6d6dSopenharmony_ci log_err("An error occurred in ucnv_fromUChars. Error: %s", u_errorName(status)); 54922e5b6d6dSopenharmony_ci return; 54932e5b6d6dSopenharmony_ci } 54942e5b6d6dSopenharmony_ci ucnv_close(conv); 54952e5b6d6dSopenharmony_ci} 54962e5b6d6dSopenharmony_ci#endif 54972e5b6d6dSopenharmony_ci 54982e5b6d6dSopenharmony_cistatic void TestJB5275_1(){ 54992e5b6d6dSopenharmony_ci 55002e5b6d6dSopenharmony_ci static const char* data = "\x3B\xB3\x0A" /* Easy characters */ 55012e5b6d6dSopenharmony_ci "\xC0\xE9\xBF\xE9\xE8\xD8\x0A" /* Gurmukhi test */ 55022e5b6d6dSopenharmony_ci /* Switch script: */ 55032e5b6d6dSopenharmony_ci "\xEF\x43\xC0\xE9\xBF\xE9\xE8\xD8\x0A" /* Bengali test */ 55042e5b6d6dSopenharmony_ci "\x3B\xB3\x0A" /* Easy characters - new line, so should default!*/ 55052e5b6d6dSopenharmony_ci "\xEF\x40\x3B\xB3\x0A"; 55062e5b6d6dSopenharmony_ci static const UChar expected[] ={ 55072e5b6d6dSopenharmony_ci 0x003b, 0x0a15, 0x000a, /* Easy characters */ 55082e5b6d6dSopenharmony_ci 0x0a5c, 0x0a4d, 0x0a39, 0x0a5c, 0x0a4d, 0x0a39, 0x000a, /* Gurmukhi test */ 55092e5b6d6dSopenharmony_ci 0x09dd, 0x09dc, 0x09cd, 0x09b9, 0x000a, /* Switch script: to Bengali*/ 55102e5b6d6dSopenharmony_ci 0x003b, 0x0a15, 0x000a, /* Easy characters - new line, so should default!*/ 55112e5b6d6dSopenharmony_ci 0x003b, 0x0a15, 0x000a /* Back to Gurmukhi*/ 55122e5b6d6dSopenharmony_ci }; 55132e5b6d6dSopenharmony_ci 55142e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 55152e5b6d6dSopenharmony_ci UConverter* conv = ucnv_open("iscii-gur", &status); 55162e5b6d6dSopenharmony_ci UChar dest[100] = {'\0'}; 55172e5b6d6dSopenharmony_ci UChar* target = dest; 55182e5b6d6dSopenharmony_ci UChar* targetLimit = dest+100; 55192e5b6d6dSopenharmony_ci const char* source = data; 55202e5b6d6dSopenharmony_ci const char* sourceLimit = data+strlen(data); 55212e5b6d6dSopenharmony_ci const UChar* exp = expected; 55222e5b6d6dSopenharmony_ci 55232e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 55242e5b6d6dSopenharmony_ci log_data_err("Unable to open converter: iscii-gur got errorCode: %s\n", u_errorName(status)); 55252e5b6d6dSopenharmony_ci return; 55262e5b6d6dSopenharmony_ci } 55272e5b6d6dSopenharmony_ci 55282e5b6d6dSopenharmony_ci log_verbose("Testing switching back to default script when new line is encountered.\n"); 55292e5b6d6dSopenharmony_ci ucnv_toUnicode(conv, &target, targetLimit, &source, sourceLimit, NULL, true, &status); 55302e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 55312e5b6d6dSopenharmony_ci log_err("conversion failed: %s \n", u_errorName(status)); 55322e5b6d6dSopenharmony_ci } 55332e5b6d6dSopenharmony_ci targetLimit = target; 55342e5b6d6dSopenharmony_ci target = dest; 55352e5b6d6dSopenharmony_ci printUSeq(target, (int)(targetLimit-target)); 55362e5b6d6dSopenharmony_ci while(target<targetLimit){ 55372e5b6d6dSopenharmony_ci if(*exp!=*target){ 55382e5b6d6dSopenharmony_ci log_err("did not get the expected output. \\u%04X != \\u%04X (got)\n", *exp, *target); 55392e5b6d6dSopenharmony_ci } 55402e5b6d6dSopenharmony_ci target++; 55412e5b6d6dSopenharmony_ci exp++; 55422e5b6d6dSopenharmony_ci } 55432e5b6d6dSopenharmony_ci ucnv_close(conv); 55442e5b6d6dSopenharmony_ci} 55452e5b6d6dSopenharmony_ci 55462e5b6d6dSopenharmony_cistatic void TestJB5275(){ 55472e5b6d6dSopenharmony_ci static const char* data = 55482e5b6d6dSopenharmony_ci /* "\xEF\x42\xEF\x41\xA4\xD5\xE5\xB3\xEA\x0A" unsupported sequence \xEF\x41 */ 55492e5b6d6dSopenharmony_ci /* "\xEF\x42\xEF\x41\xD4\xDA\xB3\xE8\xEA\x0A" unsupported sequence \xEF\x41 */ 55502e5b6d6dSopenharmony_ci /* "\xEF\x44\xEF\x41\xC8\xE1\x8B\xDB\xB3\xE8 \xB3\xE4\xC1\xE8\x0A" unsupported sequence \xEF\x41 */ 55512e5b6d6dSopenharmony_ci "\xEF\x4B\xC0\xE9\xBF\xE9\xE8\xD8\x0A" /* Gurmukhi test */ 55522e5b6d6dSopenharmony_ci "\xEF\x4A\xC0\xD4\xBF\xD4\xE8\xD8\x0A" /* Gujarati test */ 55532e5b6d6dSopenharmony_ci "\xEF\x48\x38\xB3\x0A" /* Kannada test */ 55542e5b6d6dSopenharmony_ci "\xEF\x49\x39\xB3\x0A" /* Malayalam test */ 55552e5b6d6dSopenharmony_ci "\xEF\x4A\x3A\xB3\x0A" /* Gujarati test */ 55562e5b6d6dSopenharmony_ci "\xEF\x4B\x3B\xB3\x0A" /* Punjabi test */ 55572e5b6d6dSopenharmony_ci /* "\xEF\x4C\x3C\xB3\x0A" unsupported sequence \xEF\x41 */; 55582e5b6d6dSopenharmony_ci static const UChar expected[] ={ 55592e5b6d6dSopenharmony_ci 0x0A5C, 0x0A4D, 0x0A39, 0x0A5C, 0x0A4D, 0x0A39, 0x000A, /* Gurmukhi test */ 55602e5b6d6dSopenharmony_ci 0x0AA2, 0x0AB5, 0x0AA1, 0x0AB5, 0x0ACD, 0x0AB9, 0x000A, /* Gujarati test */ 55612e5b6d6dSopenharmony_ci 0x0038, 0x0C95, 0x000A, /* Kannada test */ 55622e5b6d6dSopenharmony_ci 0x0039, 0x0D15, 0x000A, /* Malayalam test */ 55632e5b6d6dSopenharmony_ci 0x003A, 0x0A95, 0x000A, /* Gujarati test */ 55642e5b6d6dSopenharmony_ci 0x003B, 0x0A15, 0x000A, /* Punjabi test */ 55652e5b6d6dSopenharmony_ci }; 55662e5b6d6dSopenharmony_ci 55672e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 55682e5b6d6dSopenharmony_ci UConverter* conv = ucnv_open("iscii", &status); 55692e5b6d6dSopenharmony_ci UChar dest[100] = {'\0'}; 55702e5b6d6dSopenharmony_ci UChar* target = dest; 55712e5b6d6dSopenharmony_ci UChar* targetLimit = dest+100; 55722e5b6d6dSopenharmony_ci const char* source = data; 55732e5b6d6dSopenharmony_ci const char* sourceLimit = data+strlen(data); 55742e5b6d6dSopenharmony_ci const UChar* exp = expected; 55752e5b6d6dSopenharmony_ci ucnv_toUnicode(conv, &target, targetLimit, &source, sourceLimit, NULL, true, &status); 55762e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 55772e5b6d6dSopenharmony_ci log_data_err("conversion failed: %s \n", u_errorName(status)); 55782e5b6d6dSopenharmony_ci } 55792e5b6d6dSopenharmony_ci targetLimit = target; 55802e5b6d6dSopenharmony_ci target = dest; 55812e5b6d6dSopenharmony_ci 55822e5b6d6dSopenharmony_ci printUSeq(target, (int)(targetLimit-target)); 55832e5b6d6dSopenharmony_ci 55842e5b6d6dSopenharmony_ci while(target<targetLimit){ 55852e5b6d6dSopenharmony_ci if(*exp!=*target){ 55862e5b6d6dSopenharmony_ci log_err("did not get the expected output. \\u%04X != \\u%04X (got)\n", *exp, *target); 55872e5b6d6dSopenharmony_ci } 55882e5b6d6dSopenharmony_ci target++; 55892e5b6d6dSopenharmony_ci exp++; 55902e5b6d6dSopenharmony_ci } 55912e5b6d6dSopenharmony_ci ucnv_close(conv); 55922e5b6d6dSopenharmony_ci} 55932e5b6d6dSopenharmony_ci 55942e5b6d6dSopenharmony_cistatic void 55952e5b6d6dSopenharmony_ciTestIsFixedWidth() { 55962e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 55972e5b6d6dSopenharmony_ci UConverter *cnv = NULL; 55982e5b6d6dSopenharmony_ci int32_t i; 55992e5b6d6dSopenharmony_ci 56002e5b6d6dSopenharmony_ci const char *fixedWidth[] = { 56012e5b6d6dSopenharmony_ci "US-ASCII", 56022e5b6d6dSopenharmony_ci "UTF32", 56032e5b6d6dSopenharmony_ci "ibm-5478_P100-1995" 56042e5b6d6dSopenharmony_ci }; 56052e5b6d6dSopenharmony_ci 56062e5b6d6dSopenharmony_ci const char *notFixedWidth[] = { 56072e5b6d6dSopenharmony_ci "GB18030", 56082e5b6d6dSopenharmony_ci "UTF8", 56092e5b6d6dSopenharmony_ci "windows-949-2000", 56102e5b6d6dSopenharmony_ci "UTF16" 56112e5b6d6dSopenharmony_ci }; 56122e5b6d6dSopenharmony_ci 56132e5b6d6dSopenharmony_ci for (i = 0; i < UPRV_LENGTHOF(fixedWidth); i++) { 56142e5b6d6dSopenharmony_ci cnv = ucnv_open(fixedWidth[i], &status); 56152e5b6d6dSopenharmony_ci if (cnv == NULL || U_FAILURE(status)) { 56162e5b6d6dSopenharmony_ci log_data_err("Error open converter: %s - %s \n", fixedWidth[i], u_errorName(status)); 56172e5b6d6dSopenharmony_ci continue; 56182e5b6d6dSopenharmony_ci } 56192e5b6d6dSopenharmony_ci 56202e5b6d6dSopenharmony_ci if (!ucnv_isFixedWidth(cnv, &status)) { 56212e5b6d6dSopenharmony_ci log_err("%s is a fixedWidth converter but returned false.\n", fixedWidth[i]); 56222e5b6d6dSopenharmony_ci } 56232e5b6d6dSopenharmony_ci ucnv_close(cnv); 56242e5b6d6dSopenharmony_ci } 56252e5b6d6dSopenharmony_ci 56262e5b6d6dSopenharmony_ci for (i = 0; i < UPRV_LENGTHOF(notFixedWidth); i++) { 56272e5b6d6dSopenharmony_ci cnv = ucnv_open(notFixedWidth[i], &status); 56282e5b6d6dSopenharmony_ci if (cnv == NULL || U_FAILURE(status)) { 56292e5b6d6dSopenharmony_ci log_data_err("Error open converter: %s - %s \n", notFixedWidth[i], u_errorName(status)); 56302e5b6d6dSopenharmony_ci continue; 56312e5b6d6dSopenharmony_ci } 56322e5b6d6dSopenharmony_ci 56332e5b6d6dSopenharmony_ci if (ucnv_isFixedWidth(cnv, &status)) { 56342e5b6d6dSopenharmony_ci log_err("%s is NOT a fixedWidth converter but returned true.\n", notFixedWidth[i]); 56352e5b6d6dSopenharmony_ci } 56362e5b6d6dSopenharmony_ci ucnv_close(cnv); 56372e5b6d6dSopenharmony_ci } 56382e5b6d6dSopenharmony_ci} 5639