Back to index

glibc  2.9
tst-iconv7.c
Go to the documentation of this file.
00001 #include <iconv.h>
00002 #include <locale.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 static int
00008 do_test (void)
00009 {
00010   setlocale (LC_ALL, "de_DE.UTF-8");
00011 
00012   iconv_t cd = iconv_open ("ISO-2022-JP//TRANSLIT", "");
00013   if (cd == (iconv_t) -1)
00014     {
00015       puts ("iconv_open failed");
00016       return 1;
00017     }
00018 
00019   char instr1[] = "\xc2\xa3\xe2\x82\xac\n";
00020   const char expstr1[] = "\033$B!r\033(BEUR\n";
00021   char outstr[32];
00022   size_t inlen = sizeof (instr1);
00023   size_t outlen = sizeof (outstr);
00024   char *inptr = instr1;
00025   char *outptr = outstr;
00026   size_t r = iconv (cd, &inptr, &inlen, &outptr, &outlen);
00027   if (r != 1
00028       || inlen != 0
00029       || outlen != sizeof (outstr) - sizeof (expstr1)
00030       || memcmp (outstr, expstr1, sizeof (expstr1)) != 0)
00031     {
00032       puts ("wrong first conversion");
00033       return 1;
00034     }
00035 
00036   char instr2[] = "\xe3\x88\xb1\n";
00037   const char expstr2[] = "(\033$B3t\033(B)\n";
00038   inlen = sizeof (instr2);
00039   outlen = sizeof (outstr);
00040   inptr = instr2;
00041   outptr = outstr;
00042   r = iconv (cd, &inptr, &inlen, &outptr, &outlen);
00043   if (r != 1
00044       || inlen != 0
00045       || outlen != sizeof (outstr) - sizeof (expstr2)
00046       || memcmp (outstr, expstr2, sizeof (expstr2)) != 0)
00047     {
00048       puts ("wrong second conversion");
00049       return 1;
00050     }
00051 
00052   if (iconv_close (cd) != 0)
00053     {
00054       puts ("iconv_close failed");
00055       return 1;
00056     }
00057   return 0;
00058 }
00059 
00060 #define TEST_FUNCTION do_test ()
00061 #include "../test-skeleton.c"