16f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/********************************************************************
26f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * COPYRIGHT:
36f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Copyright (c) 1997-2012, International Business Machines Corporation and
46f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * others. All Rights Reserved.
56f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org ********************************************************************/
66f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*******************************************************************************
76f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org* File CCONVTST.C
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org* Modification History:
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*        Name                     Description
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*    Steven R. Loomis     7/8/1999      Adding input buffer test
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org********************************************************************************
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdio.h>
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cstring.h"
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uloc.h"
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucnv.h"
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucnv_err.h"
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucnv_cb.h"
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cintltst.h"
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/utypes.h"
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ustring.h"
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucol.h"
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/utf16.h"
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cmemory.h"
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "nucnvtst.h"
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message);
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message);
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_COLLATION
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug981(void);
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug1293(void);
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ;
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestConverterTypesAndStarters(void);
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestAmbiguous(void);
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestSignatureDetection(void);
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF7(void);
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestIMAP(void);
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF8(void);
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestCESU8(void);
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF16(void);
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF16BE(void);
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF16LE(void);
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF32(void);
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF32BE(void);
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF32LE(void);
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestLATIN1(void);
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestSBCS(void);
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDBCS(void);
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestMBCS(void);
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestICCRunout(void);
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef U_ENABLE_GENERIC_ISO_2022
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022(void);
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_JP(void);
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_JP_1(void);
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_JP_2(void);
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_KR(void);
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_KR_1(void);
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_CN(void);
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   /*
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO_2022_CN_EXT(void);
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJIS(void);
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestHZ(void);
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestSCSU(void);
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestEBCDIC_STATEFUL(void);
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestGB18030(void);
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestLMBCS(void);
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug255(void);
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestEBCDICUS4XML(void);
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   /*
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug915(void);
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISCII(void);
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestCoverageMBCS(void);
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug2346(void);
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug2411(void);
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJB5275(void);
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJB5275_1(void);
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestJitterbug6175(void);
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestIsFixedWidth(void);
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestInBufSizes(void);
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestRoundTrippingAllUTF(void);
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestConv(const uint16_t in[],
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     int len,
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     const char* conv,
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     const char* lang,
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     char byteArr[],
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     int byteArrLen);
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* open a converter, using test data if it begins with '@' */
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err);
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define NEW_MAX_BUFFER 999
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t  gInBufferSize = NEW_MAX_BUFFER;
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t  gOutBufferSize = NEW_MAX_BUFFER;
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic char     gNuConvTestName[1024];
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define nct_min(x,y)  ((x<y) ? x : y)
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err)
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  if(cnv && cnv[0] == '@') {
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return ucnv_openPackage(loadTestData(err), cnv+1, err);
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  } else {
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return ucnv_open(cnv, err);
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  }
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void printSeq(const unsigned char* a, int len)
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i=0;
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("{");
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while (i<len)
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("0x%02x ", a[i++]);
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("}\n");
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void printUSeq(const UChar* a, int len)
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i=0;
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("{U+");
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while (i<len) log_verbose("0x%04x ", a[i++]);
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("}\n");
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void printSeqErr(const unsigned char* a, int len)
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i=0;
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fprintf(stderr, "{");
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while (i<len)
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        fprintf(stderr, "0x%02x ", a[i++]);
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fprintf(stderr, "}\n");
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void printUSeqErr(const UChar* a, int len)
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i=0;
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fprintf(stderr, "{U+");
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while (i<len)
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        fprintf(stderr, "0x%04x ", a[i++]);
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    fprintf(stderr,"}\n");
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message)
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     const char* s0;
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     const char* s=(char*)source;
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     const int32_t *r=results;
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     UErrorCode errorCode=U_ZERO_ERROR;
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     UChar32 c;
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     while(s<limit) {
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        s0=s;
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        c=ucnv_getNextUChar(cnv, &s, limit, &errorCode);
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(errorCode==U_INDEX_OUTOFBOUNDS_ERROR) {
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break; /* no more significant input */
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if(U_FAILURE(errorCode)) {
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("%s ucnv_getNextUChar() failed: %s\n", message, u_errorName(errorCode));
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if(
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* test the expected number of input bytes only if >=0 */
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            (*r>=0 && (int32_t)(s-s0)!=*r) ||
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            c!=*(r+1)
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ) {
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("%s ucnv_getNextUChar() result %lx from %d bytes, should have been %lx from %d bytes.\n",
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                message, c, (s-s0), *(r+1), *r);
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        r+=2;
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message)
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     const char* s=(char*)source;
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     UErrorCode errorCode=U_ZERO_ERROR;
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     uint32_t c;
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     c=ucnv_getNextUChar(cnv, &s, limit, &errorCode);
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     if(errorCode != expected){
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Expected:%s when %s-----Got:%s\n", myErrorName(expected), message, myErrorName(errorCode));
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     }
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     if(c != 0xFFFD && c != 0xffff){
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Expected return value of 0xfffd or 0xffff when %s-----Got 0x%lx\n", message, c);
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     }
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestInBufSizes(void)
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,1);
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 1
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,2);
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,3);
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,4);
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,5);
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,6);
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(1,1);
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(2,3);
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(3,2);
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestOutBufSizes(void)
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 1
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,NEW_MAX_BUFFER);
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(1,NEW_MAX_BUFFER);
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(2,NEW_MAX_BUFFER);
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(3,NEW_MAX_BUFFER);
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(4,NEW_MAX_BUFFER);
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TestNewConvertWithBufferSizes(5,NEW_MAX_BUFFER);
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid addTestNewConvert(TestNode** root)
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestInBufSizes, "tsconv/nucnvtst/TestInBufSizes");
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestOutBufSizes, "tsconv/nucnvtst/TestOutBufSizes");
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestConverterTypesAndStarters, "tsconv/nucnvtst/TestConverterTypesAndStarters");
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestAmbiguous, "tsconv/nucnvtst/TestAmbiguous");
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestSignatureDetection, "tsconv/nucnvtst/TestSignatureDetection");
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF7, "tsconv/nucnvtst/TestUTF7");
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestIMAP, "tsconv/nucnvtst/TestIMAP");
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF8, "tsconv/nucnvtst/TestUTF8");
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   /* test ucnv_getNextUChar() for charsets that encode single surrogates with complete byte sequences */
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestCESU8, "tsconv/nucnvtst/TestCESU8");
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF16, "tsconv/nucnvtst/TestUTF16");
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF16BE, "tsconv/nucnvtst/TestUTF16BE");
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF16LE, "tsconv/nucnvtst/TestUTF16LE");
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF32, "tsconv/nucnvtst/TestUTF32");
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF32BE, "tsconv/nucnvtst/TestUTF32BE");
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestUTF32LE, "tsconv/nucnvtst/TestUTF32LE");
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestLMBCS, "tsconv/nucnvtst/TestLMBCS");
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestLATIN1, "tsconv/nucnvtst/TestLATIN1");
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestSBCS, "tsconv/nucnvtst/TestSBCS");
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestDBCS, "tsconv/nucnvtst/TestDBCS");
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestICCRunout, "tsconv/nucnvtst/TestICCRunout");
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestMBCS, "tsconv/nucnvtst/TestMBCS");
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef U_ENABLE_GENERIC_ISO_2022
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022, "tsconv/nucnvtst/TestISO_2022");
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_JP, "tsconv/nucnvtst/TestISO_2022_JP");
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJIS, "tsconv/nucnvtst/TestJIS");
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_JP_1, "tsconv/nucnvtst/TestISO_2022_JP_1");
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_JP_2, "tsconv/nucnvtst/TestISO_2022_JP_2");
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_KR, "tsconv/nucnvtst/TestISO_2022_KR");
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_KR_1, "tsconv/nucnvtst/TestISO_2022_KR_1");
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_CN, "tsconv/nucnvtst/TestISO_2022_CN");
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   /*
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISO_2022_CN_EXT, "tsconv/nucnvtst/TestISO_2022_CN_EXT");
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug915, "tsconv/nucnvtst/TestJitterbug915");
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    */
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestHZ, "tsconv/nucnvtst/TestHZ");
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestSCSU, "tsconv/nucnvtst/TestSCSU");
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestEBCDIC_STATEFUL, "tsconv/nucnvtst/TestEBCDIC_STATEFUL");
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestGB18030, "tsconv/nucnvtst/TestGB18030");
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug255, "tsconv/nucnvtst/TestJitterbug255");
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestEBCDICUS4XML, "tsconv/nucnvtst/TestEBCDICUS4XML");
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestISCII, "tsconv/nucnvtst/TestISCII");
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJB5275, "tsconv/nucnvtst/TestJB5275");
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJB5275_1, "tsconv/nucnvtst/TestJB5275_1");
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_COLLATION
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug981, "tsconv/nucnvtst/TestJitterbug981");
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug1293, "tsconv/nucnvtst/TestJitterbug1293");
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS");
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestRoundTrippingAllUTF, "tsconv/nucnvtst/TestRoundTrippingAllUTF");
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346");
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411");
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175");
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   addTest(root, &TestIsFixedWidth, "tsconv/nucnvtst/TestIsFixedWidth");
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Note that this test already makes use of statics, so it's not really
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   multithread safe.
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   This convenience function lets us make the error messages actually useful.
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void setNuConvTestName(const char *codepage, const char *direction)
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        codepage,
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        direction,
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (int)gInBufferSize,
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (int)gOutBufferSize);
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgtypedef enum
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TC_OK       = 0,  /* test was OK */
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TC_MISMATCH = 1,  /* Match failed - err was printed */
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  TC_FAIL     = 2   /* Test failed, don't print an err because it was already printed. */
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org} ETestConvertResult;
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Note: This function uses global variables and it will not do offset
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgchecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic ETestConvertResult testConvertFromU( const UChar *source, int sourceLen,  const uint8_t *expect, int expectLen,
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                const char *codepage, const int32_t *expectOffsets , UBool useFallback)
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *conv = 0;
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char    junkout[NEW_MAX_BUFFER]; /* FIX */
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *p;
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar *src;
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *end;
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *targ;
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t *offs;
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i;
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t   realBufferSize;
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *realBufferEnd;
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar *realSourceEnd;
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar *sourceLimit;
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool checkOffsets = TRUE;
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool doFlush;
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<NEW_MAX_BUFFER;i++)
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        junkout[i] = (char)0xF0;
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<NEW_MAX_BUFFER;i++)
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        junokout[i] = 0xFF;
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setNuConvTestName(codepage, "FROM");
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("\n=========  %s\n", gNuConvTestName);
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    conv = my_ucnv_open(codepage, &status);
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status))
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("Couldn't open converter %s\n",codepage);
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_FAIL;
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(useFallback){
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_setFallback(conv,useFallback);
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Converter opened..\n");
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    src = source;
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    targ = junkout;
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    offs = junokout;
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realBufferEnd = junkout + realBufferSize;
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realSourceEnd = source + sourceLen;
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if ( gOutBufferSize != realBufferSize || gInBufferSize != NEW_MAX_BUFFER )
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        checkOffsets = FALSE;
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    do
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      end = nct_min(targ + gOutBufferSize, realBufferEnd);
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      doFlush = (UBool)(sourceLimit == realSourceEnd);
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if(targ == realBufferEnd) {
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_FAIL;
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      status = U_ZERO_ERROR;
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      ucnv_fromUnicode (conv,
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        &targ,
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        end,
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        &src,
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        sourceLimit,
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        checkOffsets ? offs : NULL,
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        doFlush, /* flush if we're at the end of the input data */
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        &status);
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && sourceLimit < realSourceEnd) );
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status)) {
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_err("Problem doing fromUnicode to %s, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName);
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      return TC_FAIL;
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                sourceLen, targ-junkout);
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(getTestOption(VERBOSITY_OPTION))
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      char junk[9999];
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      char offset_str[9999];
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      char *ptr;
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      junk[0] = 0;
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      offset_str[0] = 0;
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      for(ptr = junkout;ptr<targ;ptr++) {
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sprintf(junk + strlen(junk), "0x%02x, ", (int)(0xFF & *ptr));
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sprintf(offset_str + strlen(offset_str), "0x%02x, ", (int)(0xFF & junokout[ptr-junkout]));
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose(junk);
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printSeq((const uint8_t *)expect, expectLen);
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if ( checkOffsets ) {
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("\nOffsets:");
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose(offset_str);
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose("\n");
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(conv);
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(expectLen != targ-junkout) {
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      fprintf(stderr, "Got:\n");
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      fprintf(stderr, "Expected:\n");
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printSeqErr((const unsigned char*)expect, expectLen);
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      return TC_MISMATCH;
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (checkOffsets && (expectOffsets != 0) ) {
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose("comparing %d offsets..\n", targ-junkout);
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("did not get the expected offsets. %s\n", gNuConvTestName);
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("\n");
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Got  :     ");
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(p=junkout;p<targ;p++) {
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("%d,", junokout[p-junkout]);
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("\n");
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Expected:  ");
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(i=0; i<(targ-junkout); i++) {
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("%d,", expectOffsets[i]);
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("\n");
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("comparing..\n");
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!memcmp(junkout, expect, expectLen)) {
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_verbose("Matches!\n");
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      return TC_OK;
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_err("String does not match u->%s\n", gNuConvTestName);
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printUSeqErr(source, sourceLen);
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      fprintf(stderr, "Got:\n");
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printSeqErr((const unsigned char *)junkout, expectLen);
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      fprintf(stderr, "Expected:\n");
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      printSeqErr((const unsigned char *)expect, expectLen);
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      return TC_MISMATCH;
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Note: This function uses global variables and it will not do offset
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgchecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen,
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                          const char *codepage, const int32_t *expectOffsets, UBool useFallback)
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *conv = 0;
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar    junkout[NEW_MAX_BUFFER]; /* FIX */
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *src;
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *realSourceEnd;
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *srcLimit;
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar *p;
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar *targ;
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar *end;
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t *offs;
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i;
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool   checkOffsets = TRUE;
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t   realBufferSize;
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar *realBufferEnd;
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<NEW_MAX_BUFFER;i++)
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        junkout[i] = 0xFFFE;
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<NEW_MAX_BUFFER;i++)
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        junokout[i] = -1;
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setNuConvTestName(codepage, "TO");
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("\n=========  %s\n", gNuConvTestName);
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    conv = my_ucnv_open(codepage, &status);
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status))
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("Couldn't open converter %s\n",gNuConvTestName);
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_FAIL;
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(useFallback){
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_setFallback(conv,useFallback);
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Converter opened..\n");
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    src = (const char *)source;
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    targ = junkout;
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    offs = junokout;
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realBufferEnd = junkout + realBufferSize;
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    realSourceEnd = src + sourcelen;
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if ( gOutBufferSize != realBufferSize ||  gInBufferSize != NEW_MAX_BUFFER )
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        checkOffsets = FALSE;
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    do
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        end = nct_min( targ + gOutBufferSize, realBufferEnd);
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(targ == realBufferEnd)
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjet=%08lx %s",targ,gNuConvTestName);
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return TC_FAIL;
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* oldTarg = targ; */
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_toUnicode (conv,
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &targ,
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                end,
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &src,
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                srcLimit,
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                checkOffsets ? offs : NULL,
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of hte source data */
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &status);
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*        offs += (targ-oldTarg); */
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status))
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Problem doing %s toUnicode, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName);
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_FAIL;
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sourcelen, targ-junkout);
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(getTestOption(VERBOSITY_OPTION))
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char junk[9999];
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char offset_str[9999];
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *ptr;
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        junk[0] = 0;
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        offset_str[0] = 0;
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(ptr = junkout;ptr<targ;ptr++)
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*ptr);
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[ptr-junkout]);
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose(junk);
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printUSeq(expect, expectlen);
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( checkOffsets )
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          {
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("\nOffsets:");
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose(offset_str);
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          }
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("\n");
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(conv);
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (checkOffsets && (expectOffsets != 0))
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t))){
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("did not get the expected offsets. %s\n",gNuConvTestName);
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Got:      ");
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(p=junkout;p<targ;p++) {
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("%d,", junokout[p-junkout]);
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("\n");
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Expected: ");
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(i=0; i<(targ-junkout); i++) {
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("%d,", expectOffsets[i]);
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("\n");
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("output:   ");
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(i=0; i<(targ-junkout); i++) {
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("%X,", junkout[i]);
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("\n");
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("input:    ");
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(i=0; i<(src-(const char *)source); i++) {
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("%X,", (unsigned char)source[i]);
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("\n");
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!memcmp(junkout, expect, expectlen*2))
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("Matches!\n");
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_OK;
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("String does not match. %s\n", gNuConvTestName);
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("String does not match. %s\n", gNuConvTestName);
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("\nGot:");
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printUSeqErr(junkout, expectlen);
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("\nExpected:");
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printUSeqErr(expect, expectlen);
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return TC_MISMATCH;
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/** test chars #1 */
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*  1 2 3  1Han 2Han 3Han .  */
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar   sampleText[] =
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xD840, 0xDC21 };
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar sampleTextRoundTripUnmappable[] =
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xfffd };
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedUTF8[] =
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E, 0xf0, 0xa0, 0x80, 0xa1 };
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toUTF8Offs[] =
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x08, 0x08, 0x08, 0x08 };
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmUTF8Offs[] =
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d, 0x000e, 0x000e };
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef U_ENABLE_GENERIC_ISO_2022
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Same as UTF8, but with ^[%B preceeding */
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const const uint8_t expectedISO2022[] =
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x1b, 0x25, 0x42, 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E };
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toISO2022Offs[]     =
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { -1, -1, -1, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04,
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07 }; /* right? */
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmISO2022Offs[] =
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x000a, 0x000d, 0x0010 }; /* is this right? */
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*  1 2 3 0, <SO> h1 h2 h3 <SI> . EBCDIC_STATEFUL */
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedIBM930[] =
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0xF1, 0xF2, 0xF3, 0x00, 0x0E, 0x45, 0x41, 0x45, 0x42, 0x45, 0x43, 0x0F, 0x4B, 0x0e, 0xfe, 0xfe, 0x0f };
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toIBM930Offs[] =
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, -1 };
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmIBM930Offs[] =
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009, 0x000c, 0x000e };
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 1 2 3 0 h1 h2 h3 . MBCS*/
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedIBM943[] =
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0x31, 0x32, 0x33, 0x00, 0x88, 0xea, 0x93, 0xf1, 0x8e, 0x4f, 0x2e, 0xfc, 0xfc };
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toIBM943Offs    [] =
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08 };
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmIBM943Offs[] =
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0006, 0x0008, 0x000a, 0x000b };
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 1 2 3 0 h1 h2 h3 . DBCS*/
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedIBM9027[] =
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x4c, 0x41, 0x4c, 0x48, 0x4c, 0x55, 0xfe, 0xfe, 0xfe, 0xfe };
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toIBM9027Offs    [] =
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08 };
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     /* 1 2 3 0 <?> <?> <?> . SBCS*/
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedIBM920[] =
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2e, 0x1a };
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toIBM920Offs    [] =
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     {  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 1 2 3 0 <?> <?> <?> . SBCS*/
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedISO88593[] =
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a };
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toISO88593Offs[]     =
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 1 2 3 0 <?> <?> <?> . <?> LATIN_1*/
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedLATIN1[] =
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a };
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toLATIN1Offs[]     =
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*  etc */
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedUTF16BE[] =
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x4e, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x00, 0x2e, 0xd8, 0x40, 0xdc, 0x21 };
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toUTF16BEOffs[]=
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 };
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmUTF16BEOffs[] =
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c,  0x000e, 0x0010, 0x0010 };
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedUTF16LE[] =
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0x2e, 0x00, 0x40, 0xd8, 0x21, 0xdc };
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toUTF16LEOffs[]=
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06,  0x07, 0x07, 0x08, 0x08, 0x08, 0x08 };
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmUTF16LEOffs[] =
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 };
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedUTF32BE[] =
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x00, 0x00, 0x31,
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x00, 0x32,
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x00, 0x33,
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x00, 0x00,
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x4e, 0x00,
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x4e, 0x8c,
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x4e, 0x09,
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x00, 0x2e,
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x02, 0x00, 0x21 };
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toUTF32BEOffs[]=
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x00, 0x00, 0x00,
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x01, 0x01, 0x01, 0x01,
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x02, 0x02, 0x02, 0x02,
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x03, 0x03, 0x03, 0x03,
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x04, 0x04, 0x04, 0x04,
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x05, 0x05, 0x05, 0x05,
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x06, 0x06, 0x06, 0x06,
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x07, 0x07, 0x07, 0x07,
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x08, 0x08, 0x08, 0x08,
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x08, 0x08, 0x08, 0x08 };
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmUTF32BEOffs[] =
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018,  0x001c, 0x0020, 0x0020 };
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedUTF32LE[] =
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x31, 0x00, 0x00, 0x00,
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x32, 0x00, 0x00, 0x00,
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x33, 0x00, 0x00, 0x00,
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x00, 0x00, 0x00,
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x00, 0x4e, 0x00, 0x00,
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x8c, 0x4e, 0x00, 0x00,
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x09, 0x4e, 0x00, 0x00,
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x2e, 0x00, 0x00, 0x00,
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x21, 0x00, 0x02, 0x00 };
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toUTF32LEOffs[]=
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x00, 0x00, 0x00, 0x00,
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x01, 0x01, 0x01, 0x01,
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x02, 0x02, 0x02, 0x02,
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x03, 0x03, 0x03, 0x03,
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x04, 0x04, 0x04, 0x04,
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x05, 0x05, 0x05, 0x05,
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x06, 0x06, 0x06, 0x06,
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x07, 0x07, 0x07, 0x07,
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x08, 0x08, 0x08, 0x08,
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       0x08, 0x08, 0x08, 0x08 };
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmUTF32LEOffs[] =
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 };
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/** Test chars #2 **/
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Sahha [health],  slashed h's */
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar malteseUChars[] = { 0x0053, 0x0061, 0x0127, 0x0127, 0x0061 };
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedMaltese913[] = { 0x53, 0x61, 0xB1, 0xB1, 0x61 };
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* LMBCS */
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const UChar LMBCSUChars[]     = { 0x0027, 0x010A, 0x0000, 0x0127, 0x2666, 0x0220 };
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t expectedLMBCS[] = { 0x27, 0x06, 0x04, 0x00, 0x01, 0x73, 0x01, 0x04, 0x14, 0x02, 0x20 };
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t toLMBCSOffs[]   = { 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x04 , 0x05, 0x05, 0x05 };
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t fmLMBCSOffs[]   = { 0x0000, 0x0001, 0x0003, 0x0004, 0x0006, 0x0008};
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*********************************** START OF CODE finally *************/
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    gInBufferSize = insize;
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    gOutBufferSize = outsize;
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("\n\n\nTesting conversions with InputBufferSize = %d, OutputBufferSize = %d\n", gInBufferSize, gOutBufferSize);
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF-8*/
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs,FALSE );
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Test surrogate behaviour for UTF8\n");
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar testinput[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01 };
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t expectedUTF8test2[]= { 0xe2, 0x82, 0xac,
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                           0xf0, 0x90, 0x90, 0x81,
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                           0xef, 0xbf, 0xbd
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3 };
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(testinput, sizeof(testinput)/sizeof(testinput[0]),
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                         expectedUTF8test2, sizeof(expectedUTF8test2), "UTF8", offsets,FALSE );
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022)
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*ISO-2022*/
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedISO2022, sizeof(expectedISO2022), "ISO_2022", toISO2022Offs,FALSE );
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF16 LE*/
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs,FALSE );
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF16 BE*/
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedUTF16BE, sizeof(expectedUTF16BE), "utf-16be", toUTF16BEOffs,FALSE );
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF32 LE*/
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedUTF32LE, sizeof(expectedUTF32LE), "utf-32le", toUTF32LEOffs,FALSE );
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF32 BE*/
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedUTF32BE, sizeof(expectedUTF32BE), "utf-32be", toUTF32BEOffs,FALSE );
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*LATIN_1*/
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedLATIN1, sizeof(expectedLATIN1), "LATIN_1", toLATIN1Offs,FALSE );
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*EBCDIC_STATEFUL*/
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs,FALSE );
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE );
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*MBCS*/
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs,FALSE );
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*DBCS*/
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedIBM9027, sizeof(expectedIBM9027), "@ibm9027", toIBM9027Offs,FALSE );
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*SBCS*/
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedIBM920, sizeof(expectedIBM920), "ibm-920", toIBM920Offs,FALSE );
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*SBCS*/
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE );
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/****/
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF-8*/
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF8, sizeof(expectedUTF8),
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs,FALSE);
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022)
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*ISO-2022*/
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedISO2022, sizeof(expectedISO2022),
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ISO_2022", fmISO2022Offs,FALSE);
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF16 LE*/
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE);
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF16 BE*/
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF16BE, sizeof(expectedUTF16BE),
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16be", fmUTF16BEOffs,FALSE);
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF32 LE*/
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF32LE, sizeof(expectedUTF32LE),
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32le", fmUTF32LEOffs,FALSE);
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*UTF32 BE*/
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF32BE, sizeof(expectedUTF32BE),
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32be", fmUTF32BEOffs,FALSE);
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*EBCDIC_STATEFUL*/
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleTextRoundTripUnmappable,
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-930", fmIBM930Offs,FALSE);
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*MBCS*/
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedIBM943, sizeof(expectedIBM943),sampleTextRoundTripUnmappable,
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-943", fmIBM943Offs,FALSE);
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Try it again to make sure it still works */
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE);
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedMaltese913, sizeof(expectedMaltese913),
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]), "latin3", NULL,FALSE);
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]),
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedMaltese913, sizeof(expectedMaltese913), "iso-8859-3", NULL,FALSE );
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*LMBCS*/
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertFromU(LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]),
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedLMBCS, sizeof(expectedLMBCS), "LMBCS-1", toLMBCSOffs,FALSE );
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testConvertToU(expectedLMBCS, sizeof(expectedLMBCS),
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]), "LMBCS-1", fmLMBCSOffs,FALSE);
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* UTF-7 examples are mostly from http://www.imc.org/rfc2152 */
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* encode directly set D and set O */
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf7[] = {
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                Hi Mom -+Jjo--!
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                A+ImIDkQ.
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                +-
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                +ZeVnLIqe-
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            */
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21,
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2b, 0x2d,
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar unicode[] = {
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                Hi Mom -<WHITE SMILING FACE>-!
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                A<NOT IDENTICAL TO><ALPHA>.
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                +
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                [Japanese word "nihongo"]
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            */
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21,
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x41, 0x2262, 0x0391, 0x2e,
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2b,
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x65e5, 0x672c, 0x8a9e
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t toUnicodeOffsets[] = {
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14,
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            15, 17, 19, 23,
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            24,
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            27, 29, 32
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t fromUnicodeOffsets[] = {
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10,
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            11, 12, 12, 12, 13, 13, 13, 13, 14,
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            15, 15,
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            16, 16, 16, 17, 17, 17, 18, 18, 18, 18
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* same but escaping set O (the exclamation mark) */
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf7Restricted[] = {
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                Hi Mom -+Jjo--+ACE-
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                A+ImIDkQ.
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                +-
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                +ZeVnLIqe-
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            */
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d,
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2b, 0x2d,
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t toUnicodeOffsetsR[] = {
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15,
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            19, 21, 23, 27,
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            28,
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            31, 33, 36
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t fromUnicodeOffsetsR[] = {
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10,
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            11, 12, 12, 12, 13, 13, 13, 13, 14,
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            15, 15,
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            16, 16, 16, 17, 17, 17, 18, 18, 18, 18
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE);
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(utf7, sizeof(utf7), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7", toUnicodeOffsets,FALSE);
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7Restricted, sizeof(utf7Restricted), "UTF-7,version=1", fromUnicodeOffsetsR,FALSE);
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(utf7Restricted, sizeof(utf7Restricted), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7,version=1", toUnicodeOffsetsR,FALSE);
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * IMAP-mailbox-name examples are mostly from http://www.imc.org/rfc2152,
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * modified according to RFC 2060,
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * and supplemented with the one example in RFC 2060 itself.
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t imap[] = {
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*  Hi Mom -&Jjo--!
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                A&ImIDkQ-.
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &-
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &ZeVnLIqe-
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                \
10406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ~peter
10416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /mail
10426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /&ZeVnLIqe-
10436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /&U,BTFw-
10446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            */
10456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x26, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21,
10466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x41, 0x26, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2d, 0x2e,
10476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x26, 0x2d,
10486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d,
10496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x5c,
10506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x7e, 0x70, 0x65, 0x74, 0x65, 0x72,
10516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x6d, 0x61, 0x69, 0x6c,
10526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d,
10536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x26, 0x55, 0x2c, 0x42, 0x54, 0x46, 0x77, 0x2d
10546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar unicode[] = {
10566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*  Hi Mom -<WHITE SMILING FACE>-!
10576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                A<NOT IDENTICAL TO><ALPHA>.
10586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                &
10596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                [Japanese word "nihongo"]
10606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                \
10616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ~peter
10626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /mail
10636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /<65e5, 672c, 8a9e>
10646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /<53f0, 5317>
10656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            */
10666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21,
10676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x41, 0x2262, 0x0391, 0x2e,
10686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x26,
10696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x65e5, 0x672c, 0x8a9e,
10706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x5c,
10716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x7e, 0x70, 0x65, 0x74, 0x65, 0x72,
10726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x6d, 0x61, 0x69, 0x6c,
10736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x65e5, 0x672c, 0x8a9e,
10746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x2f, 0x53f0, 0x5317
10756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t toUnicodeOffsets[] = {
10776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14,
10786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            15, 17, 19, 24,
10796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            25,
10806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            28, 30, 33,
10816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            37,
10826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            38, 39, 40, 41, 42, 43,
10836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            44, 45, 46, 47, 48,
10846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            49, 51, 53, 56,
10856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            60, 62, 64
10866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t fromUnicodeOffsets[] = {
10886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10,
10896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            11, 12, 12, 12, 13, 13, 13, 13, 13, 14,
10906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            15, 15,
10916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            16, 16, 16, 17, 17, 17, 18, 18, 18, 18,
10926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            19,
10936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            20, 21, 22, 23, 24, 25,
10946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            26, 27, 28, 29, 30,
10956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34,
10966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            35, 36, 36, 36, 37, 37, 37, 37, 37
10976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
10986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, imap, sizeof(imap), "IMAP-mailbox-name", fromUnicodeOffsets,FALSE);
11006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(imap, sizeof(imap), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "IMAP-mailbox-name", toUnicodeOffsets,FALSE);
11026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test UTF-8 bad data handling*/
11056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf8[]={
11076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x61,
11086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xf7, 0xbf, 0xbf, 0xbf,         /* > 10FFFF */
11096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00,
11106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62,
11116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfb, 0xbf, 0xbf, 0xbf, 0xbf,   /* > 10FFFF */
11126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfb, 0xbf, 0xbf, 0xbf, 0xbf,   /* > 10FFFF */
11136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xf4, 0x8f, 0xbf, 0xbf,         /* 10FFFF */
11146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xdf, 0xbf,                     /* 7ff */
11156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xbf,                           /* truncated tail */
11166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xf4, 0x90, 0x80, 0x80,         /* 11FFFF */
11176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x02
11186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint16_t utf8Expected[]={
11216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0061,
11226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,
11236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0000,
11246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0062,
11256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,
11266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,
11276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xdbff, 0xdfff,
11286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x07ff,
11296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,
11306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,
11316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0002
11326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t utf8Offsets[]={
11356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 1, 5, 6, 7, 12, 17, 17, 21, 23, 24, 28
11366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(utf8, sizeof(utf8),
11386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                       utf8Expected, sizeof(utf8Expected)/sizeof(utf8Expected[0]), "utf-8", utf8Offsets ,FALSE);
11396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test UTF-32BE bad data handling*/
11436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf32[]={
11456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x00, 0x61,
11466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x11, 0x00, 0x00,         /* 0x110000 out of range */
11476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x10, 0xff, 0xff,         /* 0x10FFFF in range */
11486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x00, 0x62,
11496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
11506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x7f, 0xff, 0xff, 0xff,         /* 0x7fffffff out of range */
11516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x01, 0x62,
11526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x02, 0x62
11536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint16_t utf32Expected[]={
11556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0061,
11566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0x110000 out of range */
11576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xDBFF,         /* 0x10FFFF in range */
11586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xDFFF,
11596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0062,
11606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0xffffffff out of range */
11616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0x7fffffff out of range */
11626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0162,
11636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0262
11646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t utf32Offsets[]={
11666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 4, 8, 8, 12, 16, 20, 24, 28
11676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf32ExpectedBack[]={
11696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x00, 0x61,
11706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0xff, 0xfd,         /* 0x110000 out of range */
11716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x10, 0xff, 0xff,         /* 0x10FFFF in range */
11726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x00, 0x62,
11736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0xff, 0xfd,         /* 0xffffffff out of range */
11746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0xff, 0xfd,         /* 0x7fffffff out of range */
11756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x01, 0x62,
11766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x02, 0x62
11776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t utf32OffsetsBack[]={
11796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0,0,0,0,
11806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            1,1,1,1,
11816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,2,2,2,
11826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,4,4,4,
11836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            5,5,5,5,
11846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            6,6,6,6,
11856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            7,7,7,7,
11866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            8,8,8,8
11876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
11886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(utf32, sizeof(utf32),
11906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                       utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32be", utf32Offsets ,FALSE);
11916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]),
11926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32be", utf32OffsetsBack, FALSE);
11936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test UTF-32LE bad data handling*/
11966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf32[]={
11986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x61, 0x00, 0x00, 0x00,
11996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x00, 0x00, 0x11, 0x00,         /* 0x110000 out of range */
12006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xff, 0xff, 0x10, 0x00,         /* 0x10FFFF in range */
12016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x00, 0x00, 0x00,
12026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
12036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xff, 0xff, 0xff, 0x7f,         /* 0x7fffffff out of range */
12046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x01, 0x00, 0x00,
12056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x02, 0x00, 0x00,
12066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
12076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint16_t utf32Expected[]={
12096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0061,
12106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0x110000 out of range */
12116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xDBFF,         /* 0x10FFFF in range */
12126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xDFFF,
12136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0062,
12146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0xffffffff out of range */
12156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfffd,         /* 0x7fffffff out of range */
12166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0162,
12176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x0262
12186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
12196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t utf32Offsets[]={
12206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0, 4, 8, 8, 12, 16, 20, 24, 28
12216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
12226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t utf32ExpectedBack[]={
12236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x61, 0x00, 0x00, 0x00,
12246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfd, 0xff, 0x00, 0x00,         /* 0x110000 out of range */
12256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xff, 0xff, 0x10, 0x00,         /* 0x10FFFF in range */
12266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x00, 0x00, 0x00,
12276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfd, 0xff, 0x00, 0x00,         /* 0xffffffff out of range */
12286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0xfd, 0xff, 0x00, 0x00,         /* 0x7fffffff out of range */
12296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x01, 0x00, 0x00,
12306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0x62, 0x02, 0x00, 0x00
12316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
12326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t utf32OffsetsBack[]={
12336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0,0,0,0,
12346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            1,1,1,1,
12356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,2,2,2,
12366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,4,4,4,
12376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            5,5,5,5,
12386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            6,6,6,6,
12396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            7,7,7,7,
12406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            8,8,8,8
12416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
12426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(utf32, sizeof(utf32),
12436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32le", utf32Offsets,FALSE );
12446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]),
12456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32le", utf32OffsetsBack, FALSE);
12466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestCoverageMBCS(){
12506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
12516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
12526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *directory = loadTestData(&status);
12536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char* tdpath = NULL;
12546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char* saveDirectory = (char*)malloc(sizeof(char) *(strlen(u_getDataDirectory())+1));
12556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int len = strlen(directory);
12566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char* index=NULL;
12576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    tdpath = (char*) malloc(sizeof(char) * (len * 2));
12596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uprv_strcpy(saveDirectory,u_getDataDirectory());
12606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Retrieved data directory %s \n",saveDirectory);
12616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uprv_strcpy(tdpath,directory);
12626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    index=strrchr(tdpath,(char)U_FILE_SEP_CHAR);
12636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if((unsigned int)(index-tdpath) != (strlen(tdpath)-1)){
12656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            *(index+1)=0;
12666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_setDataDirectory(tdpath);
12686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("ICU data directory is set to: %s \n" ,tdpath);
12696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*some more test to increase the code coverage in MBCS.  Create an test converter from test1.ucm
12726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      which is test file for MBCS conversion with single-byte codepage data.*/
12736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
12746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* MBCS with single byte codepage data test1.ucm*/
12766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0x0003};
12776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const uint8_t expectedtest1[] = { 0x00, 0x05, 0xff, 0x07, 0xff,};
12786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t  totest1Offs[]        = { 0, 1, 2, 3, 5, };
12796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*from Unicode*/
12816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
12826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedtest1, sizeof(expectedtest1), "@test1", totest1Offs,FALSE );
12836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*some more test to increase the code coverage in MBCS.  Create an test converter from test3.ucm
12866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      which is test file for MBCS conversion with three-byte codepage data.*/
12876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
12886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* MBCS with three byte codepage data test3.ucm*/
12906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e};
12916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const uint8_t expectedtest3[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x0b,  0x07,  0x01, 0x02, 0x0a,  0xff,};
12926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t  totest3Offs[]        = { 0, 1, 2, 3, 3, 3, 4, 6, 6, 6, 8};
12936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const uint8_t test3input[]    = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x0b,  0x07,  0x01, 0x02, 0x0a, 0x01, 0x02, 0x0c,};
12956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd};
12966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t fromtest3Offs[]       = { 0, 1, 2, 3, 6, 6, 7, 7, 10 };
12976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*from Unicode*/
12996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
13006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedtest3, sizeof(expectedtest3), "@test3", totest3Offs,FALSE );
13016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*to Unicode*/
13036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(test3input, sizeof(test3input),
13046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", fromtest3Offs ,FALSE);
13056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*some more test to increase the code coverage in MBCS.  Create an test converter from test4.ucm
13096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      which is test file for MBCS conversion with four-byte codepage data.*/
13106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
13116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* MBCS with three byte codepage data test4.ucm*/
13136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e};
13146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t expectedtest4[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x03, 0x0b,  0x07,  0x01, 0x02, 0x03, 0x0a,  0xff,};
13156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t totest4Offs[]   = { 0, 1, 2, 3, 3, 3, 3, 4, 6, 6, 6, 6, 8,};
13166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t test4input[]    = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x03, 0x0b,  0x07,  0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0c,};
13186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd};
13196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t fromtest4Offs[] = { 0, 1, 2, 3, 7, 7, 8, 8, 12,};
13206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*from Unicode*/
13226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
13236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedtest4, sizeof(expectedtest4), "@test4", totest4Offs,FALSE );
13246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*to Unicode*/
13266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testConvertToU(test4input, sizeof(test4input),
13276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", fromtest4Offs,FALSE );
13286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
13316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    free(tdpath);
13326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* restore the original data directory */
13336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Setting the data directory to %s \n", saveDirectory);
13346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_setDataDirectory(saveDirectory);
13356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    free(saveDirectory);
13366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
13376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestConverterType(const char *convName, UConverterType convType) {
13416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter* myConverter;
13426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode err = U_ZERO_ERROR;
13436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    myConverter = my_ucnv_open(convName, &err);
13456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(err)) {
13476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("Failed to create an %s converter\n", convName);
13486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
13496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else
13516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
13526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (ucnv_getType(myConverter)!=convType) {
13536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ucnv_getType Failed for %s. Got enum value 0x%X\n",
13546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                convName, convType);
13556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
13576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("ucnv_getType %s ok\n", convName);
13586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(myConverter);
13616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestConverterTypesAndStarters()
13646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
13666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter* myConverter;
13676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode err = U_ZERO_ERROR;
13686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool mystarters[256];
13696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*    const UBool expectedKSCstarters[256] = {
13716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
13856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
13896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
13966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};*/
13976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing KSC, ibm-930, ibm-878  for starters and their conversion types.");
14006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    myConverter = ucnv_open("ksc", &err);
14026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(err)) {
14036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      log_data_err("Failed to create an ibm-ksc converter\n");
14046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      return;
14056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else
14076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
14086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (ucnv_getType(myConverter)!=UCNV_MBCS)
14096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ucnv_getType Failed for ibm-949\n");
14106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
14116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("ucnv_getType ibm-949 ok\n");
14126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(myConverter!=NULL)
14146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ucnv_getStarters(myConverter, mystarters, &err);
14156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*if (memcmp(expectedKSCstarters, mystarters, sizeof(expectedKSCstarters)))
14176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("Failed ucnv_getStarters for ksc\n");
14186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          else
14196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_verbose("ucnv_getStarters ok\n");*/
14206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(myConverter);
14236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("ibm-930", UCNV_EBCDIC_STATEFUL);
14256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("ibm-878", UCNV_SBCS);
14266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
14276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("iso-8859-1", UCNV_LATIN_1);
14296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("ibm-1208", UCNV_UTF8);
14316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("utf-8", UCNV_UTF8);
14336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("UTF-16BE", UCNV_UTF16_BigEndian);
14346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("UTF-16LE", UCNV_UTF16_LittleEndian);
14356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("UTF-32BE", UCNV_UTF32_BigEndian);
14366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("UTF-32LE", UCNV_UTF32_LittleEndian);
14376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
14396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if defined(U_ENABLE_GENERIC_ISO_2022)
14416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("iso-2022", UCNV_ISO_2022);
14426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
14436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("hz", UCNV_HZ);
14456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
14466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("scsu", UCNV_SCSU);
14486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
14506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("x-iscii-de", UCNV_ISCII);
14516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
14526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("ascii", UCNV_US_ASCII);
14546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("utf-7", UCNV_UTF7);
14556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("IMAP-mailbox-name", UCNV_IMAP_MAILBOX);
14566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestConverterType("bocu-1", UCNV_BOCU1);
14576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
14606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestAmbiguousConverter(UConverter *cnv) {
14616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char inBytes[3]={ 0x61, 0x5B, 0x5c };
14626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar outUnicode[20]={ 0, 0, 0, 0 };
14636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *s;
14656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar *u;
14666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode;
14676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool isAmbiguous;
14686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* try to convert an 'a', a square bracket and a US-ASCII backslash */
14706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errorCode=U_ZERO_ERROR;
14716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s=inBytes;
14726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u=outUnicode;
14736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_toUnicode(cnv, &u, u+20, &s, s+3, NULL, TRUE, &errorCode);
14746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
14756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* we do not care about general failures in this test; the input may just not be mappable */
14766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
14776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(outUnicode[0]!=0x61 || outUnicode[1]!=0x5B || outUnicode[2]==0xfffd) {
14806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* not a close ASCII-family encoding, or 0x5c is unassigned/illegal: this test is not applicable */
14816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* There are some encodings that are partially ASCII based,
14826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        like the ISO-7 and GSM series of codepages, which we ignore. */
14836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
14846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    isAmbiguous=ucnv_isAmbiguous(cnv);
14876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* check that outUnicode[1]!=0x5c is exactly the same as ucnv_isAmbiguous() */
14896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if((outUnicode[2]!=0x5c)!=isAmbiguous) {
14906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("error: converter \"%s\" needs a backslash fix: %d but ucnv_isAmbiguous()==%d\n",
14916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ucnv_getName(cnv, &errorCode), outUnicode[2]!=0x5c, isAmbiguous);
14926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
14936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(outUnicode[2]!=0x5c) {
14966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* needs fixup, fix it */
14976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_fixFileSeparator(cnv, outUnicode, (int32_t)(u-outUnicode));
14986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(outUnicode[2]!=0x5c) {
14996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* the fix failed */
15006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("error: ucnv_fixFileSeparator(%s) failed\n", ucnv_getName(cnv, &errorCode));
15016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
15026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestAmbiguous()
15076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
15086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
15096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *ascii_cnv = 0, *sjis_cnv = 0, *cnv;
15106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char target[] = {
15116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* "\\usr\\local\\share\\data\\icutest.txt" */
15126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x5c, 0x75, 0x73, 0x72,
15136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x5c, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
15146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x5c, 0x73, 0x68, 0x61, 0x72, 0x65,
15156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x5c, 0x64, 0x61, 0x74, 0x61,
15166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x5c, 0x69, 0x63, 0x75, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74,
15176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0
15186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
15196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar asciiResult[200], sjisResult[200];
15206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t /*asciiLength = 0,*/ sjisLength = 0, i;
15216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *name;
15226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* enumerate all converters */
15246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status=U_ZERO_ERROR;
15256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0; (name=ucnv_getAvailableName(i))!=NULL; ++i) {
15266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cnv=ucnv_open(name, &status);
15276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_SUCCESS(status)) {
15286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            TestAmbiguousConverter(cnv);
15296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ucnv_close(cnv);
15306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
15316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("error: unable to open available converter \"%s\"\n", name);
15326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
15336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_LEGACY_CONVERSION
15376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sjis_cnv = ucnv_open("ibm-943", &status);
15386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
15396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("Failed to create a SJIS converter\n");
15416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
15426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ascii_cnv = ucnv_open("LATIN-1", &status);
15446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
15456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("Failed to create a LATIN-1 converter\n");
15476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(sjis_cnv);
15486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
15496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* convert target from SJIS to Unicode */
15516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sjisLength = ucnv_toUChars(sjis_cnv, sjisResult, sizeof(sjisResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status);
15526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
15536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Failed to convert the SJIS string.\n");
15556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(sjis_cnv);
15566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(ascii_cnv);
15576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
15586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* convert target from Latin-1 to Unicode */
15606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*asciiLength =*/ ucnv_toUChars(ascii_cnv, asciiResult, sizeof(asciiResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status);
15616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
15626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Failed to convert the Latin-1 string.\n");
15646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(sjis_cnv);
15656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(ascii_cnv);
15666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
15676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!ucnv_isAmbiguous(sjis_cnv))
15696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("SJIS converter should contain ambiguous character mappings.\n");
15716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(sjis_cnv);
15726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_close(ascii_cnv);
15736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
15746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(sjisResult, asciiResult) == 0)
15766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("File separators for SJIS don't need to be fixed.\n");
15786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_fixFileSeparator(sjis_cnv, sjisResult, sjisLength);
15806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (u_strcmp(sjisResult, asciiResult) != 0)
15816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Fixing file separator for SJIS failed.\n");
15836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(sjis_cnv);
15856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(ascii_cnv);
15866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
15876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
15906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestSignatureDetection(){
15916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* with null terminated strings */
15926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char* data[] = {
15946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF\x00\x00",     /* UTF-16BE */
15956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x00\x00",     /* UTF-16LE */
15966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF\x00",     /* UTF-8    */
15976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF\x00",     /* SCSU     */
15986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF",             /* UTF-16BE */
16006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE",             /* UTF-16LE */
16016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF",         /* UTF-8    */
16026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF",         /* SCSU     */
16036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF\x41\x42",     /* UTF-16BE */
16056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x41\x41",     /* UTF-16LE */
16066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF\x41",     /* UTF-8    */
16076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF\x41",     /* SCSU     */
16086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x2B\x2F\x76\x38\x2D", /* UTF-7    */
16106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x2B\x2F\x76\x38\x41", /* UTF-7    */
16116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x2B\x2F\x76\x39\x41", /* UTF-7    */
16126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x2B\x2F\x76\x2B\x41", /* UTF-7    */
16136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x2B\x2F\x76\x2F\x41",  /* UTF-7    */
16146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xDD\x73\x66\x73"      /* UTF-EBCDIC */
16166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
16176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char* expected[] = {
16186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
16196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
16206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
16216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
16226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
16246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
16256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
16266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
16276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
16296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
16306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
16316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
16326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-7",
16346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-7",
16356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-7",
16366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-7",
16376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-7",
16386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-EBCDIC"
16396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
16406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t expectedLength[] ={
16416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
16536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            5,
16576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
16586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
16596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
16606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
16616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4
16626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
16636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int i=0;
16646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode err;
16656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t signatureLength = -1;
16666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* source = NULL;
16676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* enc = NULL;
16686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for( ; i<sizeof(data)/sizeof(char*); i++){
16696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err = U_ZERO_ERROR;
16706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            source = data[i];
16716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            enc = ucnv_detectUnicodeSignature(source, -1 , &signatureLength, &err);
16726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(U_FAILURE(err)){
16736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err));
16746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
16756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(enc == NULL || strcmp(enc,expected[i]) !=0){
16776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc);
16786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
16796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(signatureLength != expectedLength[i]){
16816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]);
16826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char* data[] = {
16876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF\x00",         /* UTF-16BE */
16886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x00",         /* UTF-16LE */
16896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF\x00",     /* UTF-8    */
16906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF\x00",     /* SCSU     */
16916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x00\x00\xFE\xFF",     /* UTF-32BE */
16926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x00\x00",     /* UTF-32LE */
16936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF",             /* UTF-16BE */
16946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE",             /* UTF-16LE */
16956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF",         /* UTF-8    */
16966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF",         /* SCSU     */
16976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x00\x00\xFE\xFF",     /* UTF-32BE */
16986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x00\x00",     /* UTF-32LE */
16996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFE\xFF\x41\x42",     /* UTF-16BE */
17006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x41\x41",     /* UTF-16LE */
17016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xEF\xBB\xBF\x41",     /* UTF-8    */
17026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x0E\xFE\xFF\x41",     /* SCSU     */
17036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\x00\x00\xFE\xFF\x41", /* UTF-32BE */
17046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\xFE\x00\x00\x42", /* UTF-32LE */
17056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFB\xEE\x28",         /* BOCU-1   */
17066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\xFF\x41\x42"          /* NULL     */
17076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
17086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int len[] = {
17096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            5,
17266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            5,
17276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3
17296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
17306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char* expected[] = {
17326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
17336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
17346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
17356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
17366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32BE",
17376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32LE",
17386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
17396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
17406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
17416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
17426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32BE",
17436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32LE",
17446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16BE",
17456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-16LE",
17466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-8",
17476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "SCSU",
17486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32BE",
17496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "UTF-32LE",
17506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "BOCU-1",
17516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                NULL
17526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
17536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const int32_t expectedLength[] ={
17546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            2,
17686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            4,
17726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
17736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0
17746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
17756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int i=0;
17766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode err;
17776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t signatureLength = -1;
17786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t sourceLength=-1;
17796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* source = NULL;
17806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* enc = NULL;
17816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for( ; i<sizeof(data)/sizeof(char*); i++){
17826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err = U_ZERO_ERROR;
17836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            source = data[i];
17846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sourceLength = len[i];
17856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            enc = ucnv_detectUnicodeSignature(source, sourceLength , &signatureLength, &err);
17866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(U_FAILURE(err)){
17876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err));
17886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
17896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(enc == NULL || strcmp(enc,expected[i]) !=0){
17916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(expected[i] !=NULL){
17926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc);
17936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                 continue;
17946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
17956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(signatureLength != expectedLength[i]){
17976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]);
17986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF7() {
18046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
18056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
18066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* H - +Jjo- - ! +- +2AHcAQ */
18076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x48,
18086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2d,
18096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2b, 0x4a, 0x6a, 0x6f,
18106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2d, 0x2d,
18116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x21,
18126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2b, 0x2d,
18136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2b, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51
18146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
18156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
18176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
18186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
18196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x48,
18206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x2d,
18216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x263a, /* <WHITE SMILING FACE> */
18226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x2d,
18236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x21,
18246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x2b,
18256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        7, 0x10401
18266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
18276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *cnvName;
18296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
18306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
18316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("UTF-7", &errorCode);
18326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
18336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF-7 converter: %s\n", u_errorName(errorCode)); /* sholdn't be a data err */
18346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
18356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "UTF-7");
18376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
18386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
18396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cnvName = ucnv_getName(cnv, &errorCode);
18406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "UTF-7") != 0) {
18416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("UTF-7 converter is called %s: %s\n", cnvName, u_errorName(errorCode));
18426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
18446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestIMAP() {
18476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
18486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
18496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* H - &Jjo- - ! &- &2AHcAQ- \ */
18506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x48,
18516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2d,
18526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x26, 0x4a, 0x6a, 0x6f,
18536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x2d, 0x2d,
18546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x21,
18556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x26, 0x2d,
18566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x26, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51, 0x2d
18576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
18586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
18606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
18616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
18626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x48,
18636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x2d,
18646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x263a, /* <WHITE SMILING FACE> */
18656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x2d,
18666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x21,
18676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x26,
18686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        7, 0x10401
18696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
18706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *cnvName;
18726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
18736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
18746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("IMAP-mailbox-name", &errorCode);
18756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
18766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a IMAP-mailbox-name converter: %s\n", u_errorName(errorCode)); /* sholdn't be a data err */
18776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
18786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "IMAP-mailbox-name");
18806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
18816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
18826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cnvName = ucnv_getName(cnv, &errorCode);
18836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "IMAP-mailbox-name") != 0) {
18846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("IMAP-mailbox-name converter is called %s: %s\n", cnvName, u_errorName(errorCode));
18856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
18876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF8() {
18906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
18916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
18926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61,
18936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc2, 0x80,
18946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xe0, 0xa0, 0x80,
18956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x90, 0x80, 0x80,
18966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf4, 0x84, 0x8c, 0xa1,
18976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x90, 0x90, 0x81
18986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
18996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
19016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
19026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
19036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x61,
19046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x80,
19056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        3, 0x800,
19066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10000,
19076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x104321,
19086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10401
19096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* error test input */
19126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in2[]={
19136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61,
19146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc0, 0x80,                     /* illegal non-shortest form */
19156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xe0, 0x80, 0x80,               /* illegal non-shortest form */
19166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x80, 0x80, 0x80,         /* illegal non-shortest form */
19176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc0, 0xc0,                     /* illegal trail byte */
19186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf4, 0x90, 0x80, 0x80,         /* 0x110000 out of range */
19196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf8, 0x80, 0x80, 0x80, 0x80,   /* too long */
19206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xfe,                           /* illegal byte altogether */
19216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x62
19226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected error test results */
19256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results2[]={
19266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
19276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x61,
19286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        22, 0x62
19296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverterToUCallback cb;
19326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const void *p;
19336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in,*limit=(const char *)in+sizeof(in);
19356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
19366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("UTF-8", &errorCode);
19376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
19386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF-8 converter: %s\n", u_errorName(errorCode));
19396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "UTF-8");
19426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
19436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
19446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test error behavior with a skip callback */
19466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
19476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in2;
19486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    limit=(const char *)(in2+sizeof(in2));
19496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results2, "UTF-8");
19506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
19526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestCESU8() {
19556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
19566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
19576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61,
19586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc2, 0x80,
19596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xe0, 0xa0, 0x80,
19606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80,
19616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xed, 0xb0, 0x81, 0xed, 0xa0, 0x82,
19626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf,
19636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xef, 0xbf, 0xbc
19646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
19676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
19686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
19696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x61,
19706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x80,
19716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        3, 0x800,
19726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        6, 0x10000,
19736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        3, 0xdc01,
19746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        -1,0xd802,  /* may read 3 or 6 bytes */
19756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        -1,0x10ffff,/* may read 0 or 3 bytes */
19766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        3, 0xfffc
19776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* error test input */
19806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in2[]={
19816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61,
19826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc0, 0x80,                     /* illegal non-shortest form */
19836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xe0, 0x80, 0x80,               /* illegal non-shortest form */
19846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x80, 0x80, 0x80,         /* illegal non-shortest form */
19856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xc0, 0xc0,                     /* illegal trail byte */
19866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x90, 0x80, 0x80,         /* illegal 4-byte supplementary code point */
19876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf4, 0x84, 0x8c, 0xa1,         /* illegal 4-byte supplementary code point */
19886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf0, 0x90, 0x90, 0x81,         /* illegal 4-byte supplementary code point */
19896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf4, 0x90, 0x80, 0x80,         /* 0x110000 out of range */
19906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xf8, 0x80, 0x80, 0x80, 0x80,   /* too long */
19916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xfe,                           /* illegal byte altogether */
19926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x62
19936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
19946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected error test results */
19966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results2[]={
19976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
19986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        1, 0x61,
19996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        34, 0x62
20006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverterToUCallback cb;
20036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const void *p;
20046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in,*limit=(const char *)in+sizeof(in);
20066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
20076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("CESU-8", &errorCode);
20086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
20096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a CESU-8 converter: %s\n", u_errorName(errorCode));
20106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "CESU-8");
20136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
20146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
20156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test error behavior with a skip callback */
20176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
20186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in2;
20196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    limit=(const char *)(in2+sizeof(in2));
20206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results2, "CESU-8");
20216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
20236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF16() {
20266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
20276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in1[]={
20286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xfe, 0xff, 0x4e, 0x00, 0xfe, 0xff
20296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in2[]={
20316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xff, 0xfe, 0x4e, 0x00, 0xfe, 0xff
20326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in3[]={
20346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xfe, 0xfe, 0x4e, 0x00, 0xfe, 0xff, 0xd8, 0x40, 0xdc, 0x01
20356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
20386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results1[]={
20396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
20406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x4e00,
20416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xfeff
20426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results2[]={
20446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
20456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x004e,
20466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xfffe
20476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results3[]={
20496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
20506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xfefe,
20516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x4e00,
20526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xfeff,
20536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x20001
20546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source, *limit;
20576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
20596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("UTF-16", &errorCode);
20606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
20616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF-16 converter: %s\n", u_errorName(errorCode));
20626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in1, limit=(const char *)in1+sizeof(in1);
20666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results1, "UTF-16");
20676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in2, limit=(const char *)in2+sizeof(in2);
20696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
20706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results2, "UTF-16");
20716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in3, limit=(const char *)in3+sizeof(in3);
20736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
20746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results3, "UTF-16");
20756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
20776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
20786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
20796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
20816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF16BE() {
20846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
20856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
20866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x61,
20876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0xc0,
20886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x31,
20896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0xf4,
20906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xce, 0xfe,
20916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xd8, 0x01, 0xdc, 0x01
20926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
20956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
20966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
20976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x61,
20986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xc0,
20996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x31,
21006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xf4,
21016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0xcefe,
21026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10401
21036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
21066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
21076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("utf-16be", &errorCode);
21086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
21096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF16-BE converter: %s\n", u_errorName(errorCode));
21106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
21116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "UTF-16BE");
21136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
21146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
21156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*Test for the condition where there is an invalid character*/
21166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
21176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t source2[]={0x61};
21186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
21196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
21206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
21226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
21236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Test disabled because currently the UTF-16BE/LE converters are supposed
21246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * to not set errors for unpaired surrogates.
21256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * This may change with
21266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
21276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
21286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*Test for the condition where there is a surrogate pair*/
21306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
21316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const uint8_t source2[]={0xd8, 0x01};
21326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
21336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
21356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
21366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
21396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestUTF16LE() {
21406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
21416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
21426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61, 0x00,
21436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x31, 0x00,
21446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x4e, 0x2e,
21456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x4e, 0x00,
21466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x01, 0xd8, 0x01, 0xdc
21476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
21506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
21516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
21526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x61,
21536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x31,
21546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x2e4e,
21556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        2, 0x4e,
21566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10401
21576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
21606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
21616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("utf-16le", &errorCode);
21626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
21636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF16-LE converter: %s\n", u_errorName(errorCode));
21646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
21656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "UTF-16LE");
21676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
21686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
21696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*Test for the condition where there is an invalid character*/
21706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
21716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t source2[]={0x61};
21726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
21736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
21746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
21766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
21776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Test disabled because currently the UTF-16BE/LE converters are supposed
21786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * to not set errors for unpaired surrogates.
21796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * This may change with
21806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
21816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
21826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*Test for the condition where there is a surrogate character*/
21846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
21856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const uint8_t source2[]={0x01, 0xd8};
21866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
21876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
21896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
21916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUTF32() {
21946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
21956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in1[]={
21966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xfe, 0xff,   0x00, 0x10, 0x0f, 0x00,   0x00, 0x00, 0xfe, 0xff
21976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in2[]={
21996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xff, 0xfe, 0x00, 0x00,   0x00, 0x10, 0x0f, 0x00,   0xfe, 0xff, 0x00, 0x00
22006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in3[]={
22026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xfe, 0xfe,   0x00, 0x10, 0x0f, 0x00,   0x00, 0x00, 0xd8, 0x40,   0x00, 0x00, 0xdc, 0x01
22036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
22066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results1[]={
22076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
22086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        8, 0x100f00,
22096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfeff
22106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results2[]={
22126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
22136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        8, 0x0f1000,
22146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffe
22156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results3[]={
22176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
22186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfefe,
22196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x100f00,
22206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd, /* unmatched surrogate */
22216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd  /* unmatched surrogate */
22226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source, *limit;
22256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
22276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("UTF-32", &errorCode);
22286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
22296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF-32 converter: %s\n", u_errorName(errorCode));
22306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
22316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in1, limit=(const char *)in1+sizeof(in1);
22346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results1, "UTF-32");
22356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in2, limit=(const char *)in2+sizeof(in2);
22376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
22386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results2, "UTF-32");
22396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in3, limit=(const char *)in3+sizeof(in3);
22416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
22426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results3, "UTF-32");
22436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
22456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_resetToUnicode(cnv);
22466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
22476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
22496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
22506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
22526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestUTF32BE() {
22536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
22546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
22556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x00, 0x61,
22566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x30, 0x61,
22576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xdc, 0x00,
22586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xd8, 0x00,
22596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xdf, 0xff,
22606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0xff, 0xfe,
22616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x10, 0xab, 0xcd,
22626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x10, 0xff, 0xff
22636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
22666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
22676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
22686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x61,
22696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x3061,
22706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
22716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
22726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
22736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffe,
22746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10abcd,
22756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x10ffff
22766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* error test input */
22796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in2[]={
22806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x00, 0x61,
22816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x11, 0x00, 0x00,         /* 0x110000 out of range */
22826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x00, 0x62,
22836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
22846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x7f, 0xff, 0xff, 0xff,         /* 0x7fffffff out of range */
22856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x01, 0x62,
22866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0x00, 0x02, 0x62
22876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected error test results */
22906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results2[]={
22916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
22926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4,  0x61,
22936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        8,  0x62,
22946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        12, 0x162,
22956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4,  0x262
22966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverterToUCallback cb;
22996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const void *p;
23006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
23026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
23036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UConverter *cnv=ucnv_open("UTF-32BE", &errorCode);
23046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
23056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Unable to open a UTF-32BE converter: %s\n", u_errorName(errorCode));
23066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
23076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
23086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results, "UTF-32BE");
23096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test the condition when source >= sourceLimit */
23116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
23126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test error behavior with a skip callback */
23146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
23156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source=(const char *)in2;
23166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    limit=(const char *)(in2+sizeof(in2));
23176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TestNextUChar(cnv, source, limit, results2, "UTF-32BE");
23186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(cnv);
23206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
23216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
23236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgTestUTF32LE() {
23246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test input */
23256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const uint8_t in[]={
23266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61, 0x00, 0x00, 0x00,
23276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x61, 0x30, 0x00, 0x00,
23286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0xdc, 0x00, 0x00,
23296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x00, 0xd8, 0x00, 0x00,
23306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xff, 0xdf, 0x00, 0x00,
23316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xfe, 0xff, 0x00, 0x00,
23326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xcd, 0xab, 0x10, 0x00,
23336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0xff, 0xff, 0x10, 0x00
23346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
23356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* expected test results */
23376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t results[]={
23386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* number of bytes read, code point */
23396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x61,
23406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0x3061,
23416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
23426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
23436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4, 0xfffd,
23446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        4