[BZ #4439]
[glibc/pb-stable.git] / stdlib / testmb.c
blob45dae7db61fb3e7b79c07d28277ce9a1e272bc03
1 #include <stdio.h>
2 #include <stdlib.h>
4 int
5 main (int argc, char *argv[])
7 wchar_t w[10];
8 char c[10];
9 int i;
10 int lose = 0;
12 i = mbstowcs (w, "bar", 4);
13 if (!(i == 3 && w[1] == 'a'))
15 puts ("mbstowcs FAILED!");
16 lose = 1;
19 mbstowcs (w, "blah", 5);
20 i = wcstombs (c, w, 10);
21 if (i != 4)
23 puts ("wcstombs FAILED!");
24 lose = 1;
27 if (mblen ("foobar", 7) != 1)
29 puts ("mblen 1 FAILED!");
30 lose = 1;
33 if (mblen ("", 1) != 0)
35 puts ("mblen 2 FAILED!");
36 lose = 1;
40 int r;
41 char c = 'x';
42 wchar_t wc;
43 char mbc[MB_CUR_MAX];
45 if ((r = mbtowc (&wc, &c, MB_CUR_MAX)) <= 0)
47 printf ("conversion to wide failed, result: %d\n", r);
48 lose = 1;
50 else
52 printf ("wide value: 0x%04lx\n", (unsigned long) wc);
53 mbc[0] = '\0';
54 if ((r = wctomb (mbc, wc)) <= 0)
56 printf ("conversion to multibyte failed, result: %d\n", r);
57 lose = 1;
63 puts (lose ? "Test FAILED!" : "Test succeeded.");
64 return lose;