xmltest.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #! /bin/sh
  2. # EXPAT TEST SCRIPT FOR W3C XML TEST SUITE
  3. # This script can be used to exercise Expat against the
  4. # w3c.org xml test suite, available from
  5. # http://www.w3.org/XML/Test/xmlts20020606.zip.
  6. # To run this script, first set XMLWF so that xmlwf can be
  7. # found, then set the output directory with OUTPUT.
  8. # The script lists all test cases where Expat shows a discrepancy
  9. # from the expected result. Test cases where only the canonical
  10. # output differs are prefixed with "Output differs:", and a diff file
  11. # is generated in the appropriate subdirectory under $OUTPUT.
  12. # If there are output files provided, the script will use
  13. # output from xmlwf and compare the desired output against it.
  14. # However, one has to take into account that the canonical output
  15. # produced by xmlwf conforms to an older definition of canonical XML
  16. # and does not generate notation declarations.
  17. MYDIR="`dirname \"$0\"`"
  18. cd "$MYDIR"
  19. MYDIR="`pwd`"
  20. XMLWF="`dirname \"$MYDIR\"`/xmlwf/xmlwf"
  21. # XMLWF=/usr/local/bin/xmlwf
  22. TS="$MYDIR/XML-Test-Suite"
  23. # OUTPUT must terminate with the directory separator.
  24. OUTPUT="$TS/out/"
  25. # OUTPUT=/home/tmp/xml-testsuite-out/
  26. # RunXmlwfNotWF file reldir
  27. # reldir includes trailing slash
  28. RunXmlwfNotWF() {
  29. file="$1"
  30. reldir="$2"
  31. $XMLWF -p "$file" > outfile || return $?
  32. read outdata < outfile
  33. if test "$outdata" = "" ; then
  34. echo "Expected well-formed: $reldir$file"
  35. return 1
  36. else
  37. return 0
  38. fi
  39. }
  40. # RunXmlwfWF file reldir
  41. # reldir includes trailing slash
  42. RunXmlwfWF() {
  43. file="$1"
  44. reldir="$2"
  45. $XMLWF -p -d "$OUTPUT$reldir" "$file" > outfile || return $?
  46. read outdata < outfile
  47. if test "$outdata" = "" ; then
  48. if [ -f "out/$file" ] ; then
  49. diff "$OUTPUT$reldir$file" "out/$file" > outfile
  50. if [ -s outfile ] ; then
  51. cp outfile "$OUTPUT$reldir$file.diff"
  52. echo "Output differs: $reldir$file"
  53. return 1
  54. fi
  55. fi
  56. return 0
  57. else
  58. echo "In $reldir: $outdata"
  59. return 1
  60. fi
  61. }
  62. SUCCESS=0
  63. ERROR=0
  64. UpdateStatus() {
  65. if [ "$1" -eq 0 ] ; then
  66. SUCCESS=`expr $SUCCESS + 1`
  67. else
  68. ERROR=`expr $ERROR + 1`
  69. fi
  70. }
  71. ##########################
  72. # well-formed test cases #
  73. ##########################
  74. cd "$TS/xmlconf"
  75. for xmldir in ibm/valid/P* \
  76. ibm/invalid/P* \
  77. xmltest/valid/ext-sa \
  78. xmltest/valid/not-sa \
  79. xmltest/invalid \
  80. xmltest/invalid/not-sa \
  81. xmltest/valid/sa \
  82. sun/valid \
  83. sun/invalid ; do
  84. cd "$TS/xmlconf/$xmldir"
  85. mkdir -p "$OUTPUT$xmldir"
  86. for xmlfile in *.xml ; do
  87. RunXmlwfWF "$xmlfile" "$xmldir/"
  88. UpdateStatus $?
  89. done
  90. rm outfile
  91. done
  92. cd "$TS/xmlconf/oasis"
  93. mkdir -p "$OUTPUT"oasis
  94. for xmlfile in *pass*.xml ; do
  95. RunXmlwfWF "$xmlfile" "oasis/"
  96. UpdateStatus $?
  97. done
  98. rm outfile
  99. ##############################
  100. # not well-formed test cases #
  101. ##############################
  102. cd "$TS/xmlconf"
  103. for xmldir in ibm/not-wf/P* \
  104. ibm/not-wf/misc \
  105. xmltest/not-wf/ext-sa \
  106. xmltest/not-wf/not-sa \
  107. xmltest/not-wf/sa \
  108. sun/not-wf ; do
  109. cd "$TS/xmlconf/$xmldir"
  110. for xmlfile in *.xml ; do
  111. RunXmlwfNotWF "$xmlfile" "$xmldir/"
  112. UpdateStatus $?
  113. done
  114. rm outfile
  115. done
  116. cd "$TS/xmlconf/oasis"
  117. for xmlfile in *fail*.xml ; do
  118. RunXmlwfNotWF "$xmlfile" "oasis/"
  119. UpdateStatus $?
  120. done
  121. rm outfile
  122. echo "Passed: $SUCCESS"
  123. echo "Failed: $ERROR"