Update.
[platform/upstream/glibc.git] / wcsmbs / wcsmbs-tst1.c
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, idx=0;
14   char buf[100], *pchar;
15   wchar_t tmp[10];
16   wchar_t tmp1[]={L'W',L'o',L'r',L'l',L'd',L'\0'};
17   char str[]="Hello";
18   int result = 0;
19
20   pchar= setlocale (LC_ALL, "");
21   printf ("locale : %s\n",pchar);
22   printf ("MB_CUR_MAX %d\n", MB_CUR_MAX);
23
24   puts("---- test 1 ------");
25   test = mbstowcs (tmp, str, (strlen (str) + 1) * sizeof (char));
26   printf ("size of string by mbstowcs %d\n", test);
27   if (test != strlen (str))
28     result = 1;
29   idx += wctomb (&buf[0], tmp[0]);
30   idx += wctomb (&buf[idx], tmp[1]);
31   buf[idx] = 0;
32   printf ("orig string %s\n", str);
33   printf ("string by wctomb %s\n", buf);
34   printf ("string by %%C %C", tmp[0]);
35   if (tmp[0] != L'H')
36     result = 1;
37   printf ("%C\n", tmp[1]);
38   if (tmp[1] != L'e')
39     result = 1;
40   printf ("string by %%S %S\n", tmp);
41   if (wcscmp (tmp, L"Hello") != 0)
42     result = 1;
43   puts("---- test 2 ------");
44   printf ("wchar string %S\n", tmp1);
45   printf ("wchar %C\n", tmp1[0]);
46   test = wcstombs (buf, tmp1, (wcslen (tmp1) + 1) * sizeof (wchar_t));
47   printf ("size of string by wcstombs %d\n", test);
48   if (test != wcslen (tmp1))
49     result = 1;
50   test = wcslen (tmp1);
51   printf ("size of string by wcslen %d\n", test);
52   printf ("char %s\n", buf);
53   if (strcmp (buf, "World") != 0)
54     result = 1;
55   puts("------------------");
56
57   return result;
58 }