home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 December
/
PCWorld_2000-12_cd.bin
/
Komunikace
/
Comanche
/
xuibuilder
/
TclDOM-1.6
/
tests
/
node.test
< prev
next >
Wrap
Text File
|
2000-11-02
|
7KB
|
193 lines
# Commands covered: ::dom::node
#
# 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 Zveno Pty Ltd.
#
# $Id: node.test,v 1.1.1.1 1996/02/22 06:06:14 daniel Exp $
if {[string compare test [info procs test]] == 1} then {source defs}
if {[catch {package require dom 1.0}]} {
catch {puts stderr "Cannot load dom 1.0 package"}
return
}
set doc [::dom::DOMImplementation create]
set top [::dom::document createElement $doc Test]
set child1 [::dom::document createElement $top Child1]
set child2 [::dom::document createTextNode $top Child2]
set child3 [::dom::document createElement $top Child3]
# NB. All factory methods are tested in document.test
test node-1.1 {cget -nodeName} {
::dom::node cget $top -nodeName
} Test
test node-2.1 {cget -nodeType} {
::dom::node cget $top -nodeType
} element
test node-3.1 {cget -parentNode top} {
::dom::node cget $top -parentNode
} $doc
test node-3.2 {cget -parentNode document} {
::dom::node cget $doc -parentNode
} {}
test node-3.3 {cget -parentNode leaf} {
::dom::node cget $child1 -parentNode
} $top
test node-4.11 {cget -childNodes} {
set [::dom::node cget $doc -childNodes]
} [list $top]
test node-4.2 {cget -childNodes top} {
set [::dom::node cget $top -childNodes]
} [list $child1 $child2 $child3]
test node-4.3 {cget -childNodes leaf} {
set [::dom::node cget $child1 -childNodes]
} {}
test node-4.4 {cget -childNodes textNode} {
::dom::node cget $child2 -childNodes
} {}
test node-5.1 {cget -firstChild} {
::dom::node cget $top -firstChild
} $child1
test node-5.2 {cget -firstChild document} {
::dom::node cget $doc -firstChild
} $top
test node-6.1 {cget -lastChild} {
::dom::node cget $top -lastChild
} $child3
test node-6.2 {cget -lastChild document} {
::dom::node cget $doc -lastChild
} $top
test node-7.1 {cget -previousSibling first} {
::dom::node cget $child1 -previousSibling
} {}
test node-7.2 {cget -previousSibling last} {
::dom::node cget $child3 -previousSibling
} $child2
test node-8.1 {cget -nextSibling first} {
::dom::node cget $child1 -nextSibling
} $child2
test node-8.2 {cget -nextSibling last} {
::dom::node cget $child3 -nextSibling
} {}
test node-9.1 {cget -attributes} {
array get [::dom::node cget $top -attributes]
} {}
test node-10.1 {cget -nodeValue} {
::dom::node cget $top -nodeValue
} {}
test node-10.2 {cget -nodeValue text} {
::dom::node cget $child2 -nodeValue
} Child2
set branchA [dom::document createElement $top Branch]
set branchB [dom::document createElement $top Branch]
set new [dom::document createElement $branchA MoveMe]
set ref [dom::document createElement $branchB Reference]
test node-11.1 {insertBefore, different parent} {
::dom::node insertBefore $branchB $new $ref
# new should now have branchB as parent
# branchA should have no children
# branchB should have children {$new $ref}
list [dom::node cget $new -parentNode] [set [dom::node cget $branchA -childNodes]] \
[set [dom::node cget $branchB -childNodes]]
} [list $branchB {} [list $new $ref]]
test node-11.2 {insertBefore, same parent} {
::dom::node insertBefore $branchB $ref $new
# ref should still have branchB as its parent
# branchB should have children {$ref $new}
list [dom::node cget $ref -parentNode] [set [dom::node cget $branchB -childNodes]]
} [list $branchB [list $ref $new]]
test node-11.3 {insertBefore, no ref child given, node with no children} {
::dom::node insertBefore $branchA $new
# new should have parent branchA
# branchA should have child new
# branchB should have only child ref
list [dom::node cget $new -parentNode] [set [dom::node cget $branchA -childNodes]] \
[set [dom::node cget $branchB -childNodes]]
} [list $branchA $new $ref]
test node-11.4 {insertBefore, no ref child given, node with children} {
::dom::node insertBefore $branchA $ref
# ref should have parent branchA
# branchA should have children {$new $ref}
# branchB should have no children
list [dom::node cget $ref -parentNode] [set [dom::node cget $branchA -childNodes]] \
[set [dom::node cget $branchB -childNodes]]
} [list $branchA [list $new $ref] {}]
set parent [dom::document createElement $top Remove]
set n1 [dom::document createTextNode $parent {Leave me alone}]
set rem [dom::document createElement $parent RemoveMe]
set n2 [dom::document createTextNode $parent {Leave me alone}]
test node-12.1 {removeChild} {
set oldchild [::dom::node removeChild $parent $rem]
list $oldchild [set [::dom::node cget $parent -childNodes]] [::dom::node cget $oldchild -parentNode]
} [list $rem [list $n1 $n2] {}]
test node-12.2 {removeChild: error, wrong num args} {
set result [catch {::dom::node removeChild $top} msg]
list $result $msg
} {1 {wrong number of arguments}}
test node-12.3 {removeChild: error, wrong num args} {
set result [catch {::dom::node removeChild $top $child1 $child3} msg]
list $result $msg
} {1 {wrong number of arguments}}
test node-12.4 {removeChild: error, not a child} {
set result [catch {::dom::node removeChild $doc $child1} msg]
list $result $msg
} [list 1 "node \"$child1\" is not a child"]
set branchA [dom::document createElement $top ReplaceA]
set branchB [dom::document createElement $top ReplaceB]
set new [dom::document createElement $branchA MoveMe]
set replace [dom::document createElement $branchB ReplaceMe]
test node-13.1 {replaceChild: } {
::dom::node replaceChild $branchB $new $replace
# replace becomes orphaned (no parent)
# new has parent branchB
# branchB has children {$new}
# branchA has no children
list [::dom::node cget $replace -parentNode] [::dom::node cget $new -parentNode] \
[set [::dom::node cget $branchB -childNodes]] [set [::dom::node cget $branchA -childNodes]]
} [list {} $branchB [list $new] {}]
set branchA [dom::document createElement $top AppendA]
set branchB [dom::document createElement $top AppendB]
set node [dom::document createElement $branchA MoveMe]
set after [dom::document createElement $branchB AfterMe]
test node-14.1 {appendChild} {
::dom::node appendChild $branchB $node
# node should have parent branchB
# Branch A should have no children
# Branch B should have children: {$after $node}
list [::dom::node cget $node -parentNode] \
[set [::dom::node cget $branchA -childNodes]] \
[set [::dom::node cget $branchB -childNodes]]
} [list $branchB {} [list $after $node]]
set cloneNode [dom::document createElement $top Clone]
set clone1 [dom::document createElement $cloneNode Nested {id one}]
set clone2 [dom::document createElement $cloneNode Nested {id two}]
dom::document createElement $cloneNode Nested {id three}
dom::document createTextNode $clone1 {text for node 1}
dom::document createTextNode $clone2 {text for node 2}
test node-15.1 {cloneNode} {
set cloned [dom::node cloneNode $cloneNode -deep yes]
set orig [dom::DOMImplementation serialize $cloneNode]
set new [dom::DOMImplementation serialize $cloned]
list [[string compare $orig $new] [dom::node parent $cloned]]
} {0 {}}