1 #! /bin/sh -e
   2 
   3 #
   4 # Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22 # CA 95054 USA or visit www.sun.com if you need additional information or
  23 # have any questions.
  24 #
  25 
  26 # @test
  27 # @bug 4630463 4630971 4636448 4701617 4721296 4710890 6247817
  28 # @summary Tests miscellaneous native2ascii bugfixes and regressions
  29 
  30 
  31 if [ "${TESTSRC}" = "" ]; then TESTSRC=.; fi
  32 if [ "${TESTJAVA}" = "" ]; then TESTJAVA=$1; shift; fi
  33 
  34 case `uname -s` in
  35   Windows*) OS=Windows;;
  36   SunOS|Linux) OS=Unix;;
  37 esac
  38 
  39 N2A=$TESTJAVA/bin/native2ascii
  40 
  41 check() {
  42   bug=$1; shift
  43   expected=$1; shift
  44   out=$1; shift
  45 
  46   # Strip carriage returns from output when comparing with n2a test output
  47   # on win32 systems
  48   if [ OS = Windows ]; then
  49      tr -d '\015' <$out >$out.1
  50   else
  51      cp $out $out.1
  52   fi
  53   if (set -x; diff -c $expected $out.1); then
  54     echo "$bug passed"
  55   else
  56     echo "$bug failed"
  57     exit 1
  58   fi
  59 }
  60 
  61 # Check that native2ascii -reverse with an ISO-8859-1 encoded file works
  62 # as documented. 4630463 fixes a bug in the ISO-8859-1 encoder which
  63 # prevented encoding of valid ISO-8859-1 chars > 0x7f
  64 
  65 rm -f x.*
  66 $N2A -reverse -encoding ISO-8859-1 $TESTSRC/A2N_4630463 x.out
  67 check 4630463 $TESTSRC/A2N_4630463.expected x.out
  68 
  69 # Take file encoded in ISO-8859-1 with range of chars ,  0x7f < c < 0xff
  70 # invoke native2ascii with input filename and output filename identical
  71 # Ensure that output file is as expected by comparing to expected output.
  72 # 4636448 Fixed bug whereby output file was clobbered if infile and outfile
  73 # referred to same filename.  This bug only applies to Solaris/Linux, since on
  74 # Windows you can't write to a file that's open for reading.
  75 
  76 if [ $OS = Unix ]; then
  77   rm -f x.*
  78   cp $TESTSRC/N2A_4636448 x.in
  79   chmod +w x.in
  80   ls -l x.in
  81   if $N2A -encoding ISO-8859-1 x.in x.in; then
  82     check 4636448 $TESTSRC/N2A_4636448.expected x.in
  83   fi
  84 fi
  85 
  86 # Ensure that files containing backslashes adjacent to EOF don't
  87 # hang native2ascii -reverse
  88 
  89 rm -f x.*
  90 $N2A -reverse -encoding ISO-8859-1 $TESTSRC/A2N_4630971 x.out
  91 check 4630971 $TESTSRC/A2N_4630971 x.out
  92 
  93 # Check reverse (char -> native) encoding of Japanese Halfwidth
  94 # Katakana characters for MS932 (default WinNT Japanese encoding)
  95 # Regression test for bugID 4701617
  96 
  97 rm -f x.*
  98 $N2A -reverse -encoding MS932 $TESTSRC/A2N_4701617 x.out
  99 check 4701617 $TESTSRC/A2N_4701617.expected x.out
 100 
 101 # for win32 only ensure when output file pre-exists that
 102 # native2ascii tool will simply overwrite with the expected
 103 # output file (fixed bugID 4710890)
 104 
 105 if [ OS = Windows ]; then
 106    rm -f x.*
 107    cp $TESTSRC/test3 x.in
 108    chmod a+x x.in
 109    ls -l x.in
 110    touch x.out
 111    $N2A -encoding ISO-8859-1 x.in x.out
 112    check 4710890 $TESTSRC/test3 x.out
 113 fi
 114 
 115 rm -rf x.*
 116 $N2A -reverse $TESTSRC/A2N_6247817 x.out
 117 check 4701617 $TESTSRC/A2N_6247817 x.out
 118