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 130 131 132 133 134 135 136 137 138
|
# Commands covered: ::dom::element
#
# 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 Explain
# http://www.explain.com.au/
# Copyright (c) 1998-2004 Zveno Pty Ltd.
#
# $Id: element.test,v 1.9 2004/02/24 20:16:10 balls Exp $
package require tcltest
source [file join [tcltest::workingDirectory] tcldomutils.tcl]
testPackage dom
namespace eval ::dom::elementTest {
namespace import -force ::tcltest::*
variable SETUP {
set doc [dom::create]
set top [$doc createElement Test]
dom::node appendChild $doc $top
set e1 [$doc createElement Element]
$top appendChild $e1
}
variable CLEANUP {
dom::destroy $doc
}
test element-1.1 {cget -tagName} -setup $SETUP -body {
dom::element cget $top -tagName
} -cleanup $CLEANUP -result Test
test element-1.2 {cget -tagName} -setup $SETUP -body {
dom::element cget $e1 -tagName
} -cleanup $CLEANUP -result Element
test element-1.3 {error: cget -tagName on non-element node} -setup $SETUP -match glob -body {
expectError {
dom::element cget $doc -tagName
}
} -cleanup $CLEANUP -result {malformed node token*}
test element-1.4 {error: cget} -setup $SETUP -match glob -body {
expectError {
dom::element cget
}
} -cleanup $CLEANUP -result {wrong # args*}
test element-1.5 {error:cget} -setup $SETUP -match glob -body {
expectError {
dom::element cget $e1
}
} -cleanup $CLEANUP -result {wrong # args*}
test element-2.1 {error: configure -tagName, read-only option} -setup $SETUP -match glob -body {
expectError {
dom::element configure $e1 -tagName Error
}
} -cleanup $CLEANUP -result {option * cannot be modified}
test element-3.1 {setAttribute} -constraints {dom_c} -setup $SETUP -body {
dom::element setAttribute $e1 class success
} -cleanup $CLEANUP -result {}
test element-3.1 {setAttribute} -constraints {dom_tcl || dom_libxml2} -setup $SETUP -body {
dom::element setAttribute $e1 class success
} -cleanup $CLEANUP -result success
test element-3.2 {error: setAttribute, wrong number args} -setup $SETUP -match glob -body {
expectError {
dom::element setAttribute $e1 href
}
} -cleanup $CLEANUP -result {wrong # args*}
# TODO: test that illegal attribute names are rejected
test element-4.1 {getAttribute} -setup {
eval $SETUP
dom::element setAttribute $e1 class success
} -body {
dom::element getAttribute $e1 class
} -cleanup $CLEANUP -result success
test element-4.2 {error: getAttribute, wrong number args} -setup $SETUP -match glob -body {
expectError {
dom::element getAttribute $e1
}
} -cleanup $CLEANUP -result {wrong # args*}
test element-4.3 {getAttribute, undefined attribute} -setup $SETUP -body {
# According to DOM spec this should not raise an exception
set rc [catch {dom::element getAttribute $e1 unknown} ans]
list $rc $ans
} -cleanup $CLEANUP -result [list 0 {}]
# TODO: check that attribute values are escaped correctly
test element-5.1 {removeAttribute} -setup {
eval $SETUP
dom::element setAttribute $e1 class success
} -body {
dom::element removeAttribute $e1 class
} -cleanup $CLEANUP -result {}
test element-5.2 {removeAttribute a nonexistent attribute} -setup $SETUP -body {
dom::element removeAttribute $e1 class
# this should be a no-op.
} -cleanup $CLEANUP -result {}
# Attribute nodes are not yet implemented
test element-6.1 {getAttributeNode} -constraints {not_implemented} -setup $SETUP -body {
} -cleanup $CLEANUP -result {}
test element-7.1 {setAttributeNode} -constraints {not_implemented} -setup $SETUP -body {
} -cleanup $CLEANUP -result {}
test element-8.1 {removeAttributeNode} -constraints {not_implemented} -setup $SETUP -body {
} -cleanup $CLEANUP -result {}
test element-9.1 {getElementsByTagName} -constraints {emptyTest} -setup $SETUP -body {
} -cleanup $CLEANUP -result {}
test element-10.1 {normalize} -constraints {emptyTest} -setup {
set doc [dom::create]
set top [dom::document createElement $doc test]
dom::document createTextNode $top {First text}
dom::document createTextNode $top {Second text}
} -body {
$top normalize
list [llength [$top children]] [$top stringValue]
} -cleanup $CLEANUP -result [list 1 {First textSecond text}]
test element-11.1 {error: method} -setup $SETUP -match glob -body {
expectError {
dom::element foo $e1
}
} -cleanup $CLEANUP -result {bad method "foo": *}
cleanupTests
}
namespace delete ::dom::elementTest
return
|