OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [i18n/] [v2_0/] [tests/] [i18nmb.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//=================================================================
2
//
3
//        i18nmb.c
4
//
5
//        General testcase for C library multibyte functions
6
//
7
//=================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     jjohnstn
44
// Contributors:  
45
// Date:          2000-11-24
46
// Description:   Contains general testcode for C library multibyte character functions
47
//
48
//
49
//####DESCRIPTIONEND####
50
 
51
// INCLUDES
52
 
53
#include <pkgconf/libc_i18n.h>     // Configuration header
54
#include <stdlib.h>
55
#include <locale.h>
56
#include <stdio.h>
57
#include <cyg/infra/testcase.h>
58
#include <string.h>
59
 
60
// FUNCTIONS
61
 
62
int
63
main( int argc, char *argv[] )
64
{
65
 
66
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_JIS
67
  unsigned char in_jis[] =
68
    "abcd\x1b$B\x23\x25\x45\x46\x1b(B23";
69
  unsigned char fmt_jis[] =
70
    "abcd\x1b$B\x23\x25\x45\x46\x1b(B%d";
71
 
72
  unsigned char * testjis[] = {
73
    "abcd\x1b$B\x23\x25\x45\x46\x1b(B",
74
    "abcd\x1b$B\x23\x25\x1b(Befg",
75
    "\x1b$B\x23\x7f\x1b(B",
76
    "\x1b$B\x44\x45\x46\x1b(B",
77
    "\x1b$B",
78
    "\x1b$B\x1b(B",
79
    "\x1b$B\x44\x45",
80
  };
81
 
82
  int mblenjis0[] = { 1, 1, 1, 1, 5, 5, 0};
83
  int mblenjis1[] = { 1, 1, 1, 1, 8, 1, 1, 1, 0 };
84
  int mblenjis2[] = { -1 };
85
  int mblenjis3[] = { 5, -1 };
86
  int mblenjis4[] = { -1 };
87
  int mblenjis5[] = { -1 };
88
  int mblenjis6[] = { -1 };
89
 
90
  int *mblenjis[] = {
91
    mblenjis0,
92
    mblenjis1,
93
    mblenjis2,
94
    mblenjis3,
95
    mblenjis4,
96
    mblenjis5,
97
    mblenjis6,
98
  };
99
 
100
  wchar_t mbtowcjis0[] = {
101
    (wchar_t)'a',
102
    (wchar_t)'b',
103
    (wchar_t)'c',
104
    (wchar_t)'d',
105
    (wchar_t)0x2325,
106
    (wchar_t)0x4546,
107
    (wchar_t)0
108
  };
109
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_JIS */
110
 
111
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_SJIS
112
  unsigned char in_sjis[] =
113
    "ab\x81\x40\x9f\x7e\xe0\x80\xef\xfcgh23";
114
  unsigned char fmt_sjis[] =
115
    "ab\x81\x40\x9f\x7e\xe0\x80\xef\xfcgh%d";
116
 
117
  unsigned char * testsjis[] = {
118
    "ab\x81\x40\x9f\x7e\xe0\x80\xef\xfcgh",
119
    "\x80\x40",
120
    "\xa0\x40",
121
    "\xdf\x40",
122
    "\xf0\x40",
123
    "\x84\x3f",
124
    "\x85\x7f",
125
    "\x86\xfd",
126
    "\x81",
127
  };
128
 
129
  int mblensjis0[] = { 1, 1, 2, 2, 2, 2, 1, 1, 0};
130
  int mblensjis1[] = { 1, 1, 0 };
131
  int mblensjis2[] = { 1, 1, 0 };
132
  int mblensjis3[] = { 1, 1, 0 };
133
  int mblensjis4[] = { 1, 1, 0 };
134
  int mblensjis5[] = { -1 };
135
  int mblensjis6[] = { -1 };
136
  int mblensjis7[] = { -1 };
137
  int mblensjis8[] = { -1 };
138
 
139
  int *mblensjis[] = {
140
    mblensjis0,
141
    mblensjis1,
142
    mblensjis2,
143
    mblensjis3,
144
    mblensjis4,
145
    mblensjis5,
146
    mblensjis6,
147
    mblensjis7,
148
    mblensjis8,
149
  };
150
 
151
  wchar_t mbtowcsjis0[] = {
152
    (wchar_t)'a',
153
    (wchar_t)'b',
154
    (wchar_t)0x8140,
155
    (wchar_t)0x9f7e,
156
    (wchar_t)0xe080,
157
    (wchar_t)0xeffc,
158
    (wchar_t)'g',
159
    (wchar_t)'h',
160
    (wchar_t)0
161
  };
162
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_SJIS */
163
 
164
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_EUCJP
165
  unsigned char in_eucjp[] =
166
    "ab\xa1\xa1\xa2\xfe\xe0\xfd\xef\xfcgh23";
167
  unsigned char fmt_eucjp[] =
168
    "ab\xa1\xa1\xa2\xfe\xe0\xfd\xef\xfcgh%d";
169
 
170
  unsigned char * testeucjp[] = {
171
    "ab\xa1\xa1\xa2\xfe\xe0\xfd\xef\xfcgh",
172
    "\x80\xa1",
173
    "\xa0\xa1",
174
    "\xff\xa1",
175
    "\x40\xa1",
176
    "\xa3\x3f",
177
    "\xa4\x7f",
178
    "\xa5\xff",
179
    "\xb1",
180
  };
181
 
182
  int mbleneucjp0[] = { 1, 1, 2, 2, 2, 2, 1, 1, 0};
183
  int mbleneucjp1[] = { 1, -1 };
184
  int mbleneucjp2[] = { 1, -1 };
185
  int mbleneucjp3[] = { 1, -1 };
186
  int mbleneucjp4[] = { 1, -1 };
187
  int mbleneucjp5[] = { -1 };
188
  int mbleneucjp6[] = { -1 };
189
  int mbleneucjp7[] = { -1 };
190
  int mbleneucjp8[] = { -1 };
191
 
192
  int *mbleneucjp[] = {
193
    mbleneucjp0,
194
    mbleneucjp1,
195
    mbleneucjp2,
196
    mbleneucjp3,
197
    mbleneucjp4,
198
    mbleneucjp5,
199
    mbleneucjp6,
200
    mbleneucjp7,
201
    mbleneucjp8,
202
  };
203
 
204
  wchar_t mbtowceucjp0[] = {
205
    (wchar_t)'a',
206
    (wchar_t)'b',
207
    (wchar_t)0xa1a1,
208
    (wchar_t)0xa2fe,
209
    (wchar_t)0xe0fd,
210
    (wchar_t)0xeffc,
211
    (wchar_t)'g',
212
    (wchar_t)'h',
213
    (wchar_t)0
214
  };
215
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_EUCJP */
216
 
217
  wchar_t wcbuff[100];
218
  char buff[100];
219
 
220
  char *ptr, *locale;
221
  int result, i, j, k;
222
  wchar_t *wcptr;
223
 
224
  k=k; locale=locale; // silence warnings
225
 
226
  CYG_TEST_INIT();
227
 
228
  CYG_TEST_INFO( "Starting tests from testcase " __FILE__ " for C library "
229
                 "<stdlib.h> multi-byte character functions" );
230
 
231
  setlocale (LC_ALL, "C");
232
 
233
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 1, "MB_CUR_MAX");
234
 
235
  CYG_TEST_PASS_FAIL( mblen(NULL, 0) == 0, "mblen(NULL, 0)");
236
 
237
  CYG_TEST_PASS_FAIL( mbtowc(NULL, NULL, 0) == 0, "mbtowc(NULL, NULL, 0)");
238
 
239
  CYG_TEST_PASS_FAIL( wctomb(NULL, 0) == 0, "wctomb(NULL, 0)");
240
 
241
  ptr = "abcdefghijklmnop";
242
  result = 1;
243
  j = 0;
244
  while (result > 0)
245
    {
246
      result = mblen (ptr, MB_CUR_MAX);
247
      ptr += result;
248
      ++j;
249
    }
250
 
251
  CYG_TEST_PASS_FAIL( result == 0, "mblen (ptr, MB_CUR_MAX)");
252
  CYG_TEST_PASS_FAIL( j == strlen("abcdefghijklmnop") + 1, "j");
253
 
254
  ptr = "1234567890";
255
  wcptr = wcbuff;
256
  memset(wcbuff, 'K', 40);
257
  result = 1;
258
  while (result > 0)
259
    {
260
      result = mbtowc (wcptr, ptr, MB_CUR_MAX);
261
      CYG_TEST_PASS_FAIL( *wcptr == (wchar_t)*ptr, "*wcptr");
262
      ptr += result;
263
      wcptr++;
264
      ++j;
265
    }
266
 
267
  CYG_TEST_PASS_FAIL( wcptr - wcbuff == 11, "wcptr - wcbuff");
268
  CYG_TEST_PASS_FAIL( wcbuff[10] == 0, "wcbuff[10]");
269
 
270
  memset (buff, 'K', 40);
271
  ptr = buff;
272
  wcptr = wcbuff;
273
  result = 1;
274
 
275
  for (i = 0; i < 11; ++i)
276
    {
277
      result = wctomb (ptr, *wcptr);
278
      ptr += result;
279
      wcptr++;
280
    }
281
 
282
  CYG_TEST_PASS_FAIL( strcmp("1234567890", buff) == 0, "strcmp(\"1234567890\", buff");
283
 
284
  memset (wcbuff, 'K', 40);
285
  result = mbstowcs (wcbuff, "abcdef", 7);
286
  CYG_TEST_PASS_FAIL( result == 6, "mbstowcs (wcbuff, \"abcdef\", 7)");
287
  CYG_TEST_PASS_FAIL(*((char *)(&wcbuff[7])) == 'K', "*((char *)(&wcbuff[7]))");
288
  CYG_TEST_PASS_FAIL( wcbuff[6] == 0, "wcbuff[6]");
289
 
290
  memset(buff, 'K', 20);
291
  result = wcstombs (buff, wcbuff, 20);
292
  CYG_TEST_PASS_FAIL( result == 6, "wcstombs (buff, wcbuff, 20)");
293
  CYG_TEST_PASS_FAIL( strcmp(buff, "abcdef") == 0, "strcmp(buff, \"abcdef\")");
294
 
295
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_JIS
296
 
297
  CYG_TEST_INFO( "Testing C-JIS locale" );
298
 
299
  locale = setlocale (LC_CTYPE, "C-JIS");
300
  CYG_TEST_PASS_FAIL( locale != NULL, "setlocale (LC_CTYPE, \"C-JIS\")");
301
 
302
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-JIS") == 0, "strcmp(locale, \"C-JIS\")");
303
 
304
  locale = setlocale (LC_CTYPE, NULL);
305
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-JIS") == 0, "setlocale(LC_CTYPE, NULL)");
306
 
307
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 8, "MB_CUR_MAX");
308
 
309
  CYG_TEST_PASS_FAIL( mblen(NULL, 0) != 0, "mblen(NULL, 0)");
310
 
311
  CYG_TEST_PASS_FAIL( mbtowc(NULL, NULL, 0) != 0, "mbtowc(NULL, NULL, 0)");
312
 
313
  CYG_TEST_PASS_FAIL( wctomb(NULL, 0) != 0, "wctomb(NULL, 0)");
314
 
315
  for (i = 0; i < sizeof(testjis) / sizeof(char *); ++i)
316
    {
317
      ptr = testjis[i];
318
      result = 1;
319
      j = 0;
320
      while (result > 0)
321
        {
322
          result = mblen (ptr, MB_CUR_MAX);
323
          CYG_TEST_PASS_FAIL( result == mblenjis[i][j], "mblen (ptr, MB_CUR_MAX)");
324
          ptr += result;
325
          ++j;
326
        }
327
    }
328
 
329
  ptr = testjis[0];
330
  wcptr = wcbuff;
331
  memset(wcbuff, 'K', 40);
332
  result = 1;
333
  j = 0;
334
  while (result > 0)
335
    {
336
      result = mbtowc (wcptr, ptr, MB_CUR_MAX);
337
      CYG_TEST_PASS_FAIL( result == mblenjis0[j], "mbtowc (wcptr, ptr, MB_CUR_MAX)");
338
      CYG_TEST_PASS_FAIL( *wcptr == mbtowcjis0[j], "*wcptr");
339
      ptr += result;
340
      wcptr++;
341
      ++j;
342
    }
343
 
344
  CYG_TEST_PASS_FAIL( wcptr - wcbuff == 7, "wcptr - wcbuff");
345
  CYG_TEST_PASS_FAIL( wcbuff[6] == 0, "wcbuff[6]");
346
 
347
  memset (buff, 'K', 40);
348
  ptr = buff;
349
  wcptr = wcbuff;
350
  result = 1;
351
 
352
  for (i = 0; i < 7; ++i)
353
    {
354
      result = wctomb (ptr, *wcptr);
355
      ptr += result;
356
      wcptr++;
357
    }
358
 
359
  CYG_TEST_PASS_FAIL( strcmp(testjis[0], buff) == 0, "strcmp(testjis[0], buff");
360
 
361
  result = wctomb (buff, (wchar_t)0x1111);
362
  CYG_TEST_PASS_FAIL( result == -1, "wctomb(buff, (wchar_t)0x1111)");
363
 
364
  result = mbstowcs (wcbuff, testjis[3], 8);
365
  CYG_TEST_PASS_FAIL( result == -1, "mbstowcs(wcbuff, testjis[3], 8)");
366
 
367
  memset (wcbuff, 'K', 40);
368
  result = mbstowcs (wcbuff, testjis[0], 8);
369
  CYG_TEST_PASS_FAIL( result == 6, "mbstowcs(wcbuff, testjis[0], 8)");
370
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[7])) == 'K', "*((char *)(&wcbuff[7]))");
371
  CYG_TEST_PASS_FAIL( wcbuff[6] == 0, "wcbuff[6]");
372
 
373
  memset (wcbuff, 'K', 40);
374
  result = mbstowcs (wcbuff, testjis[0], 6);
375
  CYG_TEST_PASS_FAIL( result == 6, "mbstowcs (wcbuff, testjis[0], 6)");
376
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[6])) == 'K', "*((char *)(&wcbuff[6]))");
377
 
378
  memset (wcbuff, 'K', 40);
379
  result = mbstowcs (wcbuff, testjis[0], 7);
380
  CYG_TEST_PASS_FAIL( result == 6, "mbstowcs (wcbuff, testjis[0], 7)");
381
  CYG_TEST_PASS_FAIL(*((char *)(&wcbuff[7])) == 'K', "*((char *)(&wcbuff[7]))");
382
  CYG_TEST_PASS_FAIL( wcbuff[6] == 0, "wcbuff[6]");
383
 
384
  memset(buff, 'K', 20);
385
  result = wcstombs (buff, wcbuff, 20);
386
  CYG_TEST_PASS_FAIL( result == 14, "wcstombs (buff, wcbuff, 20)");
387
  CYG_TEST_PASS_FAIL( strcmp(buff, testjis[0]) == 0, "strcmp(buff, testjis[0])");
388
 
389
  memset (buff, 'K', 20);
390
  result = wcstombs (buff, wcbuff, 14);
391
  CYG_TEST_PASS_FAIL( result == 14, "wcstombs (buff, wcbuff, 14)");
392
  CYG_TEST_PASS_FAIL( memcmp (buff, testjis[0], 14) == 0, "memcmp (buff, testjis[0], 14)");
393
  CYG_TEST_PASS_FAIL( buff[14] == 'K', "buff[14]");
394
 
395
  memset (buff, 'K', 20);
396
  result = wcstombs (buff, wcbuff, 15);
397
  CYG_TEST_PASS_FAIL( result == 14, "wcstombs (buff, wcbuff, 15)");
398
  CYG_TEST_PASS_FAIL( memcmp (buff, testjis[0], 14) == 0, "memcmp (buff, testjis[0], 14)");
399
  CYG_TEST_PASS_FAIL( buff[14] == '\0', "buff[14]");
400
 
401
  result = wcstombs (buff, (wchar_t *)"\x23\x10", 2);
402
  CYG_TEST_PASS_FAIL( result == -1, "wcstombs (buff, (wchar_t *)\"\x23\x10\", 2)");
403
 
404
  result = sscanf (in_jis, fmt_jis, &k);
405
  CYG_TEST_PASS_FAIL( result == 1, "sscanf (in_jis, fmt_jis, &k)");
406
  CYG_TEST_PASS_FAIL( k == 23, "k");
407
 
408
  sprintf (buff, fmt_jis, 23);
409
  CYG_TEST_PASS_FAIL( strcmp(buff, in_jis) == 0, "sprintf(buff, fmt_jis, 23)");
410
 
411
  locale = setlocale(LC_ALL, "C");
412
  locale = setlocale(LC_CTYPE, NULL);
413
 
414
  CYG_TEST_PASS_FAIL( strcmp(locale, "C") == 0, "previous locale");
415
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 1, "MB_CUR_MAX");
416
 
417
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_JIS */
418
 
419
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_SJIS
420
 
421
  CYG_TEST_INFO( "Testing C-SJIS locale" );
422
 
423
  locale = setlocale (LC_CTYPE, "C-SJIS");
424
  CYG_TEST_PASS_FAIL( locale != NULL, "setlocale (LC_CTYPE, \"C-SJIS\")");
425
 
426
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-SJIS") == 0, "setlocale(LC_CTYPE, \"C-SJIS\")");
427
 
428
  locale = setlocale (LC_CTYPE, NULL);
429
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-SJIS") == 0, "setlocale(LC_CTYPE, NULL)");
430
 
431
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 2, "MB_CUR_MAX");
432
 
433
  CYG_TEST_PASS_FAIL( mblen(NULL, 0) == 0, "mblen(NULL, 0)");
434
 
435
  CYG_TEST_PASS_FAIL( mbtowc(NULL, NULL, 0) == 0, "mbtowc(NULL, NULL, 0)");
436
 
437
  CYG_TEST_PASS_FAIL( wctomb(NULL, 0) == 0, "wctomb(NULL, 0)");
438
 
439
  for (i = 0; i < sizeof(testsjis) / sizeof(char *); ++i)
440
    {
441
      ptr = testsjis[i];
442
      result = 1;
443
      j = 0;
444
      while (result > 0)
445
        {
446
          result = mblen (ptr, MB_CUR_MAX);
447
          CYG_TEST_PASS_FAIL( result == mblensjis[i][j], "mblen (ptr, MB_CUR_MAX)");
448
          ptr += result;
449
          ++j;
450
        }
451
    }
452
 
453
  ptr = testsjis[0];
454
  wcptr = wcbuff;
455
  memset(wcbuff, 'K', 40);
456
  result = 1;
457
  j = 0;
458
  while (result > 0)
459
    {
460
      result = mbtowc (wcptr, ptr, MB_CUR_MAX);
461
      CYG_TEST_PASS_FAIL( result == mblensjis0[j], "mbtowc (wcptr, ptr, MB_CUR_MAX)");
462
      CYG_TEST_PASS_FAIL( *wcptr == mbtowcsjis0[j], "*wcptr");
463
      ptr += result;
464
      wcptr++;
465
      ++j;
466
    }
467
 
468
  CYG_TEST_PASS_FAIL( wcptr - wcbuff == 9, "wcptr - wcbuff");
469
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
470
 
471
  memset (buff, 'K', 40);
472
  ptr = buff;
473
  wcptr = wcbuff;
474
  result = 1;
475
 
476
  for (i = 0; i < 9; ++i)
477
    {
478
      result = wctomb (ptr, *wcptr);
479
      ptr += result;
480
      wcptr++;
481
    }
482
 
483
  CYG_TEST_PASS_FAIL( strcmp(testsjis[0], buff) == 0, "strcmp(testsjis[0], buff");
484
 
485
  result = wctomb (buff, (wchar_t)0x1111);
486
  CYG_TEST_PASS_FAIL( result == -1, "wctomb(buff, (wchar_t)0x1111)");
487
 
488
  result = mbstowcs (wcbuff, testsjis[5], 8);
489
  CYG_TEST_PASS_FAIL( result == -1, "mbstowcs(wcbuff, testjis[3], 8)");
490
 
491
  memset (wcbuff, 'K', 40);
492
  result = mbstowcs (wcbuff, testsjis[0], 20);
493
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs(wcbuff, testsjis[0], 20)");
494
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[9])) == 'K', "*((char *)(&wcbuff[9]))");
495
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
496
 
497
  memset (wcbuff, 'K', 40);
498
  result = mbstowcs (wcbuff, testsjis[0], 8);
499
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs (wcbuff, testsjis[0], 8)");
500
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[8])) == 'K', "*((char *)(&wcbuff[8]))");
501
 
502
  memset (wcbuff, 'K', 40);
503
  result = mbstowcs (wcbuff, testsjis[0], 9);
504
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs (wcbuff, testsjis[0], 9)");
505
  CYG_TEST_PASS_FAIL(*((char *)(&wcbuff[9])) == 'K', "*((char *)(&wcbuff[9]))");
506
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
507
 
508
  memset(buff, 'K', 20);
509
  result = wcstombs (buff, wcbuff, 20);
510
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 20)");
511
  CYG_TEST_PASS_FAIL( strcmp(buff, testsjis[0]) == 0, "strcmp(buff, testjis[0])");
512
 
513
  memset (buff, 'K', 20);
514
  result = wcstombs (buff, wcbuff, 12);
515
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 12)");
516
  CYG_TEST_PASS_FAIL( memcmp (buff, testsjis[0], 12) == 0, "memcmp (buff, testsjis[0], 12)");
517
  CYG_TEST_PASS_FAIL( buff[12] == 'K', "buff[12]");
518
 
519
  memset (buff, 'K', 20);
520
  result = wcstombs (buff, wcbuff, 13);
521
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 12)");
522
  CYG_TEST_PASS_FAIL( memcmp (buff, testsjis[0], 13) == 0, "memcmp (buff, testsjis[0], 13)");
523
  CYG_TEST_PASS_FAIL( buff[12] == '\0', "buff[12]");
524
 
525
  result = wcstombs (buff, (wchar_t *)"\x23\x10", 2);
526
  CYG_TEST_PASS_FAIL( result == -1, "wcstombs (buff, (wchar_t *)\"\x23\x10\", 2)");
527
 
528
  result = sscanf (in_sjis, fmt_sjis, &k);
529
  CYG_TEST_PASS_FAIL( result == 1, "sscanf (in_sjis, fmt_sjis, &k)");
530
  CYG_TEST_PASS_FAIL( k == 23, "k");
531
 
532
  sprintf (buff, fmt_sjis, 23);
533
  CYG_TEST_PASS_FAIL( strcmp(buff, in_sjis) == 0, "sprintf(buff, fmt_sjis, 23)");
534
 
535
  locale = setlocale(LC_ALL, "C");
536
  locale = setlocale(LC_CTYPE, NULL);
537
 
538
  CYG_TEST_PASS_FAIL( strcmp(locale, "C") == 0, "previous locale");
539
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 1, "MB_CUR_MAX");
540
 
541
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_SJIS */
542
 
543
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_EUCJP
544
 
545
  CYG_TEST_INFO( "Testing C-EUCJP locale" );
546
 
547
  locale = setlocale (LC_CTYPE, "C-EUCJP");
548
  CYG_TEST_PASS_FAIL( locale != NULL, "setlocale (LC_CTYPE, \"C-EUCJP\")");
549
 
550
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-EUCJP") == 0, "setlocale(LC_CTYPE, \"C-EUCJP\")");
551
 
552
  locale = setlocale (LC_CTYPE, NULL);
553
  CYG_TEST_PASS_FAIL( strcmp(locale, "C-EUCJP") == 0, "current locale");
554
 
555
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 2, "MB_CUR_MAX");
556
 
557
  CYG_TEST_PASS_FAIL( mblen(NULL, 0) == 0, "mblen(NULL, 0)");
558
 
559
  CYG_TEST_PASS_FAIL( mbtowc(NULL, NULL, 0) == 0, "mbtowc(NULL, NULL, 0)");
560
 
561
  CYG_TEST_PASS_FAIL( wctomb(NULL, 0) == 0, "wctomb(NULL, 0)");
562
 
563
  for (i = 0; i < sizeof(testeucjp) / sizeof(char *); ++i)
564
    {
565
      ptr = testeucjp[i];
566
      result = 1;
567
      j = 0;
568
      while (result > 0)
569
        {
570
          result = mblen (ptr, MB_CUR_MAX);
571
          CYG_TEST_PASS_FAIL( result == mbleneucjp[i][j], "mblen (ptr, MB_CUR_MAX)");
572
          ptr += result;
573
          ++j;
574
        }
575
    }
576
 
577
  ptr = testeucjp[0];
578
  wcptr = wcbuff;
579
  memset(wcbuff, 'K', 40);
580
  result = 1;
581
  j = 0;
582
  while (result > 0)
583
    {
584
      result = mbtowc (wcptr, ptr, MB_CUR_MAX);
585
      CYG_TEST_PASS_FAIL( result == mbleneucjp0[j], "mbtowc (wcptr, ptr, MB_CUR_MAX)");
586
      CYG_TEST_PASS_FAIL( *wcptr == mbtowceucjp0[j], "*wcptr");
587
      ptr += result;
588
      wcptr++;
589
      ++j;
590
    }
591
 
592
  CYG_TEST_PASS_FAIL( wcptr - wcbuff == 9, "wcptr - wcbuff");
593
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
594
 
595
  memset (buff, 'K', 40);
596
  ptr = buff;
597
  wcptr = wcbuff;
598
  result = 1;
599
 
600
  for (i = 0; i < 9; ++i)
601
    {
602
      result = wctomb (ptr, *wcptr);
603
      ptr += result;
604
      wcptr++;
605
    }
606
 
607
  CYG_TEST_PASS_FAIL( strcmp(testeucjp[0], buff) == 0, "strcmp(testeucjp[0], buff");
608
 
609
  result = wctomb (buff, (wchar_t)0x1111);
610
  CYG_TEST_PASS_FAIL( result == -1, "wctomb(buff, (wchar_t)0x1111)");
611
 
612
  result = mbstowcs (wcbuff, testeucjp[5], 8);
613
  CYG_TEST_PASS_FAIL( result == -1, "mbstowcs(wcbuff, testjis[3], 8)");
614
 
615
  memset (wcbuff, 'K', 40);
616
  result = mbstowcs (wcbuff, testeucjp[0], 20);
617
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs(wcbuff, testeucjp[0], 20)");
618
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[9])) == 'K', "*((char *)(&wcbuff[9]))");
619
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
620
 
621
  memset (wcbuff, 'K', 40);
622
  result = mbstowcs (wcbuff, testeucjp[0], 8);
623
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs (wcbuff, testeucjp[0], 8)");
624
  CYG_TEST_PASS_FAIL( *((char *)(&wcbuff[8])) == 'K', "*((char *)(&wcbuff[8]))");
625
 
626
  memset (wcbuff, 'K', 40);
627
  result = mbstowcs (wcbuff, testeucjp[0], 9);
628
  CYG_TEST_PASS_FAIL( result == 8, "mbstowcs (wcbuff, testeucjp[0], 9)");
629
  CYG_TEST_PASS_FAIL(*((char *)(&wcbuff[9])) == 'K', "*((char *)(&wcbuff[9]))");
630
  CYG_TEST_PASS_FAIL( wcbuff[8] == 0, "wcbuff[8]");
631
 
632
  memset(buff, 'K', 20);
633
  result = wcstombs (buff, wcbuff, 20);
634
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 20)");
635
  CYG_TEST_PASS_FAIL( strcmp(buff, testeucjp[0]) == 0, "strcmp(buff, testjis[0])");
636
 
637
  memset (buff, 'K', 20);
638
  result = wcstombs (buff, wcbuff, 12);
639
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 12)");
640
  CYG_TEST_PASS_FAIL( memcmp (buff, testeucjp[0], 12) == 0, "memcmp (buff, testeucjp[0], 12)");
641
  CYG_TEST_PASS_FAIL( buff[12] == 'K', "buff[12]");
642
 
643
  memset (buff, 'K', 20);
644
  result = wcstombs (buff, wcbuff, 13);
645
  CYG_TEST_PASS_FAIL( result == 12, "wcstombs (buff, wcbuff, 12)");
646
  CYG_TEST_PASS_FAIL( memcmp (buff, testeucjp[0], 13) == 0, "memcmp (buff, testeucjp[0], 13)");
647
  CYG_TEST_PASS_FAIL( buff[12] == '\0', "buff[12]");
648
 
649
  result = wcstombs (buff, (wchar_t *)"\x23\x10", 2);
650
  CYG_TEST_PASS_FAIL( result == -1, "wcstombs (buff, (wchar_t *)\"\x23\x10\", 2)");
651
 
652
  result = sscanf (in_eucjp, fmt_eucjp, &k);
653
  CYG_TEST_PASS_FAIL( result == 1, "sscanf (in_eucjp, fmt_eucjp, &k)");
654
  CYG_TEST_PASS_FAIL( k == 23, "k");
655
 
656
  sprintf (buff, fmt_eucjp, 23);
657
  CYG_TEST_PASS_FAIL( strcmp(buff, in_eucjp) == 0, "sprintf(buff, fmt_eucjp, 23)");
658
 
659
  locale = setlocale(LC_ALL, "C");
660
  locale = setlocale(LC_CTYPE, NULL);
661
 
662
  CYG_TEST_PASS_FAIL( strcmp(locale, "C") == 0, "previous locale");
663
  CYG_TEST_PASS_FAIL( MB_CUR_MAX == 1, "MB_CUR_MAX");
664
 
665
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_EUCJP */
666
 
667
 
668
  CYG_TEST_FINISH( "Finished tests from testcase " __FILE__ " for C library "
669
                     "<stdlib.h> multibyte character functions" );
670
 
671
  return 0;
672
 
673
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.