1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
3fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius * Copyright (c) 1997-2014, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*******************************************************************************
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CCONVTST.C
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*        Name                     Description
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*    Steven R. Loomis     7/8/1999      Adding input buffer test
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************************
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv_err.h"
2085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "unicode/ucnv_cb.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucol.h"
25103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#include "unicode/utf16.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h"
2750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "nucnvtst.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
30b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message);
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message);
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug981(void);
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
3654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#if !UCONFIG_NO_LEGACY_CONVERSION
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug1293(void);
3854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#endif
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ;
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestConverterTypesAndStarters(void);
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAmbiguous(void);
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSignatureDetection(void);
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF7(void);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestIMAP(void);
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF8(void);
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestCESU8(void);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF16(void);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF16BE(void);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF16LE(void);
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF32(void);
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF32BE(void);
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUTF32LE(void);
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestLATIN1(void);
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSBCS(void);
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDBCS(void);
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestMBCS(void);
5950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO
6050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestICCRunout(void);
6150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_ENABLE_GENERIC_ISO_2022
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022(void);
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_JP(void);
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_JP_1(void);
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_JP_2(void);
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_KR(void);
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_KR_1(void);
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_CN(void);
7327f654740f2a26ad62a5c155af9199af9e69b889claireho#if 0
7427f654740f2a26ad62a5c155af9199af9e69b889claireho   /*
7527f654740f2a26ad62a5c155af9199af9e69b889claireho    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
7627f654740f2a26ad62a5c155af9199af9e69b889claireho    */
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISO_2022_CN_EXT(void);
7827f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJIS(void);
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestHZ(void);
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSCSU(void);
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestEBCDIC_STATEFUL(void);
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestGB18030(void);
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestLMBCS(void);
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug255(void);
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestEBCDICUS4XML(void);
9127f654740f2a26ad62a5c155af9199af9e69b889claireho#if 0
9227f654740f2a26ad62a5c155af9199af9e69b889claireho   /*
9327f654740f2a26ad62a5c155af9199af9e69b889claireho    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
9427f654740f2a26ad62a5c155af9199af9e69b889claireho    */
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug915(void);
9627f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestISCII(void);
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestCoverageMBCS(void);
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug2346(void);
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJitterbug2411(void);
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJB5275(void);
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestJB5275_1(void);
10485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestJitterbug6175(void);
105b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
106b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestIsFixedWidth(void);
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
10950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestInBufSizes(void);
11050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestRoundTrippingAllUTF(void);
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestConv(const uint16_t in[],
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                     int len,
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                     const char* conv,
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                     const char* lang,
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                     char byteArr[],
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                     int byteArrLen);
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* open a converter, using test data if it begins with '@' */
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err);
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define NEW_MAX_BUFFER 999
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t  gInBufferSize = NEW_MAX_BUFFER;
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t  gOutBufferSize = NEW_MAX_BUFFER;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char     gNuConvTestName[1024];
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define nct_min(x,y)  ((x<y) ? x : y)
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UConverter *my_ucnv_open(const char *cnv, UErrorCode *err)
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(cnv && cnv[0] == '@') {
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return ucnv_openPackage(loadTestData(err), cnv+1, err);
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } else {
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return ucnv_open(cnv, err);
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void printSeq(const unsigned char* a, int len)
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i=0;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("{");
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (i<len)
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("0x%02x ", a[i++]);
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("}\n");
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void printUSeq(const UChar* a, int len)
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i=0;
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("{U+");
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (i<len) log_verbose("0x%04x ", a[i++]);
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("}\n");
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void printSeqErr(const unsigned char* a, int len)
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i=0;
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr, "{");
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (i<len)
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "0x%02x ", a[i++]);
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr, "}\n");
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void printUSeqErr(const UChar* a, int len)
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i=0;
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr, "{U+");
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (i<len)
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "0x%04x ", a[i++]);
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,"}\n");
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message)
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* s0;
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* s=(char*)source;
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const int32_t *r=results;
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UErrorCode errorCode=U_ZERO_ERROR;
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UChar32 c;
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     while(s<limit) {
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        s0=s;
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        c=ucnv_getNextUChar(cnv, &s, limit, &errorCode);
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(errorCode==U_INDEX_OUTOFBOUNDS_ERROR) {
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break; /* no more significant input */
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else if(U_FAILURE(errorCode)) {
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("%s ucnv_getNextUChar() failed: %s\n", message, u_errorName(errorCode));
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else if(
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* test the expected number of input bytes only if >=0 */
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            (*r>=0 && (int32_t)(s-s0)!=*r) ||
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            c!=*(r+1)
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ) {
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("%s ucnv_getNextUChar() result %lx from %d bytes, should have been %lx from %d bytes.\n",
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                message, c, (s-s0), *(r+1), *r);
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        r+=2;
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message)
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* s=(char*)source;
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UErrorCode errorCode=U_ZERO_ERROR;
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t c;
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     c=ucnv_getNextUChar(cnv, &s, limit, &errorCode);
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     if(errorCode != expected){
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Expected:%s when %s-----Got:%s\n", myErrorName(expected), message, myErrorName(errorCode));
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     if(c != 0xFFFD && c != 0xffff){
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Expected return value of 0xfffd or 0xffff when %s-----Got 0x%lx\n", message, c);
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestInBufSizes(void)
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,1);
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,2);
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,3);
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,4);
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,5);
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,6);
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(1,1);
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(2,3);
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(3,2);
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestOutBufSizes(void)
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,NEW_MAX_BUFFER);
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(1,NEW_MAX_BUFFER);
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(2,NEW_MAX_BUFFER);
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(3,NEW_MAX_BUFFER);
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(4,NEW_MAX_BUFFER);
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TestNewConvertWithBufferSizes(5,NEW_MAX_BUFFER);
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addTestNewConvert(TestNode** root)
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
25250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FILE_IO
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestInBufSizes, "tsconv/nucnvtst/TestInBufSizes");
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestOutBufSizes, "tsconv/nucnvtst/TestOutBufSizes");
25550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestConverterTypesAndStarters, "tsconv/nucnvtst/TestConverterTypesAndStarters");
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestAmbiguous, "tsconv/nucnvtst/TestAmbiguous");
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestSignatureDetection, "tsconv/nucnvtst/TestSignatureDetection");
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF7, "tsconv/nucnvtst/TestUTF7");
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestIMAP, "tsconv/nucnvtst/TestIMAP");
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF8, "tsconv/nucnvtst/TestUTF8");
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* test ucnv_getNextUChar() for charsets that encode single surrogates with complete byte sequences */
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestCESU8, "tsconv/nucnvtst/TestCESU8");
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF16, "tsconv/nucnvtst/TestUTF16");
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF16BE, "tsconv/nucnvtst/TestUTF16BE");
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF16LE, "tsconv/nucnvtst/TestUTF16LE");
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF32, "tsconv/nucnvtst/TestUTF32");
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF32BE, "tsconv/nucnvtst/TestUTF32BE");
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestUTF32LE, "tsconv/nucnvtst/TestUTF32LE");
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestLMBCS, "tsconv/nucnvtst/TestLMBCS");
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestLATIN1, "tsconv/nucnvtst/TestLATIN1");
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestSBCS, "tsconv/nucnvtst/TestSBCS");
28050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FILE_IO
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestDBCS, "tsconv/nucnvtst/TestDBCS");
28250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   addTest(root, &TestICCRunout, "tsconv/nucnvtst/TestICCRunout");
28350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestMBCS, "tsconv/nucnvtst/TestMBCS");
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_ENABLE_GENERIC_ISO_2022
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISO_2022, "tsconv/nucnvtst/TestISO_2022");
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
28959d709d503bab6e2b61931737e662dd293b40578ccornelius
290103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius   addTest(root, &TestISO_2022_JP, "tsconv/nucnvtst/TestISO_2022_JP");
291b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   addTest(root, &TestJIS, "tsconv/nucnvtst/TestJIS");
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISO_2022_JP_1, "tsconv/nucnvtst/TestISO_2022_JP_1");
29359d709d503bab6e2b61931737e662dd293b40578ccornelius   // android-changed (no have ISO_2022_JP_2) -- addTest(root, &TestISO_2022_JP_2, "tsconv/nucnvtst/TestISO_2022_JP_2");
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISO_2022_KR, "tsconv/nucnvtst/TestISO_2022_KR");
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISO_2022_KR_1, "tsconv/nucnvtst/TestISO_2022_KR_1");
29659d709d503bab6e2b61931737e662dd293b40578ccornelius   // android-changed (no ISO-2022-CN) -- addTest(root, &TestISO_2022_CN, "tsconv/nucnvtst/TestISO_2022_CN");
29750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   /*
29850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISO_2022_CN_EXT, "tsconv/nucnvtst/TestISO_2022_CN_EXT");
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJitterbug915, "tsconv/nucnvtst/TestJitterbug915");
30150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    */
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestHZ, "tsconv/nucnvtst/TestHZ");
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestSCSU, "tsconv/nucnvtst/TestSCSU");
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestEBCDIC_STATEFUL, "tsconv/nucnvtst/TestEBCDIC_STATEFUL");
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestGB18030, "tsconv/nucnvtst/TestGB18030");
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJitterbug255, "tsconv/nucnvtst/TestJitterbug255");
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestEBCDICUS4XML, "tsconv/nucnvtst/TestEBCDICUS4XML");
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestISCII, "tsconv/nucnvtst/TestISCII");
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJB5275, "tsconv/nucnvtst/TestJB5275");
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJB5275_1, "tsconv/nucnvtst/TestJB5275_1");
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
31659d709d503bab6e2b61931737e662dd293b40578ccornelius   // android-removed (no collation tailoring rules)  -- addTest(root, &TestJitterbug981, "tsconv/nucnvtst/TestJitterbug981");
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJitterbug1293, "tsconv/nucnvtst/TestJitterbug1293");
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
32350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS");
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestRoundTrippingAllUTF, "tsconv/nucnvtst/TestRoundTrippingAllUTF");
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346");
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411");
33259d709d503bab6e2b61931737e662dd293b40578ccornelius   // android-removed (no full ISO2022 CJK tables)  -- addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175");
333b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   addTest(root, &TestIsFixedWidth, "tsconv/nucnvtst/TestIsFixedWidth");
334b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#endif
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Note that this test already makes use of statics, so it's not really
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   multithread safe.
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   This convenience function lets us make the error messages actually useful.
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void setNuConvTestName(const char *codepage, const char *direction)
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        codepage,
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        direction,
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)gInBufferSize,
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)gOutBufferSize);
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef enum
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TC_OK       = 0,  /* test was OK */
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TC_MISMATCH = 1,  /* Match failed - err was printed */
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  TC_FAIL     = 2   /* Test failed, don't print an err because it was already printed. */
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} ETestConvertResult;
358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Note: This function uses global variables and it will not do offset
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic ETestConvertResult testConvertFromU( const UChar *source, int sourceLen,  const uint8_t *expect, int expectLen,
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                const char *codepage, const int32_t *expectOffsets , UBool useFallback)
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *conv = 0;
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char    junkout[NEW_MAX_BUFFER]; /* FIX */
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *p;
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *src;
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *end;
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *targ;
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t *offs;
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t   realBufferSize;
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *realBufferEnd;
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *realSourceEnd;
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *sourceLimit;
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool checkOffsets = TRUE;
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool doFlush;
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<NEW_MAX_BUFFER;i++)
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        junkout[i] = (char)0xF0;
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<NEW_MAX_BUFFER;i++)
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        junokout[i] = 0xFF;
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setNuConvTestName(codepage, "FROM");
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("\n=========  %s\n", gNuConvTestName);
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    conv = my_ucnv_open(codepage, &status);
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status))
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open converter %s\n",codepage);
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_FAIL;
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(useFallback){
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_setFallback(conv,useFallback);
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Converter opened..\n");
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    src = source;
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    targ = junkout;
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    offs = junokout;
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realBufferEnd = junkout + realBufferSize;
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realSourceEnd = source + sourceLen;
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( gOutBufferSize != realBufferSize || gInBufferSize != NEW_MAX_BUFFER )
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        checkOffsets = FALSE;
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    do
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      end = nct_min(targ + gOutBufferSize, realBufferEnd);
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      doFlush = (UBool)(sourceLimit == realSourceEnd);
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(targ == realBufferEnd) {
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_FAIL;
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      status = U_ZERO_ERROR;
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucnv_fromUnicode (conv,
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        &targ,
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        end,
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        &src,
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        sourceLimit,
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        checkOffsets ? offs : NULL,
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        doFlush, /* flush if we're at the end of the input data */
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        &status);
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && sourceLimit < realSourceEnd) );
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Problem doing fromUnicode to %s, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName);
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return TC_FAIL;
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                sourceLen, targ-junkout);
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44827f654740f2a26ad62a5c155af9199af9e69b889claireho    if(getTestOption(VERBOSITY_OPTION))
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char junk[9999];
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char offset_str[9999];
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char *ptr;
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      junk[0] = 0;
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      offset_str[0] = 0;
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      for(ptr = junkout;ptr<targ;ptr++) {
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sprintf(junk + strlen(junk), "0x%02x, ", (int)(0xFF & *ptr));
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sprintf(offset_str + strlen(offset_str), "0x%02x, ", (int)(0xFF & junokout[ptr-junkout]));
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose(junk);
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printSeq((const uint8_t *)expect, expectLen);
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if ( checkOffsets ) {
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("\nOffsets:");
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose(offset_str);
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("\n");
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(conv);
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(expectLen != targ-junkout) {
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
474b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho      fprintf(stderr, "Got:\n");
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
476b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho      fprintf(stderr, "Expected:\n");
477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printSeqErr((const unsigned char*)expect, expectLen);
478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return TC_MISMATCH;
479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (checkOffsets && (expectOffsets != 0) ) {
482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("comparing %d offsets..\n", targ-junkout);
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("did not get the expected offsets. %s\n", gNuConvTestName);
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("\n");
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Got  :     ");
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(p=junkout;p<targ;p++) {
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_err("%d,", junokout[p-junkout]);
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("\n");
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Expected:  ");
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i=0; i<(targ-junkout); i++) {
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_err("%d,", expectOffsets[i]);
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("\n");
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("comparing..\n");
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!memcmp(junkout, expect, expectLen)) {
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("Matches!\n");
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return TC_OK;
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("String does not match u->%s\n", gNuConvTestName);
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printUSeqErr(source, sourceLen);
507b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho      fprintf(stderr, "Got:\n");
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printSeqErr((const unsigned char *)junkout, expectLen);
509b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho      fprintf(stderr, "Expected:\n");
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      printSeqErr((const unsigned char *)expect, expectLen);
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return TC_MISMATCH;
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Note: This function uses global variables and it will not do offset
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchecking without gOutBufferSize and gInBufferSize set to NEW_MAX_BUFFER */
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen,
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                          const char *codepage, const int32_t *expectOffsets, UBool useFallback)
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *conv = 0;
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar    junkout[NEW_MAX_BUFFER]; /* FIX */
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *src;
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *realSourceEnd;
527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *srcLimit;
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *p;
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *targ;
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *end;
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t *offs;
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool   checkOffsets = TRUE;
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t   realBufferSize;
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *realBufferEnd;
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<NEW_MAX_BUFFER;i++)
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        junkout[i] = 0xFFFE;
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<NEW_MAX_BUFFER;i++)
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        junokout[i] = -1;
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setNuConvTestName(codepage, "TO");
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("\n=========  %s\n", gNuConvTestName);
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    conv = my_ucnv_open(codepage, &status);
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status))
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open converter %s\n",gNuConvTestName);
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_FAIL;
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(useFallback){
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_setFallback(conv,useFallback);
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Converter opened..\n");
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    src = (const char *)source;
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    targ = junkout;
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    offs = junokout;
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realBufferEnd = junkout + realBufferSize;
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    realSourceEnd = src + sourcelen;
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( gOutBufferSize != realBufferSize ||  gInBufferSize != NEW_MAX_BUFFER )
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        checkOffsets = FALSE;
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    do
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        end = nct_min( targ + gOutBufferSize, realBufferEnd);
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(targ == realBufferEnd)
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjet=%08lx %s",targ,gNuConvTestName);
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return TC_FAIL;
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* oldTarg = targ; */
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_toUnicode (conv,
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &targ,
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                end,
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &src,
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                srcLimit,
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                checkOffsets ? offs : NULL,
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of hte source data */
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &status);
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*        offs += (targ-oldTarg); */
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status))
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Problem doing %s toUnicode, errcode %s %s\n", codepage, myErrorName(status), gNuConvTestName);
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_FAIL;
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sourcelen, targ-junkout);
60927f654740f2a26ad62a5c155af9199af9e69b889claireho    if(getTestOption(VERBOSITY_OPTION))
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char junk[9999];
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char offset_str[9999];
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar *ptr;
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        junk[0] = 0;
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        offset_str[0] = 0;
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(ptr = junkout;ptr<targ;ptr++)
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*ptr);
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[ptr-junkout]);
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose(junk);
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printUSeq(expect, expectlen);
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if ( checkOffsets )
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          {
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("\nOffsets:");
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose(offset_str);
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          }
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("\n");
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(conv);
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (checkOffsets && (expectOffsets != 0))
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t))){
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("did not get the expected offsets. %s\n",gNuConvTestName);
641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("Got:      ");
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(p=junkout;p<targ;p++) {
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("%d,", junokout[p-junkout]);
644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("\n");
646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("Expected: ");
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(i=0; i<(targ-junkout); i++) {
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("%d,", expectOffsets[i]);
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("\n");
651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("output:   ");
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(i=0; i<(targ-junkout); i++) {
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("%X,", junkout[i]);
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("\n");
656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("input:    ");
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(i=0; i<(src-(const char *)source); i++) {
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("%X,", (unsigned char)source[i]);
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("\n");
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!memcmp(junkout, expect, expectlen*2))
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Matches!\n");
667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_OK;
668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("String does not match. %s\n", gNuConvTestName);
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("String does not match. %s\n", gNuConvTestName);
673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printf("\nGot:");
674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printUSeqErr(junkout, expectlen);
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printf("\nExpected:");
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        printUSeqErr(expect, expectlen);
677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TC_MISMATCH;
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** test chars #1 */
685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*  1 2 3  1Han 2Han 3Han .  */
686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar   sampleText[] =
68785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xD840, 0xDC21 };
68885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    static const UChar sampleTextRoundTripUnmappable[] =
68985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xfffd };
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedUTF8[] =
69385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E, 0xf0, 0xa0, 0x80, 0xa1 };
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toUTF8Offs[] =
69585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x08, 0x08, 0x08, 0x08 };
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmUTF8Offs[] =
69785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d, 0x000e, 0x000e };
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_ENABLE_GENERIC_ISO_2022
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Same as UTF8, but with ^[%B preceeding */
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const const uint8_t expectedISO2022[] =
702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x1b, 0x25, 0x42, 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E };
703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toISO2022Offs[]     =
704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { -1, -1, -1, 0x00, 0x01, 0x02, 0x03, 0x04, 0x04,
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07 }; /* right? */
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmISO2022Offs[] =
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x000a, 0x000d, 0x0010 }; /* is this right? */
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*  1 2 3 0, <SO> h1 h2 h3 <SI> . EBCDIC_STATEFUL */
711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedIBM930[] =
71285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0xF1, 0xF2, 0xF3, 0x00, 0x0E, 0x45, 0x41, 0x45, 0x42, 0x45, 0x43, 0x0F, 0x4B, 0x0e, 0xfe, 0xfe, 0x0f };
713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toIBM930Offs[] =
71485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, -1 };
715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmIBM930Offs[] =
71685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009, 0x000c, 0x000e };
717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* 1 2 3 0 h1 h2 h3 . MBCS*/
719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedIBM943[] =
72085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0x31, 0x32, 0x33, 0x00, 0x88, 0xea, 0x93, 0xf1, 0x8e, 0x4f, 0x2e, 0xfc, 0xfc };
721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toIBM943Offs    [] =
72285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08 };
723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmIBM943Offs[] =
72485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0006, 0x0008, 0x000a, 0x000b };
725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* 1 2 3 0 h1 h2 h3 . DBCS*/
727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedIBM9027[] =
72885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x4c, 0x41, 0x4c, 0x48, 0x4c, 0x55, 0xfe, 0xfe, 0xfe, 0xfe };
729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toIBM9027Offs    [] =
73085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08 };
731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     /* 1 2 3 0 <?> <?> <?> . SBCS*/
733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedIBM920[] =
73485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2e, 0x1a };
735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toIBM920Offs    [] =
73685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     {  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* 1 2 3 0 <?> <?> <?> . SBCS*/
739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedISO88593[] =
74085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a };
741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toISO88593Offs[]     =
74285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* 1 2 3 0 <?> <?> <?> . <?> LATIN_1*/
745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedLATIN1[] =
74685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a };
747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toLATIN1Offs[]     =
74885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*  etc */
752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedUTF16BE[] =
75385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x4e, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x00, 0x2e, 0xd8, 0x40, 0xdc, 0x21 };
754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toUTF16BEOffs[]=
75585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 };
756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmUTF16BEOffs[] =
75785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c,  0x000e, 0x0010, 0x0010 };
758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedUTF16LE[] =
76085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0x2e, 0x00, 0x40, 0xd8, 0x21, 0xdc };
761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toUTF16LEOffs[]=
76285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06,  0x07, 0x07, 0x08, 0x08, 0x08, 0x08 };
763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmUTF16LEOffs[] =
76485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 };
765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedUTF32BE[] =
767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x00, 0x00, 0x00, 0x31,
768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x00, 0x32,
769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x00, 0x33,
770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x00, 0x00,
771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x4e, 0x00,
772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x4e, 0x8c,
773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x4e, 0x09,
77485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x00, 0x00, 0x00, 0x2e,
77585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x00, 0x02, 0x00, 0x21 };
776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toUTF32BEOffs[]=
777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x00, 0x00, 0x00, 0x00,
778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x01, 0x01, 0x01, 0x01,
779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x02, 0x02, 0x02, 0x02,
780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x03, 0x03, 0x03, 0x03,
781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x04, 0x04, 0x04, 0x04,
782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x05, 0x05, 0x05, 0x05,
783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x06, 0x06, 0x06, 0x06,
784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x07, 0x07, 0x07, 0x07,
78585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x08, 0x08, 0x08, 0x08,
786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x08, 0x08, 0x08, 0x08 };
787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmUTF32BEOffs[] =
78885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018,  0x001c, 0x0020, 0x0020 };
789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedUTF32LE[] =
791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x31, 0x00, 0x00, 0x00,
792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x32, 0x00, 0x00, 0x00,
793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x33, 0x00, 0x00, 0x00,
794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x00, 0x00, 0x00,
795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x00, 0x4e, 0x00, 0x00,
796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x8c, 0x4e, 0x00, 0x00,
797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x09, 0x4e, 0x00, 0x00,
79885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x2e, 0x00, 0x00, 0x00,
79985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x21, 0x00, 0x02, 0x00 };
800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toUTF32LEOffs[]=
801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     { 0x00, 0x00, 0x00, 0x00,
802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x01, 0x01, 0x01, 0x01,
803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x02, 0x02, 0x02, 0x02,
804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x03, 0x03, 0x03, 0x03,
805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x04, 0x04, 0x04, 0x04,
806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x05, 0x05, 0x05, 0x05,
807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x06, 0x06, 0x06, 0x06,
808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x07, 0x07, 0x07, 0x07,
80985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho       0x08, 0x08, 0x08, 0x08,
810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       0x08, 0x08, 0x08, 0x08 };
811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmUTF32LEOffs[] =
81285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 };
813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** Test chars #2 **/
818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Sahha [health],  slashed h's */
820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar malteseUChars[] = { 0x0053, 0x0061, 0x0127, 0x0127, 0x0061 };
821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedMaltese913[] = { 0x53, 0x61, 0xB1, 0xB1, 0x61 };
822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* LMBCS */
824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar LMBCSUChars[]     = { 0x0027, 0x010A, 0x0000, 0x0127, 0x2666, 0x0220 };
825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t expectedLMBCS[] = { 0x27, 0x06, 0x04, 0x00, 0x01, 0x73, 0x01, 0x04, 0x14, 0x02, 0x20 };
826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t toLMBCSOffs[]   = { 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x04 , 0x05, 0x05, 0x05 };
827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t fmLMBCSOffs[]   = { 0x0000, 0x0001, 0x0003, 0x0004, 0x0006, 0x0008};
828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*********************************** START OF CODE finally *************/
829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    gInBufferSize = insize;
831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    gOutBufferSize = outsize;
832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("\n\n\nTesting conversions with InputBufferSize = %d, OutputBufferSize = %d\n", gInBufferSize, gOutBufferSize);
834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF-8*/
837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs,FALSE );
839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test surrogate behaviour for UTF8\n");
841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const UChar testinput[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01 };
843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t expectedUTF8test2[]= { 0xe2, 0x82, 0xac,
844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           0xf0, 0x90, 0x90, 0x81,
845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           0xef, 0xbf, 0xbd
846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3 };
848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(testinput, sizeof(testinput)/sizeof(testinput[0]),
849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                         expectedUTF8test2, sizeof(expectedUTF8test2), "UTF8", offsets,FALSE );
850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022)
855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*ISO-2022*/
856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedISO2022, sizeof(expectedISO2022), "ISO_2022", toISO2022Offs,FALSE );
858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF16 LE*/
861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs,FALSE );
863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF16 BE*/
864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedUTF16BE, sizeof(expectedUTF16BE), "utf-16be", toUTF16BEOffs,FALSE );
866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF32 LE*/
867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedUTF32LE, sizeof(expectedUTF32LE), "utf-32le", toUTF32LEOffs,FALSE );
869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF32 BE*/
870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedUTF32BE, sizeof(expectedUTF32BE), "utf-32be", toUTF32BEOffs,FALSE );
872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*LATIN_1*/
874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedLATIN1, sizeof(expectedLATIN1), "LATIN_1", toLATIN1Offs,FALSE );
876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*EBCDIC_STATEFUL*/
879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs,FALSE );
881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE );
884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*MBCS*/
886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs,FALSE );
889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*DBCS*/
890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedIBM9027, sizeof(expectedIBM9027), "@ibm9027", toIBM9027Offs,FALSE );
892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*SBCS*/
893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedIBM920, sizeof(expectedIBM920), "ibm-920", toIBM920Offs,FALSE );
895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*SBCS*/
896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE );
898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/****/
902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF-8*/
904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF8, sizeof(expectedUTF8),
905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs,FALSE);
906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022)
907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*ISO-2022*/
908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedISO2022, sizeof(expectedISO2022),
909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ISO_2022", fmISO2022Offs,FALSE);
910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF16 LE*/
913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE);
915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF16 BE*/
916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF16BE, sizeof(expectedUTF16BE),
917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16be", fmUTF16BEOffs,FALSE);
918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF32 LE*/
919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF32LE, sizeof(expectedUTF32LE),
920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32le", fmUTF32LEOffs,FALSE);
921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*UTF32 BE*/
922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF32BE, sizeof(expectedUTF32BE),
923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32be", fmUTF32BEOffs,FALSE);
924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*EBCDIC_STATEFUL*/
92785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleTextRoundTripUnmappable,
92885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-930", fmIBM930Offs,FALSE);
929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*MBCS*/
93085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    testConvertToU(expectedIBM943, sizeof(expectedIBM943),sampleTextRoundTripUnmappable,
93185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-943", fmIBM943Offs,FALSE);
932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Try it again to make sure it still works */
935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE);
937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedMaltese913, sizeof(expectedMaltese913),
940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]), "latin3", NULL,FALSE);
941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]),
943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedMaltese913, sizeof(expectedMaltese913), "iso-8859-3", NULL,FALSE );
944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*LMBCS*/
946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertFromU(LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]),
947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        expectedLMBCS, sizeof(expectedLMBCS), "LMBCS-1", toLMBCSOffs,FALSE );
948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testConvertToU(expectedLMBCS, sizeof(expectedLMBCS),
949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]), "LMBCS-1", fmLMBCSOffs,FALSE);
950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* UTF-7 examples are mostly from http://www.imc.org/rfc2152 */
953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* encode directly set D and set O */
955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf7[] = {
956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*
957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                Hi Mom -+Jjo--!
958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                A+ImIDkQ.
959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                +-
960b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                +ZeVnLIqe-
961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            */
962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21,
963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2b, 0x2d,
965b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const UChar unicode[] = {
968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*
969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                Hi Mom -<WHITE SMILING FACE>-!
970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                A<NOT IDENTICAL TO><ALPHA>.
971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                +
972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                [Japanese word "nihongo"]
973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            */
974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21,
975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x41, 0x2262, 0x0391, 0x2e,
976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2b,
977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x65e5, 0x672c, 0x8a9e
978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t toUnicodeOffsets[] = {
980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14,
981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            15, 17, 19, 23,
982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            24,
983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            27, 29, 32
984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t fromUnicodeOffsets[] = {
986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10,
987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            11, 12, 12, 12, 13, 13, 13, 13, 14,
988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            15, 15,
989b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            16, 16, 16, 17, 17, 17, 18, 18, 18, 18
990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* same but escaping set O (the exclamation mark) */
993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf7Restricted[] = {
994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*
995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                Hi Mom -+Jjo--+ACE-
996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                A+ImIDkQ.
997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                +-
998b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                +ZeVnLIqe-
999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            */
1000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d,
1001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e,
1002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2b, 0x2d,
1003b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d
1004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t toUnicodeOffsetsR[] = {
1006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15,
1007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            19, 21, 23, 27,
1008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            28,
1009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            31, 33, 36
1010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t fromUnicodeOffsetsR[] = {
1012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10,
1013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            11, 12, 12, 12, 13, 13, 13, 13, 14,
1014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            15, 15,
1015b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            16, 16, 16, 17, 17, 17, 18, 18, 18, 18
1016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE);
1019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(utf7, sizeof(utf7), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7", toUnicodeOffsets,FALSE);
1021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7Restricted, sizeof(utf7Restricted), "UTF-7,version=1", fromUnicodeOffsetsR,FALSE);
1023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(utf7Restricted, sizeof(utf7Restricted), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7,version=1", toUnicodeOffsetsR,FALSE);
1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
1028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * IMAP-mailbox-name examples are mostly from http://www.imc.org/rfc2152,
1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * modified according to RFC 2060,
1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * and supplemented with the one example in RFC 2060 itself.
1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t imap[] = {
1034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*  Hi Mom -&Jjo--!
1035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                A&ImIDkQ-.
1036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &-
1037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &ZeVnLIqe-
1038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                \
1039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ~peter
1040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /mail
1041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /&ZeVnLIqe-
1042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /&U,BTFw-
1043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            */
1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x26, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21,
1045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x41, 0x26, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2d, 0x2e,
1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x26, 0x2d,
1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d,
1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x5c,
1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x7e, 0x70, 0x65, 0x74, 0x65, 0x72,
1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x6d, 0x61, 0x69, 0x6c,
1051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x26, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d,
1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x26, 0x55, 0x2c, 0x42, 0x54, 0x46, 0x77, 0x2d
1053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const UChar unicode[] = {
1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*  Hi Mom -<WHITE SMILING FACE>-!
1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                A<NOT IDENTICAL TO><ALPHA>.
1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                &
1058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                [Japanese word "nihongo"]
1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                \
1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ~peter
1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /mail
1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /<65e5, 672c, 8a9e>
1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /<53f0, 5317>
1064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            */
1065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x263a, 0x2d, 0x21,
1066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x41, 0x2262, 0x0391, 0x2e,
1067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x26,
1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x65e5, 0x672c, 0x8a9e,
1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x5c,
1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x7e, 0x70, 0x65, 0x74, 0x65, 0x72,
1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x6d, 0x61, 0x69, 0x6c,
1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x65e5, 0x672c, 0x8a9e,
1073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x2f, 0x53f0, 0x5317
1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t toUnicodeOffsets[] = {
1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 14,
1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            15, 17, 19, 24,
1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            25,
1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            28, 30, 33,
1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            37,
1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            38, 39, 40, 41, 42, 43,
1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            44, 45, 46, 47, 48,
1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            49, 51, 53, 56,
1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            60, 62, 64
1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t fromUnicodeOffsets[] = {
1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10,
1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            11, 12, 12, 12, 13, 13, 13, 13, 13, 14,
1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            15, 15,
1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            16, 16, 16, 17, 17, 17, 18, 18, 18, 18,
1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            19,
1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            20, 21, 22, 23, 24, 25,
1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            26, 27, 28, 29, 30,
1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34,
1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            35, 36, 36, 36, 37, 37, 37, 37, 37
1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, imap, sizeof(imap), "IMAP-mailbox-name", fromUnicodeOffsets,FALSE);
1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(imap, sizeof(imap), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "IMAP-mailbox-name", toUnicodeOffsets,FALSE);
1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test UTF-8 bad data handling*/
1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf8[]={
1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x61,
1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xf7, 0xbf, 0xbf, 0xbf,         /* > 10FFFF */
1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00,
1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62,
1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfb, 0xbf, 0xbf, 0xbf, 0xbf,   /* > 10FFFF */
1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfb, 0xbf, 0xbf, 0xbf, 0xbf,   /* > 10FFFF */
1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xf4, 0x8f, 0xbf, 0xbf,         /* 10FFFF */
1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xdf, 0xbf,                     /* 7ff */
1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xbf,                           /* truncated tail */
1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xf4, 0x90, 0x80, 0x80,         /* 11FFFF */
1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x02
1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint16_t utf8Expected[]={
1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0061,
1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,
1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0000,
1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0062,
1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,
1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,
1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xdbff, 0xdfff,
1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x07ff,
1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,
1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,
1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0002
1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t utf8Offsets[]={
1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 1, 5, 6, 7, 12, 17, 17, 21, 23, 24, 28
1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(utf8, sizeof(utf8),
1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                       utf8Expected, sizeof(utf8Expected)/sizeof(utf8Expected[0]), "utf-8", utf8Offsets ,FALSE);
1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test UTF-32BE bad data handling*/
1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf32[]={
1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x00, 0x61,
1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x11, 0x00, 0x00,         /* 0x110000 out of range */
1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x10, 0xff, 0xff,         /* 0x10FFFF in range */
1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x00, 0x62,
1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x7f, 0xff, 0xff, 0xff,         /* 0x7fffffff out of range */
1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x01, 0x62,
1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x02, 0x62
1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint16_t utf32Expected[]={
1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0061,
1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0x110000 out of range */
1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xDBFF,         /* 0x10FFFF in range */
1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xDFFF,
1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0062,
1159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0xffffffff out of range */
1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0x7fffffff out of range */
1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0162,
1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0262
1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t utf32Offsets[]={
1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 4, 8, 8, 12, 16, 20, 24, 28
1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf32ExpectedBack[]={
1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x00, 0x61,
1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0xff, 0xfd,         /* 0x110000 out of range */
1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x10, 0xff, 0xff,         /* 0x10FFFF in range */
1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x00, 0x62,
1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0xff, 0xfd,         /* 0xffffffff out of range */
1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0xff, 0xfd,         /* 0x7fffffff out of range */
1174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x01, 0x62,
1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x02, 0x62
1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t utf32OffsetsBack[]={
1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0,0,0,0,
1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            1,1,1,1,
1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,2,2,2,
1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,4,4,4,
1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            5,5,5,5,
1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            6,6,6,6,
1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            7,7,7,7,
1185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            8,8,8,8
1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(utf32, sizeof(utf32),
1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                       utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32be", utf32Offsets ,FALSE);
1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]),
1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32be", utf32OffsetsBack, FALSE);
1192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test UTF-32LE bad data handling*/
1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf32[]={
1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x61, 0x00, 0x00, 0x00,
1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x00, 0x00, 0x11, 0x00,         /* 0x110000 out of range */
1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xff, 0xff, 0x10, 0x00,         /* 0x10FFFF in range */
1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x00, 0x00, 0x00,
1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xff, 0xff, 0xff, 0x7f,         /* 0x7fffffff out of range */
1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x01, 0x00, 0x00,
1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x02, 0x00, 0x00,
1205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint16_t utf32Expected[]={
1208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0061,
1209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0x110000 out of range */
1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xDBFF,         /* 0x10FFFF in range */
1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xDFFF,
1212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0062,
1213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0xffffffff out of range */
1214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfffd,         /* 0x7fffffff out of range */
1215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0162,
1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x0262
1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t utf32Offsets[]={
1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0, 4, 8, 8, 12, 16, 20, 24, 28
1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t utf32ExpectedBack[]={
1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x61, 0x00, 0x00, 0x00,
1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfd, 0xff, 0x00, 0x00,         /* 0x110000 out of range */
1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xff, 0xff, 0x10, 0x00,         /* 0x10FFFF in range */
1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x00, 0x00, 0x00,
1226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfd, 0xff, 0x00, 0x00,         /* 0xffffffff out of range */
1227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0xfd, 0xff, 0x00, 0x00,         /* 0x7fffffff out of range */
1228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x01, 0x00, 0x00,
1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0x62, 0x02, 0x00, 0x00
1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t utf32OffsetsBack[]={
1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0,0,0,0,
1233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            1,1,1,1,
1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,2,2,2,
1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,4,4,4,
1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            5,5,5,5,
1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            6,6,6,6,
1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            7,7,7,7,
1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            8,8,8,8
1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(utf32, sizeof(utf32),
1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32le", utf32Offsets,FALSE );
1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]),
1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32le", utf32OffsetsBack, FALSE);
1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestCoverageMBCS(){
1249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
1250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *directory = loadTestData(&status);
1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char* tdpath = NULL;
1253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char* saveDirectory = (char*)malloc(sizeof(char) *(strlen(u_getDataDirectory())+1));
1254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int len = strlen(directory);
1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char* index=NULL;
1256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    tdpath = (char*) malloc(sizeof(char) * (len * 2));
1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_strcpy(saveDirectory,u_getDataDirectory());
1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Retrieved data directory %s \n",saveDirectory);
1260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_strcpy(tdpath,directory);
1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index=strrchr(tdpath,(char)U_FILE_SEP_CHAR);
1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if((unsigned int)(index-tdpath) != (strlen(tdpath)-1)){
1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            *(index+1)=0;
1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_setDataDirectory(tdpath);
1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("ICU data directory is set to: %s \n" ,tdpath);
1268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*some more test to increase the code coverage in MBCS.  Create an test converter from test1.ucm
1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      which is test file for MBCS conversion with single-byte codepage data.*/
1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* MBCS with single byte codepage data test1.ucm*/
1275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0x0003};
1276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const uint8_t expectedtest1[] = { 0x00, 0x05, 0xff, 0x07, 0xff,};
1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t  totest1Offs[]        = { 0, 1, 2, 3, 5, };
1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*from Unicode*/
1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expectedtest1, sizeof(expectedtest1), "@test1", totest1Offs,FALSE );
1282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*some more test to increase the code coverage in MBCS.  Create an test converter from test3.ucm
1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      which is test file for MBCS conversion with three-byte codepage data.*/
1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* MBCS with three byte codepage data test3.ucm*/
1289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e};
1290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const uint8_t expectedtest3[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x0b,  0x07,  0x01, 0x02, 0x0a,  0xff,};
1291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t  totest3Offs[]        = { 0, 1, 2, 3, 3, 3, 4, 6, 6, 6, 8};
1292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const uint8_t test3input[]    = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x0b,  0x07,  0x01, 0x02, 0x0a, 0x01, 0x02, 0x0c,};
1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd};
1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t fromtest3Offs[]       = { 0, 1, 2, 3, 6, 6, 7, 7, 10 };
1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*from Unicode*/
1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
1299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expectedtest3, sizeof(expectedtest3), "@test3", totest3Offs,FALSE );
1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*to Unicode*/
1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(test3input, sizeof(test3input),
1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", fromtest3Offs ,FALSE);
1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*some more test to increase the code coverage in MBCS.  Create an test converter from test4.ucm
1308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      which is test file for MBCS conversion with four-byte codepage data.*/
1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* MBCS with three byte codepage data test4.ucm*/
1312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const UChar unicodeInput[]    = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0x000e};
1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t expectedtest4[] = { 0x00, 0x05, 0xff, 0x01, 0x02, 0x03, 0x0b,  0x07,  0x01, 0x02, 0x03, 0x0a,  0xff,};
1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t totest4Offs[]   = { 0, 1, 2, 3, 3, 3, 3, 4, 6, 6, 6, 6, 8,};
1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t test4input[]    = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x03, 0x0b,  0x07,  0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0c,};
1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56, 0xfffd};
1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t fromtest4Offs[] = { 0, 1, 2, 3, 7, 7, 8, 8, 12,};
1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*from Unicode*/
1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expectedtest4, sizeof(expectedtest4), "@test4", totest4Offs,FALSE );
1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*to Unicode*/
1325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        testConvertToU(test4input, sizeof(test4input),
1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", fromtest4Offs,FALSE );
1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(tdpath);
1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* restore the original data directory */
1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Setting the data directory to %s \n", saveDirectory);
1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_setDataDirectory(saveDirectory);
1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(saveDirectory);
1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestConverterType(const char *convName, UConverterType convType) {
1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter* myConverter;
1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myConverter = my_ucnv_open(convName, &err);
1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(err)) {
1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Failed to create an %s converter\n", convName);
1347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
1350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ucnv_getType(myConverter)!=convType) {
1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ucnv_getType Failed for %s. Got enum value 0x%X\n",
1353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                convName, convType);
1354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else {
1356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("ucnv_getType %s ok\n", convName);
1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(myConverter);
1360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestConverterTypesAndStarters()
1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter* myConverter;
1366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
1367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool mystarters[256];
1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*    const UBool expectedKSCstarters[256] = {
1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};*/
1396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Testing KSC, ibm-930, ibm-878  for starters and their conversion types.");
1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myConverter = ucnv_open("ksc", &err);
1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(err)) {
1402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_data_err("Failed to create an ibm-ksc converter\n");
1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
1406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ucnv_getType(myConverter)!=UCNV_MBCS)
1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ucnv_getType Failed for ibm-949\n");
1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
1410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("ucnv_getType ibm-949 ok\n");
1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(myConverter!=NULL)
1413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucnv_getStarters(myConverter, mystarters, &err);
1414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*if (memcmp(expectedKSCstarters, mystarters, sizeof(expectedKSCstarters)))
1416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_err("Failed ucnv_getStarters for ksc\n");
1417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          else
1418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_verbose("ucnv_getStarters ok\n");*/
1419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(myConverter);
1422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("ibm-930", UCNV_EBCDIC_STATEFUL);
1424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("ibm-878", UCNV_SBCS);
1425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("iso-8859-1", UCNV_LATIN_1);
1428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("ibm-1208", UCNV_UTF8);
1430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("utf-8", UCNV_UTF8);
1432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("UTF-16BE", UCNV_UTF16_BigEndian);
1433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("UTF-16LE", UCNV_UTF16_LittleEndian);
1434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("UTF-32BE", UCNV_UTF32_BigEndian);
1435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("UTF-32LE", UCNV_UTF32_LittleEndian);
1436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
1438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if defined(U_ENABLE_GENERIC_ISO_2022)
1440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("iso-2022", UCNV_ISO_2022);
1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("hz", UCNV_HZ);
1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("scsu", UCNV_SCSU);
1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("x-iscii-de", UCNV_ISCII);
1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("ascii", UCNV_US_ASCII);
1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("utf-7", UCNV_UTF7);
1454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("IMAP-mailbox-name", UCNV_IMAP_MAILBOX);
1455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestConverterType("bocu-1", UCNV_BOCU1);
1456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
1459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestAmbiguousConverter(UConverter *cnv) {
1460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char inBytes[3]={ 0x61, 0x5B, 0x5c };
1461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar outUnicode[20]={ 0, 0, 0, 0 };
1462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *s;
1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *u;
1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode;
1466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool isAmbiguous;
1467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* try to convert an 'a', a square bracket and a US-ASCII backslash */
1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    errorCode=U_ZERO_ERROR;
1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    s=inBytes;
1471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u=outUnicode;
1472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_toUnicode(cnv, &u, u+20, &s, s+3, NULL, TRUE, &errorCode);
1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
1474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* we do not care about general failures in this test; the input may just not be mappable */
1475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(outUnicode[0]!=0x61 || outUnicode[1]!=0x5B || outUnicode[2]==0xfffd) {
1479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* not a close ASCII-family encoding, or 0x5c is unassigned/illegal: this test is not applicable */
1480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* There are some encodings that are partially ASCII based,
1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        like the ISO-7 and GSM series of codepages, which we ignore. */
1482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    isAmbiguous=ucnv_isAmbiguous(cnv);
1486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* check that outUnicode[1]!=0x5c is exactly the same as ucnv_isAmbiguous() */
1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if((outUnicode[2]!=0x5c)!=isAmbiguous) {
1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("error: converter \"%s\" needs a backslash fix: %d but ucnv_isAmbiguous()==%d\n",
1490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucnv_getName(cnv, &errorCode), outUnicode[2]!=0x5c, isAmbiguous);
1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(outUnicode[2]!=0x5c) {
1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* needs fixup, fix it */
1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_fixFileSeparator(cnv, outUnicode, (int32_t)(u-outUnicode));
1497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(outUnicode[2]!=0x5c) {
1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* the fix failed */
1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error: ucnv_fixFileSeparator(%s) failed\n", ucnv_getName(cnv, &errorCode));
1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAmbiguous()
1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *ascii_cnv = 0, *sjis_cnv = 0, *cnv;
1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char target[] = {
1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* "\\usr\\local\\share\\data\\icutest.txt" */
1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x5c, 0x75, 0x73, 0x72,
1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x5c, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x5c, 0x73, 0x68, 0x61, 0x72, 0x65,
1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x5c, 0x64, 0x61, 0x74, 0x61,
1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x5c, 0x69, 0x63, 0x75, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74,
1516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0
1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar asciiResult[200], sjisResult[200];
151950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    int32_t /*asciiLength = 0,*/ sjisLength = 0, i;
1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *name;
1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* enumerate all converters */
1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0; (name=ucnv_getAvailableName(i))!=NULL; ++i) {
1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cnv=ucnv_open(name, &status);
1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
152759d709d503bab6e2b61931737e662dd293b40578ccornelius            /* BEGIN android-changed. To save space Android does not build full ISO-2022-CN CJK tables. */
1528ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho            const char* cnvName = ucnv_getName(cnv, &status);
1529ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho            if (strlen(cnvName) < 8 ||
15301075f6926e4af3f528e85c035e2e547786590562Elliott Hughes                strncmp(cnvName, "ISO_2022_CN", 8) != 0) {
153159d709d503bab6e2b61931737e662dd293b40578ccornelius            TestAmbiguousConverter(cnv);
1532ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho            }
1533ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho            /* END android-changed */
15348393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius            ucnv_close(cnv);
1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error: unable to open available converter \"%s\"\n", name);
1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status=U_ZERO_ERROR;
1538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_LEGACY_CONVERSION
1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sjis_cnv = ucnv_open("ibm-943", &status);
1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status))
1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Failed to create a SJIS converter\n");
1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ascii_cnv = ucnv_open("LATIN-1", &status);
1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status))
1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Failed to create a LATIN-1 converter\n");
1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(sjis_cnv);
1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* convert target from SJIS to Unicode */
1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sjisLength = ucnv_toUChars(sjis_cnv, sjisResult, sizeof(sjisResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status);
1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status))
1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Failed to convert the SJIS string.\n");
1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(sjis_cnv);
1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(ascii_cnv);
1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* convert target from Latin-1 to Unicode */
156550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    /*asciiLength =*/ ucnv_toUChars(ascii_cnv, asciiResult, sizeof(asciiResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status);
1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status))
1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Failed to convert the Latin-1 string.\n");
1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(sjis_cnv);
1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(ascii_cnv);
1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!ucnv_isAmbiguous(sjis_cnv))
1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("SJIS converter should contain ambiguous character mappings.\n");
1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(sjis_cnv);
1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_close(ascii_cnv);
1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (u_strcmp(sjisResult, asciiResult) == 0)
1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("File separators for SJIS don't need to be fixed.\n");
1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_fixFileSeparator(sjis_cnv, sjisResult, sjisLength);
1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (u_strcmp(sjisResult, asciiResult) != 0)
1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Fixing file separator for SJIS failed.\n");
1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(sjis_cnv);
1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(ascii_cnv);
1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestSignatureDetection(){
1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* with null terminated strings */
1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char* data[] = {
1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF\x00\x00",     /* UTF-16BE */
1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x00\x00",     /* UTF-16LE */
1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF\x00",     /* UTF-8    */
1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF\x00",     /* SCSU     */
1603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF",             /* UTF-16BE */
1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE",             /* UTF-16LE */
1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF",         /* UTF-8    */
1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF",         /* SCSU     */
1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF\x41\x42",     /* UTF-16BE */
1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x41\x41",     /* UTF-16LE */
1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF\x41",     /* UTF-8    */
1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF\x41",     /* SCSU     */
1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x2B\x2F\x76\x38\x2D", /* UTF-7    */
1615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x2B\x2F\x76\x38\x41", /* UTF-7    */
1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x2B\x2F\x76\x39\x41", /* UTF-7    */
1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x2B\x2F\x76\x2B\x41", /* UTF-7    */
1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x2B\x2F\x76\x2F\x41",  /* UTF-7    */
1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xDD\x73\x66\x73"      /* UTF-EBCDIC */
1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char* expected[] = {
1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-7",
1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-7",
1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-7",
1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-7",
1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-7",
1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-EBCDIC"
1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t expectedLength[] ={
1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            5,
1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4
1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int i=0;
1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UErrorCode err;
1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t signatureLength = -1;
1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* source = NULL;
1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* enc = NULL;
1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for( ; i<sizeof(data)/sizeof(char*); i++){
1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            err = U_ZERO_ERROR;
1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            source = data[i];
1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            enc = ucnv_detectUnicodeSignature(source, -1 , &signatureLength, &err);
1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(U_FAILURE(err)){
1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err));
1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                continue;
1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(enc == NULL || strcmp(enc,expected[i]) !=0){
1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc);
1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                continue;
1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(signatureLength != expectedLength[i]){
1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("ucnv_detectUnicodeSignature failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]);
1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char* data[] = {
1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF\x00",         /* UTF-16BE */
1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x00",         /* UTF-16LE */
1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF\x00",     /* UTF-8    */
1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF\x00",     /* SCSU     */
1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x00\x00\xFE\xFF",     /* UTF-32BE */
1697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x00\x00",     /* UTF-32LE */
1698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF",             /* UTF-16BE */
1699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE",             /* UTF-16LE */
1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF",         /* UTF-8    */
1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF",         /* SCSU     */
1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x00\x00\xFE\xFF",     /* UTF-32BE */
1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x00\x00",     /* UTF-32LE */
1704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFE\xFF\x41\x42",     /* UTF-16BE */
1705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x41\x41",     /* UTF-16LE */
1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xEF\xBB\xBF\x41",     /* UTF-8    */
1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x0E\xFE\xFF\x41",     /* SCSU     */
1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\x00\x00\xFE\xFF\x41", /* UTF-32BE */
1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\xFE\x00\x00\x42", /* UTF-32LE */
1710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFB\xEE\x28",         /* BOCU-1   */
1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "\xFF\x41\x42"          /* NULL     */
1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int len[] = {
1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            5,
1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            5,
1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3
1734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char* expected[] = {
1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32BE",
1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32LE",
1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32BE",
1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32LE",
1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16BE",
1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-16LE",
1751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-8",
1752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "SCSU",
1753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32BE",
1754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "UTF-32LE",
1755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "BOCU-1",
1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                NULL
1757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const int32_t expectedLength[] ={
1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            2,
1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            4,
1777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            3,
1778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            0
1779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int i=0;
1781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UErrorCode err;
1782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t signatureLength = -1;
1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t sourceLength=-1;
1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* source = NULL;
1785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* enc = NULL;
1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for( ; i<sizeof(data)/sizeof(char*); i++){
1787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            err = U_ZERO_ERROR;
1788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            source = data[i];
1789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            sourceLength = len[i];
1790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            enc = ucnv_detectUnicodeSignature(source, sourceLength , &signatureLength, &err);
1791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(U_FAILURE(err)){
1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Error: %s\n", source,i,u_errorName(err));
1793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                continue;
1794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(enc == NULL || strcmp(enc,expected[i]) !=0){
1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(expected[i] !=NULL){
1797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i. Expected: %s. Got: %s\n",source,i,expected[i],enc);
1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 continue;
1799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(signatureLength != expectedLength[i]){
1802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("ucnv_detectUnicodeSignature test2 failed for source : %s at index :%i.Expected Length: %i. Got length: %i\n",source,i,signatureLength,expectedLength[i]);
1803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
180850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTF7() {
1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
1811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* H - +Jjo- - ! +- +2AHcAQ */
1812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x48,
1813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2d,
1814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2b, 0x4a, 0x6a, 0x6f,
1815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2d, 0x2d,
1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x21,
1817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2b, 0x2d,
1818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2b, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51
1819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
1823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
1824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x48,
1825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x2d,
1826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x263a, /* <WHITE SMILING FACE> */
1827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x2d,
1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x21,
1829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x2b,
1830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        7, 0x10401
1831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *cnvName;
1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
1836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("UTF-7", &errorCode);
1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF-7 converter: %s\n", u_errorName(errorCode)); /* sholdn't be a data err */
1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "UTF-7");
1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cnvName = ucnv_getName(cnv, &errorCode);
1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "UTF-7") != 0) {
1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("UTF-7 converter is called %s: %s\n", cnvName, u_errorName(errorCode));
1847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
185150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestIMAP() {
1852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* H - &Jjo- - ! &- &2AHcAQ- \ */
1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x48,
1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2d,
1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x26, 0x4a, 0x6a, 0x6f,
1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x2d, 0x2d,
1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x21,
1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x26, 0x2d,
1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x26, 0x32, 0x41, 0x48, 0x63, 0x41, 0x51, 0x2d
1862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x48,
1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x2d,
1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x263a, /* <WHITE SMILING FACE> */
1870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x2d,
1871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x21,
1872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x26,
1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        7, 0x10401
1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *cnvName;
1877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("IMAP-mailbox-name", &errorCode);
1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a IMAP-mailbox-name converter: %s\n", u_errorName(errorCode)); /* sholdn't be a data err */
1882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "IMAP-mailbox-name");
1885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cnvName = ucnv_getName(cnv, &errorCode);
1888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(errorCode) || uprv_strcmp(cnvName, "IMAP-mailbox-name") != 0) {
1889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("IMAP-mailbox-name converter is called %s: %s\n", cnvName, u_errorName(errorCode));
1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
189450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTF8() {
1895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61,
1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc2, 0x80,
1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xe0, 0xa0, 0x80,
1900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x90, 0x80, 0x80,
1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf4, 0x84, 0x8c, 0xa1,
1902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x90, 0x90, 0x81
1903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
1908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x61,
1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x80,
1910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        3, 0x800,
1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10000,
1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x104321,
1913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10401
1914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error test input */
1917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in2[]={
1918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61,
1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc0, 0x80,                     /* illegal non-shortest form */
1920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xe0, 0x80, 0x80,               /* illegal non-shortest form */
1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x80, 0x80, 0x80,         /* illegal non-shortest form */
1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc0, 0xc0,                     /* illegal trail byte */
1923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf4, 0x90, 0x80, 0x80,         /* 0x110000 out of range */
1924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf8, 0x80, 0x80, 0x80, 0x80,   /* too long */
1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xfe,                           /* illegal byte altogether */
1926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x62
1927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected error test results */
1930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results2[]={
1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x61,
1933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        22, 0x62
1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterToUCallback cb;
1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *p;
1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in,*limit=(const char *)in+sizeof(in);
1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("UTF-8", &errorCode);
1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
1943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF-8 converter: %s\n", u_errorName(errorCode));
1944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "UTF-8");
1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
1949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test error behavior with a skip callback */
1951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
1952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in2;
1953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    limit=(const char *)(in2+sizeof(in2));
1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results2, "UTF-8");
1955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
195950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestCESU8() {
1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
1961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
1962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61,
1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc2, 0x80,
1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xe0, 0xa0, 0x80,
1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80,
1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xed, 0xb0, 0x81, 0xed, 0xa0, 0x82,
1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf,
1968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xef, 0xbf, 0xbc
1969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
1972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x61,
1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x80,
1976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        3, 0x800,
1977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        6, 0x10000,
1978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        3, 0xdc01,
1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        -1,0xd802,  /* may read 3 or 6 bytes */
1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        -1,0x10ffff,/* may read 0 or 3 bytes */
1981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        3, 0xfffc
1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error test input */
1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in2[]={
1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61,
1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc0, 0x80,                     /* illegal non-shortest form */
1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xe0, 0x80, 0x80,               /* illegal non-shortest form */
1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x80, 0x80, 0x80,         /* illegal non-shortest form */
1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xc0, 0xc0,                     /* illegal trail byte */
1991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x90, 0x80, 0x80,         /* illegal 4-byte supplementary code point */
1992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf4, 0x84, 0x8c, 0xa1,         /* illegal 4-byte supplementary code point */
1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf0, 0x90, 0x90, 0x81,         /* illegal 4-byte supplementary code point */
1994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf4, 0x90, 0x80, 0x80,         /* 0x110000 out of range */
1995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xf8, 0x80, 0x80, 0x80, 0x80,   /* too long */
1996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xfe,                           /* illegal byte altogether */
1997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x62
1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected error test results */
2001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results2[]={
2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        1, 0x61,
2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        34, 0x62
2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterToUCallback cb;
2008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *p;
2009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in,*limit=(const char *)in+sizeof(in);
2011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("CESU-8", &errorCode);
2013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a CESU-8 converter: %s\n", u_errorName(errorCode));
2015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "CESU-8");
2018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test error behavior with a skip callback */
2022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
2023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in2;
2024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    limit=(const char *)(in2+sizeof(in2));
2025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results2, "CESU-8");
2026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
203050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTF16() {
2031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in1[]={
2033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xfe, 0xff, 0x4e, 0x00, 0xfe, 0xff
2034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in2[]={
2036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xff, 0xfe, 0x4e, 0x00, 0xfe, 0xff
2037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in3[]={
2039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xfe, 0xfe, 0x4e, 0x00, 0xfe, 0xff, 0xd8, 0x40, 0xdc, 0x01
2040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results1[]={
2044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x4e00,
2046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xfeff
2047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results2[]={
2049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x004e,
2051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xfffe
2052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results3[]={
2054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xfefe,
2056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x4e00,
2057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xfeff,
2058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x20001
2059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source, *limit;
2062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("UTF-16", &errorCode);
2065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF-16 converter: %s\n", u_errorName(errorCode));
2067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in1, limit=(const char *)in1+sizeof(in1);
2071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results1, "UTF-16");
2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in2, limit=(const char *)in2+sizeof(in2);
2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results2, "UTF-16");
2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in3, limit=(const char *)in3+sizeof(in3);
2078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results3, "UTF-16");
2080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
208850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTF16BE() {
2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
2091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x61,
2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0xc0,
2093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x31,
2094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0xf4,
2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xce, 0xfe,
2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xd8, 0x01, 0xdc, 0x01
2097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x61,
2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xc0,
2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x31,
2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xf4,
2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0xcefe,
2107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10401
2108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
2111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("utf-16be", &errorCode);
2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF16-BE converter: %s\n", u_errorName(errorCode));
2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "UTF-16BE");
2118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*Test for the condition where there is an invalid character*/
2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t source2[]={0x61};
2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
2125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
2127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Test disabled because currently the UTF-16BE/LE converters are supposed
2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * to not set errors for unpaired surrogates.
2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * This may change with
2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
2132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
2133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*Test for the condition where there is a surrogate pair*/
2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const uint8_t source2[]={0xd8, 0x01};
2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
2140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
2144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestUTF16LE() {
2145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
2147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61, 0x00,
2148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x31, 0x00,
2149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x4e, 0x2e,
2150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x4e, 0x00,
2151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x01, 0xd8, 0x01, 0xdc
2152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
2156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x61,
2158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x31,
2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x2e4e,
2160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        2, 0x4e,
2161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10401
2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("utf-16le", &errorCode);
2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF16-LE converter: %s\n", u_errorName(errorCode));
2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "UTF-16LE");
2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*Test for the condition where there is an invalid character*/
2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
2176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t source2[]={0x61};
2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Test disabled because currently the UTF-16BE/LE converters are supposed
2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * to not set errors for unpaired surrogates.
2184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * This may change with
2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
2186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
2187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*Test for the condition where there is a surrogate character*/
2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const uint8_t source2[]={0x01, 0xd8};
2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
219850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestUTF32() {
2199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in1[]={
2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xfe, 0xff,   0x00, 0x10, 0x0f, 0x00,   0x00, 0x00, 0xfe, 0xff
2202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in2[]={
2204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xff, 0xfe, 0x00, 0x00,   0x00, 0x10, 0x0f, 0x00,   0xfe, 0xff, 0x00, 0x00
2205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in3[]={
2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xfe, 0xfe,   0x00, 0x10, 0x0f, 0x00,   0x00, 0x00, 0xd8, 0x40,   0x00, 0x00, 0xdc, 0x01
2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results1[]={
2212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        8, 0x100f00,
2214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfeff
2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results2[]={
2217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        8, 0x0f1000,
2219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffe
2220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results3[]={
2222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfefe,
2224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x100f00,
2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd, /* unmatched surrogate */
2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd  /* unmatched surrogate */
2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source, *limit;
2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("UTF-32", &errorCode);
2233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF-32 converter: %s\n", u_errorName(errorCode));
2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in1, limit=(const char *)in1+sizeof(in1);
2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results1, "UTF-32");
2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in2, limit=(const char *)in2+sizeof(in2);
2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results2, "UTF-32");
2244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in3, limit=(const char *)in3+sizeof(in3);
2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results3, "UTF-32");
2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_resetToUnicode(cnv);
2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
2257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestUTF32BE() {
2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x00, 0x61,
2261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x30, 0x61,
2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xdc, 0x00,
2263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xd8, 0x00,
2264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xdf, 0xff,
2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0xff, 0xfe,
2266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x10, 0xab, 0xcd,
2267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x10, 0xff, 0xff
2268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
2272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x61,
2274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x3061,
2275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffe,
2279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10abcd,
2280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x10ffff
2281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error test input */
2284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in2[]={
2285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x00, 0x61,
2286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x11, 0x00, 0x00,         /* 0x110000 out of range */
2287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x00, 0x62,
2288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xff, 0xff, 0xff, 0xff,         /* 0xffffffff out of range */
2289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x7f, 0xff, 0xff, 0xff,         /* 0x7fffffff out of range */
2290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x01, 0x62,
2291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0x00, 0x02, 0x62
2292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected error test results */
2295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results2[]={
2296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4,  0x61,
2298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        8,  0x62,
2299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        12, 0x162,
2300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4,  0x262
2301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterToUCallback cb;
2304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *p;
2305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
2307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
2308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv=ucnv_open("UTF-32BE", &errorCode);
2309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
2310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Unable to open a UTF-32BE converter: %s\n", u_errorName(errorCode));
2311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
2312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results, "UTF-32BE");
2314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test the condition when source >= sourceLimit */
2316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
2317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test error behavior with a skip callback */
2319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_SKIP, NULL, &cb, &p, &errorCode);
2320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(const char *)in2;
2321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    limit=(const char *)(in2+sizeof(in2));
2322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNextUChar(cnv, source, limit, results2, "UTF-32BE");
2323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(cnv);
2325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
2328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTestUTF32LE() {
2329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test input */
2330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const uint8_t in[]={
2331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61, 0x00, 0x00, 0x00,
2332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x61, 0x30, 0x00, 0x00,
2333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0xdc, 0x00, 0x00,
2334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0x00, 0xd8, 0x00, 0x00,
2335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xff, 0xdf, 0x00, 0x00,
2336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xfe, 0xff, 0x00, 0x00,
2337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xcd, 0xab, 0x10, 0x00,
2338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        0xff, 0xff, 0x10, 0x00
2339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* expected test results */
2342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const int32_t results[]={
2343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* number of bytes read, code point */
2344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x61,
2345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0x3061,
2346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffd,
2349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        4, 0xfffe,
2350