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