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