/iconvdata/run-iconv-test.sh

https://github.com/nitinkamble/x32-glibc · Shell · 192 lines · 125 code · 24 blank · 43 comment · 23 complexity · 6e2b9fe239ca21957649f860cd674a1d MD5 · raw file

  1. #! /bin/sh -f
  2. # Run available iconv(1) tests.
  3. # Copyright (C) 1998-2002, 2005, 2006, 2008 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5. # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
  6. #
  7. # The GNU C Library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with the GNU C Library; if not, write to the Free
  17. # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. # 02111-1307 USA.
  19. codir=$1
  20. # We use always the same temporary file.
  21. temp1=$codir/iconvdata/iconv-test.xxx
  22. temp2=$codir/iconvdata/iconv-test.yyy
  23. trap "rm -f $temp1 $temp2" 1 2 3 15
  24. # We must tell the iconv(1) program where the modules we want to use can
  25. # be found.
  26. GCONV_PATH=$codir/iconvdata
  27. export GCONV_PATH
  28. # We have to have some directories in the library path.
  29. LIBPATH=$codir:$codir/iconvdata
  30. # How the start the iconv(1) program.
  31. ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \
  32. $codir/iconv/iconv_prog'
  33. # Which echo?
  34. if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
  35. ac_n=-n ac_c= ac_t=
  36. else
  37. ac_n= ac_c='\c' ac_t=
  38. fi
  39. # We read the file named TESTS. All non-empty lines not starting with
  40. # `#' are interpreted as commands.
  41. failed=0
  42. while read from to subset targets; do
  43. # Ignore empty and comment lines.
  44. if test -z "$subset" || test "$from" = '#'; then continue; fi
  45. # Expand the variables now.
  46. PROG=`eval echo $ICONV`
  47. if test -n "$targets"; then
  48. for t in $targets; do
  49. if test -f testdata/$from; then
  50. echo $ac_n " test data: $from -> $t $ac_c"
  51. $PROG -f $from -t $t testdata/$from > $temp1 ||
  52. { if test $? -gt 128; then exit 1; fi
  53. echo "FAILED"; failed=1; continue; }
  54. echo $ac_n "OK$ac_c"
  55. if test -s testdata/$from..$t; then
  56. LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
  57. { echo "/FAILED"; failed=1; continue; }
  58. echo $ac_n "/OK$ac_c"
  59. fi
  60. echo $ac_n " -> $from $ac_c"
  61. $PROG -f $t -t $to -o $temp2 $temp1 ||
  62. { if test $? -gt 128; then exit 1; fi
  63. echo "FAILED"; failed=1; continue; }
  64. echo $ac_n "OK$ac_c"
  65. test -s $temp1 &&
  66. LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
  67. { echo "/FAILED"; failed=1; continue; }
  68. echo "/OK"
  69. rm -f $temp1 $temp2
  70. fi
  71. # Now test some bigger text, entirely in ASCII. If ASCII is no subset
  72. # of the coded character set we convert the text to this coded character
  73. # set. Otherwise we convert to all the TARGETS.
  74. if test $subset = Y; then
  75. echo $ac_n " suntzu: $from -> $t -> $to $ac_c"
  76. $PROG -f $from -t $t testdata/suntzus |
  77. $PROG -f $t -t $to > $temp1 ||
  78. { if test $? -gt 128; then exit 1; fi
  79. echo "FAILED"; failed=1; continue; }
  80. echo $ac_n "OK$ac_c"
  81. LC_ALL=C cmp testdata/suntzus $temp1 ||
  82. { echo "/FAILED"; failed=1; continue; }
  83. echo "/OK"
  84. fi
  85. rm -f $temp1
  86. # And tests where iconv(1) has to handle charmaps.
  87. if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi
  88. if test -f ../localedata/charmaps/$from &&
  89. test -f ../localedata/charmaps/$tc &&
  90. test -f testdata/$from &&
  91. ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then
  92. echo $ac_n "test charmap: $from -> $t $ac_c"
  93. $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \
  94. testdata/$from > $temp1 ||
  95. { if test $? -gt 128; then exit 1; fi
  96. echo "FAILED"; failed=1; continue; }
  97. echo $ac_n "OK$ac_c"
  98. if test -s testdata/$from..$t; then
  99. LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
  100. { echo "/FAILED"; failed=1; continue; }
  101. echo $ac_n "/OK$ac_c"
  102. fi
  103. echo $ac_n " -> $from $ac_c"
  104. $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \
  105. -o $temp2 $temp1 ||
  106. { if test $? -gt 128; then exit 1; fi
  107. echo "FAILED"; failed=1; continue; }
  108. echo $ac_n "OK$ac_c"
  109. test -s $temp1 &&
  110. LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
  111. { echo "/FAILED"; failed=1; continue; }
  112. echo "/OK"
  113. rm -f $temp1 $temp2
  114. fi
  115. done
  116. fi
  117. if test "$subset" = N; then
  118. echo $ac_n " suntzu: ASCII -> $to -> ASCII $ac_c"
  119. $PROG -f ASCII -t $to testdata/suntzus |
  120. $PROG -f $to -t ASCII > $temp1 ||
  121. { if test $? -gt 128; then exit 1; fi
  122. echo "FAILED"; failed=1; continue; }
  123. echo $ac_n "OK$ac_c"
  124. LC_ALL=C cmp testdata/suntzus $temp1 ||
  125. { echo "/FAILED"; failed=1; continue; }
  126. echo "/OK"
  127. fi
  128. done < TESTS
  129. # We read the file named TESTS2. All non-empty lines not starting with
  130. # `#' are interpreted as commands.
  131. while read utf8 from filename; do
  132. # Ignore empty and comment lines.
  133. if test -z "$filename" || test "$utf8" = '#'; then continue; fi
  134. # Expand the variables now.
  135. PROG=`eval echo $ICONV`
  136. # Test conversion to the endianness dependent encoding.
  137. echo $ac_n "test encoder: $utf8 -> $from $ac_c"
  138. $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1
  139. LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
  140. LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
  141. { echo "/FAILED"; failed=1; continue; }
  142. echo "OK"
  143. # Test conversion from the endianness dependent encoding.
  144. echo $ac_n "test decoder: $from -> $utf8 $ac_c"
  145. $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1
  146. LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
  147. { echo "/FAILED"; failed=1; continue; }
  148. $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1
  149. LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
  150. { echo "/FAILED"; failed=1; continue; }
  151. echo "OK"
  152. # Test byte swapping behaviour.
  153. echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c"
  154. $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1
  155. LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
  156. { echo "/FAILED"; failed=1; continue; }
  157. echo "OK"
  158. # Test byte swapping behaviour.
  159. echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c"
  160. $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1
  161. LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
  162. { echo "/FAILED"; failed=1; continue; }
  163. echo "OK"
  164. done < TESTS2
  165. exit $failed
  166. # Local Variables:
  167. # mode:shell-script
  168. # End: