1 /* Copyright (C) 2008, 2018, 2022 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 Lesser General Public
6 License as published by the Free Software Foundation; either version 2.1
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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU LIBICONV Library; see the file COPYING.LIB.
16 If not, see <https://www.gnu.org/licenses/>. */
24 /* This test checks that the behaviour of iconv() in the situation of an
25 invalid multibyte character after a shift sequence is consistent whether
26 the entire buffer is passed at once, or whether it is passed in two
27 subsequent calls. Based on a bug report from
28 Roman Rybalko <roman_rybalko@users.sourceforge.net>
29 at <https://savannah.gnu.org/bugs/?24216>. */
33 static const char input
[] = "+2D/YQNhB";
42 cd
= iconv_open ("UTF-8", "UTF-7");
49 outleft
= sizeof (buf
);
50 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
52 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
53 r, errno, inptr - input, outptr - buf);
55 // r = -1 errno = 84 inconsumed = 4 outproduced = 0
57 // r = -1 errno = 84 inconsumed = 1 outproduced = 0
59 if (!(r
== (size_t)(-1) && errno
== EILSEQ
60 && inptr
- input
== 1 && outptr
- buf
== 0))
67 static const char input
[20] = "+2D/YQNhB";
76 cd
= iconv_open ("UTF-8", "UTF-7");
83 outleft
= sizeof (buf
);
84 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
86 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
87 r, errno, inptr - input, outptr - buf);
89 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
91 // r = -1 errno = 22 (EINVAL) inconsumed = 1 outproduced = 0
93 if (!(r
== (size_t)(-1) && errno
== EINVAL
94 && inptr
- input
== 1 && outptr
- buf
== 0))
97 inleft
= input
+ 20 - inptr
;
98 r
= iconv (cd
, (ICONV_CONST
char **) &inptr
, &inleft
, &outptr
, &outleft
);
100 printf ("r = %d errno = %d inconsumed = %d outproduced = %d\n",
101 r, errno, inptr - input, outptr - buf);
103 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
105 // r = -1 errno = 84 (EILSEQ) inconsumed = 1 outproduced = 0
107 if (!(r
== (size_t)(-1) && errno
== EILSEQ
108 && inptr
- input
== 1 && outptr
- buf
== 0))