1 /* bug 17197: check that iconv doesn't emit invalid extra shift character
2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
29 static const char *charsets
[] =
30 { "IBM930", "IBM933", "IBM935", "IBM937", "IBM939" };
31 static const char *expects
[] =
32 { "\016\x44\x4d\017", "\016\x41\x63\017", "\016\x44\x4d\017",
33 "\016\x44\x4d\017", "\016\x44\x4d\017" };
36 for (int i
= 0; i
< sizeof (charsets
) / sizeof (*charsets
); i
++)
38 const char *charset
= charsets
[i
];
39 iconv_t cd
= iconv_open (charset
, "UTF-8");
40 if (cd
== (iconv_t
) -1)
42 printf ("iconv_open failed (%s)\n", charset
);
47 char input
[] = "\xe2\x88\x9e.";
48 const char *expect1
= expects
[i
];
49 const char expect2
[] = "\x4b";
50 size_t input_len
= sizeof (input
);
52 size_t inlen
= input_len
;
53 size_t outlen
= sizeof (output
);
55 char *outptr
= output
;
56 /* First round: expect conversion to stop before ".". */
57 size_t r
= iconv (cd
, &inptr
, &inlen
, &outptr
, &outlen
);
61 || inptr
!= input
+ input_len
- 2
63 || memcmp (output
, expect1
, sizeof (output
)) != 0)
65 printf ("wrong first conversion (%s)", charset
);
70 outlen
= sizeof (output
);
72 r
= iconv (cd
, &inptr
, &inlen
, &outptr
, &outlen
);
75 || outlen
!= sizeof (output
) - sizeof (expect2
)
76 || memcmp (output
, expect2
, sizeof (expect2
)) != 0)
78 printf ("wrong second conversion (%s)\n", charset
);
83 if (iconv_close (cd
) != 0)
85 printf ("iconv_close failed (%s)\n", charset
);
93 #define TEST_FUNCTION do_test ()
94 #include "../test-skeleton.c"