]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/expat/tests/xmltest.sh
MFV r355071: libbsdxml (expat) 2.2.9.
[FreeBSD/FreeBSD.git] / contrib / expat / tests / xmltest.sh
1 #! /usr/bin/env bash
2
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
9 # To run this script, first set XMLWF below so that xmlwf can be
10 # 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
23 shopt -s nullglob
24
25 # Note: OUTPUT must terminate with the directory separator.
26 OUTPUT="$PWD/tests/out/"
27 TS="$PWD/tests/"
28
29 MYDIR="`dirname \"$0\"`"
30 cd "$MYDIR"
31 MYDIR="`pwd`"
32 XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
33 # Unicode-aware diff utility
34 DIFF="${MYDIR}/udiffer.py"
35
36
37 # RunXmlwfNotWF file reldir
38 # reldir includes trailing slash
39 RunXmlwfNotWF() {
40   file="$1"
41   reldir="$2"
42   if $XMLWF -p "$file" > /dev/null; then
43       echo "Expected not well-formed: $reldir$file"
44       return 1
45   else
46       return 0
47   fi 
48 }
49
50 # RunXmlwfWF file reldir
51 # reldir includes trailing slash
52 RunXmlwfWF() {
53   file="$1"
54   reldir="$2"
55   $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
56   read outdata < outfile 
57   if test "$outdata" = "" ; then 
58       if [ -f "out/$file" ] ; then 
59           $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile 
60           if [ -s outfile ] ; then 
61               cp outfile "$OUTPUT$reldir$file.diff"
62               echo "Output differs: $reldir$file"
63               return 1
64           fi 
65       fi 
66       return 0
67   else 
68       echo "In $reldir: $outdata"
69       return 1
70   fi 
71 }
72
73 SUCCESS=0
74 ERROR=0
75
76 UpdateStatus() {
77   if [ "$1" -eq 0 ] ; then
78     SUCCESS=`expr $SUCCESS + 1`
79   else
80     ERROR=`expr $ERROR + 1`
81   fi
82 }
83
84 ##########################
85 # well-formed test cases #
86 ##########################
87
88 cd "$TS/xmlconf"
89 for xmldir in ibm/valid/P* \
90               ibm/invalid/P* \
91               xmltest/valid/ext-sa \
92               xmltest/valid/not-sa \
93               xmltest/invalid \
94               xmltest/invalid/not-sa \
95               xmltest/valid/sa \
96               sun/valid \
97               sun/invalid ; do
98   cd "$TS/xmlconf/$xmldir"
99   mkdir -p "$OUTPUT$xmldir"
100   for xmlfile in $(ls -1 *.xml | sort -d) ; do
101       [[ -f "$xmlfile" ]] || continue
102       RunXmlwfWF "$xmlfile" "$xmldir/"
103       UpdateStatus $?
104   done
105   rm -f outfile
106 done
107
108 cd "$TS/xmlconf/oasis"
109 mkdir -p "$OUTPUT"oasis
110 for xmlfile in *pass*.xml ; do
111     RunXmlwfWF "$xmlfile" "oasis/"
112     UpdateStatus $?
113 done
114 rm outfile
115
116 ##############################
117 # not well-formed test cases #
118 ##############################
119
120 cd "$TS/xmlconf"
121 for xmldir in ibm/not-wf/P* \
122               ibm/not-wf/p28a \
123               ibm/not-wf/misc \
124               xmltest/not-wf/ext-sa \
125               xmltest/not-wf/not-sa \
126               xmltest/not-wf/sa \
127               sun/not-wf ; do
128   cd "$TS/xmlconf/$xmldir"
129   for xmlfile in *.xml ; do
130       RunXmlwfNotWF "$xmlfile" "$xmldir/"
131       UpdateStatus $?
132   done
133 done
134
135 cd "$TS/xmlconf/oasis"
136 for xmlfile in *fail*.xml ; do
137     RunXmlwfNotWF "$xmlfile" "oasis/"
138     UpdateStatus $?
139 done
140
141 echo "Passed: $SUCCESS"
142 echo "Failed: $ERROR"