1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int
main(int argc,char * argv[])5 main (int argc, char *argv[])
6 {
7 wchar_t w[10];
8 char c[10];
9 int i;
10 int lose = 0;
11
12 i = mbstowcs (w, "bar", 4);
13 if (!(i == 3 && w[1] == 'a'))
14 {
15 puts ("mbstowcs FAILED!");
16 lose = 1;
17 }
18
19 i = mbstowcs (NULL, "bar", 4);
20 if (!(i == 3 && w[1] == 'a'))
21 {
22 puts ("mbstowcs FAILED2!");
23 lose = 1;
24 }
25
26 mbstowcs (w, "blah", 5);
27 i = wcstombs (c, w, 10);
28 if (i != 4)
29 {
30 puts ("wcstombs FAILED!");
31 lose = 1;
32 }
33
34 if (mblen ("foobar", 7) != 1)
35 {
36 puts ("mblen 1 FAILED!");
37 lose = 1;
38 }
39
40 if (mblen ("", 1) != 0)
41 {
42 puts ("mblen 2 FAILED!");
43 lose = 1;
44 }
45
46 {
47 int r;
48 char c = 'x';
49 wchar_t wc;
50 char mbc[MB_CUR_MAX];
51
52 if ((r = mbtowc (&wc, &c, MB_CUR_MAX)) <= 0)
53 {
54 printf ("conversion to wide failed, result: %d\n", r);
55 lose = 1;
56 }
57 else
58 {
59 printf ("wide value: 0x%04lx\n", (unsigned long) wc);
60 mbc[0] = '\0';
61 if ((r = wctomb (mbc, wc)) <= 0)
62 {
63 printf ("conversion to multibyte failed, result: %d\n", r);
64 lose = 1;
65 }
66 }
67
68 }
69
70 puts (lose ? "Test FAILED!" : "Test succeeded.");
71 return lose;
72 }
73