nss_db: Propagate ERANGE error if parse_line fails [BZ #19837]
[glibc.git] / wcsmbs / wcsmbs-tst1.c
blob0d0e18f63a180af201338973565e5d12e50c8b25
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 <stdlib.h>
6 #include <string.h>
7 #include <wctype.h>
8 #include <locale.h>
10 int
11 main (void)
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;
21 pchar = setlocale (LC_ALL, "de_DE.UTF-8");
22 printf ("locale : %s\n",pchar);
23 printf ("MB_CUR_MAX %Zd\n", MB_CUR_MAX);
25 puts ("---- test 1 ------");
26 test = mbstowcs (tmp, str, (strlen (str) + 1) * sizeof (char));
27 printf ("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 ("orig string %s\n", str);
34 printf ("string by wctomb %s\n", buf);
35 printf ("string by %%C %C", (wint_t) tmp[0]);
36 if (tmp[0] != L'H')
37 result = 1;
38 printf ("%C\n", (wint_t) tmp[1]);
39 if (tmp[1] != L'e')
40 result = 1;
41 printf ("string by %%S %S\n", tmp);
42 if (wcscmp (tmp, L"Hello") != 0)
43 result = 1;
44 puts ("---- test 2 ------");
45 printf ("wchar string %S\n", tmp1);
46 printf ("wchar %C\n", (wint_t) tmp1[0]);
47 test = wcstombs (buf, tmp1, (wcslen (tmp1) + 1) * sizeof (wchar_t));
48 printf ("size of string by wcstombs %d\n", test);
49 if (test != wcslen (tmp1))
50 result = 1;
51 test = wcslen (tmp1);
52 printf ("size of string by wcslen %d\n", test);
53 printf ("char %s\n", buf);
54 if (strcmp (buf, "World") != 0)
55 result = 1;
56 puts ("------------------");
58 return result;