File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libiconv / tests / test-shiftseq.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 13:38:46 2021 UTC (3 years, 9 months ago) by misho
Branches: libiconv, MAIN
CVS tags: v1_16p0, HEAD
libiconv 1.16

    1: /* Copyright (C) 2008, 2018 Free Software Foundation, Inc.
    2:    This file is part of the GNU LIBICONV Library.
    3: 
    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.
    8: 
    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.
   13: 
   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, see <https://www.gnu.org/licenses/>.  */
   17: 
   18: #include "config.h"
   19: 
   20: #include <stdlib.h>
   21: #include <iconv.h>
   22: #include <errno.h>
   23: 
   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>.  */
   30: 
   31: void main1 (void)
   32: {
   33:   static const char input[] = "+2D/YQNhB";
   34:   iconv_t cd;
   35:   char buf[20];
   36: 
   37:   const char * inptr;
   38:   size_t inleft;
   39:   char * outptr;
   40:   size_t outleft;
   41: 
   42:   cd = iconv_open ("UTF-8", "UTF-7");
   43:   {
   44:     size_t r;
   45: 
   46:     inptr = input;
   47:     inleft = 9;
   48:     outptr = buf;
   49:     outleft = sizeof (buf);
   50:     r = iconv (cd, (ICONV_CONST char **) &inptr, &inleft, &outptr, &outleft);
   51:     /*
   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
   58:     */
   59:     if (!(r == (size_t)(-1) && errno == EILSEQ
   60:           && inptr - input == 1 && outptr - buf == 0))
   61:       abort();
   62:   }
   63: }
   64: 
   65: void main2 (void)
   66: {
   67:   static const char input[] = "+2D/YQNhB";
   68:   iconv_t cd;
   69:   char buf[20];
   70: 
   71:   const char * inptr;
   72:   size_t inleft;
   73:   char * outptr;
   74:   size_t outleft;
   75: 
   76:   cd = iconv_open ("UTF-8", "UTF-7");
   77:   {
   78:     size_t r;
   79: 
   80:     inptr = input;
   81:     inleft = 5;
   82:     outptr = buf;
   83:     outleft = sizeof (buf);
   84:     r = iconv (cd, (ICONV_CONST char **) &inptr, &inleft, &outptr, &outleft);
   85:     /*
   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
   92:     */
   93:     if (!(r == (size_t)(-1) && errno == EINVAL
   94:           && inptr - input == 1 && outptr - buf == 0))
   95:       abort();
   96: 
   97:     inleft = input + 20 - inptr;
   98:     r = iconv (cd, (ICONV_CONST char **) &inptr, &inleft, &outptr, &outleft);
   99:     /*
  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
  106:     */
  107:     if (!(r == (size_t)(-1) && errno == EILSEQ
  108:           && inptr - input == 1 && outptr - buf == 0))
  109:       abort();
  110:   }
  111: }
  112: 
  113: int main ()
  114: {
  115:   main1 ();
  116:   main2 ();
  117:   return 0;
  118: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>