~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/test/cintltst/nccbtst.c

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 * COPYRIGHT: 
 
3
 * Copyright (c) 1997-2001, International Business Machines Corporation and
 
4
 * others. All Rights Reserved.
 
5
 ********************************************************************/
 
6
/*
 
7
* File NCCBTST.C
 
8
*
 
9
* Modification History:
 
10
*        Name                            Description
 
11
*    Madhu Katragadda     7/21/1999      Testing error callback routines
 
12
**************************************************************************************
 
13
*/
 
14
#include <stdio.h>
 
15
#include <stdlib.h>
 
16
#include <string.h>
 
17
#include <ctype.h>
 
18
#include "cstring.h"
 
19
#include "unicode/uloc.h"
 
20
#include "unicode/ucnv.h"
 
21
#include "unicode/ucnv_err.h"
 
22
#include "cintltst.h"
 
23
#include "unicode/utypes.h"
 
24
#include "unicode/ustring.h"
 
25
#include "nccbtst.h"
 
26
#define NEW_MAX_BUFFER 999
 
27
 
 
28
#define nct_min(x,y)  ((x<y) ? x : y)
 
29
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
 
30
 
 
31
static int32_t  gInBufferSize = 0;
 
32
static int32_t  gOutBufferSize = 0;
 
33
static char     gNuConvTestName[1024];
 
34
 
 
35
static void printSeq(const uint8_t* a, int len)
 
36
{
 
37
    int i=0;
 
38
    log_verbose("\n{");
 
39
    while (i<len)
 
40
        log_verbose("0x%02X, ", a[i++]);
 
41
    log_verbose("}\n");
 
42
}
 
43
 
 
44
static void printUSeq(const UChar* a, int len)
 
45
{
 
46
    int i=0;
 
47
    log_verbose("{");
 
48
    while (i<len)
 
49
        log_verbose("  0x%04x, ", a[i++]);
 
50
    log_verbose("}\n");
 
51
}
 
52
 
 
53
static void printSeqErr(const uint8_t* a, int len)
 
54
{
 
55
    int i=0;
 
56
    fprintf(stderr, "{");
 
57
    while (i<len)
 
58
        fprintf(stderr, "  0x%02x, ", a[i++]);
 
59
    fprintf(stderr, "}\n");
 
60
}
 
61
 
 
62
static void printUSeqErr(const UChar* a, int len)
 
63
{
 
64
    int i=0;
 
65
    fprintf(stderr, "{");
 
66
    while (i<len)
 
67
        fprintf(stderr, "0x%04x, ", a[i++]);
 
68
    fprintf(stderr,"}\n");
 
69
}
 
70
 
 
71
static void setNuConvTestName(const char *codepage, const char *direction)
 
72
{
 
73
    sprintf(gNuConvTestName, "[testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
 
74
            codepage,
 
75
            direction,
 
76
            gInBufferSize,
 
77
            gOutBufferSize);
 
78
}
 
79
 
 
80
 
 
81
void addTestConvertErrorCallBack(TestNode** root);
 
82
 
 
83
void addTestConvertErrorCallBack(TestNode** root)
 
84
{
 
85
    addTest(root, &TestSkipCallBack,  "tsconv/nccbtst/TestSkipCallBack");
 
86
    addTest(root, &TestStopCallBack,  "tsconv/nccbtst/TestStopCallBack");
 
87
    addTest(root, &TestSubCallBack,   "tsconv/nccbtst/TestSubCallBack");
 
88
    addTest(root, &TestSubWithValueCallBack, "tsconv/nccbtst/TestSubWithValueCallBack");
 
89
    addTest(root, &TestLegalAndOtherCallBack,  "tsconv/nccbtst/TestLegalAndOtherCallBack");
 
90
    addTest(root, &TestSingleByteCallBack,  "tsconv/nccbtst/TestSingleByteCallBack");
 
91
}
 
92
 
 
93
static void TestSkipCallBack()
 
94
{
 
95
    TestSkip(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
96
    TestSkip(1,NEW_MAX_BUFFER);
 
97
    TestSkip(1,1);
 
98
    TestSkip(NEW_MAX_BUFFER, 1);
 
99
}
 
100
 
 
101
static void TestStopCallBack()
 
102
{
 
103
    TestStop(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
104
    TestStop(1,NEW_MAX_BUFFER);
 
105
    TestStop(1,1);
 
106
    TestStop(NEW_MAX_BUFFER, 1);
 
107
}
 
108
 
 
109
static void TestSubCallBack()
 
110
{
 
111
    TestSub(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
112
    TestSub(1,NEW_MAX_BUFFER);
 
113
    TestSub(1,1);
 
114
    TestSub(NEW_MAX_BUFFER, 1);
 
115
    TestEBCDIC_STATEFUL_Sub(1, 1);
 
116
    TestEBCDIC_STATEFUL_Sub(1, NEW_MAX_BUFFER);
 
117
    TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER, 1);
 
118
    TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
119
 
 
120
 
 
121
}
 
122
 
 
123
static void TestSubWithValueCallBack()
 
124
{
 
125
    TestSubWithValue(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
126
    TestSubWithValue(1,NEW_MAX_BUFFER);
 
127
    TestSubWithValue(1,1);
 
128
    TestSubWithValue(NEW_MAX_BUFFER, 1);
 
129
}
 
130
 
 
131
static void TestLegalAndOtherCallBack()
 
132
{
 
133
    TestLegalAndOthers(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
134
    TestLegalAndOthers(1,NEW_MAX_BUFFER);
 
135
    TestLegalAndOthers(1,1);
 
136
    TestLegalAndOthers(NEW_MAX_BUFFER, 1);
 
137
}
 
138
 
 
139
static void TestSingleByteCallBack()
 
140
{
 
141
    TestSingleByte(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
 
142
    TestSingleByte(1,NEW_MAX_BUFFER);
 
143
    TestSingleByte(1,1);
 
144
    TestSingleByte(NEW_MAX_BUFFER, 1);
 
145
}
 
146
 
 
147
static void TestSkip(int32_t inputsize, int32_t outputsize)
 
148
{
 
149
    static const UChar   sampleText[] =  { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
 
150
    static const UChar  sampleText2[] =  { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
 
151
 
 
152
    static const uint8_t expskipIBM_949[]= { 
 
153
        0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
 
154
 
 
155
    static const uint8_t expskipIBM_943[] = { 
 
156
        0x9f, 0xaf, 0x9f, 0xb1, 0x89, 0x59 };
 
157
 
 
158
    static const uint8_t expskipIBM_930[] = { 
 
159
        0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x46, 0x6b };
 
160
 
 
161
    static const UChar IBM_949skiptoUnicode[]= {0x0000, 0xAC00, 0xAC01, 0xD700 };
 
162
    static const UChar IBM_943skiptoUnicode[]= { 0x6D63, 0x6D64, 0x6D66 };
 
163
    static const UChar IBM_930skiptoUnicode[]= { 0x6D63, 0x6D64, 0x6D66 };
 
164
 
 
165
 
 
166
    static const int32_t  toIBM949Offsskip [] = { 0, 1, 1, 2, 2, 4, 4};
 
167
    static const int32_t  toIBM943Offsskip [] = { 0, 0, 1, 1, 3, 3};
 
168
    static const int32_t  toIBM930Offsskip [] = { 0, 0, 0, 1, 1, 3, 3};
 
169
 
 
170
    static const int32_t  fromIBM949Offs [] = { 0, 1, 3, 5};
 
171
    static const int32_t  fromIBM943Offs [] = { 0, 2, 4};
 
172
    static const int32_t  fromIBM930Offs [] = { 1, 3, 5};
 
173
 
 
174
    gInBufferSize = inputsize;
 
175
    gOutBufferSize = outputsize;
 
176
 
 
177
    /*From Unicode*/
 
178
    log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SKIP  \n");
 
179
 
 
180
    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
 
181
            expskipIBM_949, sizeof(expskipIBM_949), "ibm-949",
 
182
            UCNV_FROM_U_CALLBACK_SKIP, toIBM949Offsskip, NULL, 0 ))
 
183
        log_err("u-> ibm-949 with skip did not match.\n");
 
184
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
185
            expskipIBM_943, sizeof(expskipIBM_943), "ibm-943",
 
186
            UCNV_FROM_U_CALLBACK_SKIP, toIBM943Offsskip, NULL, 0 ))
 
187
        log_err("u-> ibm-943 with skip did not match.\n");
 
188
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
189
            expskipIBM_930, sizeof(expskipIBM_930), "ibm-930",
 
190
            UCNV_FROM_U_CALLBACK_SKIP, toIBM930Offsskip , NULL, 0))
 
191
        log_err("u-> ibm-930 with skip did not match.\n");
 
192
 
 
193
    {
 
194
        static const UChar fromU[] = { 0x61, 0xff5e, 0x62, 0x6d63, 0xff5e, 0x6d64, 0x63, 0xff5e, 0x6d66 };
 
195
        static const uint8_t fromUBytes[] = { 0x62, 0x63, 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x64, 0x0e, 0x46, 0x6b };
 
196
        static const int32_t fromUOffsets[] = { 0, 2, 3, 3, 3, 5, 5, 6, 6, 8, 8, 8 };
 
197
 
 
198
        /* test ibm-930 (EBCDIC_STATEFUL) with fallbacks that are not taken to check correct state transitions */
 
199
        if(!testConvertFromUnicode(fromU, sizeof(fromU)/U_SIZEOF_UCHAR,
 
200
                                   fromUBytes, sizeof(fromUBytes),
 
201
                                   "ibm-930",
 
202
                                   UCNV_FROM_U_CALLBACK_SKIP, fromUOffsets,
 
203
                                   NULL, 0)
 
204
        ) {
 
205
            log_err("u->ibm-930 with skip with untaken fallbacks did not match.\n");
 
206
        }
 
207
    }
 
208
 
 
209
    {
 
210
        static const UChar usasciiFromU[] = { 0x61, 0x80, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
 
211
        static const uint8_t usasciiFromUBytes[] = { 0x61, 0x31, 0x39 };
 
212
        static const int32_t usasciiFromUOffsets[] = { 0, 3, 6 };
 
213
 
 
214
        static const UChar latin1FromU[] = { 0x61, 0xa0, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
 
215
        static const uint8_t latin1FromUBytes[] = { 0x61, 0xa0, 0x31, 0x39 };
 
216
        static const int32_t latin1FromUOffsets[] = { 0, 1, 3, 6 };
 
217
 
 
218
        /* US-ASCII */
 
219
        if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
 
220
                                   usasciiFromUBytes, sizeof(usasciiFromUBytes),
 
221
                                   "US-ASCII",
 
222
                                   UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
 
223
                                   NULL, 0)
 
224
        ) {
 
225
            log_err("u->US-ASCII with skip did not match.\n");
 
226
        }
 
227
 
 
228
        /* SBCS NLTC codepage 367 for US-ASCII */
 
229
        if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
 
230
                                   usasciiFromUBytes, sizeof(usasciiFromUBytes),
 
231
                                   "ibm-367",
 
232
                                   UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
 
233
                                   NULL, 0)
 
234
        ) {
 
235
            log_err("u->ibm-367 with skip did not match.\n");
 
236
        }
 
237
 
 
238
        /* ISO-Latin-1 */
 
239
        if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
 
240
                                   latin1FromUBytes, sizeof(latin1FromUBytes),
 
241
                                   "LATIN_1",
 
242
                                   UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
 
243
                                   NULL, 0)
 
244
        ) {
 
245
            log_err("u->LATIN_1 with skip did not match.\n");
 
246
        }
 
247
 
 
248
        /* windows-1252 */
 
249
        if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
 
250
                                   latin1FromUBytes, sizeof(latin1FromUBytes),
 
251
                                   "windows-1252",
 
252
                                   UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
 
253
                                   NULL, 0)
 
254
        ) {
 
255
            log_err("u->windows-1252 with skip did not match.\n");
 
256
        }
 
257
    }
 
258
 
 
259
    {
 
260
        static const UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
 
261
        static const uint8_t toIBM943[]= { 0x61, 0x61 };
 
262
        static const int32_t offset[]= {0, 4};
 
263
 
 
264
         /* EUC_JP*/
 
265
        static const UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
 
266
        static const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
267
            0x61, 0x8e, 0xe0,
 
268
        };
 
269
        static const int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2, 6, 7, 7};
 
270
 
 
271
        /*EUC_TW*/
 
272
        static const UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
 
273
        static const uint8_t to_euc_tw[]={ 
 
274
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
275
            0x61, 0xe6, 0xca, 0x8a,
 
276
        };
 
277
        static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 6, 7, 7, 8,};
 
278
 
 
279
        /*ISO-2022-JP*/
 
280
        static const UChar iso_2022_jp_inputText[]={0x0041, 0x00E9/*unassigned*/,0x0042, };
 
281
        static const uint8_t to_iso_2022_jp[]={ 
 
282
            0x41,       
 
283
            0x42,
 
284
 
 
285
        };
 
286
        static const int32_t from_iso_2022_jpOffs [] ={0,2};
 
287
 
 
288
        static const UChar iso_2022_jp_inputText1[]={0x3000, 0x00E9, 0x3001, };
 
289
        static const uint8_t to_iso_2022_jp1[]={ 
 
290
            0x1b,   0x24,   0x42,   0x21, 0x21,       
 
291
            0x21,   0x22,
 
292
 
 
293
        };
 
294
        static const int32_t from_iso_2022_jpOffs1 [] ={0,0,0,0,0,2,2,};
 
295
 
 
296
        /*ISO-2022-JP*/
 
297
        UChar const iso_2022_jp_inputText2[]={0x0041, 0x00E9/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
 
298
        static const uint8_t to_iso_2022_jp2[]={ 
 
299
            0x41,       
 
300
            0x43,
 
301
 
 
302
        };
 
303
        static const int32_t from_iso_2022_jpOffs2 [] ={0,2};
 
304
 
 
305
        /*ISO-2022-cn*/
 
306
        static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
 
307
        static const uint8_t to_iso_2022_cn[]={  
 
308
            0x0F,   0x41,   
 
309
            0x0F,   0x42, 
 
310
        };
 
311
        static const int32_t from_iso_2022_cnOffs [] ={ 
 
312
            0,0,
 
313
            2,2,
 
314
        };
 
315
        
 
316
        /*ISO-2022-CN*/
 
317
        static const UChar iso_2022_cn_inputText1[]={0x0041, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
 
318
        static const uint8_t to_iso_2022_cn1[]={ 
 
319
            0x0F,   0x41,   
 
320
            0x0F,   0x43, 
 
321
 
 
322
        };
 
323
        static const int32_t from_iso_2022_cnOffs1 [] ={0,0,2,2};
 
324
 
 
325
        /*ISO-2022-kr*/
 
326
        static const UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
 
327
        static const uint8_t to_iso_2022_kr[]={  
 
328
            0x1b,   0x24,   0x29,   0x43,   
 
329
            0x41,   
 
330
            0x0e,   0x25,   0x50,   
 
331
            0x25,   0x50, 
 
332
            0x0f,   0x42, 
 
333
        };
 
334
        static const int32_t from_iso_2022_krOffs [] ={ 
 
335
            -1,-1,-1,-1,
 
336
            0,
 
337
            1,1,1,
 
338
            3,3,
 
339
            4,4
 
340
        };
 
341
 
 
342
        /*ISO-2022-kr*/
 
343
        static const UChar iso_2022_kr_inputText1[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
 
344
        static const uint8_t to_iso_2022_kr1[]={  
 
345
            0x1b,   0x24,   0x29,   0x43,   
 
346
            0x41,   
 
347
            0x0e,   0x25,   0x50,   
 
348
            0x25,   0x50, 
 
349
 
 
350
        };
 
351
        static const int32_t from_iso_2022_krOffs1 [] ={ 
 
352
            -1,-1,-1,-1,
 
353
            0,
 
354
            1,1,1,
 
355
            3,3,
 
356
 
 
357
        };
 
358
        /* HZ encoding */       
 
359
        static const UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
 
360
 
 
361
        static const uint8_t to_hz[]={    
 
362
            0x7e,   0x7d,   0x41,   
 
363
            0x7e,   0x7b,   0x26,   0x30,   
 
364
            0x26,   0x30,
 
365
            0x7e,   0x7d,   0x42, 
 
366
           
 
367
        };
 
368
        static const int32_t from_hzOffs [] ={ 
 
369
            0,0,0,
 
370
            1,1,1,1,
 
371
            3,3,
 
372
            4,4,4,4
 
373
        };
 
374
 
 
375
        static const UChar hz_inputText1[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
 
376
 
 
377
        static const uint8_t to_hz1[]={    
 
378
            0x7e,   0x7d,   0x41,   
 
379
            0x7e,   0x7b,   0x26,   0x30,   
 
380
            0x26,   0x30,
 
381
 
 
382
           
 
383
        };
 
384
        static const int32_t from_hzOffs1 [] ={ 
 
385
            0,0,0,
 
386
            1,1,1,1,
 
387
            3,3,
 
388
 
 
389
        };
 
390
 
 
391
 
 
392
        static const UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
 
393
 
 
394
        static const uint8_t to_SCSU[]={    
 
395
            0x41,   
 
396
            0x42
 
397
 
 
398
           
 
399
        };
 
400
        static const int32_t from_SCSUOffs [] ={ 
 
401
            0,
 
402
            2,
 
403
 
 
404
        };
 
405
        /* ISCII */
 
406
        static const UChar iscii_inputText[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
 
407
        static const uint8_t to_iscii[]={  
 
408
            0x41,   
 
409
            0x42, 
 
410
        };
 
411
        static const int32_t from_isciiOffs [] ={ 
 
412
            0,2,
 
413
 
 
414
        };
 
415
        /*ISCII*/
 
416
        static const UChar iscii_inputText1[]={0x0044, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
 
417
        static const uint8_t to_iscii1[]={ 
 
418
            0x44,   
 
419
            0x43, 
 
420
 
 
421
        };
 
422
        static const int32_t from_isciiOffs1 [] ={0,2};
 
423
 
 
424
        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
 
425
                toIBM943, sizeof(toIBM943), "ibm-943",
 
426
                UCNV_FROM_U_CALLBACK_SKIP, offset, NULL, 0 ))
 
427
            log_err("u-> ibm-943 with skip did not match.\n");
 
428
 
 
429
        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
 
430
                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
 
431
                UCNV_FROM_U_CALLBACK_SKIP, fromEUC_JPOffs, NULL, 0 ))
 
432
            log_err("u-> euc-jp with skip did not match.\n");
 
433
 
 
434
        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
 
435
                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
 
436
                UCNV_FROM_U_CALLBACK_SKIP, from_euc_twOffs, NULL, 0 ))
 
437
            log_err("u-> euc-tw with skip did not match.\n");  
 
438
        
 
439
        /*iso_2022_jp*/
 
440
        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
 
441
                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
 
442
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs, NULL, 0 ))
 
443
            log_err("u-> iso-2022-jp with skip did not match.\n"); 
 
444
        
 
445
        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
 
446
                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
 
447
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs1, NULL, 0 ))
 
448
            log_err("u-> iso-2022-jp with skip did not match.\n"); 
 
449
        /* with context */
 
450
        if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
 
451
                to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
 
452
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs2, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
 
453
            log_err("u-> iso-2022-jp with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
454
    
 
455
        /*iso_2022_cn*/
 
456
        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
 
457
                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
 
458
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs, NULL, 0 ))
 
459
            log_err("u-> iso-2022-cn with skip did not match.\n"); 
 
460
        /*with context*/
 
461
        if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
 
462
                to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
 
463
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
 
464
            log_err("u-> iso-2022-cn with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
465
 
 
466
        /*iso_2022_kr*/
 
467
        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
 
468
                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
 
469
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs, NULL, 0 ))
 
470
            log_err("u-> iso-2022-kr with skip did not match.\n"); 
 
471
          /*with context*/
 
472
        if(!testConvertFromUnicodeWithContext(iso_2022_kr_inputText1, sizeof(iso_2022_kr_inputText1)/sizeof(iso_2022_kr_inputText1[0]),
 
473
                to_iso_2022_kr1, sizeof(to_iso_2022_kr1), "iso-2022-kr",
 
474
                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
 
475
            log_err("u-> iso-2022-kr with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
476
 
 
477
        /*hz*/
 
478
        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
 
479
                to_hz, sizeof(to_hz), "HZ",
 
480
                UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs, NULL, 0 ))
 
481
            log_err("u-> HZ with skip did not match.\n"); 
 
482
          /*with context*/
 
483
        if(!testConvertFromUnicodeWithContext(hz_inputText1, sizeof(hz_inputText1)/sizeof(hz_inputText1[0]),
 
484
                to_hz1, sizeof(to_hz1), "hz",
 
485
                UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
 
486
            log_err("u-> hz with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n"); 
 
487
        
 
488
        /*SCSU*/
 
489
        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
 
490
                to_SCSU, sizeof(to_SCSU), "SCSU",
 
491
                UCNV_FROM_U_CALLBACK_SKIP, from_SCSUOffs, NULL, 0 ))
 
492
            log_err("u-> SCSU with skip did not match.\n");
 
493
 
 
494
        /*ISCII*/
 
495
        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
 
496
                to_iscii, sizeof(to_iscii), "ISCII,version=0",
 
497
                UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs, NULL, 0 ))
 
498
            log_err("u-> iscii with skip did not match.\n"); 
 
499
        /*with context*/
 
500
        if(!testConvertFromUnicodeWithContext(iscii_inputText1, sizeof(iscii_inputText1)/sizeof(iscii_inputText1[0]),
 
501
                to_iscii1, sizeof(to_iscii1), "ISCII,version=0",
 
502
                UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
 
503
            log_err("u-> iscii with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
 
504
      
 
505
    }
 
506
 
 
507
    /*to Unicode*/
 
508
    log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SKIP  \n");
 
509
 
 
510
    if(!testConvertToUnicode(expskipIBM_949, sizeof(expskipIBM_949),
 
511
             IBM_949skiptoUnicode, sizeof(IBM_949skiptoUnicode)/sizeof(IBM_949skiptoUnicode),"ibm-949",
 
512
            UCNV_TO_U_CALLBACK_SKIP, fromIBM949Offs, NULL, 0 ))
 
513
        log_err("ibm-949->u with skip did not match.\n");
 
514
    if(!testConvertToUnicode(expskipIBM_943, sizeof(expskipIBM_943),
 
515
             IBM_943skiptoUnicode, sizeof(IBM_943skiptoUnicode)/sizeof(IBM_943skiptoUnicode[0]),"ibm-943",
 
516
            UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offs, NULL, 0 ))
 
517
        log_err("ibm-943->u with skip did not match.\n");
 
518
 
 
519
    if(!testConvertToUnicode(expskipIBM_930, sizeof(expskipIBM_930),
 
520
             IBM_930skiptoUnicode, sizeof(IBM_930skiptoUnicode)/sizeof(IBM_930skiptoUnicode[0]),"ibm-930",
 
521
            UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs, NULL, 0 ))
 
522
        log_err("ibm-930->u with skip did not match.\n");
 
523
 
 
524
    {
 
525
        static const uint8_t usasciiToUBytes[] = { 0x61, 0x80, 0x31 };
 
526
        static const UChar usasciiToU[] = { 0x61, 0x31 };
 
527
        static const int32_t usasciiToUOffsets[] = { 0, 2 };
 
528
 
 
529
        static const uint8_t latin1ToUBytes[] = { 0x61, 0xa0, 0x31 };
 
530
        static const UChar latin1ToU[] = { 0x61, 0xa0, 0x31 };
 
531
        static const int32_t latin1ToUOffsets[] = { 0, 1, 2 };
 
532
 
 
533
        /* US-ASCII */
 
534
        if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
 
535
                                 usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
 
536
                                 "US-ASCII",
 
537
                                 UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
 
538
                                 NULL, 0)
 
539
        ) {
 
540
            log_err("US-ASCII->u with skip did not match.\n");
 
541
        }
 
542
 
 
543
        /* SBCS NLTC codepage 367 for US-ASCII */
 
544
        if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
 
545
                                 usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
 
546
                                 "ibm-367",
 
547
                                 UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
 
548
                                 NULL, 0)
 
549
        ) {
 
550
            log_err("ibm-367->u with skip did not match.\n");
 
551
        }
 
552
 
 
553
        /* ISO-Latin-1 */
 
554
        if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
 
555
                                 latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
 
556
                                 "LATIN_1",
 
557
                                 UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
 
558
                                 NULL, 0)
 
559
        ) {
 
560
            log_err("LATIN_1->u with skip did not match.\n");
 
561
        }
 
562
 
 
563
        /* windows-1252 */
 
564
        if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
 
565
                                 latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
 
566
                                 "windows-1252",
 
567
                                 UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
 
568
                                 NULL, 0)
 
569
        ) {
 
570
            log_err("windows-1252->u with skip did not match.\n");
 
571
        }
 
572
    }
 
573
 
 
574
    {
 
575
        const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
 
576
            0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
 
577
        };
 
578
        UChar EBCIDIC_STATEFUL_toUnicode[] ={  0x6d63, 0x03b4 
 
579
        };
 
580
        int32_t from_EBCIDIC_STATEFULOffsets []={ 1, 5};
 
581
       
 
582
 
 
583
         /* euc-jp*/
 
584
        const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
585
            0x8f, 0xda, 0xa1,  /*unassigned*/
 
586
           0x8e, 0xe0,
 
587
        };
 
588
        UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec, 0x00a2};
 
589
        int32_t from_euc_jpOffs [] ={ 0, 1, 3, 9};
 
590
 
 
591
         /*EUC_TW*/
 
592
        const uint8_t sampleTxt_euc_tw[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
593
            0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
 
594
           0xe6, 0xca, 0x8a,
 
595
        };
 
596
        UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 0x8706, 0x8a, };
 
597
        int32_t from_euc_twOffs [] ={ 0, 1, 3, 11, 13};
 
598
                /*iso-2022-jp*/
 
599
        const uint8_t sampleTxt_iso_2022_jp[]={ 
 
600
            0x41,
 
601
            0x1b,   0x24,   0x42,   0x2A, 0x44, /*unassigned*/
 
602
             0x1b,   0x28,   0x42,   0x42,
 
603
            
 
604
        };
 
605
        UChar iso_2022_jptoUnicode[]={    0x41,0x42 };
 
606
        int32_t from_iso_2022_jpOffs [] ={  0,9   };
 
607
        
 
608
        /*iso-2022-cn*/
 
609
        const uint8_t sampleTxt_iso_2022_cn[]={ 
 
610
            0x0f,   0x41,   0x44,
 
611
            0x1B,   0x24,   0x29,   0x47, 
 
612
            0x0E,   0x40,   0x6f, /*unassigned*/
 
613
            0x0f,   0x42,
 
614
            
 
615
        };
 
616
 
 
617
        UChar iso_2022_cntoUnicode[]={    0x41, 0x44,0x42 };
 
618
        int32_t from_iso_2022_cnOffs [] ={  1,   2,   11   };
 
619
 
 
620
        /*iso-2022-kr*/
 
621
        const uint8_t sampleTxt_iso_2022_kr[]={ 
 
622
          0x1b, 0x24, 0x29,  0x43,
 
623
          0x41,
 
624
          0x0E, 0x7f, 0x1E,
 
625
          0x0e, 0x25, 0x50, 
 
626
          0x0f, 0x51,
 
627
          0x42, 0x43,
 
628
            
 
629
        };
 
630
        UChar iso_2022_krtoUnicode[]={     0x41,0x03A0,0x51, 0x42,0x43};
 
631
        int32_t from_iso_2022_krOffs [] ={  4,    9,    12,   13  , 14 };
 
632
        
 
633
        /*hz*/
 
634
        const uint8_t sampleTxt_hz[]={ 
 
635
            0x41,   
 
636
            0x7e,   0x7b,   0x26,   0x30,   
 
637
            0x7f,   0x1E, /*unassigned*/ 
 
638
            0x26,   0x30,
 
639
            0x7e,   0x7d,   0x42, 
 
640
            0x7e,   0x7b,   0x7f,   0x1E,/*unassigned*/ 
 
641
            0x7e,   0x7d,   0x42,
 
642
        };
 
643
        UChar hztoUnicode[]={  
 
644
            0x41,
 
645
            0x03a0,
 
646
            0x03A0, 
 
647
            0x42,
 
648
            0x42,};
 
649
 
 
650
        int32_t from_hzOffs [] ={0,3,7,11,18,  };
 
651
 
 
652
        /*ISCII*/
 
653
        const uint8_t sampleTxt_iscii[]={ 
 
654
            0x41,   
 
655
            0xa1,   
 
656
            0xEB,    /*unassigned*/ 
 
657
            0x26,   
 
658
            0x30,
 
659
            0xa2, 
 
660
            0xEC,    /*unassigned*/ 
 
661
            0x42,
 
662
        };
 
663
        UChar isciitoUnicode[]={  
 
664
            0x41,
 
665
            0x0901,
 
666
            0x26,
 
667
            0x30,
 
668
            0x0902, 
 
669
            0x42,
 
670
            };
 
671
 
 
672
        int32_t from_isciiOffs [] ={0,1,3,4,5,7 };
 
673
 
 
674
        /*LMBCS*/
 
675
        const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50, 
 
676
            0x12, 0x92, 0xa0, /*unassigned*/
 
677
            0x12, 0x92, 0xA1,
 
678
        };
 
679
        UChar LMBCSToUnicode[]={ 0x4e2e, 0xe5c4};
 
680
        int32_t fromLMBCS[] = {0, 6};
 
681
 
 
682
        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
 
683
             EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
 
684
            UCNV_TO_U_CALLBACK_SKIP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
 
685
        log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
 
686
 
 
687
 
 
688
 
 
689
        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
 
690
                 euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
 
691
                UCNV_TO_U_CALLBACK_SKIP, from_euc_jpOffs , NULL, 0))
 
692
            log_err("euc-jp->u with skip did not match.\n");
 
693
 
 
694
 
 
695
 
 
696
        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
 
697
                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
 
698
                UCNV_TO_U_CALLBACK_SKIP, from_euc_twOffs , NULL, 0))
 
699
            log_err("euc-tw->u with skip did not match.\n");
 
700
 
 
701
        
 
702
        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
 
703
                 iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
 
704
                UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_jpOffs , NULL, 0))
 
705
            log_err("iso-2022-jp->u with skip did not match.\n");
 
706
        
 
707
        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
 
708
                 iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
 
709
                UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_cnOffs , NULL, 0))
 
710
            log_err("iso-2022-cn->u with skip did not match.\n");
 
711
 
 
712
        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
 
713
                 iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
 
714
                UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_krOffs , NULL, 0))
 
715
            log_err("iso-2022-kr->u with skip did not match.\n");
 
716
 
 
717
        if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
 
718
                 hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
 
719
                UCNV_TO_U_CALLBACK_SKIP, from_hzOffs , NULL, 0))
 
720
            log_err("HZ->u with skip did not match.\n");
 
721
        
 
722
        if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
 
723
                 isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
 
724
                UCNV_TO_U_CALLBACK_SKIP, from_isciiOffs , NULL, 0))
 
725
            log_err("iscii->u with skip did not match.\n");
 
726
 
 
727
        if(/* broken for icu 1.6 and 1.6.0.1, do not test */uprv_strcmp("1.7", U_ICU_VERSION) != 0 && !testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
 
728
                LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS-1",
 
729
                UCNV_TO_U_CALLBACK_SKIP, fromLMBCS , NULL, 0))
 
730
            log_err("LMBCS->u with skip did not match.\n");
 
731
 
 
732
    }
 
733
    log_verbose("Testing to Unicode for UTF-8 with UCNV_TO_U_CALLBACK_SKIP \n");
 
734
    {
 
735
        const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c, 
 
736
            0xe0, 0x80,  0x61,};
 
737
        UChar    expected1[] = {  0x0031, 0x4e8c, 0x0061};
 
738
        int32_t offsets1[] = {   0x0000, 0x0001, 0x0006};
 
739
 
 
740
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
741
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
 
742
                UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
 
743
            log_err("utf8->u with skip did not match.\n");;
 
744
    }
 
745
 
 
746
    log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SKIP \n");
 
747
    {
 
748
        const uint8_t sampleText1[] = {  0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
 
749
        UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061,0xfffe,0xfffe};
 
750
        int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003,4,5};
 
751
 
 
752
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
753
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
 
754
                UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
 
755
            log_err("scsu->u with stop did not match.\n");;
 
756
    }
 
757
}
 
758
 
 
759
static void TestStop(int32_t inputsize, int32_t outputsize)
 
760
{
 
761
    static const UChar   sampleText[] =  { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
 
762
    static const UChar  sampleText2[] =  { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
 
763
 
 
764
    static const uint8_t expstopIBM_949[]= { 
 
765
        0x00, 0xb0, 0xa1, 0xb0, 0xa2};
 
766
 
 
767
    static const uint8_t expstopIBM_943[] = { 
 
768
        0x9f, 0xaf, 0x9f, 0xb1};
 
769
 
 
770
    static const uint8_t expstopIBM_930[] = { 
 
771
        0x0e, 0x5d, 0x5f, 0x5d, 0x63};
 
772
 
 
773
    static const UChar IBM_949stoptoUnicode[]= {0x0000, 0xAC00, 0xAC01};
 
774
    static const UChar IBM_943stoptoUnicode[]= { 0x6D63, 0x6D64};
 
775
    static const UChar IBM_930stoptoUnicode[]= { 0x6D63, 0x6D64};
 
776
 
 
777
 
 
778
    static const int32_t  toIBM949Offsstop [] = { 0, 1, 1, 2, 2};
 
779
    static const int32_t  toIBM943Offsstop [] = { 0, 0, 1, 1};
 
780
    static const int32_t  toIBM930Offsstop [] = { 0, 0, 0, 1, 1};
 
781
 
 
782
    static const int32_t  fromIBM949Offs [] = { 0, 1, 3};
 
783
    static const int32_t  fromIBM943Offs [] = { 0, 2};
 
784
    static const int32_t  fromIBM930Offs [] = { 1, 3};
 
785
 
 
786
    gInBufferSize = inputsize;
 
787
    gOutBufferSize = outputsize;
 
788
    /*From Unicode*/
 
789
    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
 
790
            expstopIBM_949, sizeof(expstopIBM_949), "ibm-949",
 
791
            UCNV_FROM_U_CALLBACK_STOP, toIBM949Offsstop, NULL, 0 ))
 
792
        log_err("u-> ibm-949 with stop did not match.\n");
 
793
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
794
            expstopIBM_943, sizeof(expstopIBM_943), "ibm-943",
 
795
            UCNV_FROM_U_CALLBACK_STOP, toIBM943Offsstop , NULL, 0))
 
796
        log_err("u-> ibm-943 with stop did not match.\n");
 
797
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
798
            expstopIBM_930, sizeof(expstopIBM_930), "ibm-930",
 
799
            UCNV_FROM_U_CALLBACK_STOP, toIBM930Offsstop, NULL, 0 ))
 
800
        log_err("u-> ibm-930 with stop did not match.\n");
 
801
 
 
802
    log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_STOP  \n");
 
803
    {
 
804
        static const UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
 
805
        static const uint8_t toIBM943[]= { 0x61,};
 
806
        static const int32_t offset[]= {0,} ;
 
807
 
 
808
         /*EUC_JP*/
 
809
        static const UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
 
810
        static const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,};
 
811
        static const int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2,};
 
812
 
 
813
        /*EUC_TW*/
 
814
        static const UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
 
815
        static const uint8_t to_euc_tw[]={ 
 
816
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,};
 
817
        static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2,};
 
818
        
 
819
        /*ISO-2022-JP*/
 
820
        static const UChar iso_2022_jp_inputText[]={0x0041, 0x00E9, 0x0042, };
 
821
        static const uint8_t to_iso_2022_jp[]={ 
 
822
             0x41,   
 
823
 
 
824
        };
 
825
        static const int32_t from_iso_2022_jpOffs [] ={0,};
 
826
 
 
827
        /*ISO-2022-cn*/
 
828
        static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
 
829
        static const uint8_t to_iso_2022_cn[]={  
 
830
            0x0F,   0x41,   
 
831
 
 
832
        };
 
833
        static const int32_t from_iso_2022_cnOffs [] ={ 
 
834
            0,0,
 
835
            2,2,
 
836
        };
 
837
        
 
838
        /*ISO-2022-kr*/
 
839
        static const UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
 
840
        static const uint8_t to_iso_2022_kr[]={  
 
841
            0x1b,   0x24,   0x29,   0x43,   
 
842
            0x41,   
 
843
            0x0e,   0x25,   0x50,   
 
844
        };
 
845
        static const int32_t from_iso_2022_krOffs [] ={ 
 
846
            -1,-1,-1,-1,
 
847
             0,
 
848
            1,1,1,
 
849
        };
 
850
 
 
851
        /* HZ encoding */       
 
852
        static const UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
 
853
 
 
854
        static const uint8_t to_hz[]={    
 
855
            0x7e,   0x7d, 0x41,   
 
856
            0x7e,   0x7b,   0x26,   0x30,   
 
857
           
 
858
        };
 
859
        static const int32_t from_hzOffs [] ={ 
 
860
            0, 0,0,
 
861
            1,1,1,1,
 
862
        };
 
863
 
 
864
        /*ISCII*/
 
865
        static const UChar iscii_inputText[]={ 0x0041, 0x3712, 0x0042, };
 
866
        static const uint8_t to_iscii[]={  
 
867
            0x41,   
 
868
        };
 
869
        static const int32_t from_isciiOffs [] ={ 
 
870
            0,           
 
871
        };
 
872
 
 
873
        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
 
874
                toIBM943, sizeof(toIBM943), "ibm-943",
 
875
                UCNV_FROM_U_CALLBACK_STOP, offset, NULL, 0 ))
 
876
            log_err("u-> ibm-943 with stop did not match.\n");
 
877
 
 
878
        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
 
879
                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
 
880
                UCNV_FROM_U_CALLBACK_STOP, fromEUC_JPOffs, NULL, 0 ))
 
881
            log_err("u-> euc-jp with stop did not match.\n");
 
882
 
 
883
        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
 
884
                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
 
885
                UCNV_FROM_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
 
886
            log_err("u-> euc-tw with stop did not match.\n");  
 
887
 
 
888
        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
 
889
                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
 
890
                UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
 
891
            log_err("u-> iso-2022-jp with stop did not match.\n");  
 
892
 
 
893
        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
 
894
                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
 
895
                UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
 
896
            log_err("u-> iso-2022-jp with stop did not match.\n");  
 
897
        
 
898
        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
 
899
                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
 
900
                UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_cnOffs, NULL, 0 ))
 
901
            log_err("u-> iso-2022-cn with stop did not match.\n");  
 
902
 
 
903
        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
 
904
                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
 
905
                UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_krOffs, NULL, 0 ))
 
906
            log_err("u-> iso-2022-kr with stop did not match.\n");  
 
907
        
 
908
        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
 
909
                to_hz, sizeof(to_hz), "HZ",
 
910
                UCNV_FROM_U_CALLBACK_STOP, from_hzOffs, NULL, 0 ))
 
911
            log_err("u-> HZ with stop did not match.\n");\
 
912
                
 
913
        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
 
914
                to_iscii, sizeof(to_iscii), "ISCII,version=0",
 
915
                UCNV_FROM_U_CALLBACK_STOP, from_isciiOffs, NULL, 0 ))
 
916
            log_err("u-> iscii with stop did not match.\n"); 
 
917
 
 
918
 
 
919
    }
 
920
    log_verbose("Testing fromUnicode for UTF-8 with UCNV_FROM_U_CALLBACK_STOP \n");
 
921
    {
 
922
        const UChar testinput[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01, 0xd801, 0xffff, 0x0061,};
 
923
        const uint8_t expectedUTF8[]= { 0xe2, 0x82, 0xac, 
 
924
                           0xf0, 0x90, 0x90, 0x81, 
 
925
                           0xed, 0xb0, 0x81, 0xed, 0xa0, 0x81,
 
926
                           0xef, 0xbf, 0xbf, 0x61,
 
927
                           
 
928
        };
 
929
        int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
 
930
        if(!testConvertFromUnicode(testinput, sizeof(testinput)/sizeof(testinput[0]),
 
931
                expectedUTF8, sizeof(expectedUTF8), "utf8",
 
932
                UCNV_FROM_U_CALLBACK_STOP, offsets, NULL, 0 ))
 
933
            log_err("u-> utf8 with stop did not match.\n");
 
934
    }
 
935
    log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_STOP \n");
 
936
    {
 
937
        UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
 
938
 
 
939
        const uint8_t to_SCSU[]={    
 
940
            0x41,   
 
941
           
 
942
        };
 
943
        int32_t from_SCSUOffs [] ={ 
 
944
            0,
 
945
 
 
946
        };
 
947
        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
 
948
                to_SCSU, sizeof(to_SCSU), "SCSU",
 
949
                UCNV_FROM_U_CALLBACK_STOP, from_SCSUOffs, NULL, 0 ))
 
950
            log_err("u-> SCSU with skip did not match.\n");
 
951
    
 
952
    }
 
953
    /*to Unicode*/
 
954
    if(!testConvertToUnicode(expstopIBM_949, sizeof(expstopIBM_949),
 
955
             IBM_949stoptoUnicode, sizeof(IBM_949stoptoUnicode)/sizeof(IBM_949stoptoUnicode[0]),"ibm-949",
 
956
            UCNV_TO_U_CALLBACK_STOP, fromIBM949Offs, NULL, 0 ))
 
957
        log_err("ibm-949->u with stop did not match.\n");
 
958
    if(!testConvertToUnicode(expstopIBM_943, sizeof(expstopIBM_943),
 
959
             IBM_943stoptoUnicode, sizeof(IBM_943stoptoUnicode)/sizeof(IBM_943stoptoUnicode[0]),"ibm-943",
 
960
            UCNV_TO_U_CALLBACK_STOP, fromIBM943Offs, NULL, 0 ))
 
961
        log_err("ibm-943->u with stop did not match.\n");
 
962
    if(!testConvertToUnicode(expstopIBM_930, sizeof(expstopIBM_930),
 
963
             IBM_930stoptoUnicode, sizeof(IBM_930stoptoUnicode)/sizeof(IBM_930stoptoUnicode[0]),"ibm-930",
 
964
            UCNV_TO_U_CALLBACK_STOP, fromIBM930Offs, NULL, 0 ))
 
965
        log_err("ibm-930->u with stop did not match.\n");
 
966
 
 
967
    log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_STOP \n");
 
968
    {
 
969
 
 
970
        const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
 
971
            0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
 
972
        };
 
973
        UChar EBCIDIC_STATEFUL_toUnicode[] ={  0x6d63 };
 
974
        int32_t from_EBCIDIC_STATEFULOffsets []={ 1};
 
975
 
 
976
 
 
977
         /*EUC-JP*/
 
978
        const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
979
            0x8f, 0xda, 0xa1,  /*unassigned*/
 
980
           0x8e, 0xe0,
 
981
        };
 
982
        UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec};
 
983
        int32_t from_euc_jpOffs [] ={ 0, 1, 3};
 
984
 
 
985
          /*EUC_TW*/
 
986
        const uint8_t sampleTxt_euc_tw[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
987
            0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
 
988
           0xe6, 0xca, 0x8a,
 
989
        };
 
990
        UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2};
 
991
        int32_t from_euc_twOffs [] ={ 0, 1, 3};
 
992
 
 
993
 
 
994
 
 
995
         if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
 
996
             EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
 
997
            UCNV_TO_U_CALLBACK_STOP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
 
998
        log_err("EBCIDIC_STATEFUL->u with stop did not match.\n");
 
999
 
 
1000
        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
 
1001
             euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
 
1002
            UCNV_TO_U_CALLBACK_STOP, from_euc_jpOffs , NULL, 0))
 
1003
        log_err("euc-jp->u with stop did not match.\n");
 
1004
 
 
1005
        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
 
1006
                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
 
1007
                UCNV_TO_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
 
1008
            log_err("euc-tw->u with stop did not match.\n");
 
1009
    }
 
1010
    log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_STOP \n");
 
1011
    {
 
1012
        const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c, 
 
1013
            0xe0, 0x80,  0x61,};
 
1014
        UChar    expected1[] = {  0x0031, 0x4e8c,};
 
1015
        int32_t offsets1[] = {   0x0000, 0x0001};
 
1016
 
 
1017
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
1018
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
 
1019
                UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
 
1020
            log_err("utf8->u with stop did not match.\n");;
 
1021
    }
 
1022
    log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_STOP \n");
 
1023
    {
 
1024
        const uint8_t sampleText1[] = {  0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,0x04};
 
1025
        UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061};
 
1026
        int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003};
 
1027
 
 
1028
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
1029
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
 
1030
                UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
 
1031
            log_err("scsu->u with stop did not match.\n");;
 
1032
    }
 
1033
 
 
1034
}
 
1035
 
 
1036
static void TestSub(int32_t inputsize, int32_t outputsize)
 
1037
{
 
1038
    UChar   sampleText[] =  { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
 
1039
    UChar sampleText2[]=    { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
 
1040
    
 
1041
    const uint8_t expsubIBM_949[] = 
 
1042
     { 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xaf, 0xfe, 0xc8, 0xd3 };
 
1043
 
 
1044
    const uint8_t expsubIBM_943[] = { 
 
1045
        0x9f, 0xaf, 0x9f, 0xb1, 0xfc, 0xfc, 0x89, 0x59 };
 
1046
 
 
1047
    const uint8_t expsubIBM_930[] = { 
 
1048
        0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b };
 
1049
 
 
1050
    UChar IBM_949subtoUnicode[]= {0x0000, 0xAC00, 0xAC01, 0xfffd, 0xD700 };
 
1051
    UChar IBM_943subtoUnicode[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
 
1052
    UChar IBM_930subtoUnicode[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
 
1053
 
 
1054
    int32_t toIBM949Offssub [] ={ 0, 1, 1, 2, 2, 3, 3, 4, 4};
 
1055
    int32_t toIBM943Offssub [] ={ 0, 0, 1, 1, 2, 2, 3, 3};
 
1056
    int32_t toIBM930Offssub [] ={ 0, 0, 0, 1, 1, 2, 2, 3, 3};
 
1057
 
 
1058
    int32_t  fromIBM949Offs [] = { 0, 1, 3, 5, 7};
 
1059
    int32_t  fromIBM943Offs [] = { 0, 2, 4, 6};
 
1060
    int32_t  fromIBM930Offs [] = { 1, 3, 5, 7};
 
1061
 
 
1062
    gInBufferSize = inputsize;
 
1063
    gOutBufferSize = outputsize;
 
1064
 
 
1065
    /*from unicode*/
 
1066
    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
 
1067
            expsubIBM_949, sizeof(expsubIBM_949), "ibm-949", 
 
1068
            UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM949Offssub, NULL, 0 ))
 
1069
        log_err("u-> ibm-949 with subst did not match.\n");
 
1070
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
1071
            expsubIBM_943, sizeof(expsubIBM_943), "ibm-943",
 
1072
            UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM943Offssub , NULL, 0))
 
1073
        log_err("u-> ibm-943 with subst did not match.\n");
 
1074
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
1075
            expsubIBM_930, sizeof(expsubIBM_930), "ibm-930", 
 
1076
            UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM930Offssub, NULL, 0 ))
 
1077
        log_err("u-> ibm-930 with subst did not match.\n");
 
1078
 
 
1079
    log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SUBSTITUTE  \n");
 
1080
    {
 
1081
        UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
 
1082
        const uint8_t toIBM943[]= { 0x61, 0xfc, 0xfc, 0xfc, 0xfc, 0x61 };
 
1083
        int32_t offset[]= {0, 1, 1, 3, 3, 4};
 
1084
 
 
1085
 
 
1086
        /* EUC_JP*/
 
1087
        UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
 
1088
        const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
1089
            0xf4, 0xfe, 0xf4, 0xfe, 
 
1090
            0x61, 0x8e, 0xe0,
 
1091
        };
 
1092
        int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7};
 
1093
 
 
1094
        /*EUC_TW*/
 
1095
        UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
 
1096
        const uint8_t to_euc_tw[]={ 
 
1097
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
1098
            0xfd, 0xfe, 0xfd, 0xfe,
 
1099
            0x61, 0xe6, 0xca, 0x8a,
 
1100
        };
 
1101
        int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7, 8,};
 
1102
 
 
1103
        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
 
1104
                toIBM943, sizeof(toIBM943), "ibm-943",
 
1105
                UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset, NULL, 0 ))
 
1106
            log_err("u-> ibm-943 with substitute did not match.\n");
 
1107
 
 
1108
        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
 
1109
                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
 
1110
                UCNV_FROM_U_CALLBACK_SUBSTITUTE, fromEUC_JPOffs, NULL, 0 ))
 
1111
            log_err("u-> euc-jp with substitute did not match.\n");
 
1112
 
 
1113
        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
 
1114
                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
 
1115
                UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
 
1116
            log_err("u-> euc-tw with substitute did not match.\n");  
 
1117
 
 
1118
    }
 
1119
    log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
 
1120
    {
 
1121
        UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
 
1122
 
 
1123
        const uint8_t to_SCSU[]={    
 
1124
            0x41,
 
1125
            0x0e, 0xff,0xfd,
 
1126
            0x42
 
1127
 
 
1128
           
 
1129
        };
 
1130
        int32_t from_SCSUOffs [] ={ 
 
1131
            0,
 
1132
            1,1,1,
 
1133
            2,
 
1134
 
 
1135
        };
 
1136
        if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
 
1137
                to_SCSU, sizeof(to_SCSU), "SCSU",
 
1138
                UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_SCSUOffs, NULL, 0 ))
 
1139
            log_err("u-> SCSU with skip did not match.\n");
 
1140
 
 
1141
    
 
1142
    }
 
1143
    
 
1144
    /*to unicode*/
 
1145
    if(!testConvertToUnicode(expsubIBM_949, sizeof(expsubIBM_949),
 
1146
             IBM_949subtoUnicode, sizeof(IBM_949subtoUnicode)/sizeof(IBM_949subtoUnicode[0]),"ibm-949",
 
1147
            UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM949Offs, NULL, 0 ))
 
1148
        log_err("ibm-949->u with substitute did not match.\n");
 
1149
    if(!testConvertToUnicode(expsubIBM_943, sizeof(expsubIBM_943),
 
1150
             IBM_943subtoUnicode, sizeof(IBM_943subtoUnicode)/sizeof(IBM_943subtoUnicode[0]),"ibm-943",
 
1151
            UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offs, NULL, 0 ))
 
1152
        log_err("ibm-943->u with substitute did not match.\n");
 
1153
    if(!testConvertToUnicode(expsubIBM_930, sizeof(expsubIBM_930),
 
1154
             IBM_930subtoUnicode, sizeof(IBM_930subtoUnicode)/sizeof(IBM_930subtoUnicode[0]),"ibm-930",
 
1155
            UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM930Offs, NULL, 0 ))
 
1156
        log_err("ibm-930->u with substitute did not match.\n");
 
1157
 
 
1158
    log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
 
1159
    {
 
1160
 
 
1161
        const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
 
1162
            0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
 
1163
        };
 
1164
        UChar EBCIDIC_STATEFUL_toUnicode[] ={  0x6d63, 0xfffd, 0x03b4 
 
1165
        };
 
1166
        int32_t from_EBCIDIC_STATEFULOffsets []={ 1, 3, 5};
 
1167
 
 
1168
 
 
1169
        /* EUC_JP*/
 
1170
        const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
1171
            0x8f, 0xda, 0xa1,  /*unassigned*/
 
1172
           0x8e, 0xe0, 0x8a
 
1173
        };
 
1174
        UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec, 0xfffd, 0x00a2, 0x008a };
 
1175
        int32_t from_euc_jpOffs [] ={ 0, 1, 3, 6,  9, 11 };
 
1176
 
 
1177
        /*EUC_TW*/
 
1178
        const uint8_t sampleTxt_euc_tw[]={ 
 
1179
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
1180
            0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
 
1181
            0xe6, 0xca, 0x8a,
 
1182
        };
 
1183
        UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 0xfffd, 0x8706, 0x8a, };
 
1184
        int32_t from_euc_twOffs [] ={ 0, 1, 3, 7, 11, 13};
 
1185
 
 
1186
       
 
1187
        if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
 
1188
           EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
 
1189
          UCNV_TO_U_CALLBACK_SUBSTITUTE, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
 
1190
            log_err("EBCIDIC_STATEFUL->u with substitute did not match.\n");
 
1191
 
 
1192
 
 
1193
        if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
 
1194
           euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
 
1195
          UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_jpOffs, NULL, 0 ))
 
1196
            log_err("euc-jp->u with substitute did not match.\n");
 
1197
 
 
1198
        
 
1199
        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
 
1200
           euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
 
1201
          UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
 
1202
            log_err("euc-tw->u with substitute  did not match.\n");
 
1203
 
 
1204
 
 
1205
    }
 
1206
    log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
 
1207
    {
 
1208
        const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c, 
 
1209
            0xe0, 0x80,  0x61,};
 
1210
        UChar    expected1[] = {  0x0031, 0x4e8c, 0xfffd, 0x0061};
 
1211
        int32_t offsets1[] = {   0x0000, 0x0001, 0x0004, 0x0006};
 
1212
 
 
1213
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
1214
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
 
1215
                UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
 
1216
            log_err("utf8->u with substitute did not match.\n");;
 
1217
    }
 
1218
    log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
 
1219
    {
 
1220
        const uint8_t sampleText1[] = {  0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
 
1221
        UChar    expected1[] = {  0x00ba,  0x008c,  0x00f8,  0x0061,0xfffd,0xfffd};
 
1222
        int32_t offsets1[] = {   0x0000, 0x0001,0x0002,0x0003,4,5};
 
1223
 
 
1224
        if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
 
1225
                 expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
 
1226
                UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
 
1227
            log_err("scsu->u with stop did not match.\n");;
 
1228
    }
 
1229
 
 
1230
    log_verbose("Testing ibm-930 subchar/subchar1\n");
 
1231
    {
 
1232
        static const UChar u1[]={         0x6d63,           0x6d64,     0x6d65,     0x6d66,     0xdf };
 
1233
        static const uint8_t s1[]={       0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b, 0x0f, 0x3f };
 
1234
        static const int32_t offsets1[]={ 0,    0,    0,    1,    1,    2,    2,    3,    3,    4,    4 };
 
1235
 
 
1236
        static const UChar u2[]={         0x6d63,           0x6d64,     0xfffd,     0x6d66,     0x1a };
 
1237
        static const uint8_t s2[]={       0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfc, 0xfc, 0x46, 0x6b, 0x0f, 0x57 };
 
1238
        static const int32_t offsets2[]={ 1,                3,          5,          7,          10 };
 
1239
 
 
1240
        if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), s1, ARRAY_LENGTH(s1), "ibm-930", 
 
1241
                                   UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
 
1242
        ) {
 
1243
            log_err("u->ibm-930 subchar/subchar1 did not match.\n");
 
1244
        }
 
1245
 
 
1246
        if(!testConvertToUnicode(s2, ARRAY_LENGTH(s2), u2, ARRAY_LENGTH(u2), "ibm-930", 
 
1247
                                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
 
1248
        ) {
 
1249
            log_err("ibm-930->u subchar/subchar1 did not match.\n");
 
1250
        }
 
1251
    }
 
1252
 
 
1253
    log_verbose("Testing GB 18030 with substitute callbacks\n");
 
1254
    {
 
1255
        static const UChar u1[]={
 
1256
            0x24, 0x7f, 0x80,                   0x1f9,      0x20ac,     0x4e00,     0x9fa6,                 0xffff,                 0xd800, 0xdc00,         0xdbff, 0xdfff };
 
1257
        static const uint8_t gb1[]={
 
1258
            0x24, 0x7f, 0x81, 0x30, 0x81, 0x30, 0xa8, 0xbf, 0xa2, 0xe3, 0xd2, 0xbb, 0x82, 0x35, 0x8f, 0x33, 0x84, 0x31, 0xa4, 0x39, 0x90, 0x30, 0x81, 0x30, 0xe3, 0x32, 0x9a, 0x35 };
 
1259
        static const int32_t offsets1[]={
 
1260
            0, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 10, 10, 10, 10 };
 
1261
 
 
1262
        static const UChar u2[]={
 
1263
            0x24, 0x7f, 0x80,                   0x1f9,      0x20ac,     0x4e00,     0x9fa6,                 0xffff,                 0xd800, 0xdc00,         0xfffd,                 0xdbff, 0xdfff };
 
1264
        static const uint8_t gb2[]={
 
1265
            0x24, 0x7f, 0x81, 0x30, 0x81, 0x30, 0xa8, 0xbf, 0xa2, 0xe3, 0xd2, 0xbb, 0x82, 0x35, 0x8f, 0x33, 0x84, 0x31, 0xa4, 0x39, 0x90, 0x30, 0x81, 0x30, 0xe3, 0x32, 0x9a, 0x36, 0xe3, 0x32, 0x9a, 0x35 };
 
1266
        static const int32_t offsets2[]={
 
1267
            0, 1, 2, 6, 8, 10, 12, 16, 20, 20, 24, 28, 28 };
 
1268
 
 
1269
        if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), gb1, ARRAY_LENGTH(gb1), "gb18030", 
 
1270
                                   UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
 
1271
        ) {
 
1272
            log_err("u->gb18030 with substitute did not match.\n");
 
1273
        }
 
1274
 
 
1275
        if(!testConvertToUnicode(gb2, ARRAY_LENGTH(gb2), u2, ARRAY_LENGTH(u2), "gb18030", 
 
1276
                                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
 
1277
        ) {
 
1278
            log_err("gb18030->u with substitute did not match.\n");
 
1279
        }
 
1280
    }
 
1281
 
 
1282
    log_verbose("Testing UTF-7 with substitute callbacks\n");
 
1283
    {
 
1284
        static const uint8_t utf7[]={
 
1285
         /* a~            a+AB~                         a+AB\x0c                      a+AB-                         a+AB.                         a+. */
 
1286
            0x61, 0x7e,   0x61, 0x2b, 0x41, 0x42, 0x7e, 0x61, 0x2b, 0x41, 0x42, 0x0c, 0x61, 0x2b, 0x41, 0x42, 0x2d, 0x61, 0x2b, 0x41, 0x42, 0x2e, 0x61, 0x2b, 0x2e
 
1287
        };
 
1288
        static const UChar unicode[]={
 
1289
            0x61, 0xfffd, 0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61, 0xfffd
 
1290
        };
 
1291
        static const int32_t offsets[]={
 
1292
            0,    1,      2,          4,                7,          9,                12,         14,               17,         19,               22,   23
 
1293
        };
 
1294
 
 
1295
        if(!testConvertToUnicode(utf7, ARRAY_LENGTH(utf7), unicode, ARRAY_LENGTH(unicode), "UTF-7", 
 
1296
                                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
 
1297
        ) {
 
1298
            log_err("UTF-7->u with substitute did not match.\n");
 
1299
        }
 
1300
    }
 
1301
}
 
1302
 
 
1303
static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
 
1304
{
 
1305
    UChar   sampleText[] =  { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
 
1306
    UChar  sampleText2[] =  { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
 
1307
 
 
1308
    const uint8_t expsubwvalIBM_949[]= { 
 
1309
        0x00, 0xb0, 0xa1, 0xb0, 0xa2,
 
1310
        0x25, 0x55, 0x45, 0x46, 0x36, 0x37, 0xc8, 0xd3 }; 
 
1311
 
 
1312
    const uint8_t expsubwvalIBM_943[]= { 
 
1313
        0x9f, 0xaf, 0x9f, 0xb1,
 
1314
        0x25, 0x55, 0x36, 0x44, 0x36, 0x35, 0x89, 0x59 };
 
1315
 
 
1316
    const uint8_t expsubwvalIBM_930[] = {
 
1317
        0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x6c, 0xe4, 0xf6, 0xc4, 0xf6, 0xf5, 0x0e, 0x46, 0x6b };
 
1318
 
 
1319
    int32_t toIBM949Offs [] ={ 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4};
 
1320
    int32_t toIBM943Offs [] = { 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3};
 
1321
    int32_t toIBM930Offs [] = { 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3}; /* last item: 3,3,3 because there's a shift plus a doublebyter .. */
 
1322
 
 
1323
    gInBufferSize = inputsize;
 
1324
    gOutBufferSize = outputsize;
 
1325
 
 
1326
    /*from Unicode*/
 
1327
    if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
 
1328
            expsubwvalIBM_949, sizeof(expsubwvalIBM_949), "ibm-949", 
 
1329
            UCNV_FROM_U_CALLBACK_ESCAPE, toIBM949Offs, NULL, 0 ))
 
1330
        log_err("u-> ibm-949 with subst with value did not match.\n");
 
1331
 
 
1332
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
1333
            expsubwvalIBM_943, sizeof(expsubwvalIBM_943), "ibm-943",
 
1334
            UCNV_FROM_U_CALLBACK_ESCAPE, toIBM943Offs, NULL, 0 ))
 
1335
        log_err("u-> ibm-943 with sub with value did not match.\n");
 
1336
 
 
1337
    if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
 
1338
            expsubwvalIBM_930, sizeof(expsubwvalIBM_930), "ibm-930", 
 
1339
            UCNV_FROM_U_CALLBACK_ESCAPE, toIBM930Offs, NULL, 0 ))
 
1340
        log_err("u-> ibm-930 with subst with value did not match.\n");
 
1341
 
 
1342
 
 
1343
    log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_ESCAPE  \n");
 
1344
    {
 
1345
        UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
 
1346
        const uint8_t toIBM943[]= { 0x61, 
 
1347
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1348
            0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
 
1349
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1350
            0x61 };
 
1351
        int32_t offset[]= {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4};
 
1352
 
 
1353
 
 
1354
         /* EUC_JP*/
 
1355
        UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2, };
 
1356
        const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
1357
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1358
            0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
 
1359
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1360
            0x61, 0x8e, 0xe0,
 
1361
        };
 
1362
        int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2, 
 
1363
            3, 3, 3, 3, 3, 3, 
 
1364
            3, 3, 3, 3, 3, 3,
 
1365
            5, 5, 5, 5, 5, 5,
 
1366
            6, 7, 7,
 
1367
        };
 
1368
 
 
1369
        /*EUC_TW*/
 
1370
        UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
 
1371
        const uint8_t to_euc_tw[]={ 
 
1372
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
1373
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1374
            0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
 
1375
            0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
 
1376
            0x61, 0xe6, 0xca, 0x8a,
 
1377
        };
 
1378
        int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 
 
1379
             3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5,
 
1380
             6, 7, 7, 8,
 
1381
        };
 
1382
        /*ISO-2022-JP*/
 
1383
        UChar iso_2022_jp_inputText[]={ 0x0041, 0x00E9, 0x0042,0x00E9,0x3000 };
 
1384
        const uint8_t to_iso_2022_jp[]={  
 
1385
               0x41,   
 
1386
               0x25,  0x55,   0x30,   0x30,   0x45,   0x39,   
 
1387
               0x42,
 
1388
               0x25,  0x55,   0x30,   0x30,   0x45,   0x39,
 
1389
               0x1b,  0x24,   0x42,   0x21,   0x21, 
 
1390
        };
 
1391
 
 
1392
        int32_t from_iso_2022_jpOffs [] ={ 
 
1393
            0,
 
1394
            1,1,1,1,1,1,
 
1395
            2,
 
1396
            3,3,3,3,3,3,
 
1397
            4,4,4,4,4
 
1398
        };
 
1399
        UChar iso_2022_jp_inputText1[]={ 0x3000, 0x00E9, 0x3001,0x00E9, 0x0042} ;
 
1400
        const uint8_t to_iso_2022_jp1[]={  
 
1401
            0x1b,   0x24,   0x42,   0x21, 0x21,   
 
1402
            0x1b,   0x28,   0x42,   0x25, 0x55,   0x30,   0x30,   0x45,   0x39,   
 
1403
            0x1b,   0x24,   0x42,   0x21, 0x22,
 
1404
            0x1b,   0x28,   0x42,   0x25, 0x55,   0x30,   0x30,   0x45,   0x39, 
 
1405
            0x42,
 
1406
        };
 
1407
 
 
1408
        int32_t from_iso_2022_jpOffs1 [] ={ 
 
1409
            0,0,0,0,0,
 
1410
            1,1,1,1,1,1,1,1,1,
 
1411
            2,2,2,2,2,
 
1412
            3,3,3,3,3,3,3,3,3,
 
1413
            4,
 
1414
        };
 
1415
        /* surrogate pair*/
 
1416
        UChar iso_2022_jp_inputText2[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042} ;
 
1417
        const uint8_t to_iso_2022_jp2[]={  
 
1418
                                0x1b,   0x24,   0x42,   0x21,   0x21,   
 
1419
                                0x1b,   0x28,   0x42,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1420
                                0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
 
1421
                                0x1b,   0x24,   0x42,   0x21,   0x22,
 
1422
                                0x1b,   0x28,   0x42,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1423
                                0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
 
1424
                                0x42,
 
1425
                                };
 
1426
        int32_t from_iso_2022_jpOffs2 [] ={ 
 
1427
            0,0,0,0,0,
 
1428
            1,1,1,1,1,1,1,1,1,
 
1429
            1,1,1,1,1,1,
 
1430
            3,3,3,3,3,
 
1431
            4,4,4,4,4,4,4,4,4,
 
1432
            4,4,4,4,4,4,
 
1433
            6,
 
1434
        };
 
1435
 
 
1436
        /*ISO-2022-cn*/
 
1437
        UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
 
1438
        const uint8_t to_iso_2022_cn[]={  
 
1439
            0x0F,   0x41,   
 
1440
            0x0f,   0x25, 0x55,   0x33,   0x37,   0x31,   0x32,   
 
1441
            0x42, 
 
1442
        };
 
1443
        int32_t from_iso_2022_cnOffs [] ={ 
 
1444
            0,0,
 
1445
            1,1,1,1,1,1,1,
 
1446
            2,
 
1447
        };
 
1448
        UChar iso_2022_cn_inputText1[]={ 0x4e00, 0x3712, 0x4e01, };
 
1449
        const uint8_t to_iso_2022_cn1[]={  
 
1450
                        0x1b,   0x24,   0x29,   0x41,   0x0e,   0x52,   0x3b,   
 
1451
                        0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32, 
 
1452
                        0x1b,   0x24,   0x29,   0x41,   0x0e,   0x36,   0x21,
 
1453
        };
 
1454
        int32_t from_iso_2022_cnOffs1 [] ={ 
 
1455
                0, 0, 0, 0, 0, 0, 0, 
 
1456
                1, 1, 1, 1, 1, 1, 1, 
 
1457
                2, 2, 2, 2, 2, 2, 2,
 
1458
        };
 
1459
        UChar iso_2022_cn_inputText3[]={ 0x3000, 0x3712, 0x3001, };
 
1460
        const uint8_t to_iso_2022_cn3[]={  
 
1461
               0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
 
1462
              0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32,   
 
1463
             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22, 
 
1464
        };
 
1465
        int32_t from_iso_2022_cnOffs3 [] ={ 
 
1466
            0,0,0,0,0,0,0,
 
1467
            1,1,1,1,1,1,1,
 
1468
            2,2,2,2,2,2,2
 
1469
        };
 
1470
        UChar iso_2022_cn_inputText2[]={ 0x0041, 0x3712, 0x4e00, };
 
1471
        const uint8_t to_iso_2022_cn2[]={  
 
1472
            0x0F,   0x41,   
 
1473
            0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32,   
 
1474
            0x1b,   0x24,   0x29,   0x41,   0x0e,   0x52,   0x3b,
 
1475
        };
 
1476
        int32_t from_iso_2022_cnOffs2 [] ={ 
 
1477
            0,0,
 
1478
            1,1,1,1,1,1,1,
 
1479
            2,2,2,2,2,2,2
 
1480
        };
 
1481
        
 
1482
        UChar iso_2022_cn_inputText4[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042};
 
1483
 
 
1484
        const uint8_t to_iso_2022_cn4[]={  
 
1485
                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
 
1486
                             0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1487
                             0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
 
1488
                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
 
1489
                             0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1490
                             0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
 
1491
                             0x42, 
 
1492
                             };
 
1493
        int32_t from_iso_2022_cnOffs4 [] ={ 
 
1494
            0,0,0,0,0,0,0,
 
1495
            1,1,1,1,1,1,1,
 
1496
            1,1,1,1,1,1,
 
1497
            3,3,3,3,3,3,3,
 
1498
            4,4,4,4,4,4,4,
 
1499
            4,4,4,4,4,4,
 
1500
            6
 
1501
 
 
1502
        };
 
1503
 
 
1504
        /*ISO-2022-kr*/
 
1505
        UChar iso_2022_kr_inputText2[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
 
1506
        const uint8_t to_iso_2022_kr2[]={  
 
1507
            0x1b,   0x24,   0x29,   0x43,   
 
1508
            0x41,   
 
1509
            0x0e,   0x25,   0x50,   
 
1510
            0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1511
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1512
            0x0e,   0x25,   0x50, 
 
1513
            0x0f,   0x42, 
 
1514
            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1515
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1516
            0x43
 
1517
        };
 
1518
        int32_t from_iso_2022_krOffs2 [] ={ 
 
1519
            -1,-1,-1,-1,
 
1520
             0,
 
1521
            1,1,1,
 
1522
            2,2,2,2,2,2,2,
 
1523
            2,2,2,2,2,2,
 
1524
            4,4,4,
 
1525
            5,5,
 
1526
            6,6,6,6,6,6,
 
1527
            6,6,6,6,6,6,
 
1528
            8,
 
1529
        };
 
1530
 
 
1531
        UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042,0x3712/*unassigned*/,0x43 };
 
1532
        const uint8_t to_iso_2022_kr[]={  
 
1533
            0x1b,   0x24,   0x29,   0x43,   
 
1534
            0x41,   
 
1535
            0x0e,   0x25,   0x50,   
 
1536
            0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32,  /*unassigned*/ 
 
1537
            0x0e,   0x25,   0x50, 
 
1538
            0x0f,   0x42, 
 
1539
            0x25,   0x55,   0x33,   0x37,   0x31,   0x32,  /*unassigned*/ 
 
1540
            0x43
 
1541
        };
 
1542
     
 
1543
 
 
1544
        int32_t from_iso_2022_krOffs [] ={ 
 
1545
            -1,-1,-1,-1,
 
1546
             0,
 
1547
            1,1,1,
 
1548
            2,2,2,2,2,2,2,
 
1549
            3,3,3,
 
1550
            4,4,
 
1551
            5,5,5,5,5,5,
 
1552
            6,
 
1553
        };
 
1554
        /* HZ encoding */       
 
1555
        UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
 
1556
 
 
1557
        const uint8_t to_hz[]={    
 
1558
            0x7e,   0x7d,   0x41,   
 
1559
            0x7e,   0x7b,   0x26,   0x30,   
 
1560
            0x7e,   0x7d,   0x25,   0x55,   0x30,   0x36,   0x36,   0x32,  /*unassigned*/ 
 
1561
            0x7e,   0x7b,   0x26,   0x30,
 
1562
            0x7e,   0x7d,   0x42, 
 
1563
           
 
1564
        };
 
1565
        int32_t from_hzOffs [] ={ 
 
1566
            0,0,0,
 
1567
            1,1,1,1,
 
1568
            2,2,2,2,2,2,2,2,
 
1569
            3,3,3,3,
 
1570
            4,4,4
 
1571
        };
 
1572
 
 
1573
        UChar hz_inputText2[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
 
1574
        const uint8_t to_hz2[]={   
 
1575
            0x7e,   0x7d,   0x41,   
 
1576
            0x7e,   0x7b,   0x26,   0x30,   
 
1577
            0x7e,   0x7d,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1578
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1579
            0x7e,   0x7b,   0x26,   0x30,
 
1580
            0x7e,   0x7d,   0x42, 
 
1581
            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1582
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1583
            0x43
 
1584
        };
 
1585
        int32_t from_hzOffs2 [] ={ 
 
1586
            0,0,0,
 
1587
            1,1,1,1,
 
1588
            2,2,2,2,2,2,2,2,
 
1589
            2,2,2,2,2,2,
 
1590
            4,4,4,4,
 
1591
            5,5,5,
 
1592
            6,6,6,6,6,6,
 
1593
            6,6,6,6,6,6,
 
1594
            8,
 
1595
        };
 
1596
 
 
1597
                /*ISCII*/
 
1598
        UChar iscii_inputText2[]={ 0x0041, 0x0901,0xD84D, 0xDC56/*unassigned*/,0x0902, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
 
1599
        const uint8_t to_iscii2[]={  
 
1600
            0x41,   
 
1601
            0xef,   0x42,   0xa1,    
 
1602
            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1603
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1604
            0xa2, 
 
1605
            0x42, 
 
1606
            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
 
1607
            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
 
1608
            0x43
 
1609
        };
 
1610
        int32_t from_isciiOffs2 [] ={ 
 
1611
            0,
 
1612
            1,1,1,
 
1613
            2,2,2,2,2,2,
 
1614
            2,2,2,2,2,2,
 
1615
            4,
 
1616
            5,
 
1617
            6,6,6,6,6,6,
 
1618
            6,6,6,6,6,6,
 
1619
            8,
 
1620
        };
 
1621
 
 
1622
        UChar iscii_inputText[]={ 0x0041, 0x0901,0x3712/*unassigned*/,0x0902, 0x0042,0x3712/*unassigned*/,0x43 };
 
1623
        const uint8_t to_iscii[]={   
 
1624
            0x41,   
 
1625
            0xef,   0x42,   0xa1,   
 
1626
            0x25,   0x55,   0x33,   0x37,   0x31,   0x32,  /*unassigned*/ 
 
1627
            0xa2,
 
1628
            0x42, 
 
1629
            0x25,   0x55,   0x33,   0x37,   0x31,   0x32,  /*unassigned*/ 
 
1630
            0x43
 
1631
        };
 
1632
     
 
1633
 
 
1634
        int32_t from_isciiOffs [] ={ 
 
1635
            0,
 
1636
            1,1,1,
 
1637
            2,2,2,2,2,2,
 
1638
            3,
 
1639
            4,
 
1640
            5,5,5,5,5,5,
 
1641
            6,
 
1642
        };
 
1643
 
 
1644
        if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
 
1645
                toIBM943, sizeof(toIBM943), "ibm-943",
 
1646
                UCNV_FROM_U_CALLBACK_ESCAPE, offset, NULL, 0 ))
 
1647
            log_err("u-> ibm-943 with subst with value did not match.\n");
 
1648
 
 
1649
        if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
 
1650
                to_euc_jp, sizeof(to_euc_jp), "euc-jp",
 
1651
                UCNV_FROM_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0 ))
 
1652
            log_err("u-> euc-jp with subst with value did not match.\n");
 
1653
 
 
1654
        if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
 
1655
                to_euc_tw, sizeof(to_euc_tw), "euc-tw",
 
1656
                UCNV_FROM_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0 ))
 
1657
            log_err("u-> euc-tw with subst with value did not match.\n");  
 
1658
        
 
1659
        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
 
1660
                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
 
1661
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0 ))
 
1662
            log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
 
1663
     
 
1664
        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
 
1665
                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
 
1666
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
 
1667
            log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
 
1668
        
 
1669
        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
 
1670
                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
 
1671
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
 
1672
            log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
 
1673
        
 
1674
        if(!testConvertFromUnicode(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
 
1675
                to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
 
1676
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2, NULL, 0 ))
 
1677
            log_err("u-> iso_2022_jp with subst with value did not match.\n");
 
1678
        /*ESCAPE OPTIONS*/
 
1679
        {
 
1680
            const uint8_t to_iso_2022_jp2_v2[]={  
 
1681
                    0x1b,   0x24,   0x42,   0x21,   0x21,   
 
1682
                    0x1b,   0x28,   0x42,   0x26,   0x23,   0x31,  0x34,   0x34,   0x34,   0x37, 0x30, 0x3b,   
 
1683
                      
 
1684
                    0x1b,   0x24,   0x42,   0x21,   0x22,
 
1685
                    0x1b,   0x28,   0x42,   0x26,   0x23,  0x31,  0x34,   0x34,   0x34,   0x37, 0x30, 0x3b, 
 
1686
                    
 
1687
                    0x42,
 
1688
                    };
 
1689
 
 
1690
            int32_t from_iso_2022_jpOffs2_v2 [] ={ 
 
1691
                0,0,0,0,0,
 
1692
                1,1,1,1,1,1,1,1,1,1,1,1,
 
1693
 
 
1694
                3,3,3,3,3,
 
1695
                4,4,4,4,4,4,4,4,4,4,4,4,
 
1696
 
 
1697
                6,
 
1698
            };
 
1699
 
 
1700
            if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
 
1701
                    to_iso_2022_jp2_v2, sizeof(to_iso_2022_jp2_v2), "iso-2022-jp",
 
1702
                    UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2_v2, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
 
1703
                log_err("u-> iso-2022-jp with skip & UCNV_ESCAPE_XML_DEC did not match.\n"); 
 
1704
        }
 
1705
        {
 
1706
             const uint8_t to_iso_2022_jp2_v3[]={  
 
1707
                    0x1b,   0x24,   0x42,   0x21,   0x21,   
 
1708
                    0x1b,   0x28,   0x42,   0x26,   0x23,   0x78,  0x32,   0x33,   0x34,   0x35, 0x36, 0x3b ,  
 
1709
                      
 
1710
                    0x1b,   0x24,   0x42,   0x21,   0x22,
 
1711
                    0x1b,   0x28,   0x42,   0x26,   0x23,   0x78,  0x32,   0x33,   0x34,   0x35, 0x36, 0x3b ,
 
1712
                    
 
1713
                    0x42,
 
1714
                    };
 
1715
 
 
1716
            int32_t from_iso_2022_jpOffs2_v3 [] ={ 
 
1717
                0,0,0,0,0,
 
1718
                1,1,1,1,1,1,1,1,1,1,1,1,
 
1719
 
 
1720
                3,3,3,3,3,
 
1721
                4,4,4,4,4,4,4,4,4,4,4,4,
 
1722
 
 
1723
                6,
 
1724
            };
 
1725
            if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
 
1726
                to_iso_2022_jp2_v3, sizeof(to_iso_2022_jp2_v3), "iso-2022-jp",
 
1727
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2_v3, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
 
1728
                log_err("u-> iso-2022-jp with skip & UCNV_ESCAPE_XML_HEX did not match.\n"); 
 
1729
 
 
1730
        }
 
1731
        {
 
1732
            const uint8_t to_iso_2022_cn4_v2[]={  
 
1733
                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
 
1734
                             0x0f,   0x5c,   0x75,   0x44,   0x38,   0x34,   0x44,   
 
1735
                             0x5c,   0x75,   0x44,   0x43,   0x35,   0x36,   
 
1736
                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
 
1737
                             0x0f,   0x5c,   0x75,   0x44,   0x38,   0x34,   0x44,   
 
1738
                             0x5c,   0x75,   0x44,   0x43,   0x35,   0x36,   
 
1739
                             0x42, 
 
1740
                             };
 
1741
            int32_t from_iso_2022_cnOffs4_v2 [] ={ 
 
1742
                0,0,0,0,0,0,0,
 
1743
                1,1,1,1,1,1,1,
 
1744
                1,1,1,1,1,1,
 
1745
                3,3,3,3,3,3,3,
 
1746
                4,4,4,4,4,4,4,
 
1747
                4,4,4,4,4,4,
 
1748
                6, 
 
1749
 
 
1750
            };
 
1751
            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
 
1752
                to_iso_2022_cn4_v2, sizeof(to_iso_2022_cn4_v2), "iso-2022-cn",
 
1753
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4_v2, NULL, 0,UCNV_ESCAPE_JAVA,U_ZERO_ERROR ))
 
1754
                log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_JAVA did not match.\n"); 
 
1755
 
 
1756
        }
 
1757
        {
 
1758
            const uint8_t to_iso_2022_cn4_v3[]={  
 
1759
                            0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
 
1760
                            0x0f,   0x5c,   0x55,   0x30,   0x30,   0x30,   0x32,   0x33,   0x34,   0x35,   0x36,   
 
1761
                            0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,
 
1762
                            0x0f,   0x5c,   0x55,   0x30,   0x30,   0x30,   0x32,   0x33,   0x34,   0x35,   0x36, 
 
1763
                            0x42 
 
1764
                             };
 
1765
 
 
1766
 
 
1767
            int32_t from_iso_2022_cnOffs4_v3 [] ={ 
 
1768
                0,0,0,0,0,0,0,
 
1769
                1,1,1,1,1,1,1,1,1,1,1,
 
1770
 
 
1771
                3,3,3,3,3,3,3,
 
1772
                4,4,4,4,4,4,4,4,4,4,4,
 
1773
 
 
1774
                6
 
1775
 
 
1776
            };
 
1777
            if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
 
1778
                to_iso_2022_cn4_v3, sizeof(to_iso_2022_cn4_v3), "iso-2022-cn",
 
1779
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4_v3, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
 
1780
                log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_C did not match.\n"); 
 
1781
        }
 
1782
        if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
 
1783
                to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
 
1784
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0 ))
 
1785
            log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
1786
 
 
1787
        if(!testConvertFromUnicode(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
 
1788
                to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
 
1789
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs1, NULL, 0 ))
 
1790
            log_err("u-> iso_2022_cn with subst with value did not match.\n"); 
 
1791
        if(!testConvertFromUnicode(iso_2022_cn_inputText2, sizeof(iso_2022_cn_inputText2)/sizeof(iso_2022_cn_inputText2[0]),
 
1792
                to_iso_2022_cn2, sizeof(to_iso_2022_cn2), "iso-2022-cn",
 
1793
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs2, NULL, 0 ))
 
1794
            log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
1795
        if(!testConvertFromUnicode(iso_2022_cn_inputText3, sizeof(iso_2022_cn_inputText3)/sizeof(iso_2022_cn_inputText3[0]),
 
1796
                to_iso_2022_cn3, sizeof(to_iso_2022_cn3), "iso-2022-cn",
 
1797
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs3, NULL, 0 ))
 
1798
            log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
1799
        if(!testConvertFromUnicode(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
 
1800
                to_iso_2022_cn4, sizeof(to_iso_2022_cn4), "iso-2022-cn",
 
1801
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4, NULL, 0 ))
 
1802
            log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
1803
        if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
 
1804
                to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
 
1805
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0 ))
 
1806
            log_err("u-> iso_2022_kr with subst with value did not match.\n");
 
1807
        if(!testConvertFromUnicode(iso_2022_kr_inputText2, sizeof(iso_2022_kr_inputText2)/sizeof(iso_2022_kr_inputText2[0]),
 
1808
                to_iso_2022_kr2, sizeof(to_iso_2022_kr2), "iso-2022-kr",
 
1809
                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs2, NULL, 0 ))
 
1810
            log_err("u-> iso_2022_kr2 with subst with value did not match.\n");
 
1811
        if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
 
1812
                to_hz, sizeof(to_hz), "HZ",
 
1813
                UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0 ))
 
1814
            log_err("u-> hz with subst with value did not match.\n");
 
1815
        if(!testConvertFromUnicode(hz_inputText2, sizeof(hz_inputText2)/sizeof(hz_inputText2[0]),
 
1816
                to_hz2, sizeof(to_hz2), "HZ",
 
1817
                UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs2, NULL, 0 ))
 
1818
            log_err("u-> hz with subst with value did not match.\n");
 
1819
 
 
1820
        if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
 
1821
                to_iscii, sizeof(to_iscii), "ISCII,version=0",
 
1822
                UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0 ))
 
1823
            log_err("u-> iscii with subst with value did not match.\n");
 
1824
        
 
1825
        if(!testConvertFromUnicode(iscii_inputText2, sizeof(iscii_inputText2)/sizeof(iscii_inputText2[0]),
 
1826
                to_iscii2, sizeof(to_iscii2), "ISCII,version=0",
 
1827
                UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs2, NULL, 0 ))
 
1828
            log_err("u-> iscii2 with subst with value did not match.\n");
 
1829
    }
 
1830
 
 
1831
 
 
1832
    log_verbose("Testing toUnicode with UCNV_FROM_U_CALLBACK_ESCAPE \n");
 
1833
    /*to Unicode*/
 
1834
    {
 
1835
        const uint8_t sampleTxtToU[]= { 0x00, 0x9f, 0xaf, 
 
1836
            0x81, 0xad, /*unassigned*/
 
1837
            0x89, 0xd3 };
 
1838
        UChar IBM_943toUnicode[] = { 0x0000, 0x6D63, 
 
1839
            0x25, 0x58, 0x38, 0x31, 0x25, 0x58, 0x41, 0x44,
 
1840
            0x7B87};
 
1841
        int32_t  fromIBM943Offs [] =    { 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 5};
 
1842
 
 
1843
        /* EUC_JP*/
 
1844
        const uint8_t sampleTxt_EUC_JP[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
 
1845
            0x8f, 0xda, 0xa1,  /*unassigned*/
 
1846
           0x8e, 0xe0,
 
1847
        };
 
1848
        UChar EUC_JPtoUnicode[]={ 0x0061, 0x4edd, 0x5bec,
 
1849
            0x25, 0x58, 0x38, 0x46, 0x25, 0x58, 0x44, 0x41, 0x25, 0x58, 0x41, 0x31, 
 
1850
            0x00a2 };
 
1851
        int32_t fromEUC_JPOffs [] ={ 0, 1, 3, 
 
1852
            6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
1853
            9,
 
1854
        };
 
1855
 
 
1856
        /*EUC_TW*/
 
1857
        const uint8_t sampleTxt_euc_tw[]={ 
 
1858
            0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
 
1859
            0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
 
1860
            0xe6, 0xca, 0x8a,
 
1861
        };
 
1862
        UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 
 
1863
             0x25, 0x58, 0x38, 0x45, 0x25, 0x58, 0x41, 0x41, 0x25, 0x58, 0x42, 0x42, 0x25, 0x58, 0x43, 0x43, 
 
1864
             0x8706, 0x8a, };
 
1865
        int32_t from_euc_twOffs [] ={ 0, 1, 3, 
 
1866
             7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
1867
             11, 13};
 
1868
        
 
1869
        /*iso-2022-jp*/
 
1870
        const uint8_t sampleTxt_iso_2022_jp[]={ 
 
1871
            0x1b,   0x28,   0x42,   0x41,
 
1872
            0x1b,   0x24,   0x42,   0x2A, 0x44, /*unassigned*/
 
1873
            0x1b,   0x28,   0x42,   0x42,
 
1874
            
 
1875
        };
 
1876
        UChar iso_2022_jptoUnicode[]={    0x41,0x25,0x58,0x32,0x41,0x25,0x58,0x34,0x34, 0x42 };
 
1877
        int32_t from_iso_2022_jpOffs [] ={  3,   7,   7,   7,   7,   7,   7,   7,   7,    12   };
 
1878
        
 
1879
        /*iso-2022-cn*/
 
1880
        const uint8_t sampleTxt_iso_2022_cn[]={ 
 
1881
            0x0f,   0x41,   0x44,
 
1882
            0x1B,   0x24,   0x29,   0x47, 
 
1883
            0x0E,   0x40,   0x6c, /*unassigned*/
 
1884
            0x0f,   0x42,
 
1885
            
 
1886
        };
 
1887
        UChar iso_2022_cntoUnicode[]={    0x41, 0x44,0x25,0x58,0x34,0x30,0x25,0x58,0x36,0x43,0x42 };
 
1888
        int32_t from_iso_2022_cnOffs [] ={  1,   2,   8,   8,   8,   8,   8,   8,   8,  8,    11   };
 
1889
 
 
1890
        /*iso-2022-kr*/
 
1891
        const uint8_t sampleTxt_iso_2022_kr[]={ 
 
1892
          0x1b, 0x24, 0x29,  0x43,
 
1893
          0x41,
 
1894
          0x0E, 0x7f, 0x1E,
 
1895
          0x0e, 0x25, 0x50, 
 
1896
          0x0f, 0x51,
 
1897
          0x42, 0x43,
 
1898
            
 
1899
        };
 
1900
        UChar iso_2022_krtoUnicode[]={     0x41,0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,0x03A0,0x51, 0x42,0x43};
 
1901
        int32_t from_iso_2022_krOffs [] ={  4,   6,   6,   6,   6,   6,   6,   6,   6,    9,    12,   13  , 14 };
 
1902
        
 
1903
        /*hz*/
 
1904
        const uint8_t sampleTxt_hz[]={ 
 
1905
            0x41,   
 
1906
            0x7e,   0x7b,   0x26,   0x30,   
 
1907
            0x7f,   0x1E, /*unassigned*/ 
 
1908
            0x26,   0x30,
 
1909
            0x7e,   0x7d,   0x42, 
 
1910
            0x7e,   0x7b,   0x7f,   0x1E,/*unassigned*/ 
 
1911
            0x7e,   0x7d,   0x42,
 
1912
        };
 
1913
        UChar hztoUnicode[]={  
 
1914
            0x41,
 
1915
            0x03a0,
 
1916
            0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
 
1917
            0x03A0, 
 
1918
            0x42,
 
1919
            0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
 
1920
            0x42,};
 
1921
 
 
1922
        int32_t from_hzOffs [] ={0,3,5,5,5,5,5,5,5,5,7,11,14,14,14,14,14,14,14,14,18,  };
 
1923
 
 
1924
       
 
1925
        /*iscii*/
 
1926
        const uint8_t sampleTxt_iscii[]={ 
 
1927
            0x41,   
 
1928
            0x30,   
 
1929
            0xEB, /*unassigned*/ 
 
1930
            0xa3,
 
1931
            0x42, 
 
1932
            0xEC, /*unassigned*/ 
 
1933
            0x42,
 
1934
        };
 
1935
        UChar isciitoUnicode[]={  
 
1936
            0x41,
 
1937
            0x30,
 
1938
            0x25,  0x58,  0x45, 0x42,
 
1939
            0x0903, 
 
1940
            0x42,
 
1941
            0x25,  0x58,  0x45, 0x43,
 
1942
            0x42,};
 
1943
 
 
1944
        int32_t from_isciiOffs [] ={0,1,2,2,2,2,3,4,5,5,5,5,6  };
 
1945
 
 
1946
 
 
1947
        /*LMBCS*/
 
1948
        const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50, 
 
1949
            0x12, 0x92, 0xa0, /*unassigned*/
 
1950
            0x12, 0x92, 0xa1,
 
1951
        };
 
1952
        UChar LMBCSToUnicode[]={ 0x4e2e, 
 
1953
            0x25, 0x58, 0x31, 0x32, 0x25, 0x58, 0x39, 0x32, 0x25, 0x58, 0x41, 0x30, 
 
1954
            0xe5c4, };
 
1955
        int32_t fromLMBCS[] = {0, 
 
1956
            3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
1957
            6, };
 
1958
       
 
1959
        
 
1960
        if(!testConvertToUnicode(sampleTxtToU, sizeof(sampleTxtToU),
 
1961
                 IBM_943toUnicode, sizeof(IBM_943toUnicode)/sizeof(IBM_943toUnicode[0]),"ibm-943",
 
1962
                UCNV_TO_U_CALLBACK_ESCAPE, fromIBM943Offs, NULL, 0 ))
 
1963
            log_err("ibm-943->u with substitute with value did not match.\n");
 
1964
 
 
1965
        if(!testConvertToUnicode(sampleTxt_EUC_JP, sizeof(sampleTxt_EUC_JP),
 
1966
                 EUC_JPtoUnicode, sizeof(EUC_JPtoUnicode)/sizeof(EUC_JPtoUnicode[0]),"euc-jp",
 
1967
                UCNV_TO_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0))
 
1968
            log_err("euc-jp->u with substitute with value did not match.\n");
 
1969
 
 
1970
        if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
 
1971
                 euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
 
1972
                UCNV_TO_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0))
 
1973
            log_err("euc-tw->u with substitute with value did not match.\n");
 
1974
            
 
1975
        if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
 
1976
                 iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
 
1977
                UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0))
 
1978
            log_err("iso-2022-jp->u with substitute with value did not match.\n");
 
1979
        
 
1980
        {/* test UCNV_TO_U_CALLBACK_ESCAPE with options */
 
1981
            {
 
1982
                UChar iso_2022_jptoUnicodeDec[]={ 0x0041,   
 
1983
                                                  0x0026,   0x0023,   0x0034,   0x0032,   0x003b,   
 
1984
                                                  0x0026,   0x0023,   0x0036,   0x0038,   0x003b,   
 
1985
                                                  0x0042 };
 
1986
                int32_t from_iso_2022_jpOffsDec [] ={ 3,7,7,7,7,7,7,7,7,7,7,12,  };
 
1987
                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
 
1988
                     iso_2022_jptoUnicodeDec, sizeof(iso_2022_jptoUnicodeDec)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
 
1989
                    UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsDec, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
 
1990
                log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_DEC did not match.\n");
 
1991
            }
 
1992
            {
 
1993
                UChar iso_2022_jptoUnicodeHex[]={ 0x0041, 
 
1994
                                                  0x0026, 0x0023, 0x0078, 0x0032, 0x0041, 0x003b, 
 
1995
                                                  0x0026, 0x0023, 0x0078, 0x0034, 0x0034, 0x003b, 
 
1996
                                                  0x0042 };
 
1997
                int32_t from_iso_2022_jpOffsHex [] ={  3,7,7,7,7,7,7,7,7,7,7,7,7,12   };
 
1998
                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
 
1999
                     iso_2022_jptoUnicodeHex, sizeof(iso_2022_jptoUnicodeHex)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
 
2000
                    UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsHex, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
 
2001
                log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_HEX did not match.\n");
 
2002
            }
 
2003
            {
 
2004
                UChar iso_2022_jptoUnicodeC[]={ 0x0041, 
 
2005
                                                0x005C, 0x0078, 0x0032, 0x0041,
 
2006
                                                0x005C, 0x0078, 0x0034, 0x0034, 
 
2007
                                                0x0042 };
 
2008
                int32_t from_iso_2022_jpOffsC [] ={  3,7,7,7,7,7,7,7,7,12   };
 
2009
                if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
 
2010
                     iso_2022_jptoUnicodeC, sizeof(iso_2022_jptoUnicodeC)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
 
2011
                    UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsC, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
 
2012
                log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_C did not match.\n");
 
2013
            }
 
2014
        }
 
2015
        if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
 
2016
                 iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
 
2017
                UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0))
 
2018
            log_err("iso-2022-cn->u with substitute with value did not match.\n");
 
2019
        
 
2020
        if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
 
2021
                 iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
 
2022
                UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0))
 
2023
            log_err("iso-2022-kr->u with substitute with value did not match.\n");
 
2024
 
 
2025
         if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
 
2026
                 hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
 
2027
                UCNV_TO_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0))
 
2028
            log_err("hz->u with substitute with value did not match.\n");
 
2029
 
 
2030
         if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
 
2031
                 isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
 
2032
                UCNV_TO_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0))
 
2033
            log_err("ISCII ->u with substitute with value did not match.\n");
 
2034
        /*got to confirm this*/
 
2035
        if(/* broken for icu 1.6.0.1, do not test */uprv_strcmp("1.7", U_ICU_VERSION) != 0 && !testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
 
2036
                LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS",
 
2037
                UCNV_TO_U_CALLBACK_ESCAPE, fromLMBCS, NULL, 0))
 
2038
            log_err("LMBCS->u with substitute with value did not match.\n"); 
 
2039
    }
 
2040
}
 
2041
 
 
2042
static void TestLegalAndOthers(int32_t inputsize, int32_t outputsize)
 
2043
{
 
2044
    UChar    legalText[] =  { 0x0000, 0xAC00, 0xAC01, 0xD700 };
 
2045
    const uint8_t templegal949[] ={ 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
 
2046
    int32_t  to949legal[] = {0, 1, 1, 2, 2, 3, 3};
 
2047
 
 
2048
 
 
2049
    const uint8_t text943[] = {
 
2050
        0x82, 0xa9, 0x82, 0x20, /*0xc8,*/  0x61, 0x8a, 0xbf, 0x8e, 0x9a };
 
2051
        UChar toUnicode943sub[] = { 0x304b, 0xfffd, /*0xff88,*/ 0x0061, 0x6f22,  0x5b57};
 
2052
        UChar toUnicode943skip[]= { 0x304b, /*0xff88,*/ 0x0061, 0x6f22,  0x5b57};
 
2053
        UChar toUnicode943stop[]= { 0x304b};
 
2054
 
 
2055
    int32_t  fromIBM943Offssub[]  = {0, 2, 4, 5, 7};
 
2056
    int32_t  fromIBM943Offsskip[] = { 0, 4, 5, 7};
 
2057
    int32_t  fromIBM943Offsstop[] = { 0};
 
2058
 
 
2059
    gInBufferSize = inputsize;
 
2060
    gOutBufferSize = outputsize;
 
2061
    /*checking with a legal value*/
 
2062
    if(!testConvertFromUnicode(legalText, sizeof(legalText)/sizeof(legalText[0]),
 
2063
            templegal949, sizeof(templegal949), "ibm-949",
 
2064
            UCNV_FROM_U_CALLBACK_SKIP, to949legal, NULL, 0 ))
 
2065
        log_err("u-> ibm-949 with skip did not match.\n");
 
2066
 
 
2067
    /*checking illegal value for ibm-943 with substitute*/ 
 
2068
    if(!testConvertToUnicode(text943, sizeof(text943),
 
2069
             toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
 
2070
            UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
 
2071
        log_err("ibm-943->u with subst did not match.\n");
 
2072
    /*checking illegal value for ibm-943 with skip */
 
2073
    if(!testConvertToUnicode(text943, sizeof(text943),
 
2074
             toUnicode943skip, sizeof(toUnicode943skip)/sizeof(toUnicode943skip[0]),"ibm-943",
 
2075
            UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offsskip, NULL, 0 ))
 
2076
        log_err("ibm-943->u with skip did not match.\n");
 
2077
 
 
2078
    /*checking illegal value for ibm-943 with stop */
 
2079
    if(!testConvertToUnicode(text943, sizeof(text943),
 
2080
             toUnicode943stop, sizeof(toUnicode943stop)/sizeof(toUnicode943stop[0]),"ibm-943",
 
2081
            UCNV_TO_U_CALLBACK_STOP, fromIBM943Offsstop, NULL, 0 ))
 
2082
        log_err("ibm-943->u with stop did not match.\n");
 
2083
 
 
2084
}
 
2085
 
 
2086
static void TestSingleByte(int32_t inputsize, int32_t outputsize)
 
2087
{
 
2088
    const uint8_t sampleText[] = {
 
2089
        0x82, 0xa9, 0x61, 0x62, 0x63 , 0x82,
 
2090
        0xff, /*0x82, 0xa9,*/ 0x32, 0x33};
 
2091
    UChar toUnicode943sub[] = {0x304b, 0x0061, 0x0062, 0x0063,  0xfffd,/*0x304b,*/ 0x0032, 0x0033};
 
2092
    int32_t  fromIBM943Offssub[]  = {0, 2, 3, 4, 5, 7, 8};
 
2093
    /*checking illegal value for ibm-943 with substitute*/ 
 
2094
    gInBufferSize = inputsize;
 
2095
    gOutBufferSize = outputsize;
 
2096
 
 
2097
    if(!testConvertToUnicode(sampleText, sizeof(sampleText),
 
2098
             toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
 
2099
            UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
 
2100
        log_err("ibm-943->u with subst did not match.\n");
 
2101
}
 
2102
 
 
2103
static void TestEBCDIC_STATEFUL_Sub(int32_t inputsize, int32_t outputsize)
 
2104
{
 
2105
    /*EBCDIC_STATEFUL*/
 
2106
    UChar ebcdic_inputTest[] = { 0x0061, 0x6d64, 0x0061, 0x00A2, 0x6d65, 0x0061 };
 
2107
    const uint8_t toIBM930[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x0e, 0xfe, 0xfe, 0x0f, 0x62 };
 
2108
    int32_t offset_930[]=     { 0,    1,    1,    1,    2,    2,    3,    4,    4,    4,    5,    5    };
 
2109
/*                              s     SO    doubl       SI    sng   s     SO    fe    fe    SI    s    */
 
2110
 
 
2111
    /*EBCDIC_STATEFUL with subChar=3f*/
 
2112
    const uint8_t toIBM930_subvaried[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x3f, 0x62 };
 
2113
    int32_t offset_930_subvaried[]=     { 0,    1,    1,    1,    2,    2,    3,    4,    5    };
 
2114
    const char mySubChar[]={ 0x3f};
 
2115
 
 
2116
    gInBufferSize = inputsize;
 
2117
    gOutBufferSize = outputsize;
 
2118
 
 
2119
    if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
 
2120
        toIBM930, sizeof(toIBM930), "ibm-930",
 
2121
        UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930, NULL, 0 ))
 
2122
            log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst did not match.\n");
 
2123
    
 
2124
    if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
 
2125
        toIBM930_subvaried, sizeof(toIBM930_subvaried), "ibm-930",
 
2126
        UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930_subvaried, mySubChar, 1 ))
 
2127
            log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst(setSubChar=0x3f) did not match.\n");
 
2128
}
 
2129
 
 
2130
 
 
2131
 
 
2132
UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const uint8_t *expect, int expectLen, 
 
2133
                const char *codepage, UConverterFromUCallback callback , const int32_t *expectOffsets, 
 
2134
                const char *mySubChar, int8_t len)
 
2135
{
 
2136
 
 
2137
 
 
2138
    UErrorCode status = U_ZERO_ERROR;
 
2139
    UConverter *conv = 0;
 
2140
    uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
 
2141
    int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
 
2142
    const UChar *src;
 
2143
    uint8_t *end;
 
2144
    uint8_t *targ;
 
2145
    int32_t *offs;
 
2146
    int i;
 
2147
    int32_t  realBufferSize;
 
2148
    uint8_t *realBufferEnd;
 
2149
    const UChar *realSourceEnd;
 
2150
    const UChar *sourceLimit;
 
2151
    UBool checkOffsets = TRUE;
 
2152
    UBool doFlush;
 
2153
    char junk[9999];
 
2154
    char offset_str[9999];
 
2155
    uint8_t *p;
 
2156
    UConverterFromUCallback oldAction = NULL;
 
2157
    const void* oldContext = NULL;
 
2158
 
 
2159
 
 
2160
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2161
        junkout[i] = 0xF0;
 
2162
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2163
        junokout[i] = 0xFF;
 
2164
    setNuConvTestName(codepage, "FROM");
 
2165
 
 
2166
    log_verbose("\nTesting========= %s  FROM \n  inputbuffer= %d   outputbuffer= %d\n", codepage, gInBufferSize, 
 
2167
            gOutBufferSize);
 
2168
 
 
2169
    conv = ucnv_open(codepage, &status);
 
2170
    if(U_FAILURE(status))
 
2171
    {
 
2172
        log_err("Couldn't open converter %s\n",codepage);
 
2173
        return FALSE;
 
2174
    }
 
2175
 
 
2176
    log_verbose("Converter opened..\n");
 
2177
 
 
2178
    /*----setting the callback routine----*/
 
2179
    ucnv_setFromUCallBack (conv, callback, NULL, &oldAction, &oldContext, &status);
 
2180
    if (U_FAILURE(status)) 
 
2181
    { 
 
2182
        log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
 
2183
    }
 
2184
    /*------------------------*/
 
2185
    /*setting the subChar*/
 
2186
    if(mySubChar != NULL){
 
2187
        ucnv_setSubstChars(conv, mySubChar, len, &status);
 
2188
        if (U_FAILURE(status))  { 
 
2189
            log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
 
2190
        }
 
2191
    }
 
2192
    /*------------*/
 
2193
 
 
2194
    src = source;
 
2195
    targ = junkout;
 
2196
    offs = junokout;
 
2197
 
 
2198
    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
 
2199
    realBufferEnd = junkout + realBufferSize;
 
2200
    realSourceEnd = source + sourceLen;
 
2201
 
 
2202
    if ( gOutBufferSize != realBufferSize )
 
2203
      checkOffsets = FALSE;
 
2204
 
 
2205
    if( gInBufferSize != NEW_MAX_BUFFER )
 
2206
      checkOffsets = FALSE;
 
2207
 
 
2208
    do
 
2209
    {
 
2210
        end = nct_min(targ + gOutBufferSize, realBufferEnd);
 
2211
        sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
 
2212
 
 
2213
        doFlush = (UBool)(sourceLimit == realSourceEnd);
 
2214
 
 
2215
        if(targ == realBufferEnd)
 
2216
        {
 
2217
            log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
 
2218
            return FALSE;
 
2219
        }
 
2220
        log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
 
2221
 
 
2222
 
 
2223
        status = U_ZERO_ERROR;
 
2224
 
 
2225
        ucnv_fromUnicode (conv,
 
2226
                  (char **)&targ,
 
2227
                  (const char *)end,
 
2228
                  &src,
 
2229
                  sourceLimit,
 
2230
                  checkOffsets ? offs : NULL,
 
2231
                  doFlush, /* flush if we're at the end of the input data */
 
2232
                  &status);
 
2233
    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (sourceLimit < realSourceEnd)) );
 
2234
 
 
2235
    /* allow failure codes for the stop callback */
 
2236
    if(U_FAILURE(status) &&
 
2237
       (callback != UCNV_FROM_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND)))
 
2238
    {
 
2239
        log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
 
2240
        return FALSE;
 
2241
    }
 
2242
 
 
2243
    log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
 
2244
        sourceLen, targ-junkout);
 
2245
    if(VERBOSITY)
 
2246
    {
 
2247
 
 
2248
        junk[0] = 0;
 
2249
        offset_str[0] = 0;
 
2250
        for(p = junkout;p<targ;p++)
 
2251
        {
 
2252
            sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
 
2253
            sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
 
2254
        }
 
2255
 
 
2256
        log_verbose(junk);
 
2257
        printSeq(expect, expectLen);
 
2258
        if ( checkOffsets )
 
2259
        {
 
2260
            log_verbose("\nOffsets:");
 
2261
            log_verbose(offset_str);
 
2262
        }
 
2263
        log_verbose("\n");
 
2264
    }
 
2265
    ucnv_close(conv);
 
2266
 
 
2267
 
 
2268
    if(expectLen != targ-junkout)
 
2269
    {
 
2270
        log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
 
2271
        log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
 
2272
        printSeqErr(junkout, targ-junkout);
 
2273
        printSeqErr(expect, expectLen);
 
2274
        return FALSE;
 
2275
    }
 
2276
 
 
2277
    if (checkOffsets && (expectOffsets != 0) )
 
2278
    {
 
2279
        log_verbose("comparing %d offsets..\n", targ-junkout);
 
2280
        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
 
2281
            log_err("did not get the expected offsets while %s \n", gNuConvTestName);
 
2282
            log_err("Got Output : ");
 
2283
            printSeqErr(junkout, targ-junkout);
 
2284
            log_err("Got Offsets:      ");
 
2285
            for(p=junkout;p<targ;p++)
 
2286
                log_err("%d,", junokout[p-junkout]); 
 
2287
            log_err("\n");
 
2288
            log_err("Expected Offsets: ");
 
2289
            for(i=0; i<(targ-junkout); i++)
 
2290
                log_err("%d,", expectOffsets[i]);
 
2291
            log_err("\n");
 
2292
            return FALSE;
 
2293
        }
 
2294
    }
 
2295
 
 
2296
    if(!memcmp(junkout, expect, expectLen))
 
2297
    {
 
2298
        log_verbose("String matches! %s\n", gNuConvTestName);
 
2299
        return TRUE;
 
2300
    }
 
2301
    else
 
2302
    {
 
2303
        log_err("String does not match. %s\n", gNuConvTestName);
 
2304
        log_err("source: ");
 
2305
        printUSeqErr(source, sourceLen);
 
2306
        log_err("Got:      ");
 
2307
        printSeqErr(junkout, expectLen);
 
2308
        log_err("Expected: ");
 
2309
        printSeqErr(expect, expectLen);
 
2310
        return FALSE;
 
2311
    }
 
2312
}
 
2313
UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen, 
 
2314
               const char *codepage, UConverterToUCallback callback, const int32_t *expectOffsets,
 
2315
               const char *mySubChar, int8_t len)
 
2316
{
 
2317
    UErrorCode status = U_ZERO_ERROR;
 
2318
    UConverter *conv = 0;
 
2319
    UChar   junkout[NEW_MAX_BUFFER]; /* FIX */
 
2320
    int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
 
2321
    const uint8_t *src;
 
2322
    const uint8_t *realSourceEnd;
 
2323
    const uint8_t *srcLimit;
 
2324
    UChar *targ;
 
2325
    UChar *end;
 
2326
    int32_t *offs;
 
2327
    int i;
 
2328
    UBool   checkOffsets = TRUE;
 
2329
    char junk[9999];
 
2330
    char offset_str[9999];
 
2331
    UChar *p;
 
2332
    UConverterToUCallback oldAction = NULL;
 
2333
    const void* oldContext = NULL;
 
2334
 
 
2335
    int32_t   realBufferSize;
 
2336
    UChar *realBufferEnd;
 
2337
 
 
2338
 
 
2339
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2340
        junkout[i] = 0xFFFE;
 
2341
 
 
2342
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2343
        junokout[i] = -1;
 
2344
 
 
2345
    setNuConvTestName(codepage, "TO");
 
2346
 
 
2347
    log_verbose("\n=========  %s\n", gNuConvTestName);
 
2348
 
 
2349
    conv = ucnv_open(codepage, &status);
 
2350
    if(U_FAILURE(status))
 
2351
    {
 
2352
        log_err("Couldn't open converter %s\n",gNuConvTestName);
 
2353
        return FALSE;
 
2354
    }
 
2355
 
 
2356
    log_verbose("Converter opened..\n");
 
2357
 
 
2358
    src = source;
 
2359
    targ = junkout;
 
2360
    offs = junokout;
 
2361
 
 
2362
    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
 
2363
    realBufferEnd = junkout + realBufferSize;
 
2364
    realSourceEnd = src + sourcelen;
 
2365
    /*----setting the callback routine----*/
 
2366
    ucnv_setToUCallBack (conv, callback, NULL, &oldAction, &oldContext, &status);
 
2367
    if (U_FAILURE(status)) 
 
2368
    { 
 
2369
        log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));  
 
2370
    }
 
2371
    /*-------------------------------------*/
 
2372
    /*setting the subChar*/
 
2373
    if(mySubChar != NULL){
 
2374
        ucnv_setSubstChars(conv, mySubChar, len, &status);
 
2375
        if (U_FAILURE(status))  { 
 
2376
            log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status)); 
 
2377
        }
 
2378
    }
 
2379
    /*------------*/
 
2380
 
 
2381
 
 
2382
    if ( gOutBufferSize != realBufferSize )
 
2383
        checkOffsets = FALSE;
 
2384
 
 
2385
    if( gInBufferSize != NEW_MAX_BUFFER )
 
2386
        checkOffsets = FALSE;
 
2387
 
 
2388
    do
 
2389
    {
 
2390
        end = nct_min( targ + gOutBufferSize, realBufferEnd);
 
2391
        srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
 
2392
 
 
2393
        if(targ == realBufferEnd)
 
2394
        {
 
2395
            log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
 
2396
            return FALSE;
 
2397
        }
 
2398
        log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
 
2399
 
 
2400
 
 
2401
 
 
2402
        status = U_ZERO_ERROR;
 
2403
 
 
2404
        ucnv_toUnicode (conv,
 
2405
                &targ,
 
2406
                end,
 
2407
                (const char **)&src,
 
2408
                (const char *)srcLimit,
 
2409
                checkOffsets ? offs : NULL,
 
2410
                (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */
 
2411
                &status);
 
2412
    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
 
2413
 
 
2414
    /* allow failure codes for the stop callback */
 
2415
    if(U_FAILURE(status) &&
 
2416
       (callback != UCNV_TO_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND && status != U_TRUNCATED_CHAR_FOUND)))
 
2417
    {
 
2418
        log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
 
2419
        return FALSE;
 
2420
    }
 
2421
 
 
2422
    log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
 
2423
        sourcelen, targ-junkout);
 
2424
    if(VERBOSITY)
 
2425
    {
 
2426
 
 
2427
        junk[0] = 0;
 
2428
        offset_str[0] = 0;
 
2429
 
 
2430
        for(p = junkout;p<targ;p++)
 
2431
        {
 
2432
            sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
 
2433
            sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
 
2434
        }
 
2435
 
 
2436
        log_verbose(junk);
 
2437
        printUSeq(expect, expectlen);
 
2438
        if ( checkOffsets )
 
2439
        {
 
2440
            log_verbose("\nOffsets:");
 
2441
            log_verbose(offset_str);
 
2442
        }
 
2443
        log_verbose("\n");
 
2444
    }
 
2445
    ucnv_close(conv);
 
2446
 
 
2447
    log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
 
2448
 
 
2449
    if (checkOffsets && (expectOffsets != 0))
 
2450
    {
 
2451
        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
 
2452
        {
 
2453
            log_err("did not get the expected offsets while %s \n", gNuConvTestName);
 
2454
            log_err("Got offsets:      ");
 
2455
            for(p=junkout;p<targ;p++)
 
2456
                log_err("  %2d,", junokout[p-junkout]); 
 
2457
            log_err("\n");
 
2458
            log_err("Expected offsets: ");
 
2459
            for(i=0; i<(targ-junkout); i++)
 
2460
                log_err("  %2d,", expectOffsets[i]);
 
2461
            log_err("\n");
 
2462
            log_err("Got output:       ");
 
2463
            for(i=0; i<(targ-junkout); i++)
 
2464
                log_err("0x%04x,", junkout[i]);
 
2465
            log_err("\n");
 
2466
            log_err("From source:      ");
 
2467
            for(i=0; i<(src-source); i++)
 
2468
                log_err("  0x%02x,", (unsigned char)source[i]);
 
2469
            log_err("\n");
 
2470
        }
 
2471
    }
 
2472
 
 
2473
    if(!memcmp(junkout, expect, expectlen*2))
 
2474
    {
 
2475
        log_verbose("Matches!\n");
 
2476
        return TRUE;
 
2477
    }
 
2478
    else
 
2479
    {
 
2480
        log_err("String does not match. %s\n", gNuConvTestName);
 
2481
        log_verbose("String does not match. %s\n", gNuConvTestName);
 
2482
        log_err("Got:      ");
 
2483
        printUSeqErr(junkout, expectlen);
 
2484
        log_err("Expected: ");
 
2485
        printUSeqErr(expect, expectlen);
 
2486
        log_err("\n");
 
2487
        return FALSE;
 
2488
    }
 
2489
}
 
2490
 
 
2491
UBool testConvertFromUnicodeWithContext(const UChar *source, int sourceLen,  const uint8_t *expect, int expectLen, 
 
2492
                const char *codepage, UConverterFromUCallback callback , const int32_t *expectOffsets, 
 
2493
                const char *mySubChar, int8_t len, const void* context, UErrorCode expectedError)
 
2494
{
 
2495
 
 
2496
 
 
2497
    UErrorCode status = U_ZERO_ERROR;
 
2498
    UConverter *conv = 0;
 
2499
    uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
 
2500
    int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
 
2501
    const UChar *src;
 
2502
    uint8_t *end;
 
2503
    uint8_t *targ;
 
2504
    int32_t *offs;
 
2505
    int i;
 
2506
    int32_t  realBufferSize;
 
2507
    uint8_t *realBufferEnd;
 
2508
    const UChar *realSourceEnd;
 
2509
    const UChar *sourceLimit;
 
2510
    UBool checkOffsets = TRUE;
 
2511
    UBool doFlush;
 
2512
    char junk[9999];
 
2513
    char offset_str[9999];
 
2514
    uint8_t *p;
 
2515
    UConverterFromUCallback oldAction = NULL;
 
2516
    const void* oldContext = NULL;
 
2517
 
 
2518
 
 
2519
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2520
        junkout[i] = 0xF0;
 
2521
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2522
        junokout[i] = 0xFF;
 
2523
    setNuConvTestName(codepage, "FROM");
 
2524
 
 
2525
    log_verbose("\nTesting========= %s  FROM \n  inputbuffer= %d   outputbuffer= %d\n", codepage, gInBufferSize, 
 
2526
            gOutBufferSize);
 
2527
 
 
2528
    conv = ucnv_open(codepage, &status);
 
2529
    if(U_FAILURE(status))
 
2530
    {
 
2531
        log_err("Couldn't open converter %s\n",codepage);
 
2532
        return FALSE;
 
2533
    }
 
2534
 
 
2535
    log_verbose("Converter opened..\n");
 
2536
 
 
2537
    /*----setting the callback routine----*/
 
2538
    ucnv_setFromUCallBack (conv, callback, context, &oldAction, &oldContext, &status);
 
2539
    if (U_FAILURE(status)) 
 
2540
    { 
 
2541
        log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
 
2542
    }
 
2543
    /*------------------------*/
 
2544
    /*setting the subChar*/
 
2545
    if(mySubChar != NULL){
 
2546
        ucnv_setSubstChars(conv, mySubChar, len, &status);
 
2547
        if (U_FAILURE(status))  { 
 
2548
            log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
 
2549
        }
 
2550
    }
 
2551
    /*------------*/
 
2552
 
 
2553
    src = source;
 
2554
    targ = junkout;
 
2555
    offs = junokout;
 
2556
 
 
2557
    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
 
2558
    realBufferEnd = junkout + realBufferSize;
 
2559
    realSourceEnd = source + sourceLen;
 
2560
 
 
2561
    if ( gOutBufferSize != realBufferSize )
 
2562
      checkOffsets = FALSE;
 
2563
 
 
2564
    if( gInBufferSize != NEW_MAX_BUFFER )
 
2565
      checkOffsets = FALSE;
 
2566
 
 
2567
    do
 
2568
    {
 
2569
        end = nct_min(targ + gOutBufferSize, realBufferEnd);
 
2570
        sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
 
2571
 
 
2572
        doFlush = (UBool)(sourceLimit == realSourceEnd);
 
2573
 
 
2574
        if(targ == realBufferEnd)
 
2575
        {
 
2576
            log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
 
2577
            return FALSE;
 
2578
        }
 
2579
        log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
 
2580
 
 
2581
 
 
2582
        status = U_ZERO_ERROR;
 
2583
 
 
2584
        ucnv_fromUnicode (conv,
 
2585
                  (char **)&targ,
 
2586
                  (const char *)end,
 
2587
                  &src,
 
2588
                  sourceLimit,
 
2589
                  checkOffsets ? offs : NULL,
 
2590
                  doFlush, /* flush if we're at the end of the input data */
 
2591
                  &status);
 
2592
    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (sourceLimit < realSourceEnd)) );
 
2593
 
 
2594
    /* allow failure codes for the stop callback */
 
2595
    if(U_FAILURE(status) && status != expectedError)
 
2596
    {
 
2597
        log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
 
2598
        return FALSE;
 
2599
    }
 
2600
 
 
2601
    log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
 
2602
        sourceLen, targ-junkout);
 
2603
    if(VERBOSITY)
 
2604
    {
 
2605
 
 
2606
        junk[0] = 0;
 
2607
        offset_str[0] = 0;
 
2608
        for(p = junkout;p<targ;p++)
 
2609
        {
 
2610
            sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
 
2611
            sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
 
2612
        }
 
2613
 
 
2614
        log_verbose(junk);
 
2615
        printSeq(expect, expectLen);
 
2616
        if ( checkOffsets )
 
2617
        {
 
2618
            log_verbose("\nOffsets:");
 
2619
            log_verbose(offset_str);
 
2620
        }
 
2621
        log_verbose("\n");
 
2622
    }
 
2623
    ucnv_close(conv);
 
2624
 
 
2625
 
 
2626
    if(expectLen != targ-junkout)
 
2627
    {
 
2628
        log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
 
2629
        log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
 
2630
        printSeqErr(junkout, targ-junkout);
 
2631
        printSeqErr(expect, expectLen);
 
2632
        return FALSE;
 
2633
    }
 
2634
 
 
2635
    if (checkOffsets && (expectOffsets != 0) )
 
2636
    {
 
2637
        log_verbose("comparing %d offsets..\n", targ-junkout);
 
2638
        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
 
2639
            log_err("did not get the expected offsets while %s \n", gNuConvTestName);
 
2640
            log_err("Got Output : ");
 
2641
            printSeqErr(junkout, targ-junkout);
 
2642
            log_err("Got Offsets:      ");
 
2643
            for(p=junkout;p<targ;p++)
 
2644
                log_err("%d,", junokout[p-junkout]); 
 
2645
            log_err("\n");
 
2646
            log_err("Expected Offsets: ");
 
2647
            for(i=0; i<(targ-junkout); i++)
 
2648
                log_err("%d,", expectOffsets[i]);
 
2649
            log_err("\n");
 
2650
            return FALSE;
 
2651
        }
 
2652
    }
 
2653
 
 
2654
    if(!memcmp(junkout, expect, expectLen))
 
2655
    {
 
2656
        log_verbose("String matches! %s\n", gNuConvTestName);
 
2657
        return TRUE;
 
2658
    }
 
2659
    else
 
2660
    {
 
2661
        log_err("String does not match. %s\n", gNuConvTestName);
 
2662
        log_err("source: ");
 
2663
        printUSeqErr(source, sourceLen);
 
2664
        log_err("Got:      ");
 
2665
        printSeqErr(junkout, expectLen);
 
2666
        log_err("Expected: ");
 
2667
        printSeqErr(expect, expectLen);
 
2668
        return FALSE;
 
2669
    }
 
2670
}
 
2671
UBool testConvertToUnicodeWithContext( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen, 
 
2672
               const char *codepage, UConverterToUCallback callback, const int32_t *expectOffsets,
 
2673
               const char *mySubChar, int8_t len, const void* context, UErrorCode expectedError)
 
2674
{
 
2675
    UErrorCode status = U_ZERO_ERROR;
 
2676
    UConverter *conv = 0;
 
2677
    UChar   junkout[NEW_MAX_BUFFER]; /* FIX */
 
2678
    int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
 
2679
    const uint8_t *src;
 
2680
    const uint8_t *realSourceEnd;
 
2681
    const uint8_t *srcLimit;
 
2682
    UChar *targ;
 
2683
    UChar *end;
 
2684
    int32_t *offs;
 
2685
    int i;
 
2686
    UBool   checkOffsets = TRUE;
 
2687
    char junk[9999];
 
2688
    char offset_str[9999];
 
2689
    UChar *p;
 
2690
    UConverterToUCallback oldAction = NULL;
 
2691
    const void* oldContext = NULL;
 
2692
 
 
2693
    int32_t   realBufferSize;
 
2694
    UChar *realBufferEnd;
 
2695
 
 
2696
 
 
2697
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2698
        junkout[i] = 0xFFFE;
 
2699
 
 
2700
    for(i=0;i<NEW_MAX_BUFFER;i++)
 
2701
        junokout[i] = -1;
 
2702
 
 
2703
    setNuConvTestName(codepage, "TO");
 
2704
 
 
2705
    log_verbose("\n=========  %s\n", gNuConvTestName);
 
2706
 
 
2707
    conv = ucnv_open(codepage, &status);
 
2708
    if(U_FAILURE(status))
 
2709
    {
 
2710
        log_err("Couldn't open converter %s\n",gNuConvTestName);
 
2711
        return FALSE;
 
2712
    }
 
2713
 
 
2714
    log_verbose("Converter opened..\n");
 
2715
 
 
2716
    src = source;
 
2717
    targ = junkout;
 
2718
    offs = junokout;
 
2719
 
 
2720
    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
 
2721
    realBufferEnd = junkout + realBufferSize;
 
2722
    realSourceEnd = src + sourcelen;
 
2723
    /*----setting the callback routine----*/
 
2724
    ucnv_setToUCallBack (conv, callback, context, &oldAction, &oldContext, &status);
 
2725
    if (U_FAILURE(status)) 
 
2726
    { 
 
2727
        log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));  
 
2728
    }
 
2729
    /*-------------------------------------*/
 
2730
    /*setting the subChar*/
 
2731
    if(mySubChar != NULL){
 
2732
        ucnv_setSubstChars(conv, mySubChar, len, &status);
 
2733
        if (U_FAILURE(status))  { 
 
2734
            log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status)); 
 
2735
        }
 
2736
    }
 
2737
    /*------------*/
 
2738
 
 
2739
 
 
2740
    if ( gOutBufferSize != realBufferSize )
 
2741
        checkOffsets = FALSE;
 
2742
 
 
2743
    if( gInBufferSize != NEW_MAX_BUFFER )
 
2744
        checkOffsets = FALSE;
 
2745
 
 
2746
    do
 
2747
    {
 
2748
        end = nct_min( targ + gOutBufferSize, realBufferEnd);
 
2749
        srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
 
2750
 
 
2751
        if(targ == realBufferEnd)
 
2752
        {
 
2753
            log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
 
2754
            return FALSE;
 
2755
        }
 
2756
        log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
 
2757
 
 
2758
 
 
2759
 
 
2760
        status = U_ZERO_ERROR;
 
2761
 
 
2762
        ucnv_toUnicode (conv,
 
2763
                &targ,
 
2764
                end,
 
2765
                (const char **)&src,
 
2766
                (const char *)srcLimit,
 
2767
                checkOffsets ? offs : NULL,
 
2768
                (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */
 
2769
                &status);
 
2770
    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
 
2771
 
 
2772
    /* allow failure codes for the stop callback */
 
2773
    if(U_FAILURE(status) && status!=expectedError)
 
2774
    {
 
2775
        log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
 
2776
        return FALSE;
 
2777
    }
 
2778
 
 
2779
    log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
 
2780
        sourcelen, targ-junkout);
 
2781
    if(VERBOSITY)
 
2782
    {
 
2783
 
 
2784
        junk[0] = 0;
 
2785
        offset_str[0] = 0;
 
2786
 
 
2787
        for(p = junkout;p<targ;p++)
 
2788
        {
 
2789
            sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
 
2790
            sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
 
2791
        }
 
2792
 
 
2793
        log_verbose(junk);
 
2794
        printUSeq(expect, expectlen);
 
2795
        if ( checkOffsets )
 
2796
        {
 
2797
            log_verbose("\nOffsets:");
 
2798
            log_verbose(offset_str);
 
2799
        }
 
2800
        log_verbose("\n");
 
2801
    }
 
2802
    ucnv_close(conv);
 
2803
 
 
2804
    log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
 
2805
 
 
2806
    if (checkOffsets && (expectOffsets != 0))
 
2807
    {
 
2808
        if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
 
2809
        {
 
2810
            log_err("did not get the expected offsets while %s \n", gNuConvTestName);
 
2811
            log_err("Got offsets:      ");
 
2812
            for(p=junkout;p<targ;p++)
 
2813
                log_err("  %2d,", junokout[p-junkout]); 
 
2814
            log_err("\n");
 
2815
            log_err("Expected offsets: ");
 
2816
            for(i=0; i<(targ-junkout); i++)
 
2817
                log_err("  %2d,", expectOffsets[i]);
 
2818
            log_err("\n");
 
2819
            log_err("Got output:       ");
 
2820
            for(i=0; i<(targ-junkout); i++)
 
2821
                log_err("0x%04x,", junkout[i]);
 
2822
            log_err("\n");
 
2823
            log_err("From source:      ");
 
2824
            for(i=0; i<(src-source); i++)
 
2825
                log_err("  0x%02x,", (unsigned char)source[i]);
 
2826
            log_err("\n");
 
2827
        }
 
2828
    }
 
2829
 
 
2830
    if(!memcmp(junkout, expect, expectlen*2))
 
2831
    {
 
2832
        log_verbose("Matches!\n");
 
2833
        return TRUE;
 
2834
    }
 
2835
    else
 
2836
    {
 
2837
        log_err("String does not match. %s\n", gNuConvTestName);
 
2838
        log_verbose("String does not match. %s\n", gNuConvTestName);
 
2839
        log_err("Got:      ");
 
2840
        printUSeqErr(junkout, expectlen);
 
2841
        log_err("Expected: ");
 
2842
        printUSeqErr(expect, expectlen);
 
2843
        log_err("\n");
 
2844
        return FALSE;
 
2845
    }
 
2846
}