1 | /* Based on a test program by Won Kyu Park <wkpark@chem.skku.ac.kr>. */ |
2 | |
3 | #include <wchar.h> |
4 | #include <stdio.h> |
5 | #include <stdlib.h> |
6 | #include <string.h> |
7 | #include <wctype.h> |
8 | #include <locale.h> |
9 | |
10 | int |
11 | main (void) |
12 | { |
13 | int test = 0; |
14 | int idx = 0; |
15 | char buf[100], *pchar; |
16 | wchar_t tmp[10]; |
17 | wchar_t tmp1[] = { L'W', L'o', L'r', L'l', L'd', L'\0' }; |
18 | char str[] = "Hello" ; |
19 | int result = 0; |
20 | |
21 | pchar = setlocale (LC_ALL, "de_DE.UTF-8" ); |
22 | printf (format: "locale : %s\n" ,pchar); |
23 | printf ("MB_CUR_MAX %zd\n" , MB_CUR_MAX); |
24 | |
25 | puts (s: "---- test 1 ------" ); |
26 | test = mbstowcs (pwcs: tmp, s: str, n: (strlen (str) + 1) * sizeof (char)); |
27 | printf (format: "size of string by mbstowcs %d\n" , test); |
28 | if (test != strlen (str)) |
29 | result = 1; |
30 | idx += wctomb (&buf[0], tmp[0]); |
31 | idx += wctomb (&buf[idx], tmp[1]); |
32 | buf[idx] = 0; |
33 | printf (format: "orig string %s\n" , str); |
34 | printf (format: "string by wctomb %s\n" , buf); |
35 | printf (format: "string by %%C %C" , (wint_t) tmp[0]); |
36 | if (tmp[0] != L'H') |
37 | result = 1; |
38 | printf (format: "%C\n" , (wint_t) tmp[1]); |
39 | if (tmp[1] != L'e') |
40 | result = 1; |
41 | printf (format: "string by %%S %S\n" , tmp); |
42 | if (wcscmp (s1: tmp, s2: L"Hello" ) != 0) |
43 | result = 1; |
44 | puts (s: "---- test 2 ------" ); |
45 | printf (format: "wchar string %S\n" , tmp1); |
46 | printf (format: "wchar %C\n" , (wint_t) tmp1[0]); |
47 | test = wcstombs (s: buf, pwcs: tmp1, n: (wcslen (s: tmp1) + 1) * sizeof (wchar_t)); |
48 | printf (format: "size of string by wcstombs %d\n" , test); |
49 | if (test != wcslen (s: tmp1)) |
50 | result = 1; |
51 | test = wcslen (s: tmp1); |
52 | printf (format: "size of string by wcslen %d\n" , test); |
53 | printf (format: "char %s\n" , buf); |
54 | if (strcmp (buf, "World" ) != 0) |
55 | result = 1; |
56 | puts (s: "------------------" ); |
57 | |
58 | return result; |
59 | } |
60 | |