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