Back to index

glibc  2.9
testmb.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 int
00005 main (int argc, char *argv[])
00006 {
00007   wchar_t w[10];
00008   char c[10];
00009   int i;
00010   int lose = 0;
00011 
00012   i = mbstowcs (w, "bar", 4);
00013   if (!(i == 3 && w[1] == 'a'))
00014     {
00015       puts ("mbstowcs FAILED!");
00016       lose = 1;
00017     }
00018 
00019   mbstowcs (w, "blah", 5);
00020   i = wcstombs (c, w, 10);
00021   if (i != 4)
00022     {
00023       puts ("wcstombs FAILED!");
00024       lose = 1;
00025     }
00026 
00027   if (mblen ("foobar", 7) != 1)
00028     {
00029       puts ("mblen 1 FAILED!");
00030       lose = 1;
00031     }
00032 
00033   if (mblen ("", 1) != 0)
00034     {
00035       puts ("mblen 2 FAILED!");
00036       lose = 1;
00037     }
00038 
00039   {
00040     int r;
00041     char c = 'x';
00042     wchar_t wc;
00043     char mbc[MB_CUR_MAX];
00044 
00045     if ((r = mbtowc (&wc, &c, MB_CUR_MAX)) <= 0)
00046       {
00047        printf ("conversion to wide failed, result: %d\n", r);
00048        lose = 1;
00049       }
00050     else
00051       {
00052        printf ("wide value: 0x%04lx\n", (unsigned long) wc);
00053        mbc[0] = '\0';
00054        if ((r = wctomb (mbc, wc)) <= 0)
00055          {
00056            printf ("conversion to multibyte failed, result: %d\n", r);
00057            lose = 1;
00058          }
00059       }
00060 
00061   }
00062 
00063   puts (lose ? "Test FAILED!" : "Test succeeded.");
00064   return lose;
00065 }