Update.
[platform/upstream/glibc.git] / localedata / bug-iconv-trans.c
1 #include <iconv.h>
2 #include <locale.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 int
7 main (void)
8 {
9   iconv_t cd;
10   const char str[] = "ÄäÖöÜüß";
11   const char expected[] = "AEaeOEoeUEuess";
12   char *inptr = (char *) str;
13   size_t inlen = strlen (str) + 1;
14   char outbuf[500];
15   char *outptr = outbuf;
16   size_t outlen = sizeof (outbuf);
17   int result = 0;
18   size_t n;
19
20   if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
21     {
22       puts ("setlocale failed");
23       return 1;
24     }
25
26   cd = iconv_open ("ANSI_X3.4-1968//TRANSLIT", "ISO-8859-1");
27   if (cd == (iconv_t) -1)
28     {
29       puts ("iconv_open failed");
30       return 1;
31     }
32
33   n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
34   if (n != 7)
35     {
36       printf ("iconv() returned %Zd, expected 7\n", n);
37       result = 1;
38     }
39   if (inlen != 0)
40     {
41       puts ("not all input consumed");
42       result = 1;
43     }
44   else if (inptr - str != strlen (str) + 1)
45     {
46       printf ("inptr wrong, advanced by %td\n", inptr - str);
47       result = 1;
48     }
49   if (memcmp (outbuf, expected, sizeof (expected)) != 0)
50     {
51       printf ("result wrong: \"%.*s\", expected: \"%s\"\n",
52               (int) (sizeof (outbuf) - outlen), outbuf, expected);
53       result = 1;
54     }
55   else if (outlen != sizeof (outbuf) - sizeof (expected))
56     {
57       printf ("outlen wrong: %Zd, expected %Zd\n", outlen,
58               sizeof (outbuf) - 15);
59       result = 1;
60     }
61   else
62     printf ("output is \"%s\" which is OK\n", outbuf);
63
64   return result;
65 }