source: vendor/glibc-tests/glibc/stdlib/testmb.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.0 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3
4int
5main (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 mbstowcs (w, "blah", 5);
20 i = wcstombs (c, w, 10);
21 if (i != 4)
22 {
23 puts ("wcstombs FAILED!");
24 lose = 1;
25 }
26
27 if (mblen ("foobar", 7) != 1)
28 {
29 puts ("mblen 1 FAILED!");
30 lose = 1;
31 }
32
33 if (mblen ("", 1) != 0)
34 {
35 puts ("mblen 2 FAILED!");
36 lose = 1;
37 }
38
39 {
40 int r;
41 char c = 'x';
42 wchar_t wc;
43 char mbc[MB_CUR_MAX];
44
45 if ((r = mbtowc (&wc, &c, MB_CUR_MAX)) <= 0)
46 {
47 printf ("conversion to wide failed, result: %d\n", r);
48 lose = 1;
49 }
50 else
51 {
52 printf ("wide value: 0x%04lx\n", (unsigned long) wc);
53 mbc[0] = '\0';
54 if ((r = wctomb (mbc, wc)) <= 0)
55 {
56 printf ("conversion to multibyte failed, result: %d\n", r);
57 lose = 1;
58 }
59 }
60
61 }
62
63 puts (lose ? "Test FAILED!" : "Test succeeded.");
64 return lose;
65}
Note: See TracBrowser for help on using the repository browser.