#!/bin/sh

# The test suite is the official OASIS test suite, that can be downloaded
# from www.xml.org. The name of the current archive is
#     xmlconf-19990712.tar.Z

# When running this script, run with
#   ./testsuite 0
# to suppress the summary message printed at the end

BASE=${BASE:-tests}
verbose="$1"

if [ "$verbose " = " " ]; then
  verbose=0
fi

XML=../obj/testxml
XML_SILENT="$XML -silent"   # Use for testing error messages only
XML_SILENT_VALIDATE="$XML -silent -validate" 
valid_sa="$BASE/xmltest/valid/sa"
valid_not_sa="$BASE/xmltest/valid/not-sa"
valid_ext_sa="$BASE/xmltest/valid/ext-sa"
sun_valid="$BASE/sun/valid"
oasis="$BASE/oasis"
japanese="$BASE/japanese"
out_file="testsuite.out"
old_out_file="testsuite.out.old"

# Stop running after that many failures
stop_after=200

# Set to 1 if we want to test a validating XML parser
VALIDATING=0

# Set to 1 to activate tests whose result is dubious
NOT_SURE=0

num_tests_run=0
num_failures=0

# Which tests do we want to run ?
run_valid_tests=1
run_invalid_tests=1
run_not_wf_tests=1
optional_errors=1

# special characters (these are not saved as is so that we can easily save
# that testsuite file in 7 bit mode)
x9=`printf "\0011"`
x80=`printf "\0200"`
xb7=`printf "\0267"`
xc2=`printf "\0302"`
xcc=`printf "\0314"`
x82=`printf "\0202"`
xe3=`printf "\0343"`
x9a=`printf "\0232"`
xe0=`printf "\0340"`
xb9=`printf "\0271"`
x9c=`printf "\0234"`

# Initialize the out file
if [ -f $out_file ]; then
   mv $out_file $old_out_file
fi
touch $out_file

######################################
## print_result ()
## Print the results
######################################
print_result () {
  if [ $verbose = 1 ]; then
    echo "----------------------------------"
 
    num_validating=0
    if [ $VALIDATING != 1 ]; then
       num_validating=`grep "VALIDATING ""= 1" testsuite | wc -l`
       echo " tests that should be run when validating: $num_validating"
    fi

    num_not_sure=0
    if [ $NOT_SURE != 1 ]; then
       num_not_sure=`grep "NOT_SURE ""= 1" testsuite | wc -l`
       echo " ambiguous tests: $num_not_sure"
    fi

    success=`expr $num_tests_run - $num_failures`
    total=`expr $num_tests_run + $num_not_sure + $num_validating`
   
    echo "----------------------------------"
    echo "Results: ($success / $num_tests_run) tests run, $num_failures failures"
    echo "Results: ($success / $num_tests_run) tests run, $num_failures failures" >> $out_file
    echo
  fi
    exit
}

trap print_result INT STOP QUIT KILL TERM

######################################
## expect ()
##  $1 = command to execute
##  $2 = expected output
##  $3 = input to be send to the command
######################################
expect () {
#  echo "$1"
  num_tests_run=`expr $num_tests_run + 1`
  out=`eval $1 2>&1 <<EOF
$3
EOF`
  exp="$2"
  if [ "$exp " != "$out " ]; then
     num_failures=`expr $num_failures + 1`
     echo "  Cmd: $1" >> $out_file
     echo "#---------- Test failed ----------"
     echo "  Cmd: $1"
     echo "  Got: $out"
     echo "  Expecting: $exp"

     if [ $num_failures = $stop_after ]; then
        echo
        echo "Forced stopped after $stop_after errors"
        print_result;
     fi
  fi
}

######################################
## expect_file ()
##  $1 = command to execute
##  $2 = directory
##  $3 = name of test
######################################
expect_file () {
  file=`cat $2/out/$3`
  expect "$1 $2/$3" "$file" ""
}

######################################
## Oasis tests
######################################

expect_oasis() {
  expect "$XML_SILENT $oasis/$1.xml" ""
}

if [ $run_valid_tests = 1 ]; then
    # "p01pass1" is an invalid document. See section later
    expect_oasis "p01pass2"
    # "p01pass3" is an invalid document. See section later
    [ $NOT_SURE = 1 ] && expect_oasis "p02pass1"
     # ??? "p02pass1" Removed apparently from the official suite
    # "p03pass1" is an invalid document. See section later
    # "p04pass1" is an invalid document. See section later
    # "p05pass1" is an invalid document. See section later
    expect_oasis "p06pass1"
    expect_oasis "p07pass1"
    expect_oasis "p08pass1"
    expect_oasis "p09pass1"
    expect_oasis "p10pass1"
    expect_oasis "p11pass1"
    expect_oasis "p12pass1"
    expect_oasis "p14pass1"
    # "p15pass1" is an invalid document. See section later
    # "p16pass1" is an invalid document. See section later
    # "p16pass2" is an invalid document. See section later
    # "p16pass3" is an invalid document. See section later
    # "p18pass1" is an invalid document. See section later
    # "p22pass1" is an invalid document. See section later
    # "p22pass2" is an invalid document. See section later
    # "p22pass3" is an invalid document. See section later
    expect_oasis "p22pass4"
    expect_oasis "p22pass5"
    expect_oasis "p22pass6"
    expect_oasis "p23pass1"
    expect_oasis "p23pass2"
    expect_oasis "p23pass3"
    expect_oasis "p23pass4"
    expect_oasis "p24pass1"
    expect_oasis "p24pass2"
    expect_oasis "p24pass3"
    expect_oasis "p24pass4"
    expect_oasis "p25pass1"
    expect_oasis "p25pass2"
    expect_oasis "p26pass1"
    expect_oasis "p27pass1"
    expect_oasis "p27pass2"
    expect_oasis "p27pass3"
    expect_oasis "p27pass4"
    expect_oasis "p28pass1"
    expect_oasis "p28pass2"
    expect_oasis "p28pass3"
    expect_oasis "p28pass4"
    [ $NOT_SURE = 1 ] && expect_oasis "p28pass5"
    expect_oasis "p29pass1"
    expect_oasis "p30pass1"
    expect_oasis "p30pass2"
    expect_oasis "p31pass1"
    expect_oasis "p31pass2"
    expect_oasis "p32pass1"
    expect_oasis "p32pass2"
    expect_oasis "p39pass1"
    expect_oasis "p39pass2"
    expect_oasis "p40pass1"
    expect_oasis "p40pass2"
    expect_oasis "p40pass3"
    expect_oasis "p40pass4"
    expect_oasis "p41pass1"
    expect_oasis "p41pass2"
    expect_oasis "p42pass1"
    expect_oasis "p42pass2"
    expect_oasis "p43pass1"
    expect_oasis "p44pass1"
    expect_oasis "p44pass2"
    expect_oasis "p44pass3"
    expect_oasis "p44pass4"
    expect_oasis "p44pass5"
    expect_oasis "p45pass1"
    expect_oasis "p46pass1"
    expect_oasis "p47pass1"
    expect_oasis "p48pass1"
    expect_oasis "p49pass1"
    expect_oasis "p50pass1"
    expect_oasis "p51pass1"
    expect_oasis "p52pass1"
    expect_oasis "p53pass1"
    expect_oasis "p54pass1"
    expect_oasis "p55pass1"
    expect_oasis "p56pass1"
    expect_oasis "p57pass1"
    expect_oasis "p58pass1"
    expect_oasis "p59pass1"
    expect_oasis "p60pass1"
    expect_oasis "p61pass1"
    expect_oasis "p62pass1"
    expect_oasis "p63pass1"
    expect_oasis "p64pass1"
    expect_oasis "p66pass1"
    expect_oasis "p68pass1"
    expect_oasis "p69pass1"
    expect_oasis "p70pass1"
    expect_oasis "p71pass1"
    expect_oasis "p72pass1"
    expect_oasis "p73pass1"
    expect_oasis "p74pass1"
    expect_oasis "p75pass1"
    expect_oasis "p76pass1"
fi

######################################
## Sun tests
######################################

expect_sun_valid () {
  expect_file "$XML" "$sun_valid" "$1.xml"
}

if [ $run_valid_tests = 1 ]; then
    expect_sun_valid "dtd00"
    expect_sun_valid "dtd01"
    expect_sun_valid "element"
    expect_sun_valid "optional"
    #  ??? while parsing dtdtest.dtd, we should simply the element contents
    #  nested parentheses need not be reported
    expect_sun_valid "required00"
    expect_sun_valid "sa01"
    expect_sun_valid "v-lang01"
    expect_sun_valid "v-lang02"
    expect_sun_valid "v-lang03"
    expect_sun_valid "v-lang04"
    expect_sun_valid "v-lang05"
    expect_sun_valid "v-lang06"
    expect_sun_valid "ext01"
    [ $NOT_SURE = 1 ] && expect_sun_valid "ext02"
    expect_sun_valid "empty"
    expect_sun_valid "pe00"
    expect_sun_valid "pe01"
    expect_sun_valid "pe02"
    [ $NOT_SURE = 1 ] && expect_sun_valid "sa02"
    [ $NOT_SURE = 1 ] && expect_sun_valid "sa03"
    [ $NOT_SURE = 1 ] && expect_sun_valid "sa04"
    [ $NOT_SURE = 1 ]    && expect_sun_valid "sa05"
    expect_sun_valid "sgml01"
    [ $NOT_SURE = 1 ]    && expect_sun_valid "notation01"
    [ $NOT_SURE = 1 ]        && expect_sun_valid "not-sa01"
    [ $NOT_SURE = 1 ]        && expect_sun_valid "not-sa02"
    [ $NOT_SURE = 1 ]        && expect_sun_valid "not-sa03"
    [ $NOT_SURE = 1 ]        && expect_sun_valid "not-sa04"
fi

######################################
## Japanese tests
######################################

expect_japanese() {
   expect "$XML_SILENT $japanese/$1.xml" ""
}

if [ $run_valid_tests = 1 ]; then
    [ $NOT_SURE = 1 ] && expect_japanese "pr-xml-little-endian"
    # pr-xml-little-endian.xml:2:34: External subset not found: /home/briot/internet/xml/tests/japanese/spec.dtd
    [ $NOT_SURE = 1 ] && expect_japanese "pr-xml-utf-16"
    [ $NOT_SURE = 1 ] && expect_japanese "pr-xml-utf-8"
    expect_japanese "weekly-little-endian"
    expect_japanese "weekly-utf-16"
    expect_japanese "weekly-utf-8"
fi

######################################
## Valid external standalone tests
######################################

expect_valid_ext_sa() {
   expect_file "$XML" "$valid_ext_sa" "$1.xml"
}

if [ $run_valid_tests = 1 ]; then
    expect_valid_ext_sa "001"
    expect_valid_ext_sa "002"
    expect_valid_ext_sa "003"
    expect_valid_ext_sa "004"
    expect_valid_ext_sa "005"
    expect_valid_ext_sa "006"
    expect_valid_ext_sa "007"
    [ $NOT_SURE = 1 ]      && expect_valid_ext_sa "008"
    expect_valid_ext_sa "009"
    expect_valid_ext_sa "010"
    expect_valid_ext_sa "011"
    expect_valid_ext_sa "012"
    expect_valid_ext_sa "013"
    expect_valid_ext_sa "014"
fi

######################################
## Valid not standalone tests
######################################

expect_valid_not_sa() {
   expect_file "$XML" "$valid_not_sa" "$1.xml"
}

if [ $run_valid_tests = 1 ]; then
    expect_valid_not_sa "001"
    expect_valid_not_sa "002"
    expect_valid_not_sa "003"
    expect_valid_not_sa "004"
    expect_valid_not_sa "005"
    expect_valid_not_sa "006"
    expect_valid_not_sa "007"
    expect_valid_not_sa "008"
    expect_valid_not_sa "009"
    expect_valid_not_sa "010"
    expect_valid_not_sa "011"
    expect_valid_not_sa "012"
    expect_valid_not_sa "013"
    expect_valid_not_sa "014"
    expect_valid_not_sa "015"
    expect_valid_not_sa "016"
    expect_valid_not_sa "017"
    expect_valid_not_sa "018"
    expect_valid_not_sa "019"
    [ $NOT_SURE = 1 ]  && expect_valid_not_sa "020"
    expect_valid_not_sa "021"
    expect_valid_not_sa "022"
    expect_valid_not_sa "023"
    expect_valid_not_sa "024"
    expect_valid_not_sa "025"
    expect_valid_not_sa "026"
			      expect_valid_not_sa "027"
    expect_valid_not_sa "028"
    expect_valid_not_sa "029"
    expect_valid_not_sa "030"
    expect_valid_not_sa "031"
fi

######################################
## Output tests
## The following tests must be accepted as is, with no error
######################################

expect_valid_sa() {
    expect_file "$XML" "$valid_sa" "$1.xml"
}
expect_valid_sa_error() {
    expect "$XML $valid_sa/$1.xml" "$2"
}

if [ $run_valid_tests = 1 ]; then
    expect_valid_sa "001"
    expect_valid_sa "002"
    expect_valid_sa "003"
    expect_valid_sa "004"
    expect_valid_sa "005"
    expect_valid_sa "006"
    expect_valid_sa "007"
    expect_valid_sa "008"
    expect_valid_sa "009"
    expect_valid_sa "010"
    expect_valid_sa "011"
    expect_valid_sa "012"
    expect_valid_sa "013"
    expect_valid_sa "014"
    expect_valid_sa "015"
    expect_valid_sa "016"
    expect_valid_sa "017"
    expect_valid_sa "018"
    expect_valid_sa "019"
    expect_valid_sa "020"
    expect_valid_sa "021"
    expect_valid_sa "022"
    expect_valid_sa "023"
    expect_valid_sa "024"
    expect_valid_sa "025"
    expect_valid_sa "026"
    expect_valid_sa "027"
    expect_valid_sa "028"
    expect_valid_sa "029"
    expect_valid_sa "030"
    expect_valid_sa "031"
    expect_valid_sa "032"
    expect_valid_sa "033"
    expect_valid_sa "034"
    expect_valid_sa "035"
    expect_valid_sa "036"
    expect_valid_sa "037"
    expect_valid_sa "038"
    expect_valid_sa "039"
    expect_valid_sa "040"
    expect_valid_sa "041"
    expect_valid_sa "042"
    expect_valid_sa "043"
    expect_valid_sa "044"
    expect_valid_sa "045"
    expect_valid_sa "046"
    expect_valid_sa "047"
    expect_valid_sa "048"
    expect_valid_sa "049"
    expect_valid_sa "050"
    expect_valid_sa "051"
    expect_valid_sa "052"
    expect_valid_sa "053"
    expect_valid_sa "054"
    expect_valid_sa "055"
    expect_valid_sa "056"
    expect_valid_sa "057"
    expect_valid_sa "058"
    expect_valid_sa "059"
    expect_valid_sa "060"
    expect_valid_sa "061"
    expect_valid_sa "062"
    expect_valid_sa "063"
    expect_valid_sa "064"
    expect_valid_sa "065"
    expect_valid_sa "066"
    expect_valid_sa "067"
    [ $NOT_SURE = 1 ] && expect_valid_sa "068"
    ## 068: 2.11 XML Specs say we should return 0xA
    expect_valid_sa "069"
    expect_valid_sa "070"
    expect_valid_sa "071"
    expect_valid_sa "072"
    expect_valid_sa "073"
    expect_valid_sa "074"
    expect_valid_sa "075"
    expect_valid_sa "076"
    expect_valid_sa "077"
    expect_valid_sa "078"
    expect_valid_sa "079"
    expect_valid_sa "080"
    expect_valid_sa "081"
    expect_valid_sa "082"
    expect_valid_sa "082"
    expect_valid_sa "083"
    expect_valid_sa "084"
    expect_valid_sa "085"
    expect_valid_sa "086"
    expect_valid_sa "087"
    expect_valid_sa "088"
    expect_valid_sa "089"
    expect_valid_sa "090"
    expect_valid_sa "091"
    expect_valid_sa "092"
    expect_valid_sa "093"
    expect_valid_sa_error "094" \
       "094.xml:4:25: [WF PE in internal subset] Parameter entities cannot occur in attribute values"
    [ $NOT_SURE = 1 ] && expect_valid_sa "095" # Attr must be normalized
    expect_valid_sa "096"
    expect_valid_sa "097"
    expect_valid_sa "098"
    expect_valid_sa "099"
    expect_valid_sa "100"
    expect_valid_sa "101"
    expect_valid_sa "102"
    expect_valid_sa "103"
    expect_valid_sa "104"
    [ $NOT_SURE = 1 ] && expect_valid_sa "105" # Attr must be normalized
    [ $NOT_SURE = 1 ] && expect_valid_sa "106" # Attr must be normalized
    [ $NOT_SURE = 1 ] && expect_valid_sa "107" # Attr must be normalized
    expect_valid_sa "108"
    expect_valid_sa "109"
    [ $NOT_SURE = 1 ] && expect_valid_sa "110"
    expect_valid_sa "111"
    expect_valid_sa "112"
    expect_valid_sa "113"
    expect_valid_sa "114"
    expect_valid_sa "115"
    expect_valid_sa "116"
    expect_valid_sa "117"
    expect_valid_sa "118"
    expect_valid_sa "119"
fi

###########################################
## Invalid XML documents
##
## All conforming XML 1.0 Validating Processors are required to report
## recoverable errors in the case of documents which are Invalid. Such
## errors are violations of some validity constraint (VC).
##
## Non-validating processors should accept all these documents without
## reporting errors
###########################################

expect_invalid_oasis () {
  expect "$XML_SILENT $BASE/oasis/$1.xml" "$2"
}
expect_invalid_oasis_validate () {
  expect "$XML_SILENT_VALIDATE $BASE/oasis/$1.xml" "$2"
}
expect_invalid_sa () {
  expect "$XML_SILENT $BASE/xmltest/invalid/$1.xml" "$2"
}
expect_invalid_not_wf_not_sa () {
  expect "$XML_SILENT $BASE/xmltest/not-wf/not-sa/$1.xml" "$2"
}
expect_invalid_sun () {
  expect "$XML_SILENT $BASE/sun/invalid/$1.xml" "$2"
}
expect_invalid_sun_validate () {
  expect "$XML_SILENT_VALIDATE $BASE/sun/invalid/$1.xml" "$2"
}
expect_invalid_sun_out () {
  expect "$XML_SILENT $BASE/sun/invalid/$1.xml" "$2"
}

if [ $run_invalid_tests = 1 ]; then
    expect_invalid_oasis "p01pass1" ""
    expect_invalid_oasis "p01pass3" ""
    expect_invalid_oasis "p03pass1" ""
    #expect_invalid_oasis "p04pass1"  # Not valid with namespace support
    #expect_invalid_oasis "p05pass1"  # Not valid with namespace support
    [ $VALIDATING = 1 ] && expect_invalid_oasis_validate "p06fail1" \
         "p06fail1.xml:12:13: [VC 3.3.1] requires at least one name in IDREFS and NMTOKENS"
    [ $VALIDATING = 1 ] && expect_invalid_oasis_validate "p08fail1" \
         "p08fail1.xml:9:9: [VC 3.3.1] requires at least one name in IDREFS and NMTOKENS"
    [ $VALIDATING = 1 ] && expect_invalid_oasis_validate "p08fail2" \
         "Invalid NMTOKEN character"
    expect_invalid_oasis "p15pass1" ""
    [ $NOT_SURE = 1 ] && expect_invalid_oasis "p16fail3" \
         "Space after PItarget is required"  # "pitarget..." is valid
    expect_invalid_oasis "p16pass1" ""
    expect_invalid_oasis "p16pass2" ""
    expect_invalid_oasis "p16pass3" ""
    expect_invalid_oasis "p18pass1" ""
    expect_invalid_oasis "p22pass1" ""
    expect_invalid_oasis "p22pass2" ""
    expect_invalid_oasis "p22pass3" ""
fi


if [ $run_invalid_tests = 1 ]; then
    expect_invalid_sa "001" \
        "entity %e:1:1: [4.5] Entity values must be self-contained"
    expect_invalid_sa "002" \
        "entity %e:1:1: [4.5] Entity values must be self-contained"
    expect_invalid_sa "003" \
        "003.ent:2:18: [4.5] Entity values must be self-contained"
    expect_invalid_sa "004" \
        "entity %e2:1:1: [4.5] Entity values must be self-contained"
    expect_invalid_sa "005" \
        "entity %e:1:1: [4.5] Entity values must be self-contained"
    expect_invalid_sa "006" \
        "entity %e:1:10: [4.5] Entity values must be self-contained"
fi

if [ $run_invalid_tests = 1 ]; then
    expect_invalid_not_wf_not_sa "005" \
      "005.ent:2:1: [4.1] Undefined entity '%e'"
fi


if [ $run_invalid_tests = 1 ]; then
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr01" \
      "Tests the 'Entity Name' VC for the ENTITY attribute type in ATTLIST"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr02" \
      "Tests the 'Entity Name' VC for the ENTITIES attribute type"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr03" \
      "value must be one of the ones that's declared"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr04" \
      "the names in the declaration must all be declared"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr05" \
      "Tests the 'Name Token' VC for the NMTOKEN attribute type"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr06" \
      "Tests the 'Name Token' VC for the NMTOKENS attribute type"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr07" \
      "Tests the 'Enumeration' VC by providing a value which wasn't one of\
      the choices"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr08" \
      "Tests the 'Fixed Attribute Default' VC by providing the wrong value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr09" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal IDREF value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr10" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal IDREFS value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr11" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal ENTITY value" 
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr12" \
     "Tests the 'Attribute Default Legal' VC by providing an illegal ENTITIES value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr13" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal NMTOKEN value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr14" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal NMTOKENS value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr15" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal NOTATIONS value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "attr16" \
      "Tests the 'Attribute Default Legal' VC by providing an illegal enumeration value"
    [ $VALIDATING = 1 ] && expect_invalid_sun "dtd01" \
      "Tests the No Duplicate Types VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun_validate "dtd02" \
      "dtd02.xml:3:55: [VC 4.2.2] Notation 'Encyclopaedia' must be declared"
    [ $VALIDATING = 1 ] && expect_invalid_sun "dtd03" \
      "Tests the 'Element Valid' VC (clause 2) by omitting a required element"
    expect_invalid_sun_out "dtd06" \
      "dtd06.xml:3:5: [4.1] Undefined entity '%undefined'"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el01" \
      "Tests the Element Valid VC (clause 4) by including an undeclared child\
      element"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el02" \
      "Tests the Element Valid VC (clause 1) by including elements in an\
      EMPTY content model"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el03" \
      "Tests the Element Valid VC (clause 3) by including a child element not\
      permitted by a mixed content model"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el04" \
      "Tests the Unique Element Type Declaration VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el05" \
      "Tests the No Duplicate Types VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "el06" \
      "Tests the Element Valid VC (clause 1), using one of the predefined\
      internal entities inside an EMPTY content model."
    [ $VALIDATING = 1 ] && expect_invalid_sun "id01" \
      "Tests the ID (is a Name) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id02" \
      "Tests the ID (appears once) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id03" \
      "Tests the One ID per Element Type VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id04" \
      "Tests the ID Attribute Default VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id05" \
      "Tests the ID Attribute Default VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id06" \
      "Tests the IDREF (is a Name) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id07" \
      "Tests the IDREFS (is a Names) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id08" \
      "Tests the IDREF (matches an ID) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "id09" \
      "Tests the IDREF (IDREFS matches an ID) VC"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa01" \
      "Optional whitespace is validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa02" \
      "attributes needing normalization cause a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa03" \
      "reference to externally defined entity causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa04" \
      "attributes needing defaulting cause a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa05" \
      "token attribute that needs normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa06" \
      "NOTATION attribute that needs normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa07" \
      "NMTOKEN attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa08" \
      "NMTOKENS attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa09" \
     "NMTOKENS attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa10" \
      "IDREF attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa11" \
      "IDREFS attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa12" \
      "ENTITY attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa13" \
      "ENTITIES attribute needing normalization causes a validity error"
    [ $VALIDATING = 1 ] && expect_invalid_sun "not-sa14" \
      "optional whitespace causes a validity error (even if it's CDATA whitespace)"   
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional01" \
      "Tests the Element Valid VC (clause 2) for one instance of 'children' \
      content model, providing no children where one is required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional02" \
      "Tests the Element Valid VC (clause 2) for one instance of 'children'\
      content model, providing two children where one is required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional03" \
      "Tests the Element Valid VC (clause 2) for one instance of 'children'\
     content model, providing no children where two are required."
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional04" \
      "Tests the Element Valid VC (clause 2) for one instance of 'children'\
      content model, providing three children where two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional05" \
      "providing no children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional06" \
      "providing no children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional07" \
      "roviding no children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional08" \
      "providing no children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional09" \
      "providing no children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional10" \
      "providing three children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional11" \
      "providing three children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional12" \
      "providing three children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional13" \
      "providing three children where one or two are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional14" \
      "providing three children where one or two are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional15" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional16" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional17" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional18" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional19" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional20" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional21" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ] && expect_invalid_sun "optional22" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional23" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional24" \
      "providing no children where one or more are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "optional25" \
      "providing text content where one or more elements are required"
    [ $VALIDATING = 1 ]&& expect_invalid_sun_validate "required00" \
      "required00.xml:8:6: [VC 3.3.2] Required attribute 'req' must be defined"
    [ $VALIDATING = 1 ] && expect_invalid_sun_validate "required01" \
      "required01.xml:5:27: [VC] No attribute defined for element root"
    [ $VALIDATING = 1 ] && expect_invalid_sun_validate "required02" \
      "required02.xml:5:20: [VC] No attribute defined for element root"
    [ $VALIDATING = 1 ]&& expect_invalid_sun_validate "root" \
        "root.xml:7:6: [VC 2.8] Name of root element doesn't match name of DTD ('attributes')"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "utf16b" \
      "Tests reading an invalid 'big endian' UTF-16 document"
    [ $VALIDATING = 1 ]&& expect_invalid_sun "utf16l" \
      "Tests reading an invalid 'little endian' UTF-16 document"
fi

####################################
##  Not well formed documents
##  Parsers are required to report fatal errors for not-well-formed documents,
##  except for processors that do not read certain kinds of external entities
####################################

expect_not_wf() {
   expect "$1" ""
}
expect_not_wf_sa() {
   expect "$XML_SILENT $BASE/xmltest/not-wf/sa/$1.xml" "$2"
}
expect_not_wf_sa_validate() {
   expect "$XML_SILENT_VALIDATE $BASE/xmltest/not-wf/sa/$1.xml" "$2"
}
expect_not_wf_not_sa() {
   expect "$XML_SILENT $BASE/xmltest/not-wf/not-sa/$1.xml" "$2"
}
expect_not_wf_ext_sa() {
   expect "$XML_SILENT $BASE/xmltest/not-wf/ext-sa/$1.xml" "$2"
}
expect_oasis_not_wf() {
   expect "$XML_SILENT $BASE/oasis/$1.xml" "$2"
}
expect_oasis_not_wf_validate() {
    expect "$XML_SILENT_VALIDATE $BASE/oasis/$1.xml" "$2"
}
expect_sun_not_wf() {
    expect "$XML_SILENT $BASE/sun/not-wf/$1.xml" "$2"
}

if [ $run_not_wf_tests = 1 ]; then
    expect_not_wf_ext_sa "001" \
       "001.ent:1:1: (4.1) Entity can not reference itself"
    expect_not_wf_ext_sa "002" \
       "002.ent:1:21: 'encoding' must be specified for <?xml?> in external entities"
fi

if [ $run_not_wf_tests = 1 ]; then
    expect_not_wf_not_sa "001" \
       "001.ent:3:2: [WF] Unexpected character in the DTD"
    expect_not_wf_not_sa "002" \
       "entity %e:1:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_not_sa "003" \
       "003.ent:3:1: [3.4] Conditional section must be properly terminated"
    expect_not_wf_not_sa "004" \
       "004.ent:3:1: [3.4] Conditional section must be properly terminated"
    expect_not_wf_not_sa "006" \
       "006.ent:2:1: (3.4) Conditional sections need a '[' after the INCLUDE or IGNORE"
    expect_not_wf_not_sa "007" \
       "007.ent:1:1: [2.8] Element not allowed in the DTD"
    expect_not_wf_not_sa "008" \
       "008.ent:2:17: [WF] Unterminated entity"
fi

if [ $run_not_wf_tests = 1 ]; then
    expect_sun_not_wf "attlist01" \
        "attlist01.xml:7:10: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist02" \
        "attlist02.xml:7:10: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist03" \
        "attlist03.xml:7:11: [3.3.1] Invalid character ',' in ATTLIST enumeration"
    expect_sun_not_wf "attlist04" \
        "attlist04.xml:7:10: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist05" \
        "attlist05.xml:7:11: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist06" \
        "attlist06.xml:7:10: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist07" \
        "attlist07.xml:7:10: [WF] Invalid type for attribute"
    expect_sun_not_wf "attlist08" \
        "attlist08.xml:7:18: [WF] Invalid keyword"
    expect_sun_not_wf "attlist09" \
        "attlist09.xml:5:18: [WF] Invalid keyword"
    expect_sun_not_wf "attlist10" \
        "attlist10.xml:6:20: [3.1] Attributes must be separated by spaces"
    expect_sun_not_wf "attlist11" \
        "attlist11.xml:6:20: [3.1] Attributes must be separated by spaces"
    expect_sun_not_wf "cond01" \
        "entity %MAYBE:3:1: Invalid declaration"
    expect_sun_not_wf "cond02" \
        "cond.dtd:3:1: Invalid declaration"
    expect_sun_not_wf "content01" \
        "content01.xml:3:20: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_sun_not_wf "content02" \
        "content02.xml:3:20: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_sun_not_wf "content03" \
        "content03.xml:3:20: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_sun_not_wf "decl01" \
        "decl01.ent:1:43: Text declarations <?xml?> in external entity can not specify parameters other than 'version' and 'encoding'"
    expect_sun_not_wf "dtd00" \
        "dtd00.xml:2:31: Expecting operator in content model"
    expect_sun_not_wf "dtd01" \
        "dtd01.xml:2:31: Can't mix ',' and '|' in content model"
    expect_sun_not_wf "dtd02" \
        "dtd02.xml:5:6: [WF] Unterminated entity"
    expect_sun_not_wf "dtd03" \
        "dtd03.xml:6:0: [WF] Unterminated entity"
    expect_sun_not_wf "dtd04" \
        "dtd04.xml:4:26: [WF] Expecting string after PUBLIC"
    expect_sun_not_wf "dtd05" \
        "dtd05.xml:4:34: [WF] Expecting string after SYSTEM"
    expect_sun_not_wf "dtd07" \
        "dtd07.dtd:1:20: 'encoding' must be specified for <?xml?> in external entities"
    expect_sun_not_wf "element00" \
        "element00.xml:3:5: [3.1] Tags must end with a '>' symbol"
    expect_sun_not_wf "element01" \
        "element01.xml:3:7: [3.1] Tags must end with a '>' symbol"
    expect_sun_not_wf "element02" \
        "element02.xml:3:6: [3.1] '%' is not a valid name"
    expect_sun_not_wf "element03" \
        "element03.xml:3:6: [3.1] '%' is not a valid name"
    expect_sun_not_wf "element04" \
        "element04.xml:3:5: No declaration starting with '<!' outside of DTD"
    expect_sun_not_wf "encoding01" \
        "encoding01.xml:1:31: [4.3.3] Illegal character ' ' in encoding value"
    expect_sun_not_wf "encoding02" \
        "encoding02.xml:1:31: (4.3.3) Illegal character '/' in encoding value"
    expect_sun_not_wf "encoding03" \
        "encoding03.xml:1:31: (4.3.3) Illegal character ')' in encoding value"
    expect_sun_not_wf "encoding04" \
        "encoding04.xml:1:31: (4.3.3) Illegal character ':' in encoding value"
    expect_sun_not_wf "encoding05" \
        "encoding05.xml:1:31: [4.3.3] Illegal character '@' in encoding value"
    expect_sun_not_wf "encoding06" \
        "encoding06.xml:1:31: (4.3.3) Illegal character '+' in encoding value"
    expect_sun_not_wf "encoding07" \
        "dtd07.dtd:1:20: 'encoding' must be specified for <?xml?> in external entities"
    expect_sun_not_wf "pi" \
        "pi.xml:4:10: Must have space betwee target and data"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "pubid01" \
        "pubid01.xml:6:24: Invalid PubID character '&'"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "pubid02" \
        "pubid02.xml:6:24: Invalid PubID character '<'"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "pubid03" \
        "pubid03.xml:6:24: Invalid PubID character '['"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "pubid04" \
        "pubid04.xml:6:24: Invalid PubID character '{'"
    expect_sun_not_wf "pubid05" \
        "pubid05.xml:6:0: [WF] Expecting SystemID after PUBLIC"
    expect_sun_not_wf "sgml01" \
        "sgml01.xml:8:0: [2.1] Node <root> is not closed"
	## Location is incorrect
    expect_sun_not_wf "sgml02" \
        "sgml02.xml:1:2: [2.8] <?xml?> instruction must be first in document"
    expect_sun_not_wf "sgml03" \
        "sgml03.xml:3:21: [2.5] '--' cannot appear in comments"
    expect_sun_not_wf "sgml04" \
        "sgml04.xml:7:15: [WF] Expecting element name"
    expect_sun_not_wf "sgml05" \
        "sgml05.xml:8:16: [WF] Expecting element name"
    expect_sun_not_wf "sgml06" \
        "sgml06.xml:6:15: [WF] Expecting element name"
    expect_sun_not_wf "sgml07" \
        "sgml07.xml:3:20: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_sun_not_wf "sgml08" \
        "sgml08.xml:3:20: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_sun_not_wf "sgml09" \
        "sgml09.xml:4:41: [WF] Expecting end of ELEMENT definition"
    expect_sun_not_wf "sgml10" \
        "sgml10.xml:3:66: [WF] Expecting end of ELEMENT definition"
    expect_sun_not_wf "sgml11" \
        "sgml11.xml:3:20: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_sun_not_wf "sgml12" \
        "sgml12.xml:3:20: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_sun_not_wf "sgml13" \
        "sgml13.xml:3:23: Expecting operator in content model"
fi

if [ $run_not_wf_tests = 1 ]; then
    expect_not_wf_sa "001" \
           "001.xml:3:1: [3.1] '?' is not a valid name"
    expect_not_wf_sa "002" \
           "002.xml:2:2: [3.1] '.doc' is not a valid name"
    expect_not_wf_sa "003" \
           "003.xml:1:8: [2.6] Processing Instruction must specify a target name"
    expect_not_wf_sa "004" \
           "004.xml:1:6: [2.6] Processing instruction must end with '?>'"
    expect_not_wf_sa "005" \
           "005.xml:1:6: [2.6] Processing instruction must end with '?>'"
    expect_not_wf_sa "008" \
           "008.xml:1:6: [4.1] Invalid first letter in entity name '.'"
    expect_not_wf_sa "006" \
           "006.xml:1:21: [2.5] '--' cannot appear in comments"
    expect_not_wf_sa "007" \
           "007.xml:1:6: [4.1] Entity references must end with ';'.
Did you want to use &amp; ?"
    expect_not_wf_sa "009" \
           "009.xml:1:8: [4.1] Invalid character 'R' in character reference"
    expect_not_wf_sa "010" \
           "010.xml:1:8: [4.1] Invalid first letter in entity name ' '"
    expect_not_wf_sa "011" \
           "011.xml:1:8: [3.1] Attributes must have an explicit value"
    expect_not_wf_sa "012" \
           "012.xml:1:9: [3.1] Attribute values must be quoted"
    expect_not_wf_sa "013" \
           "013.xml:1:14: [2.3] '<' not authorized in attribute values. Possible end of attribute value at 013.xml:1:12"
    expect_not_wf_sa "014" \
           "014.xml:1:10: [2.3] '<' not authorized in attribute values"
    expect_not_wf_sa "015" \
           "015.xml:1:9: [3.1] Attribute values must be quoted"
    expect_not_wf_sa "016" \
           "016.xml:1:14: Expecting a name"
    expect_not_wf_sa "017" \
           "017.xml:1:6: [2.7] CDATA sections must end with ']]>'"
    expect_not_wf_sa "018" \
           "018.xml:1:6: CDATA must be followed immediately by '['"
    expect_not_wf_sa "019" \
           "019.xml:1:8: Expecting a name"
    expect_not_wf_sa "020" \
           "020.xml:1:12: [4.1] Invalid first letter in entity name ' '"
    expect_not_wf_sa "022" \
           "022.xml:1:15: [4.1] Invalid character ':' in character reference"
    expect_not_wf_sa "023" \
           "023.xml:1:6: [3.1] '12' is not a valid name"
    expect_not_wf_sa "024" \
           "024.xml:2:2: [3.1] '123' is not a valid name"
    expect_not_wf_sa "025" \
           "025.xml:1:6: [2.4] Text may not contain the litteral ']]>'"
    expect_not_wf_sa "026" \
           "026.xml:1:7: [2.4] Text may not contain the litteral ']]>'"
    expect_not_wf_sa "027" \
           "027.xml:2:1: [2.5] Comments must end with '-->'"
    expect_not_wf_sa "028" \
           "028.xml:2:1: [2.6] Processing instruction must end with '?>'"
    expect_not_wf_sa "029" \
           "029.xml:1:10: [2.4] Text may not contain the litteral ']]>'"
    expect_not_wf_sa "030" \
           "030.xml:1:19: [2.2] Invalid character (code 12)"
    expect_not_wf_sa "031" \
           "031.xml:1:24: [2.2] Invalid character (code 12)"
    expect_not_wf_sa "032" \
           "032.xml:1:24: [2.2] Invalid character (code 12)"
    expect_not_wf_sa "033" \
           "033.xml:1:9: [2.2] Invalid character (code 27)"
    expect_not_wf_sa "034" \
           "034.xml:1:5: [2.2] Invalid character (code 12)"
    expect_not_wf_sa "035" \
           "035.xml:1:9: Expecting a name"
    expect_not_wf_sa "036" \
           "036.xml:2:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "037" \
           "037.xml:2:1: [2.1] Character references can not appear at top-level"
    expect_not_wf_sa "038" \
           "038.xml:1:22: (3.1) Attributes must have a unique name"
    expect_not_wf_sa "039" \
           "039.xml:1:9: [WF-Element Type Match] Name differ for closing tag"
    expect_not_wf_sa "040" \
           "040.xml:2:1: (2.1) Too many children for top-level node, when adding <doc>"
    expect_not_wf_sa "041" \
           "041.xml:2:1: (2.1) Too many children for top-level node, when adding <doc>"
    expect_not_wf_sa "042" \
           "042.xml:1:12: [3.1] Tags must end with a '>' symbol"
    expect_not_wf_sa "043" \
           "043.xml:2:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "044" \
           "044.xml:1:7: (2.1) Too many children for top-level node, when adding <doc>"
    expect_not_wf_sa "045" \
           "045.xml:2:3: [3] Must have spaces between tag name and attributes"
    expect_not_wf_sa "046" \
           "046.xml:2:3: [3] Must have spaces between tag name and attributes"
    expect_not_wf_sa "047" \
           "047.xml:2:4: [3.1] '/' is not a valid name"
    expect_not_wf_sa "048" \
           "048.xml:3:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "049" \
           "049.xml:3:13: [WF-Element Type Match] Name differ for closing tag"
    expect_not_wf_sa "050" \
           "050.xml:1:0: [2.1] No root element specified"
	   ## ??? Location is incorrect
    expect_not_wf_sa "051" \
           "051.xml:2:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "052" \
           "052.xml:2:1: [2.1] Character references can not appear at top-level"
    expect_not_wf_sa "053" \
           "053.xml:1:6: [WF-Element Type Match] Name differ for closing tag"
    expect_not_wf_sa "054" \
           "054.xml:2:38: [WF] Expecting SystemID after PUBLIC"
    expect_not_wf_sa "055" \
           "055.xml:2:1: [2.8] Element not allowed in the DTD"
    expect_not_wf_sa "056" \
           "056.xml:1:17: [WF] Expecting end of DTD"
    expect_not_wf_sa "057" \
           "057.xml:2:25: [WF] Expecting end of ENTITY definition"
    expect_not_wf_sa "058" \
           "058.xml:3:22: [3.3.1] Invalid character ',' in ATTLIST enumeration"
    expect_not_wf_sa "059" \
           "059.xml:3:28: [WF] Invalid default value for attribute"
    expect_not_wf_sa "060" \
           "060.xml:3:19: [WF] Invalid type for attribute"
    expect_not_wf_sa "061" \
           "061.xml:2:29: [4.2.2] Require whitespace between public and system IDs"
    expect_not_wf_sa "062" \
           "062.xml:2:13: Expecting a space"
    expect_not_wf_sa "063" \
           "063.xml:2:1: [3.4] INCLUDE and IGNORE sections only authorized in the external DTD subset"
    expect_not_wf_sa "064" \
           "064.xml:3:21: Expecting a space"
    expect_not_wf_sa "065" \
           "065.xml:3:17: [3.3] Expecting space between attribute name and type"
    expect_not_wf_sa "066" \
           "066.xml:3:27: Expecting a space"
    expect_not_wf_sa "067" \
           "067.xml:3:23: Expecting a space"
    expect_not_wf_sa "068" \
           "068.xml:3:26: [3.3.1] Space is required between NOTATION keyword and list of enumerated"
    expect_not_wf_sa "069" \
           "069.xml:4:30: [4.2.2] Expecting space before NDATA declaration"
    expect_not_wf_sa "070" \
           "070.xml:1:41: [2.5] '--' cannot appear in comments"
    expect_not_wf_sa "071" \
           "entity e3:1:1: (4.1) Entity can not reference itself"
    expect_not_wf_sa "072" "072.xml:1:6: [4.1] Undefined entity 'foo'"
    expect_not_wf_sa "073" "073.xml:4:6: [4.1] Undefined entity 'f'"
    expect_not_wf_sa "074" \
           "entity e:1:6: [4.5] Entity values must be self-contained"
    expect_not_wf_sa "075" \
           "entity e3:1:1: (4.1) Entity can not reference itself"
    expect_not_wf_sa "076" "076.xml:1:9: [4.1] Undefined entity 'foo'"
    expect_not_wf_sa "077" \
           "entity foo:1:1: [4.1] Undefined entity 'bar'"
    expect_not_wf_sa "078" \
           "078.xml:3:24: [4.1] Undefined entity 'foo'"
    expect_not_wf_sa "079" \
           "entity e3:1:1: (4.1) Entity can not reference itself"
    expect_not_wf_sa "080" \
           "entity e3:1:1: (4.1) Entity can not reference itself"
    expect_not_wf_sa "081" \
           "081.xml:4:9: [3.1] Attribute values can not reference external entities"
    expect_not_wf_sa "082" \
           "082.xml:4:24: [3.1] Attribute values can not reference external entities"
    [ $VALIDATING = 1 ] && expect_not_wf_sa_validate "083" \
           "083.xml:2:31: [VC 4.2.2] Notation 'n' must be declared"
    expect_not_wf_sa "084" \
           "084.xml:4:24: [4.1] Undefined entity 'e'"
    [ $VALIDATING = 1 ] && expect_not_wf_sa "085" \
           "085.xml:1:23: Invalid PubID character '['"
    [ $VALIDATING = 1 ] && expect_not_wf_sa "086" \
           "086.xml:2:22: Invalid PubID character '['"
    [ $VALIDATING = 1 ] && expect_not_wf_sa "087" \
           "087.xml:2:24: Invalid PubID character '['"
    expect_not_wf_sa "088" \
           "088.xml:6:13: [2.3] '<' not authorized in attribute values"
    expect_not_wf_sa "089" \
           "089.xml:2:33: [4.2] NDATA annotation not allowed for parameter entities"
    expect_not_wf_sa "090" \
           "entity e:1:9: [2.3] '<' not authorized in attribute values"
    expect_not_wf_sa "091" \
           "091.xml:3:33: [4.2] NDATA annotation not allowed for parameter entities"
    expect_not_wf_sa "092" \
           "entity e:1:9: [4.1] Invalid first letter in entity name '''"
    expect_not_wf_sa "093" \
           "093.xml:1:8: [4.1] Invalid character 'X' in character reference"
    expect_not_wf_sa "094" "094.xml:1:7: 'version' must be the first argument to <?xml?>"
    expect_not_wf_sa "095" "095.xml:1:7: 'version' must be the first argument to <?xml?>"
    expect_not_wf_sa "096" "096.xml:1:20: values must be separated by spaces"
    expect_not_wf_sa "097" \
           "097.xml:1:16: [2.8] Illegal version number in <?xml?> processing instruction"
    expect_not_wf_sa "098" \
           "098.xml:1:21: <?xml..?> arguments can only be 'version', 'encoding' or 'standalone', in that order"
    expect_not_wf_sa "099" \
           "099.xml:1:21: <?xml..?> arguments can only be 'version', 'encoding' or 'standalone', in that order"
    expect_not_wf_sa "100" \
           "100.xml:1:33: [2.9 [32]] Invalid value for standalone parameter in <?xml?>"
    expect_not_wf_sa "101" "101.xml:1:31: [4.3.3] Illegal character ' ' in encoding value"
    expect_not_wf_sa "102" \
           "102.xml:1:16: [2.8] Illegal version number in <?xml?> processing instruction"
    expect_not_wf_sa "103" \
           "103.xml:4:14: [4.5] Entity values must be self-contained"
    expect_not_wf_sa "104" \
           "104.xml:4:14: [4.5] Entity values must be self-contained"
    expect_not_wf_sa "105" "105.xml:2:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "106" "106.xml:2:1: [2.1] Character references can not appear at top-level"
    expect_not_wf_sa "107" \
           "107.xml:2:1: [2.8] Element not allowed in the DTD"
    expect_not_wf_sa "108" "108.xml:2:1: CDATA must be followed immediately by '['"
    expect_not_wf_sa "109" \
           "109.xml:4:1: [2.1] Entity references can not appear at top-level"
    expect_not_wf_sa "110" \
           "110.xml:5:1: [2.1] Entity references can not appear at top-level"
    expect_not_wf_sa "111" \
           "111.xml:4:6: [3.1] '&e;' is not a valid name"
    expect_not_wf_sa "112" "112.xml:2:1: No declaration starting with '<!' outside of DTD"
    expect_not_wf_sa "113" \
           "113.xml:2:17: [4.1] Invalid first letter in entity name '\"'"
    expect_not_wf_sa "114" \
           "114.xml:2:15: [4.1] Invalid first letter in entity name '\"'"
    expect_not_wf_sa "115" \
           "entity e:1:1: [4.1] Invalid first letter in entity name '\"'"
    expect_not_wf_sa "116" \
           "entity e:1:1: [4.3.2] Entity must be self-contained"
    expect_not_wf_sa "117" \
           "entity e:1:1: [4.3.2] Entity must be self-contained"
    expect_not_wf_sa "118" \
           "118.xml:4:6: [4.1] Invalid first letter in entity name '&'"
    expect_not_wf_sa "119" \
           "entity e:1:1: [4.3.2] Entity must be self-contained"
    expect_not_wf_sa "120" \
           "entity e:1:1: [4.1] Invalid first letter in entity name '
'"
           # ??? Message could be better for 120
    expect_not_wf_sa "121" \
           "121.xml:2:18: [WF] Expecting entity name"
    expect_not_wf_sa "122" \
           "122.xml:2:23: Can't mix ',' and '|' in content model"
    expect_not_wf_sa "123" \
            "123.xml:2:24: [WF] Expecting end of ELEMENT definition"
    expect_not_wf_sa "124" \
            "124.xml:2:26: [3.2.2] #PCDATA must be first in list"
    expect_not_wf_sa "125" \
            "125.xml:2:25: [3.2.1] Mixed contents can not be used in a list or a sequence"
    expect_not_wf_sa "126" \
            "126.xml:2:24: [3.2.2] Occurence on #PCDATA must be '*'"
    expect_not_wf_sa "127" \
            "127.xml:2:24: [3.2.2] Occurence on #PCDATA must be '*'"
    expect_not_wf_sa "128" \
            "128.xml:2:15: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_not_wf_sa "129" \
            "129.xml:2:15: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_not_wf_sa "130" \
            "130.xml:2:28: [WF] Expecting end of ELEMENT definition"
    expect_not_wf_sa "131" \
            "131.xml:2:28: [WF] Expecting end of ELEMENT definition"
    expect_not_wf_sa "132" \
            "132.xml:2:38: Can't mix ',' and '|' in content model"
    expect_not_wf_sa "133" \
            "133.xml:2:15: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_not_wf_sa "134" \
            "134.xml:2:20: [WF] Expecting end of ELEMENT definition"
    expect_not_wf_sa "135" \
            "135.xml:2:18: Expecting operator in content model"
    expect_not_wf_sa "136" \
            "136.xml:2:15: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_not_wf_sa "137" \
            "137.xml:2:14: Expecting a space"
    expect_not_wf_sa "138" \
         "138.xml:2:15: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_not_wf_sa "139" \
         "139.xml:2:15: Invalid content model: List of choices cannot be empty"
    expect_not_wf_sa "140" \
           "entity e:1:2: [3.1] '$xe3$x82$x9a' is not a valid name"
    expect_not_wf_sa "141" \
           "entity e:1:3: [3] Must have spaces between tag name and attributes"
           #???  "(2.3) 'X$xe0$xb9$x9c' is not a valid name, at 141.xml:4:8"
    expect_not_wf_sa "142" "142.xml:4:6: [2.2] Invalid character (code 0)"
    expect_not_wf_sa "143" "143.xml:4:6: [2.2] Invalid character (code 31)"
    expect_not_wf_sa "144" "144.xml:4:6: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "145" "145.xml:4:6: [2.2] Invalid character (code 55296)"
    expect_not_wf_sa "146" "146.xml:4:6: [2.2] Invalid character (code 1114112)"
    expect_not_wf_sa "147" "147.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "148" \
           "148.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "149" \
           "149.xml:3:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "150" \
           "150.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "151" \
           "151.xml:3:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "152" \
           "152.xml:1:7: 'version' must be the first argument to <?xml?>"
    expect_not_wf_sa "153" \
           "entity e:1:1: [2.8] <?xml?> instruction must be first in document"
    expect_not_wf_sa "154" \
           "154.xml:1:3: [2.6] 'XML' is not a valid processing instruction target"
    expect_not_wf_sa "155" \
           "155.xml:1:3: [2.6] 'xmL' is not a valid processing instruction target"
    expect_not_wf_sa "156" \
           "156.xml:2:3: [2.6] 'xMl' is not a valid processing instruction target"
    expect_not_wf_sa "157" \
           "157.xml:2:3: [2.6] 'xmL' is not a valid processing instruction target"
    expect_not_wf_sa "158" \
           "158.xml:4:11: [WF] Expecting element name"
    expect_not_wf_sa "159" \
           "159.xml:3:26: [4.1] Invalid first letter in entity name ' '"
    expect_not_wf_sa "160" \
        "160.xml:4:15: [WF PE in internal subset] Parameter entities cannot occur in attribute values"
    expect_not_wf_sa "161" \
        "161.xml:3:16: [WF PE in internal subset] Parameter entities cannot occur in attribute values"
    expect_not_wf_sa "162" \
        "162.xml:4:16: [WF PE in internal subset] Parameter entities cannot occur in attribute values"
    expect_not_wf_sa "163" \
            "163.xml:5:1: [2.1] Non-white space found at top level"
    expect_not_wf_sa "164" \
           "164.xml:4:1: [2.8] Unexpected character between ']' and '>' in the DTD"
    expect_not_wf_sa "165" \
           "165.xml:2:9: Expecting a space"
    expect_not_wf_sa "166" "166.xml:1:6: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "167" "167.xml:1:6: [2.2] Invalid character (code 65534)"
    expect_not_wf_sa "168" "168.xml:1:6: [2.2] Invalid character (code 55296)"
    expect_not_wf_sa "169" "169.xml:1:6: [2.2] Invalid character (code 56320)"
    expect_not_wf_sa "170" "170.xml:1:6: [2.2] Invalid character (code 1835008)"
    expect_not_wf_sa "171" "171.xml:1:6: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "172" "172.xml:1:6: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "173" "173.xml:1:9: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "174" "174.xml:1:15: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "175" "175.xml:3:15: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "176" "176.xml:4:6: [2.1] Node <doc> is not closed"
    expect_not_wf_sa "177" "177.xml:4:7: [2.2] Invalid character (code 65535)"
    expect_not_wf_sa "178" "178.xml:5:15: [2.3] '<' not authorized in attribute values"
    expect_not_wf_sa "179" \
           "179.xml:5:0: [2.3] Unterminated string"
    expect_not_wf_sa "180" \
           "180.xml:3:24: [4.1] Undefined entity 'e'"
    expect_not_wf_sa "181" \
           "entity e:1:1: [4.3.2] Entity must be self-contained"
    expect_not_wf_sa "182" \
           "entity e:1:1: [4.5] Entity values must be self-contained"
    expect_not_wf_sa "183" \
           "183.xml:2:30: [3.2.2] Nested groups and occurence operators not allowed in mixed content"
    expect_not_wf_sa "184" \
           "184.xml:2:31: [3.2.2] Nested groups and occurence operators not allowed in mixed content"
    expect_not_wf_sa "185" \
           "185.xml:3:6: [4.1] Undefined entity 'e'"
    expect_not_wf_sa "186" \
           "186.xml:5:9: [3.1] Attributes must be separated by spaces"
fi

if [ $run_not_wf_tests = 1 ]; then
    expect_oasis_not_wf "p01fail1" \
       "p01fail1.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_oasis_not_wf "p01fail2" \
       "p01fail2.xml:1:19: [2.8] <?xml?> instruction must be first in document"
    expect_oasis_not_wf "p01fail3" \
       "p01fail3.xml:1:7: (2.1) Too many children for top-level node, when adding <bad>"
    expect_oasis_not_wf "p01fail4" \
       "p01fail4.xml:1:5: [2.1] Node <doc> is not closed"
    expect_oasis_not_wf "p02fail1" \
       "p02fail1.xml:1:8: [2.2] Invalid character (code 0)"
    expect_oasis_not_wf "p02fail2" \
       "p02fail2.xml:1:8: [2.2] Invalid character (code 1)"
    expect_oasis_not_wf "p02fail4" \
       "p02fail4.xml:1:8: [2.2] Invalid character (code 3)"
    expect_oasis_not_wf "p02fail5" \
       "p02fail5.xml:1:8: [2.2] Invalid character (code 4)"
    expect_oasis_not_wf "p02fail6" \
       "p02fail6.xml:1:8: [2.2] Invalid character (code 5)"
    expect_oasis_not_wf "p02fail7" \
       "p02fail7.xml:1:8: [2.2] Invalid character (code 6)"
    expect_oasis_not_wf "p02fail8" \
       "p02fail8.xml:1:8: [2.2] Invalid character (code 7)"
    expect_oasis_not_wf "p02fail9" \
       "p02fail9.xml:1:8: [2.2] Invalid character (code 8)"
    expect_oasis_not_wf "p02fail10" \
       "p02fail10.xml:1:8: [2.2] Invalid character (code 11)"
    expect_oasis_not_wf "p02fail11" \
       "p02fail11.xml:1:8: [2.2] Invalid character (code 12)"
    expect_oasis_not_wf "p02fail12" \
       "p02fail12.xml:1:8: [2.2] Invalid character (code 14)"
    expect_oasis_not_wf "p02fail13" \
       "p02fail13.xml:1:8: [2.2] Invalid character (code 15)"
    expect_oasis_not_wf "p02fail14" \
       "p02fail14.xml:1:8: [2.2] Invalid character (code 16)"
    expect_oasis_not_wf "p02fail15" \
       "p02fail15.xml:1:8: [2.2] Invalid character (code 17)"
    expect_oasis_not_wf "p02fail16" \
       "p02fail16.xml:1:8: [2.2] Invalid character (code 18)"
    expect_oasis_not_wf "p02fail17" \
       "p02fail17.xml:1:8: [2.2] Invalid character (code 19)"
    expect_oasis_not_wf "p02fail18" \
       "p02fail18.xml:1:8: [2.2] Invalid character (code 20)"
    expect_oasis_not_wf "p02fail19" \
       "p02fail19.xml:1:8: [2.2] Invalid character (code 21)"
    expect_oasis_not_wf "p02fail20" \
       "p02fail20.xml:1:8: [2.2] Invalid character (code 22)"
    expect_oasis_not_wf "p02fail21" \
       "p02fail21.xml:1:8: [2.2] Invalid character (code 23)"
    expect_oasis_not_wf "p02fail22" \
       "p02fail22.xml:1:8: [2.2] Invalid character (code 24)"
    expect_oasis_not_wf "p02fail23" \
       "p02fail23.xml:1:8: [2.2] Invalid character (code 25)"
    expect_oasis_not_wf "p02fail24" \
       "p02fail24.xml:1:8: [2.2] Invalid character (code 26)"
    expect_oasis_not_wf "p02fail25" \
       "p02fail25.xml:1:8: [2.2] Invalid character (code 27)"
    expect_oasis_not_wf "p02fail26" \
       "p02fail26.xml:1:8: [2.2] Invalid character (code 28)"
    expect_oasis_not_wf "p02fail27" \
       "p02fail27.xml:1:8: [2.2] Invalid character (code 29)"
    expect_oasis_not_wf "p02fail28" \
       "p02fail28.xml:1:8: [2.2] Invalid character (code 30)"
    expect_oasis_not_wf "p02fail29" \
       "p02fail29.xml:1:8: [2.2] Invalid character (code 31)"
    expect_oasis_not_wf "p02fail30" \
       "p02fail30.xml:1:8: [2.2] Invalid character (code 65534)"
    expect_oasis_not_wf "p02fail31" \
       "p02fail31.xml:1:8: [2.2] Invalid character (code 65535)"
    expect_oasis_not_wf "p03fail1" \
       "p03fail1.xml:1:1: [2.2] Invalid character (code 0)"
    expect_oasis_not_wf "p03fail2" \
       "p03fail2.xml:1:1: [2.2] Invalid character (code 1)"
    expect_oasis_not_wf "p03fail3" \
       "p03fail3.xml:1:1: [2.2] Invalid character (code 2)"
    expect_oasis_not_wf "p03fail4" \
       "p03fail4.xml:1:1: [2.2] Invalid character (code 3)"
    expect_oasis_not_wf "p03fail5" \
       "p03fail5.xml:1:1: [2.2] Invalid character (code 4)"
    expect_oasis_not_wf "p03fail7" \
       "p03fail7.xml:1:1: [2.2] Invalid character (code 6)"
    expect_oasis_not_wf "p03fail8" \
       "p03fail8.xml:1:1: [2.2] Invalid character (code 7)"
    expect_oasis_not_wf "p03fail9" \
       "p03fail9.xml:1:1: [2.2] Invalid character (code 8)"
    expect_oasis_not_wf "p03fail10" \
       "p03fail10.xml:1:1: [2.2] Invalid character (code 11)"
    expect_oasis_not_wf "p03fail11" \
       "p03fail11.xml:1:1: [2.2] Invalid character (code 12)"
    expect_oasis_not_wf "p03fail12" \
       "p03fail12.xml:1:1: [2.2] Invalid character (code 14)"
    expect_oasis_not_wf "p03fail13" \
       "p03fail13.xml:1:1: [2.2] Invalid character (code 15)"
    expect_oasis_not_wf "p03fail14" \
       "p03fail14.xml:1:1: [2.2] Invalid character (code 16)"
    expect_oasis_not_wf "p03fail15" \
       "p03fail15.xml:1:1: [2.2] Invalid character (code 17)"
    expect_oasis_not_wf "p03fail16" \
       "p03fail16.xml:1:1: [2.2] Invalid character (code 18)"
    expect_oasis_not_wf "p03fail17" \
       "p03fail17.xml:1:1: [2.2] Invalid character (code 19)"
    expect_oasis_not_wf "p03fail18" \
       "p03fail18.xml:1:1: [2.2] Invalid character (code 20)"
    expect_oasis_not_wf "p03fail19" \
       "p03fail19.xml:1:1: [2.2] Invalid character (code 21)"
    expect_oasis_not_wf "p03fail20" \
       "p03fail20.xml:1:1: [2.2] Invalid character (code 22)"
    expect_oasis_not_wf "p03fail21" \
       "p03fail21.xml:1:1: [2.2] Invalid character (code 23)"
    expect_oasis_not_wf "p03fail22" \
       "p03fail22.xml:1:1: [2.2] Invalid character (code 24)"
    expect_oasis_not_wf "p03fail23" \
       "p03fail23.xml:1:1: [2.2] Invalid character (code 25)"
    expect_oasis_not_wf "p03fail24" \
       "p03fail24.xml:1:1: [2.2] Invalid character (code 26)"
    expect_oasis_not_wf "p03fail25" \
       "p03fail25.xml:1:1: [2.2] Invalid character (code 27)"
    expect_oasis_not_wf "p03fail26" \
       "p03fail26.xml:1:1: [2.2] Invalid character (code 28)"
    expect_oasis_not_wf "p03fail27" \
       "p03fail27.xml:1:1: [2.2] Invalid character (code 29)"
    expect_oasis_not_wf "p03fail28" \
       "p03fail28.xml:1:1: [2.2] Invalid character (code 30)"
    expect_oasis_not_wf "p03fail29" \
       "p03fail29.xml:1:1: [2.2] Invalid character (code 31)"
    expect_oasis_not_wf "p04fail1" \
       "p04fail1.xml:1:3: [3] Must have spaces between tag name and attributes"
    expect_oasis_not_wf "p04fail2" \
       "p04fail2.xml:1:3: [3] Must have spaces between tag name and attributes"
    expect_oasis_not_wf "p04fail3" \
       "p04fail3.xml:1:3: [3] Must have spaces between tag name and attributes"
    expect_oasis_not_wf "p05fail1" \
       "p05fail1.xml:1:2: [3.1] '0A' is not a valid name"
    expect_oasis_not_wf "p05fail2" \
       "p05fail2.xml:1:2: [3.1] '.A' is not a valid name"
    expect_oasis_not_wf "p05fail3" \
       "p05fail3.xml:1:2: [3.1] '-A' is not a valid name"
    expect_oasis_not_wf "p05fail4" \
       "p05fail4.xml:1:2: [3.1] '"$xcc$x80"A' is not a valid name"
    expect_oasis_not_wf "p05fail5" \
       "p05fail5.xml:1:2: [3.1] '"$xc2$xb7"A' is not a valid name"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p09fail1" \
       "p09fail1.dtd:2:23: [WF] Unterminated entity"
    expect_oasis_not_wf "p09fail2" \
       "p09fail2.dtd:2:22: [4.1] Invalid first letter in entity name '\"'"
    expect_oasis_not_wf "p09fail3" \
       "p09fail3.xml:4:26: [4.1] Invalid character '\"' in character reference"
    expect_oasis_not_wf "p09fail4" \
       "p09fail4.xml:4:17: [2.3] Unterminated string, possible end at p09fail4.xml:4:19"
    expect_oasis_not_wf "p09fail5" \
       "p09fail5.xml:4:17: [2.3] Unterminated string, possible end at p09fail5.xml:4:19"
    expect_oasis_not_wf "p10fail1" \
       "p10fail1.xml:1:11: [2.3] '<' not authorized in attribute values"
    expect_oasis_not_wf "p10fail2" \
       "p10fail2.xml:1:11: [4.1] Invalid first letter in entity name '\"'"
    expect_oasis_not_wf "p10fail3" \
       "p10fail3.xml:1:8: [2.3] Unterminated string, possible end at p10fail3.xml:1:12"
    expect_oasis_not_wf "p11fail1" \
       "p11fail1.xml:5:24: [2.3] Unterminated string, possible end at p11fail1.xml:5:26"
    expect_oasis_not_wf "p11fail2" \
        "p11fail2.xml:5:27: [WF] Expecting end of NOTATION definition"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail1" \
        "p12fail1.xml:5:25: Invalid PubID character '\"'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail2" \
        "p12fail2.xml:5:25: Invalid PubID character '\'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail3" \
        "p12fail3.xml:6:25: Invalid PubID character '&'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail4" \
        "p12fail4.xml:5:25: Invalid PubID character '>'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail5" \
        "p12fail5.xml:5:25: Invalid PubID character '<'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail6" \
        "p12fail6.xml:5:25: Invalid PubID character '&'"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p12fail7" \
        "p12fail7.xml:5:25: Invalid PubID character '$x9'"
    expect_oasis_not_wf "p14fail1" \
        "p14fail1.xml:1:7: Expecting a name"
    expect_oasis_not_wf "p14fail2" \
        "p14fail2.xml:1:6: [4.1] Invalid first letter in entity name ' '"
    expect_oasis_not_wf "p14fail3" \
        "p14fail3.xml:1:7: [2.4] Text may not contain the litteral ']]>'"
    expect_oasis_not_wf "p15fail1" \
        "p15fail1.xml:1:6: [2.5] '--' cannot appear in comments"
    expect_oasis_not_wf "p15fail2" \
        "p15fail2.xml:1:6: [2.5] '--' cannot appear in comments"
    expect_oasis_not_wf "p15fail3" \
        "p15fail3.xml:1:6: [2.5] '--' cannot appear in comments"
    expect_oasis_not_wf "p16fail1" \
        "p16fail1.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_oasis_not_wf "p16fail2" \
        "p16fail2.xml:1:3: [2.6] Processing Instruction must specify a target name"
    expect_oasis_not_wf "p18fail1" \
        "p18fail1.xml:1:6: No declaration starting with '<!' outside of DTD"
    expect_oasis_not_wf "p18fail2" \
        "p18fail2.xml:1:6: CDATA must be followed immediately by '['"
    expect_oasis_not_wf "p18fail3" \
        "p18fail3.xml:4:1: [2.4] Text may not contain the litteral ']]>'"
    expect_oasis_not_wf "p22fail1" \
        "p22fail1.xml:2:1: [2.8] <?xml?> instruction must be first in document"
    expect_oasis_not_wf "p22fail2" \
        "p22fail2.xml:4:1: [2.8] <?xml?> instruction must be first in document"
    expect_oasis_not_wf "p23fail1" \
        "p23fail1.xml:1:3: [2.6] 'XML' is not a valid processing instruction target"
    expect_oasis_not_wf "p23fail2" \
        "p23fail2.xml:1:7: 'version' must be the first argument to <?xml?>"
    expect_oasis_not_wf "p23fail3" \
        "p23fail3.xml:1:7: 'version' must be the first argument to <?xml?>"
    expect_oasis_not_wf "p23fail4" \
        "p23fail4.xml:1:38: <?xml..?> arguments can only be 'version', 'encoding' or 'standalone', in that order"
    expect_oasis_not_wf "p23fail5" \
        "p23fail5.xml:1:20: values must be separated by spaces"
        # ??? Diagnostic should be improved above
    expect_oasis_not_wf "p24fail1" \
        "p24fail1.xml:2:1: [2.3] '<' not authorized in attribute values. Possible end of attribute value at p24fail1.xml:1:21"
    expect_oasis_not_wf "p24fail2" \
        "p24fail2.xml:2:1: [2.3] '<' not authorized in attribute values. Possible end of attribute value at p24fail2.xml:1:21"
    expect_oasis_not_wf "p25fail1" \
        "p25fail1.xml:1:15: Expecting '=' sign"
    expect_oasis_not_wf "p26fail1" \
        "p26fail1.xml:1:16: [2.8] Illegal version number in <?xml?> processing instruction"
    expect_oasis_not_wf "p26fail2" \
        "p26fail2.xml:1:16: [2.8] Illegal version number in <?xml?> processing instruction"
    expect_oasis_not_wf "p27fail1" \
        "p27fail1.xml:2:1: [2.1] Character references can not appear at top-level"
    expect_oasis_not_wf "p28fail1" \
        "p28fail1.xml:3:1: [2.8] Element not allowed in the DTD"
    expect_oasis_not_wf "p29fail1" \
        "p29fail1.xml:3:8: [WF] Unexpected character in the DTD"
        # ??? Should improve diagnostic
    expect_oasis_not_wf "p30fail1" \
        "p30fail1.dtd:1:38: Text declarations <?xml?> in external entity can not specify parameters other than 'version' and 'encoding'"
    expect_oasis_not_wf "p31fail1" \
        "p31fail1.dtd:1:1: [2.8] Element not allowed in the DTD"
        # ??? Should improve diagnostic
    expect_oasis_not_wf "p32fail1" \
        "p32fail1.xml:2:1: [2.3] '<' not authorized in attribute values. Possible end of attribute value at p32fail1.xml:1:36"
    expect_oasis_not_wf "p32fail2" \
        "p32fail2.xml:2:1: [2.3] '<' not authorized in attribute values. Possible end of attribute value at p32fail2.xml:1:36"
    expect_oasis_not_wf "p32fail3" \
        "p32fail3.xml:1:20: values must be separated by spaces"
    expect_oasis_not_wf "p32fail4" \
        "p32fail4.xml:1:32: Parameter to 'standalone' must be quoted"
    expect_oasis_not_wf "p32fail5" \
        "p32fail5.xml:1:33: [2.9 [32]] Invalid value for standalone parameter in <?xml?>"
    expect_oasis_not_wf "p39fail1" \
        "p39fail1.xml:1:12: [2.1] Node <doc> is not closed"
    expect_oasis_not_wf "p39fail2" \
        "p39fail2.xml:1:13: [WF-Element Type Match] Name differ for closing tag"
    expect_oasis_not_wf "p39fail3" \
        "p39fail3.xml:1:0: [2.1] No root element specified"
        # ??? Location is incorrect
    expect_oasis_not_wf "p39fail4" \
        "p39fail4.xml:1:20: values must be separated by spaces"
	# ??? Diagnostic could be better
    expect_oasis_not_wf "p39fail5" \
        "p39fail5.xml:1:20: values must be separated by spaces"
	# ??? Diagnostic could be better
    expect_oasis_not_wf "p40fail1" \
        "p40fail1.xml:1:15: [3.1] Attributes must be separated by spaces"
    expect_oasis_not_wf "p40fail2" \
        "p40fail2.xml:1:2: [3.1] '3notname' is not a valid name"
    expect_oasis_not_wf "p40fail3" \
        "p40fail3.xml:1:2: [3.1] '3notname' is not a valid name"
    expect_oasis_not_wf "p40fail4" \
        "p40fail4.xml:1:2: Expecting a name"
	# ??? Should report invalid space instead
    [ $NOT_SURE = 1 ] && expect_oasis_not_wf "p41fail1" \
           "(2.3) Attribute values must be quoted, at p41fail1.xml:5:10"
    [ $NOT_SURE = 1 ] && expect_oasis_not_wf "p41fail2" \
           "(3.1) Attributes must have an explicit value, at p41fail2.xml:5:9"
    expect_oasis_not_wf "p41fail3" \
        "p41fail3.xml:1:10: [3.1] Attributes must have an explicit value"
    expect_oasis_not_wf "p42fail1" \
        "p42fail1.xml:1:8: Expecting a name"
    expect_oasis_not_wf "p42fail2" \
        "p42fail2.xml:1:11: [3.1] Tags must end with a '>' symbol"
    expect_oasis_not_wf "p42fail3" \
        "p42fail3.xml:1:5: [3] Must have spaces between tag name and attributes"
    expect_oasis_not_wf "p43fail1" \
        "p43fail1.xml:7:1: No declaration starting with '<!' outside of DTD"
    expect_oasis_not_wf "p43fail2" \
        "p43fail2.xml:7:1: [3.4] INCLUDE and IGNORE sections only authorized in the external DTD subset"
    expect_oasis_not_wf "p43fail3" \
        "p43fail3.xml:7:1: [3.4] INCLUDE and IGNORE sections only authorized in the external DTD subset"
    expect_oasis_not_wf "p44fail1" \
        "p44fail1.xml:1:2: Expecting a name"
    expect_oasis_not_wf "p44fail2" \
        "p44fail2.xml:1:5: [3] Must have spaces between tag name and attributes"
    expect_oasis_not_wf "p44fail3" \
        "p44fail3.xml:1:6: [3.1] '--bad' is not a valid name"
    expect_oasis_not_wf "p44fail4" \
        "p44fail4.xml:1:15: [3.1] Attributes must be separated by spaces"
    expect_oasis_not_wf "p44fail5" \
        "p44fail5.xml:1:16: (3.1) Attributes must have a unique name"
    expect_oasis_not_wf "p45fail1" \
           "p45fail1.xml:3:10: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p45fail2" \
           "p45fail2.xml:3:14: Expecting a space"
    expect_oasis_not_wf "p45fail3" \
           "p45fail3.xml:3:12: [WF] Expecting element name"
    expect_oasis_not_wf "p45fail4" \
           "p45fail4.xml:3:30: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p46fail1" \
           "p46fail1.xml:4:13: [WF] Invalid sequence in content model"
    expect_oasis_not_wf "p46fail2" \
           "p46fail2.xml:4:29: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p46fail3" \
           "p46fail3.xml:4:29: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p46fail4" \
           "p46fail4.xml:4:20: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p46fail5" \
           "p46fail5.xml:4:23: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p46fail6" \
           "p46fail6.xml:4:20: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p47fail1" \
           "p47fail1.xml:4:20: Can't mix ',' and '|' in content model"
    expect_oasis_not_wf "p47fail2" \
           "p47fail2.xml:4:19: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p47fail3" \
           "p47fail3.xml:4:13: [WF] Invalid content model: expecting '(', 'EMPTY' or 'ANY'"
    expect_oasis_not_wf "p47fail4" \
           "p47fail4.xml:4:21: [WF] Expecting end of ELEMENT definition"
    expect_oasis_not_wf "p48fail1" \
           "p48fail1.xml:4:13: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_oasis_not_wf "p48fail2" \
           "p48fail2.xml:4:13: [3.2.1] Invalid location '+', '?' or '*' operator"
    expect_oasis_not_wf "p49fail1" \
           "p49fail1.xml:4:20: Can't mix ',' and '|' in content model"
    expect_oasis_not_wf "p50fail1" \
           "p50fail1.xml:4:20: Can't mix ',' and '|' in content model"
    expect_oasis_not_wf "p51fail1" \
           "p51fail1.xml:3:24: [3.2.2] Occurence on #PCDATA must be '*'"
    expect_oasis_not_wf "p51fail2" \
           "p51fail2.xml:3:24: [3.2.2] Occurence on #PCDATA must be '*'"
    expect_oasis_not_wf "p51fail3" \
           "p51fail3.xml:4:24: [3.2.2] #PCDATA must be first in list"
    expect_oasis_not_wf "p51fail4" \
           "p51fail4.xml:4:26: [3.2.2] Occurence on #PCDATA must be '*'"
    expect_oasis_not_wf "p51fail5" \
           "p51fail5.xml:4:25: Can't mix ',' and '|' in content model"
    expect_oasis_not_wf "p51fail6" \
           "p51fail6.xml:4:21: [3.2.2] #PCDATA can only be used with '|' connectors"
    expect_oasis_not_wf "p51fail7" \
           "p51fail7.xml:4:29: [3.2.2] Nested groups and occurence operators not allowed in mixed content"
    expect_oasis_not_wf "p52fail1" \
           "p52fail1.xml:4:12: [WF] Expecting element name"
    expect_oasis_not_wf "p52fail2" \
           "p52fail2.xml:4:10: [WF] Expecting element name"
    expect_oasis_not_wf "p53fail1" \
           "p53fail1.xml:4:24: Expecting a space"
    expect_oasis_not_wf "p53fail2" \
           "p53fail2.xml:4:18: [3.3] Expecting space between attribute name and type"
    expect_oasis_not_wf "p53fail3" \
           "p53fail3.xml:4:27: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p53fail4" \
           "p53fail4.xml:4:24: Expecting a space"
           # ??? Diagnostic could be better
    expect_oasis_not_wf "p53fail5" \
           "p53fail5.xml:4:15: Expecting a name"
    expect_oasis_not_wf "p54fail1" \
           "p54fail1.xml:4:24: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p55fail1" \
           "p55fail1.xml:4:24: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p56fail1" \
           "p56fail1.xml:4:21: Expecting a space"
	   # ??? Error should be: no IDS type
    expect_oasis_not_wf "p56fail2" \
           "p56fail2.xml:4:20: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p56fail3" \
           "p56fail3.xml:4:20: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p56fail4" \
           "p56fail4.xml:4:25: Expecting a space"
    expect_oasis_not_wf "p56fail5" \
           "p56fail5.xml:4:21: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p57fail1" \
           "p57fail1.xml:4:28: [WF] Invalid default value for attribute"
    expect_oasis_not_wf "p58fail1" \
           "p58fail1.xml:6:28: Invalid content model: List of choices cannot be empty"
    expect_oasis_not_wf "p58fail2" \
           "p58fail2.xml:6:30: [3.3.1] Invalid character ',' in ATTLIST enumeration"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf_validate "p58fail3" \
           "p58fail3.xml:6:27: [VC 3.3.1] Notation '0b' must be defined"
    expect_oasis_not_wf "p58fail4" \
           "p58fail4.xml:6:27: [WF] Invalid type for attribute"
    expect_oasis_not_wf "p58fail5" \
           "p58fail5.xml:6:27: [3.3.1] Space is required between NOTATION keyword and list of enumerated"
    expect_oasis_not_wf "p58fail6" \
           "p58fail6.xml:5:28: Expecting operator in content model"
    expect_oasis_not_wf "p58fail7" \
           "p58fail7.xml:5:28: Expecting operator in content model"
    expect_oasis_not_wf "p58fail8" \
           "p58fail8.xml:5:28: Invalid name in content model: \""
    expect_oasis_not_wf "p59fail1" \
           "p59fail1.xml:4:19: Invalid content model: List of choices cannot be empty"
    expect_oasis_not_wf "p59fail2" \
           "p59fail2.xml:4:21: [3.3.1] Invalid character ',' in ATTLIST enumeration"
    expect_oasis_not_wf "p59fail3" \
           "p59fail3.xml:4:19: Invalid name in content model: \""
    expect_oasis_not_wf "p60fail1" \
           "p60fail1.xml:4:26: [WF] Invalid keyword"
    expect_oasis_not_wf "p60fail2" \
           "p60fail2.xml:4:31: Expecting a space"
    expect_oasis_not_wf "p60fail3" \
           "p60fail3.xml:4:35: Expecting a name"
    expect_oasis_not_wf "p60fail4" \
           "p60fail4.xml:4:31: Expecting a space"
    expect_oasis_not_wf "p60fail5" \
           "p60fail5.xml:4:34: [3.1] '#REQUIRED' is not a valid name"
    expect_oasis_not_wf "p61fail1" \
           "p61fail1.dtd:2:8: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p62fail1" \
           "p62fail1.dtd:1:11: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p62fail2" \
           "p62fail2.dtd:3:2: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p63fail1" \
           "p63fail1.dtd:2:10: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p63fail2" \
           "p63fail2.dtd:3:1: [3.4] Conditional section must be properly terminated"
    expect_oasis_not_wf "p64fail1" \
           "p64fail1.dtd:2:33: [2.4] Text may not contain the litteral ']]>'"
    expect_oasis_not_wf "p64fail2" \
           "p64fail2.dtd:3:1: [3.4] Conditional section must be properly terminated"
    expect_oasis_not_wf "p66fail1" \
       "p66fail1.xml:1:10: [4.1] Invalid character '<' in character reference"
    expect_oasis_not_wf "p66fail2" \
       "p66fail2.xml:1:8: [4.1] Invalid character ' ' in character reference"
    expect_oasis_not_wf "p66fail3" \
       "p66fail3.xml:1:8: [4.1] Invalid character 'A' in character reference"
    expect_oasis_not_wf "p66fail4" \
       "p66fail4.xml:1:10: [4.1] Invalid character 'G' in character reference"
    expect_oasis_not_wf "p66fail5" \
       "p66fail5.xml:1:6: [2.2] Invalid character (code 5)"
    expect_oasis_not_wf "p66fail6" \
       "p66fail6.xml:1:6: [2.2] Invalid character (code 55298)"
    expect_oasis_not_wf "p68fail1" \
       "p68fail1.xml:7:1: [4.1] Entity references must end with ';'.
Did you want to use &amp; ?"
    expect_oasis_not_wf "p68fail2" \
       "p68fail2.xml:7:1: [4.1] Invalid first letter in entity name ' '"
    expect_oasis_not_wf "p68fail3" \
       "p68fail3.xml:7:1: [4.1] Entity references must end with ';'.
Did you want to use &amp; ?"
    expect_oasis_not_wf "p69fail1" \
           "p69fail1.xml:5:4: [WF] Unterminated entity"
    expect_oasis_not_wf "p69fail2" \
           "p69fail2.xml:5:2: [WF] Unterminated entity"
    expect_oasis_not_wf "p69fail3" \
           "p69fail3.xml:5:4: [WF] Unterminated entity"
    expect_oasis_not_wf "p70fail1" \
           "p70fail1.xml:4:11: [WF] Expecting entity name"
    expect_oasis_not_wf "p71fail1" \
           "p71fail1.xml:4:12: Expecting a space"
    expect_oasis_not_wf "p71fail2" \
           "p71fail2.xml:4:13: [WF] Expecting entity name"
    expect_oasis_not_wf "p71fail3" \
           "p71fail3.xml:4:3: [WF] Unexpected character in the DTD"
    expect_oasis_not_wf "p71fail4" \
           "p71fail4.xml:4:9: Expecting a space"
    expect_oasis_not_wf "p72fail1" \
           "p72fail1.xml:4:9: Expecting a space"
    expect_oasis_not_wf "p72fail2" \
           "p72fail2.xml:4:13: [WF] Expecting entity name"
    expect_oasis_not_wf "p72fail3" \
           "p72fail3.xml:4:14: Expecting a space"
    expect_oasis_not_wf "p72fail4" \
           "p72fail4.xml:4:15: [WF] Expecting entity name"
    expect_oasis_not_wf "p73fail1" \
           "p73fail1.xml:5:18: [WF] Invalid definition for ENTITY"
    expect_oasis_not_wf "p73fail2" \
           "p73fail2.xml:5:33: [WF] Expecting end of ENTITY definition"
    expect_oasis_not_wf "p73fail3" \
           "p73fail3.xml:5:37: [WF] Expecting end of ENTITY definition"
    expect_oasis_not_wf "p73fail4" \
           "p73fail4.xml:5:14: [WF] Invalid definition for ENTITY"
    expect_oasis_not_wf "p73fail5" \
           "p73fail5.xml:5:18: [WF] Invalid definition for ENTITY"
    expect_oasis_not_wf "p74fail1" \
           "p74fail1.xml:4:32: [4.2] NDATA annotation not allowed for parameter entities"
    expect_oasis_not_wf "p74fail2" \
           "p74fail2.xml:4:14: Expecting a space"
    expect_oasis_not_wf "p74fail3" \
           "p74fail3.xml:3:36: [WF] Expecting end of ENTITY definition"
    expect_oasis_not_wf "p75fail1" \
           "p75fail1.xml:3:20: Expecting a space"
    expect_oasis_not_wf "p75fail2" \
           "p75fail2.xml:3:20: Expecting a space"
    expect_oasis_not_wf "p75fail3" \
           "p75fail3.xml:3:31: [4.2.2] Require whitespace between public and system IDs"
    expect_oasis_not_wf "p75fail4" \
           "p75fail4.xml:3:33: [WF] Expecting end of ENTITY definition"
    expect_oasis_not_wf "p75fail5" \
           "p75fail5.xml:3:38: [WF] Expecting SystemID after PUBLIC"
    expect_oasis_not_wf "p75fail6" \
           "p75fail6.xml:3:32: [WF] Expecting SystemID after PUBLIC"
    expect_oasis_not_wf "p76fail1" \
           "p76fail1.xml:5:29: [4.2.2] Expecting space before NDATA declaration"
    expect_oasis_not_wf "p76fail2" \
           "p76fail2.xml:5:35: [WF] Expecting end of ENTITY definition"
    expect_oasis_not_wf "p76fail3" \
           "p76fail3.xml:5:35: Expecting a space"
    expect_oasis_not_wf "p76fail4" \
           "p76fail4.xml:7:19: [WF] Expecting notation name"
fi

##########################
## Optional errors
##########################

if [ $optional_errors = 1 ]; then
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang01" \
        "lang01.xml:5:21: [2.12] Invalid language specification"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang02" \
        "lang02.xml:5:23: [2.12] Invalid language specification"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang03" \
        "lang03.xml:5:21: [2.12] Invalid language specification"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang04" \
        "lang04.xml:5:24: [2.12] Invalid language specification"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang05" \
        "lang05.xml:5:25: [2.12] Invalid language specification"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "lang06" \
        "lang06.xml:5:25: [2.12] Invalid language specification"
    expect_invalid_sun "pe01" \
        "pe01.dtd:4:24: [3.1] Attribute values can not reference external entities"
    [ $VALIDATING = 1 ] && expect_sun_not_wf "uri01" \
        "(4.2.2) SYSTEM ids may not have URI fragments"
    [ $VALIDATING = 1 ] && expect_oasis_not_wf "p11pass1" \
        "(2.3, 4.2.2) system literals may not contain URI fragments"
fi

if [ $optional_errors = 1 ]; then
    # encoding not supported
    # ??? We must report a fatal error in that case
    [ $VALIDATING = 1 ] && expect_japanese "pr-xml-euc-jp"
    [ $VALIDATING = 1 ] && expect_japanese "pr-xml-iso-2022-jp"
    [ $VALIDATING = 1 ] && expect_japanese "weekly-iso-2022-jp"
    [ $VALIDATING = 1 ] && expect_japanese "weekly-shift_jis"
    [ $VALIDATING = 1 ] && expect_japanese "weekly-euc-jp"
    [ $VALIDATING = 1 ] && expect_japanese "pr-xml-shift_jis"
fi

#########################
## Internal testsuite
#########################

if [ -d act_testsuite/ ]; then
  (cd act_testsuite
   echo "-- Running ACT testsuite"
   ./run
  )
fi
 

print_result
