# 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) 1998-2002 Zveno Pty Ltd. # # $Id: element.test,v 1.7 2003/01/23 19:47:03 balls Exp $ package require tcltest; namespace import -force ::tcltest::* source testutils.tcl testPackage dom proc addChild {parent child} { ::dom::node appendChild $parent $child return $child } set doc [dom::DOMImplementation create] set top [addChild $doc [dom::document createElement $doc Test]] set e1 [addChild $top [dom::document createElement $top Element]] test element-1.1 {cget -tagName} -body { dom::element cget $top -tagName } -result Test test element-1.2 {cget -tagName} -body { dom::element cget $e1 -tagName } -result Element test element-1.3 {error: cget -tagName on non-element node} -body { catch {dom::element cget $doc -tagName} msg } -result 1 test element-1.4 {error: cget} -body { catch {dom::element cget} } -result 1 test element-1.5 {error:cget} -body { catch {dom::element cget $e1} } -result 1 test element-2.1 {error: configure -tagName, read-only option} -body { catch {dom::element configure $e1 -tagName Error} } -result 1 test element-3.1 {setAttribute} -constraints {dom_c} -body { dom::element setAttribute $e1 class success } -result {} test element-3.1 {setAttribute} -constraints {dom_tcl || dom_libxml2} -body { dom::element setAttribute $e1 class success } -result success test element-3.2 {error: setAttribute, wrong number args} -body { catch {dom::element setAttribute $e1 href} } -result 1 # TODO: test that illegal attribute names are rejected test element-4.1 {getAttribute} -body { dom::element getAttribute $e1 class } -result success test element-4.2 {error: getAttribute, wrong number args} -body { catch {dom::element getAttribute $e1} } -result 1 test element-4.3 {getAttribute, undefined attribute} -body { # According to DOM spec this should not raise an exception set rc [catch {dom::element getAttribute $e1 unknown} ans] list $rc $ans } -result [list 0 {}] # TODO: check that attribute values are escaped correctly test element-5.1 {removeAttribute} -body { dom::element removeAttribute $e1 class } -result {} test element-5.2 {removeAttribute a nonexistent attribute} -body { dom::element removeAttribute $e1 class # this should be a no-op. } -result {} # Attribute nodes are not yet implemented test element-6.1 {getAttributeNode} -constraints {knownBug} -body { } -result {} test element-7.1 {setAttributeNode} -constraints {knownBug} -body { } -result {} test element-8.1 {removeAttributeNode} -constraints {knownBug} -body { } -result {} test element-9.1 {getElementsByTagName} -constraints {emptyTest} -body { } -result {} test element-10.1 {normalize} -constraints {emptyTest} -body { } -result {} test element-11.1 {error: method} -constraints {dom_c} -body { expectError { dom::element foo $e1 } {bad method "foo": *} } -result 1 # cleanup ::tcltest::cleanupTests return