1# Commands covered: ::dom::element 2# 3# This file contains a collection of tests for one or more of the 4# TclDOM commands. Sourcing this file into Tcl runs the tests and 5# generates output for errors. No output means no errors were found. 6# 7# Copyright (c) 1998-2002 Zveno Pty Ltd. 8# 9# $Id: element.test,v 1.7 2003/01/23 19:47:03 balls Exp $ 10 11package require tcltest; namespace import -force ::tcltest::* 12source testutils.tcl 13testPackage dom 14 15proc addChild {parent child} { 16 ::dom::node appendChild $parent $child 17 return $child 18} 19 20set doc [dom::DOMImplementation create] 21set top [addChild $doc [dom::document createElement $doc Test]] 22set e1 [addChild $top [dom::document createElement $top Element]] 23 24test element-1.1 {cget -tagName} -body { 25 dom::element cget $top -tagName 26} -result Test 27test element-1.2 {cget -tagName} -body { 28 dom::element cget $e1 -tagName 29} -result Element 30test element-1.3 {error: cget -tagName on non-element node} -body { 31 catch {dom::element cget $doc -tagName} msg 32} -result 1 33test element-1.4 {error: cget} -body { 34 catch {dom::element cget} 35} -result 1 36test element-1.5 {error:cget} -body { 37 catch {dom::element cget $e1} 38} -result 1 39 40test element-2.1 {error: configure -tagName, read-only option} -body { 41 catch {dom::element configure $e1 -tagName Error} 42} -result 1 43 44test element-3.1 {setAttribute} -constraints {dom_c} -body { 45 dom::element setAttribute $e1 class success 46} -result {} 47test element-3.1 {setAttribute} -constraints {dom_tcl || dom_libxml2} -body { 48 dom::element setAttribute $e1 class success 49} -result success 50test element-3.2 {error: setAttribute, wrong number args} -body { 51 catch {dom::element setAttribute $e1 href} 52} -result 1 53# TODO: test that illegal attribute names are rejected 54 55test element-4.1 {getAttribute} -body { 56 dom::element getAttribute $e1 class 57} -result success 58test element-4.2 {error: getAttribute, wrong number args} -body { 59 catch {dom::element getAttribute $e1} 60} -result 1 61test element-4.3 {getAttribute, undefined attribute} -body { 62 # According to DOM spec this should not raise an exception 63 set rc [catch {dom::element getAttribute $e1 unknown} ans] 64 list $rc $ans 65} -result [list 0 {}] 66 67# TODO: check that attribute values are escaped correctly 68 69test element-5.1 {removeAttribute} -body { 70 dom::element removeAttribute $e1 class 71} -result {} 72 73test element-5.2 {removeAttribute a nonexistent attribute} -body { 74 dom::element removeAttribute $e1 class 75 # this should be a no-op. 76} -result {} 77 78# Attribute nodes are not yet implemented 79test element-6.1 {getAttributeNode} -constraints {knownBug} -body { 80} -result {} 81 82test element-7.1 {setAttributeNode} -constraints {knownBug} -body { 83} -result {} 84 85test element-8.1 {removeAttributeNode} -constraints {knownBug} -body { 86} -result {} 87 88test element-9.1 {getElementsByTagName} -constraints {emptyTest} -body { 89} -result {} 90 91test element-10.1 {normalize} -constraints {emptyTest} -body { 92} -result {} 93 94test element-11.1 {error: method} -constraints {dom_c} -body { 95 expectError { 96 dom::element foo $e1 97 } {bad method "foo": *} 98} -result 1 99 100# cleanup 101::tcltest::cleanupTests 102return 103