Fix macro file 'serial' numbers for 'aclocal --install'.
[libiconv.git] / tests / test-shiftseq.c
blob84eada0119f11c010dc16b5b73425631c644080a
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/>. */
18 #include "config.h"
20 #include <stdlib.h>
21 #include <iconv.h>
22 #include <errno.h>
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>. */
31 void main1 (void)
33 static const char input[] = "+2D/YQNhB";
34 iconv_t cd;
35 char buf[20];
37 const char * inptr;
38 size_t inleft;
39 char * outptr;
40 size_t outleft;
42 cd = iconv_open ("UTF-8", "UTF-7");
44 size_t r;
46 inptr = input;
47 inleft = 9;
48 outptr = buf;
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);
54 // glibc:
55 // r = -1 errno = 84 inconsumed = 4 outproduced = 0
56 // libiconv:
57 // r = -1 errno = 84 inconsumed = 1 outproduced = 0
59 if (!(r == (size_t)(-1) && errno == EILSEQ
60 && inptr - input == 1 && outptr - buf == 0))
61 abort();
65 void main2 (void)
67 static const char input[20] = "+2D/YQNhB";
68 iconv_t cd;
69 char buf[20];
71 const char * inptr;
72 size_t inleft;
73 char * outptr;
74 size_t outleft;
76 cd = iconv_open ("UTF-8", "UTF-7");
78 size_t r;
80 inptr = input;
81 inleft = 5;
82 outptr = buf;
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);
88 // glibc:
89 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
90 // libiconv:
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))
95 abort();
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);
102 // glibc:
103 // r = -1 errno = 84 (EILSEQ) inconsumed = 4 outproduced = 0
104 // libiconv:
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))
109 abort();
113 int main ()
115 main1 ();
116 main2 ();
117 return 0;