1 /* Copyright (C) 2008 Free Software Foundation, Inc.
2 This file is part of the GNU LIBICONV Library.
4 The GNU LIBICONV Library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 The GNU LIBICONV Library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU LIBICONV Library; see the file COPYING.LIB.
16 If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
17 Fifth Floor, Boston, MA 02110-1301, USA. */
25 /* This test checks that the behaviour of iconv() in the situation of an
26 invalid multibyte character after a shift sequence is consistent whether
27 the entire buffer is passed at once, or whether it is passed in two
28 subsequent calls. Based on a bug report from
29 Roman Rybalko <roman_rybalko@users.sourceforge.net>
30 at <http://savannah.gnu.org/bugs/?24216>. */
34 static const char input
[] = "+2D/YQNhB";
43 cd
= iconv_open ("UTF-8", "UTF-7");
50 outleft
= sizeof (buf
);
51 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
53 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
54 r, errno, inptr - input, outptr - buf);
56 // r = -1 errno = 84 inconsumed = 4 outproduced = 0
58 // r = -1 errno = 84 inconsumed = 1 outproduced = 0
60 if (!(r
== (size_t)(-1) && errno
== EILSEQ
61 && inptr
- input
== 1 && outptr
- buf
== 0))
68 static const char input
[] = "+2D/YQNhB";
77 cd
= iconv_open ("UTF-8", "UTF-7");
84 outleft
= sizeof (buf
);
85 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
87 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
88 r, errno, inptr - input, outptr - buf);
90 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
92 // r = -1 errno = 22 (EINVAL) inconsumed = 1 outproduced = 0
94 if (!(r
== (size_t)(-1) && errno
== EINVAL
95 && inptr
- input
== 1 && outptr
- buf
== 0))
98 inleft
= input
+ 20 - inptr
;
99 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
101 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
102 r, errno, inptr - input, outptr - buf);
104 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
106 // r = -1 errno = 84 (EILSEQ) inconsumed = 1 outproduced = 0
108 if (!(r
== (size_t)(-1) && errno
== EILSEQ
109 && inptr
- input
== 1 && outptr
- buf
== 0))