Edit

thodg/libiconv/tests/check-ebcdic

Branch :

  • Show log

    Commit

  • Author : Mike Fulton
    Date : 2023-05-12 22:41:08
    Hash : 153d4079
    Message : On z/OS, set a charset tag on iconv's output file. For the concept of charset tags as external metadata on z/OS files, see <https://lists.gnu.org/archive/html/bug-gnu-libiconv/2023-04/msg00021.html>. * src/zos-tag.h: New file. * src/iconv.c: Include zos-tag.h. (convert): Add a 'tocode' parameter. On z/OS, turn off auto-conversion and tag the output file. (main): Update callers. * tests/check-ebcdic: On z/OS, make all test files initially untagged. * tests/check-tag: New file. * tests/Makefile.in (check): Pass the host_os to check-ebcdic. Invoke check-tag.

  • tests/check-ebcdic
  • #!/bin/sh
    # Check of ICONV_EBCDIC_ZOS_UNIX environment variable.
    set -e
    host_os="$1"
    iconv=../src/iconv_no_i18n
    
    # This test is only meaningful when the EBCDIC encodings are included.
    if $iconv -l | grep IBM-1047 > /dev/null; then
    
      if test "${host_os}" = 'openedition' ; then
        # On z/OS, make all the files 'untagged'
        rm -f tmp-ok-lf tmp-ok-nel tmp-ok-x15 tmp-ok-x25
        touch tmp-ok-lf
        touch tmp-ok-nel
        touch tmp-ok-x15
        touch tmp-ok-x25
        chtag -r tmp-ok-lf
        chtag -r tmp-ok-nel
        chtag -r tmp-ok-x15
        chtag -r tmp-ok-x25
      fi
    
      printf '\150\145\154\154\157\012' > tmp-ok-lf
      printf '\150\145\154\154\157\302\205' > tmp-ok-nel
    
      printf '\210\205\223\223\226\025' > tmp-ok-x15
      printf '\210\205\223\223\226\045' > tmp-ok-x25
    
      # Check that by default, EBCDIC 0x15 maps to U+0085.
      unset ICONV_EBCDIC_ZOS_UNIX
    
      $iconv -f UTF-8 -t IBM-1047 < tmp-ok-nel > tmp-out1
      $iconv -f ASCII -t IBM-1047 < tmp-ok-lf > tmp-out2
      cmp tmp-out1 tmp-ok-x15
      cmp tmp-out2 tmp-ok-x25
    
      $iconv -f IBM-1047 -t UTF-8 < tmp-ok-x15 > tmp-out1
      $iconv -f IBM-1047 -t ASCII < tmp-ok-x25 > tmp-out2
      cmp tmp-out1 tmp-ok-nel
      cmp tmp-out2 tmp-ok-lf
    
      # Check that with the ZOS_UNIX surface, EBCDIC 0x15 maps to U+000A.
    
      $iconv -f ASCII -t IBM-1047/ZOS_UNIX < tmp-ok-lf > tmp-out1
      $iconv -f UTF-8 -t IBM-1047/ZOS_UNIX < tmp-ok-nel > tmp-out2
      cmp tmp-out1 tmp-ok-x15
      cmp tmp-out2 tmp-ok-x25
    
      $iconv -f IBM-1047/ZOS_UNIX -t ASCII < tmp-ok-x15 > tmp-out1
      $iconv -f IBM-1047/ZOS_UNIX -t UTF-8 < tmp-ok-x25 > tmp-out2
      cmp tmp-out1 tmp-ok-lf
      cmp tmp-out2 tmp-ok-nel
    
      # Check that the ZOS_UNIX surface can be used with //TRANSLIT and //IGNORE.
    
      printf '\357\275\210\342\204\257\360\235\232\225\360\235\232\225\342\200\242\n' \
        | $iconv -f UTF-8 -t IBM-1047/ZOS_UNIX/TRANSLIT > tmp-out1
      cmp tmp-out1 tmp-ok-x15
    
      printf 'hello\342\202\254\n' \
        | $iconv -f UTF-8 -t IBM-1047/ZOS_UNIX/IGNORE > tmp-out1
      cmp tmp-out1 tmp-ok-x15
    
      # Check that with a specific environment variable, EBCDIC 0x15 maps to U+000A.
      ICONV_EBCDIC_ZOS_UNIX=1
      export ICONV_EBCDIC_ZOS_UNIX
    
      $iconv -f ASCII -t IBM-1047 < tmp-ok-lf > tmp-out1
      $iconv -f UTF-8 -t IBM-1047 < tmp-ok-nel > tmp-out2
      cmp tmp-out1 tmp-ok-x15
      cmp tmp-out2 tmp-ok-x25
    
      $iconv -f IBM-1047 -t ASCII < tmp-ok-x15 > tmp-out1
      $iconv -f IBM-1047 -t UTF-8 < tmp-ok-x25 > tmp-out2
      cmp tmp-out1 tmp-ok-lf
      cmp tmp-out2 tmp-ok-nel
    
      rm -f tmp-in* tmp-out* tmp-ok*
    fi
    
    exit 0