view test/sun/tools/native2ascii/ @ 11738:2d74b35ca24d

8067964: Native2ascii doesn't close one of the streams it opens Summary: Change to use try-with-resources; also clean up code formatting. Reviewed-by: chegar
author igerasim
date Mon, 11 Jul 2016 22:31:43 +0300
parents 272483f6650b
line wrap: on
line source
#! /bin/sh -e

# Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit if you need additional information or have any
# questions.

# @test
# @bug 4630463 4630971 4636448 4701617 4721296 4710890 6247817 7021987 8067964
# @summary Tests miscellaneous native2ascii bugfixes and regressions

if [ "${TESTSRC}" = "" ]; then TESTSRC=.; fi
if [ "${TESTJAVA}" = "" ]; then TESTJAVA=$1; shift; fi

case `uname -s` in
  Windows* | CYGWIN*) OS=Windows;;
  SunOS|Linux) OS=Unix;;


check() {
  bug=$1; shift
  expected=$1; shift
  out=$1; shift

  # Strip carriage returns from output when comparing with n2a test output
  # on win32 systems
  if [ ${OS} = Windows ]; then
     sed -e 's@\\r@@g' $out >$out.1
     sed -e 's@\\r@@g' $expected >$out.expected
     cp $out $out.1
     cp $expected $out.expected
  if (set -x; diff -c $out.expected $out.1); then
    echo "$bug passed"
    echo "$bug failed"
    exit 1

# Check that native2ascii -reverse with an ISO-8859-1 encoded file works
# as documented. 4630463 fixes a bug in the ISO-8859-1 encoder which
# prevented encoding of valid ISO-8859-1 chars > 0x7f

rm -f x.*
$N2A -reverse -encoding ISO-8859-1 $TESTSRC/A2N_4630463 x.out
check 4630463 $TESTSRC/A2N_4630463.expected x.out

# Take file encoded in ISO-8859-1 with range of chars ,  0x7f < c < 0xff
# invoke native2ascii with input filename and output filename identical
# Ensure that output file is as expected by comparing to expected output.
# 4636448 Fixed bug whereby output file was clobbered if infile and outfile
# referred to same filename.  This bug only applies to Solaris/Linux, since on
# Windows you can't write to a file that's open for reading.

if [ $OS = Unix ]; then
  rm -f x.*
  cp $TESTSRC/N2A_4636448
  chmod +w
  ls -l
  if $N2A -encoding ISO-8859-1; then
    check 4636448 $TESTSRC/N2A_4636448.expected

# Ensure that files containing backslashes adjacent to EOF don't
# hang native2ascii -reverse

rm -f x.*
$N2A -reverse -encoding ISO-8859-1 $TESTSRC/A2N_4630971 x.out
check 4630971 $TESTSRC/A2N_4630971 x.out

# Check reverse (char -> native) encoding of Japanese Halfwidth
# Katakana characters for MS932 (default WinNT Japanese encoding)
# Regression test for bugID 4701617

rm -f x.*
$N2A -reverse -encoding MS932 $TESTSRC/A2N_4701617 x.out
check 4701617 $TESTSRC/A2N_4701617.expected x.out

# Check that the inputfile appears in the error message when not found

$N2A $badin x.out | grep "$badin" > /dev/null
if [ $? != 0 ]; then
    echo "\"$badin\" expected to appear in error message"
    exit 1

# for win32 only ensure when output file pre-exists that
# native2ascii tool will simply overwrite with the expected
# output file (fixed bugID 4710890)

if [ OS = Windows ]; then
   rm -f x.*
   cp $TESTSRC/test3
   chmod a+x
   ls -l
   touch x.out
   $N2A -encoding ISO-8859-1 x.out
   check 4710890 $TESTSRC/test3 x.out

rm -rf x.*
$N2A -reverse $TESTSRC/A2N_6247817 x.out
check 4701617 $TESTSRC/A2N_6247817 x.out