4 |
BEGIN { plan tests => 10 } |
BEGIN { plan tests => 10 } |
5 |
|
|
6 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
7 |
|
use Message::Util::Error; |
8 |
|
|
9 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $dom = Message::DOM::DOMImplementation->____new; |
10 |
my $doc = $dom->create_document; |
my $doc = $dom->create_document; |
44 |
|
|
45 |
ok $cn->can ('length') ? 1 : 0, 1, 'can childNodes.length [0]'; |
ok $cn->can ('length') ? 1 : 0, 1, 'can childNodes.length [0]'; |
46 |
ok $cn->length, 0, 'childNodes.length [0]'; |
ok $cn->length, 0, 'childNodes.length [0]'; |
47 |
|
ok 0+@$cn, 0, '@{child_nodes} [0]'; |
48 |
|
|
49 |
ok $cn->can ('item') ? 1 : 0, 1, 'can childNodes.item'; |
ok $cn->can ('item') ? 1 : 0, 1, 'can childNodes.item'; |
50 |
ok $cn->item (0), undef, 'childNodes.item (0) [0]'; |
ok $cn->item (0), undef, 'childNodes.item (0) [0]'; |
51 |
ok $cn->item (1), undef, 'childNodes.item (1) [0]'; |
ok $cn->item (1), undef, 'childNodes.item (1) [0]'; |
52 |
ok $cn->item (-1), undef, 'childNodes.item (-1) [0]'; |
ok $cn->item (-1), undef, 'childNodes.item (-1) [0]'; |
53 |
ok $cn->item (undef), undef, 'childNodes.item (undef) [0]'; |
ok $cn->item (undef), undef, 'childNodes.item (undef) [0]'; |
54 |
|
ok $cn->[0], undef, 'child_nodes->[0] [0]'; |
55 |
|
ok $cn->[1], undef, 'child_nodes->[1] [0]'; |
56 |
|
|
57 |
$parent->append_child ($node1); |
$parent->append_child ($node1); |
58 |
|
|
62 |
ok $cn->item (1), undef, 'childNodes.item (1) [1]'; |
ok $cn->item (1), undef, 'childNodes.item (1) [1]'; |
63 |
ok $cn->item (-1), undef, 'childNodes.item (-1) [1]'; |
ok $cn->item (-1), undef, 'childNodes.item (-1) [1]'; |
64 |
ok $cn->item (undef), $node1, 'childNodes.item (undef) [1]'; |
ok $cn->item (undef), $node1, 'childNodes.item (undef) [1]'; |
65 |
|
ok $cn->[0], $node1, 'child_nodes->[0] [1]'; |
66 |
|
ok $cn->[1], undef, 'child_nodes->[1] [1]'; |
67 |
|
ok exists $cn->[0] ? 1 : 0, 1, 'exists child_nodes->[0] [1]'; |
68 |
|
ok exists $cn->[1] ? 1 : 0, 0, 'exists child_nodes->[1] [1]'; |
69 |
|
|
70 |
$parent->append_child ($node2); |
$parent->append_child ($node2); |
71 |
|
|
75 |
ok $cn->item (1), $node2, 'childNodes.item (1) [2]'; |
ok $cn->item (1), $node2, 'childNodes.item (1) [2]'; |
76 |
ok $cn->item (-1), undef, 'childNodes.item (-1) [2]'; |
ok $cn->item (-1), undef, 'childNodes.item (-1) [2]'; |
77 |
ok $cn->item (undef), $node1, 'childNodes.item (undef) [2]'; |
ok $cn->item (undef), $node1, 'childNodes.item (undef) [2]'; |
78 |
|
ok $cn->[0], $node1, 'child_nodes->[0] [2]'; |
79 |
|
ok $cn->[1], $node2, 'child_nodes->[1] [2]'; |
80 |
|
|
81 |
ok $cn eq $cn ? 1 : 0, 1, 'A eq A'; |
ok $cn eq $cn ? 1 : 0, 1, 'A eq A'; |
82 |
ok $cn ne $cn ? 1 : 0, 0, 'A ne A'; |
ok $cn ne $cn ? 1 : 0, 0, 'A ne A'; |
102 |
ok $cn ne $cn3 ? 1 : 0, 1, 'A ne B (A == B)'; |
ok $cn ne $cn3 ? 1 : 0, 1, 'A ne B (A == B)'; |
103 |
ok $cn == $cn3 ? 1 : 0, 1, 'A == B (A == B)'; |
ok $cn == $cn3 ? 1 : 0, 1, 'A == B (A == B)'; |
104 |
ok $cn != $cn3 ? 1 : 0, 0, 'A != B (A == B)'; |
ok $cn != $cn3 ? 1 : 0, 0, 'A != B (A == B)'; |
105 |
|
|
106 |
|
$cn->[2] = $node1a; |
107 |
|
ok $cn->[2], $node1a, 'child_nodes->[2] setter (item)'; |
108 |
|
ok 0+@$cn, 3, 'child_nodes->[2] setter (length)'; |
109 |
|
|
110 |
|
$cn->[4] = $node2a; |
111 |
|
ok $cn->[3], $node2a, 'child_nodes->[3] setter (item)'; |
112 |
|
ok $cn->[4], undef, 'child_nodes->[4] setter (item)'; |
113 |
|
ok 0+@$cn, 4, 'child_nodes->[4] setter (length)'; |
114 |
|
## TODO: Add replaceChild test |
115 |
|
|
116 |
|
my $deleted = delete $cn->[4]; |
117 |
|
ok $deleted, undef, 'delete child_nodes->[4]'; |
118 |
|
ok $cn->[3], $node2a, 'delete child_nodes->[4] item(3)'; |
119 |
|
ok $cn->[4], undef, 'delete child_nodes->[4] item(4)'; |
120 |
|
|
121 |
|
$deleted = delete $cn->[0]; |
122 |
|
ok $deleted, $node1, 'delete child_nodes->[0]'; |
123 |
|
ok $cn->[0], $node2, 'delete child_nodes->[0] item(0)'; |
124 |
|
ok $cn->[1], $node1a, 'delete child_nodes->[0] item(1)'; |
125 |
|
ok $cn->[2], $node2a, 'delete child_nodes->[0] item(2)'; |
126 |
|
ok $cn->[3], undef, 'delete child_nodes->[0] item(3)'; |
127 |
|
ok $cn->[4], undef, 'delete child_nodes->[0] item(4)'; |
128 |
|
|
129 |
|
my @a = @$cn; |
130 |
|
ok 0+@a, 3; |
131 |
|
ok $a[0], $node2, '@ = @{child_nodes} item(0)'; |
132 |
|
ok $a[1], $node1a, '@ = @{child_nodes} item(1)'; |
133 |
|
ok $a[2], $node2a, '@ = @{child_nodes} item(2)'; |
134 |
|
ok $a[3], undef, '@ = @{child_nodes} item(3)'; |
135 |
|
|
136 |
|
@$cn = (); |
137 |
|
ok 0+@$cn, 0, 'child_nodes->clear'; |
138 |
} |
} |
139 |
|
|
140 |
## TODO: tests for @{$node_list} and @{$empty_node_list} |
for my $parent (create_leaf_nodes ()) { |
141 |
|
my $node1; |
142 |
|
my $node2; |
143 |
|
my $node1a; |
144 |
|
my $node2a; |
145 |
|
$node1 = $doc->create_text_node ('text1'); |
146 |
|
$node2 = $doc->create_text_node ('text2'); |
147 |
|
$node1a = $doc->create_text_node ('text1'); |
148 |
|
$node2a = $doc->create_text_node ('text2'); |
149 |
|
|
150 |
|
my $cn = $parent->child_nodes; |
151 |
|
ok UNIVERSAL::isa ($cn, 'Message::IF::NodeList') ? 1 : 0, 1, |
152 |
|
'childNodes.interface'; |
153 |
|
ok $cn ? 1 : 0, 1, 'bool'; |
154 |
|
|
155 |
|
ok $cn->can ('manakai_read_only') ? 1 : 0, 1, 'can childNodes.manakaiReadOnly'; |
156 |
|
$parent->manakai_set_read_only (1); |
157 |
|
ok $cn->manakai_read_only ? 1 : 0, 1, 'childNodes.manakaiReadOnly (1)'; |
158 |
|
$parent->manakai_set_read_only (0); |
159 |
|
ok $cn->manakai_read_only ? 1 : 0, 1, 'childNodes.manakaiReadOnly (0)'; |
160 |
|
|
161 |
|
ok $cn->can ('length') ? 1 : 0, 1, 'can childNodes.length [0]'; |
162 |
|
ok $cn->length, 0, 'childNodes.length [0]'; |
163 |
|
ok 0+@$cn, 0, '@{child_nodes} [0]'; |
164 |
|
|
165 |
|
ok $cn->can ('item') ? 1 : 0, 1, 'can childNodes.item'; |
166 |
|
ok $cn->item (0), undef, 'childNodes.item (0) [0]'; |
167 |
|
ok $cn->item (1), undef, 'childNodes.item (1) [0]'; |
168 |
|
ok $cn->item (-1), undef, 'childNodes.item (-1) [0]'; |
169 |
|
ok $cn->item (undef), undef, 'childNodes.item (undef) [0]'; |
170 |
|
ok $cn->[0], undef, 'child_nodes->[0] [0]'; |
171 |
|
ok $cn->[1], undef, 'child_nodes->[1] [0]'; |
172 |
|
ok exists $cn->[0] ? 1 : 0, 0, 'exists child_nodes->[0] [1]'; |
173 |
|
ok exists $cn->[1] ? 1 : 0, 0, 'exists child_nodes->[1] [1]'; |
174 |
|
|
175 |
|
ok $cn eq $cn ? 1 : 0, 1, 'A eq A'; |
176 |
|
ok $cn ne $cn ? 1 : 0, 0, 'A ne A'; |
177 |
|
ok $cn == $cn ? 1 : 0, 1, 'A == A'; |
178 |
|
ok $cn != $cn ? 1 : 0, 0, 'A != A'; |
179 |
|
|
180 |
|
my $cn2 = $parent->child_nodes; |
181 |
|
ok $cn eq $cn2 ? 1 : 0, 1, "A eq A'"; |
182 |
|
ok $cn ne $cn2 ? 1 : 0, 0, "A ne A'"; |
183 |
|
ok $cn == $cn2 ? 1 : 0, 1, "A == A'"; |
184 |
|
ok $cn != $cn2 ? 1 : 0, 0, "A != A'"; |
185 |
|
|
186 |
|
my $parenta = $doc->create_element ('element'); |
187 |
|
my $cn3 = $parenta->child_nodes; |
188 |
|
ok $cn eq $cn3 ? 1 : 0, 0, 'A eq B (A != B)'; |
189 |
|
ok $cn ne $cn3 ? 1 : 0, 1, 'A ne B (A != B)'; |
190 |
|
ok $cn == $cn3 ? 1 : 0, 1, 'A == B (A != B)'; |
191 |
|
ok $cn != $cn3 ? 1 : 0, 0, 'A != B (A != B)'; |
192 |
|
|
193 |
|
try { |
194 |
|
$cn->[2] = $node1a; |
195 |
|
ok 0, 1, $parent->node_name . '->child_nodes->[2] = $node'; |
196 |
|
} catch Message::IF::DOMException with { |
197 |
|
my $err = shift; |
198 |
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
199 |
|
$parent->node_name . '->child_nodes->[2] = $node'; |
200 |
|
}; |
201 |
|
ok 0+@$cn, 0, $parent->node_name . '->child_nodes->[2] (length)'; |
202 |
|
|
203 |
|
try { |
204 |
|
delete $cn->[4]; |
205 |
|
ok 0, 1, $parent->node_name . '->child_nodes->[2] delete'; |
206 |
|
} catch Message::IF::DOMException with { |
207 |
|
my $err = shift; |
208 |
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
209 |
|
$parent->node_name . '->child_nodes->[2] delete'; |
210 |
|
}; |
211 |
|
|
212 |
|
my @a = @$cn; |
213 |
|
ok 0+@a, 0, $parent->node_type . '->child_nodes @{} = 0+'; |
214 |
|
|
215 |
|
try { |
216 |
|
@$cn = (); |
217 |
|
ok 0, 1, $parent->node_name . '->child_nodes->[2] delete'; |
218 |
|
} catch Message::IF::DOMException with { |
219 |
|
my $err = shift; |
220 |
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
221 |
|
$parent->node_name . '->child_nodes @{} CLEAR'; |
222 |
|
}; |
223 |
|
} |
224 |
|
|
225 |
sub create_leaf_nodes () { |
sub create_leaf_nodes () { |
226 |
( |
( |
244 |
$doc->create_document_type_definition ('dt1'), |
$doc->create_document_type_definition ('dt1'), |
245 |
); |
); |
246 |
} # create_parent_nodes |
} # create_parent_nodes |
247 |
|
|
248 |
|
=head1 LICENSE |
249 |
|
|
250 |
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
251 |
|
|
252 |
|
This program is free software; you can redistribute it and/or |
253 |
|
modify it under the same terms as Perl itself. |
254 |
|
|
255 |
|
=cut |
256 |
|
|
257 |
|
## $Date$ |