1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
# Commands covered: ::dom::validate
#
# This file contains a collection of tests for one or more of the
# TclDOM commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 2008-2009 Explain
# Copyright (c) 2003-2004 Zveno Pty Ltd.
#
# $Id: validate.test,v 1.4 2004/01/19 21:37:41 balls Exp $
package require tcltest
source [file join [tcltest::workingDirectory] tcldomutils.tcl]
testPackage dom
namespace eval ::dom::validateTest {
namespace import -force ::tcltest::*
variable SETUP {
set inst [dom::parse {<!DOCTYPE Test [
<!ELEMENT Test (#PCDATA)>
]>
<Test>This is a valid document</Test>
}]
}
variable CLEANUP {
dom::destroy $inst
}
variable SCHEMASETUP {
set inst [dom::parse {<Test>a simple test document</Test>}]
set schema [dom::parse {<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'
elementFormDefault='unqualified'
attributeFormDefault='unqualified'>
<xsd:element name='Test' type='xsd:string'/>
</xsd:schema>
}]
}
variable SCHEMACLEANUP {
dom::destroy $inst
dom::destroy $schema
}
### DTD validation
test validate-1.1 {validate too few args} -setup $SETUP -constraints {dom_libxml2} -match glob -body {
expectError {
$inst dtd
}
} -cleanup $CLEANUP -result {wrong # args*}
test validate-1.2 {validate too many args} -setup $SETUP -constraints {dom_libxml2} -match glob -body {
expectError {
$inst dtd validate another
}
} -cleanup $CLEANUP -result {wrong # args*}
test validate-1.3 {validate correct doc} -setup $SETUP -constraints {dom_libxml2} -body {
$inst dtd validate
} -cleanup $CLEANUP -result {}
test validate-1.4 {validate invalid doc} -constraints {dom_libxml2} -setup {
set bad [dom::parse {<!DOCTYPE Test [
<!ELEMENT Test (#PCDATA)>
]>
<Test>This is <emphasis>not</emphasis> a valid document</Test>}]
} -match glob -body {
expectError {
$bad dtd validate
}
} -cleanup {
dom::destroy $bad
} -result {*unknown-element-type*}
### WXS Schema-validation
test validate-2.1 {schema compile} -setup $SCHEMASETUP -constraints {dom_libxml2} -match glob -body {
$schema schema compile
} -cleanup $SCHEMACLEANUP -result {}
test validate-2.2 {schema method too few args} -setup $SCHEMASETUP -constraints {dom_libxml2} -match glob -body {
expectError {
$schema schema
}
} -cleanup $SCHEMACLEANUP -result {wrong # args*}
test validate-2.3 {schema compile too many args} -setup $SCHEMASETUP -constraints {dom_libxml2} -match glob -body {
expectError {
$schema schema compile another
}
} -cleanup $SCHEMACLEANUP -result {wrong # args*}
test validate-2.4 {schema validate valid doc} -constraints {dom_libxml2} -setup {
eval $SCHEMASETUP
$schema schema compile
} -body {
$schema schema validate $inst
} -cleanup $SCHEMACLEANUP -result {}
test validate-2.5 {schema validate invalid doc} -match regexp -constraints {dom_libxml2} -setup {
eval $SCHEMASETUP
$schema schema compile
set bad [dom::parse {<Test>a <emphasis>simple</emphasis> test document</Test>}]
} -body {
expectError {
$schema schema validate $bad
}
} -cleanup {
eval $SCHEMACLEANUP
} -result {.*invalid-element.*|.*Element content is not allowed.*}
test validate-2.6 {schema compile invalid schema} -constraints {dom_libxml2} -match glob -setup {
eval $SCHEMASETUP
set badschema [dom::parse {<schema>this is not a schema</schema>}]
} -body {
expectError {
$badschema schema compile
}
} -cleanup {
eval $SCHEMACLEANUP
} -result {* is not a schema*}
cleanupTests
}
namespace delete ::dom::validateTest
return
|