blob: 2b8cb196b385c11cba7d69e3f7a1529387fadc88 [file] [log] [blame]
Paul Duffinba34a0c2017-02-27 14:40:16 +00001#! /usr/bin/env bash
The Android Open Source Projectb80e2872009-03-03 19:29:30 -08002
3# EXPAT TEST SCRIPT FOR W3C XML TEST SUITE
4
5# This script can be used to exercise Expat against the
6# w3c.org xml test suite, available from
7# http://www.w3.org/XML/Test/xmlts20020606.zip.
8
Elliott Hughes35e432d2012-09-09 14:23:38 -07009# To run this script, first set XMLWF below so that xmlwf can be
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080010# found, then set the output directory with OUTPUT.
11
12# The script lists all test cases where Expat shows a discrepancy
13# from the expected result. Test cases where only the canonical
14# output differs are prefixed with "Output differs:", and a diff file
15# is generated in the appropriate subdirectory under $OUTPUT.
16
17# If there are output files provided, the script will use
18# output from xmlwf and compare the desired output against it.
19# However, one has to take into account that the canonical output
20# produced by xmlwf conforms to an older definition of canonical XML
21# and does not generate notation declarations.
22
Paul Duffinba34a0c2017-02-27 14:40:16 +000023shopt -s nullglob
24
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080025MYDIR="`dirname \"$0\"`"
26cd "$MYDIR"
27MYDIR="`pwd`"
Elliott Hughes72472942018-01-10 08:36:10 -080028XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080029# XMLWF=/usr/local/bin/xmlwf
Paul Duffinba34a0c2017-02-27 14:40:16 +000030TS="$MYDIR"
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080031# OUTPUT must terminate with the directory separator.
32OUTPUT="$TS/out/"
33# OUTPUT=/home/tmp/xml-testsuite-out/
Elliott Hughes72472942018-01-10 08:36:10 -080034# Unicode-aware diff utility
35DIFF="$TS/udiffer.py"
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080036
37
38# RunXmlwfNotWF file reldir
39# reldir includes trailing slash
40RunXmlwfNotWF() {
41 file="$1"
42 reldir="$2"
43 $XMLWF -p "$file" > outfile || return $?
44 read outdata < outfile
45 if test "$outdata" = "" ; then
Elliott Hughes35e432d2012-09-09 14:23:38 -070046 echo "Expected not well-formed: $reldir$file"
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080047 return 1
48 else
49 return 0
50 fi
51}
52
53# RunXmlwfWF file reldir
54# reldir includes trailing slash
55RunXmlwfWF() {
56 file="$1"
57 reldir="$2"
Elliott Hughes72472942018-01-10 08:36:10 -080058 $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080059 read outdata < outfile
60 if test "$outdata" = "" ; then
61 if [ -f "out/$file" ] ; then
Elliott Hughes72472942018-01-10 08:36:10 -080062 $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
The Android Open Source Projectb80e2872009-03-03 19:29:30 -080063 if [ -s outfile ] ; then
64 cp outfile "$OUTPUT$reldir$file.diff"
65 echo "Output differs: $reldir$file"
66 return 1
67 fi
68 fi
69 return 0
70 else
71 echo "In $reldir: $outdata"
72 return 1
73 fi
74}
75
76SUCCESS=0
77ERROR=0
78
79UpdateStatus() {
80 if [ "$1" -eq 0 ] ; then
81 SUCCESS=`expr $SUCCESS + 1`
82 else
83 ERROR=`expr $ERROR + 1`
84 fi
85}
86
87##########################
88# well-formed test cases #
89##########################
90
91cd "$TS/xmlconf"
92for xmldir in ibm/valid/P* \
93 ibm/invalid/P* \
94 xmltest/valid/ext-sa \
95 xmltest/valid/not-sa \
96 xmltest/invalid \
97 xmltest/invalid/not-sa \
98 xmltest/valid/sa \
99 sun/valid \
100 sun/invalid ; do
101 cd "$TS/xmlconf/$xmldir"
102 mkdir -p "$OUTPUT$xmldir"
Elliott Hughes72472942018-01-10 08:36:10 -0800103 for xmlfile in $(ls -1 *.xml | sort -d) ; do
104 [[ -f "$xmlfile" ]] || continue
The Android Open Source Projectb80e2872009-03-03 19:29:30 -0800105 RunXmlwfWF "$xmlfile" "$xmldir/"
106 UpdateStatus $?
107 done
Paul Duffinba34a0c2017-02-27 14:40:16 +0000108 rm -f outfile
The Android Open Source Projectb80e2872009-03-03 19:29:30 -0800109done
110
111cd "$TS/xmlconf/oasis"
112mkdir -p "$OUTPUT"oasis
113for xmlfile in *pass*.xml ; do
114 RunXmlwfWF "$xmlfile" "oasis/"
115 UpdateStatus $?
116done
117rm outfile
118
119##############################
120# not well-formed test cases #
121##############################
122
123cd "$TS/xmlconf"
124for xmldir in ibm/not-wf/P* \
Elliott Hughes35e432d2012-09-09 14:23:38 -0700125 ibm/not-wf/p28a \
The Android Open Source Projectb80e2872009-03-03 19:29:30 -0800126 ibm/not-wf/misc \
127 xmltest/not-wf/ext-sa \
128 xmltest/not-wf/not-sa \
129 xmltest/not-wf/sa \
130 sun/not-wf ; do
131 cd "$TS/xmlconf/$xmldir"
132 for xmlfile in *.xml ; do
133 RunXmlwfNotWF "$xmlfile" "$xmldir/"
134 UpdateStatus $?
135 done
136 rm outfile
137done
138
139cd "$TS/xmlconf/oasis"
140for xmlfile in *fail*.xml ; do
141 RunXmlwfNotWF "$xmlfile" "oasis/"
142 UpdateStatus $?
143done
144rm outfile
145
146echo "Passed: $SUCCESS"
147echo "Failed: $ERROR"