1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
use strict; |
use strict; |
3 |
use Test; |
use Test; |
4 |
BEGIN { plan tests => 2808 } |
BEGIN { plan tests => 4918 } |
5 |
|
|
6 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
7 |
use Message::Util::Error; |
use Message::Util::Error; |
42 |
); |
); |
43 |
} # create_parent_nodes |
} # create_parent_nodes |
44 |
|
|
45 |
|
sub create_leaf_nodes () { |
46 |
|
( |
47 |
|
$doc->create_cdata_section ('cdata1'), |
48 |
|
$doc->create_comment ('comment1'), |
49 |
|
$doc->create_notation ('notation1'), |
50 |
|
$doc->create_processing_instruction ('pi1', 'pi1data'), |
51 |
|
$doc->create_text_node ('text1'), |
52 |
|
); |
53 |
|
} # create_leaf_nodes |
54 |
|
|
55 |
## Constants |
## Constants |
56 |
my $constants = [ |
my $constants = [ |
57 |
[ELEMENT_NODE => 1], |
[ELEMENT_NODE => 1], |
75 |
[DOCUMENT_POSITION_CONTAINS => 0x08], |
[DOCUMENT_POSITION_CONTAINS => 0x08], |
76 |
[DOCUMENT_POSITION_CONTAINED_BY => 0x10], |
[DOCUMENT_POSITION_CONTAINED_BY => 0x10], |
77 |
[DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC => 0x20], |
[DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC => 0x20], |
78 |
|
|
79 |
|
[NODE_CLONED => 1], |
80 |
|
[NODE_IMPORTED => 2], |
81 |
|
[NODE_DELETED => 3], |
82 |
|
[NODE_RENAMED => 4], |
83 |
|
[NODE_ADOPTED => 5], |
84 |
]; |
]; |
85 |
|
|
86 |
my $tests = { |
my $tests = { |
110 |
attr_get_bool => { |
attr_get_bool => { |
111 |
has_attributes => 0, |
has_attributes => 0, |
112 |
has_child_nodes => 0, |
has_child_nodes => 0, |
113 |
|
is_id => 0, |
114 |
manakai_read_only => 0, |
manakai_read_only => 0, |
115 |
specified => 1, |
specified => 1, |
116 |
}, |
}, |
143 |
attr_get_bool => { |
attr_get_bool => { |
144 |
has_attributes => 0, |
has_attributes => 0, |
145 |
has_child_nodes => 1, |
has_child_nodes => 1, |
146 |
|
is_id => 0, |
147 |
manakai_read_only => 0, |
manakai_read_only => 0, |
148 |
specified => 1, |
specified => 1, |
149 |
}, |
}, |
171 |
attr_get_bool => { |
attr_get_bool => { |
172 |
has_attributes => 0, |
has_attributes => 0, |
173 |
has_child_nodes => 0, |
has_child_nodes => 0, |
174 |
|
is_id => 0, |
175 |
manakai_read_only => 0, |
manakai_read_only => 0, |
176 |
specified => 1, |
specified => 1, |
177 |
}, |
}, |
199 |
attr_get_bool => { |
attr_get_bool => { |
200 |
has_attributes => 0, |
has_attributes => 0, |
201 |
has_child_nodes => 0, |
has_child_nodes => 0, |
202 |
|
is_id => 0, |
203 |
manakai_read_only => 0, |
manakai_read_only => 0, |
204 |
specified => 1, |
specified => 1, |
205 |
}, |
}, |
227 |
attr_get_bool => { |
attr_get_bool => { |
228 |
has_attributes => 0, |
has_attributes => 0, |
229 |
has_child_nodes => 0, |
has_child_nodes => 0, |
230 |
|
is_id => 0, |
231 |
manakai_read_only => 0, |
manakai_read_only => 0, |
232 |
specified => 1, |
specified => 1, |
233 |
}, |
}, |
431 |
}, |
}, |
432 |
}, |
}, |
433 |
document_type => { |
document_type => { |
434 |
node => sub { return $doc->implementation->create_document_type ('n') }, |
node => sub { |
435 |
|
return $doc->implementation->create_document_type ('n', '', ''); |
436 |
|
}, |
437 |
attr_get => { |
attr_get => { |
438 |
attributes => undef, |
attributes => undef, |
439 |
base_uri => undef, |
base_uri => undef, |
442 |
manakai_expanded_uri => undef, |
manakai_expanded_uri => undef, |
443 |
first_child => undef, |
first_child => undef, |
444 |
implementation => $dom, |
implementation => $dom, |
445 |
|
internal_subset => '', |
446 |
last_child => undef, |
last_child => undef, |
447 |
local_name => undef, |
local_name => undef, |
448 |
manakai_local_name => undef, |
manakai_local_name => undef, |
455 |
parent_node => undef, |
parent_node => undef, |
456 |
prefix => undef, |
prefix => undef, |
457 |
previous_sibling => undef, |
previous_sibling => undef, |
458 |
public_id => undef, |
public_id => '', |
459 |
system_id => undef, |
system_id => '', |
460 |
}, |
}, |
461 |
attr_get_bool => { |
attr_get_bool => { |
462 |
has_attributes => 0, |
has_attributes => 0, |
474 |
manakai_expanded_uri => undef, |
manakai_expanded_uri => undef, |
475 |
first_child => undef, |
first_child => undef, |
476 |
implementation => $dom, |
implementation => $dom, |
477 |
|
internal_subset => '', |
478 |
last_child => undef, |
last_child => undef, |
479 |
local_name => undef, |
local_name => undef, |
480 |
manakai_local_name => undef, |
manakai_local_name => undef, |
487 |
parent_node => undef, |
parent_node => undef, |
488 |
prefix => undef, |
prefix => undef, |
489 |
previous_sibling => undef, |
previous_sibling => undef, |
490 |
public_id => undef, |
public_id => '', |
491 |
system_id => undef, |
system_id => '', |
492 |
}, |
}, |
493 |
attr_get_bool => { |
attr_get_bool => { |
494 |
has_attributes => 0, |
has_attributes => 0, |
499 |
element => { |
element => { |
500 |
node => sub { return $doc->create_element ('e') }, |
node => sub { return $doc->create_element ('e') }, |
501 |
attr_get => { |
attr_get => { |
|
## TODO: attributes => |
|
502 |
base_uri => undef, |
base_uri => undef, |
503 |
manakai_base_uri => undef, |
manakai_base_uri => undef, |
504 |
manakai_expanded_uri => 'e', |
manakai_expanded_uri => 'e', |
515 |
parent_node => undef, |
parent_node => undef, |
516 |
prefix => undef, |
prefix => undef, |
517 |
previous_sibling => undef, |
previous_sibling => undef, |
518 |
|
tag_name => 'e', |
519 |
}, |
}, |
520 |
attr_get_bool => { |
attr_get_bool => { |
521 |
has_attributes => 0, |
has_attributes => 0, |
526 |
element_ns_default => { |
element_ns_default => { |
527 |
node => sub { return $doc->create_element_ns ('http://test/', 'f') }, |
node => sub { return $doc->create_element_ns ('http://test/', 'f') }, |
528 |
attr_get => { |
attr_get => { |
|
## TODO: attributes => |
|
529 |
base_uri => undef, |
base_uri => undef, |
530 |
manakai_base_uri => undef, |
manakai_base_uri => undef, |
531 |
manakai_expanded_uri => 'http://test/f', |
manakai_expanded_uri => 'http://test/f', |
542 |
parent_node => undef, |
parent_node => undef, |
543 |
prefix => undef, |
prefix => undef, |
544 |
previous_sibling => undef, |
previous_sibling => undef, |
545 |
|
tag_name => 'f', |
546 |
}, |
}, |
547 |
attr_get_bool => { |
attr_get_bool => { |
548 |
has_attributes => 0, |
has_attributes => 0, |
553 |
element_ns_prefiexed => { |
element_ns_prefiexed => { |
554 |
node => sub { return $doc->create_element_ns ('http://test/', 'e:f') }, |
node => sub { return $doc->create_element_ns ('http://test/', 'e:f') }, |
555 |
attr_get => { |
attr_get => { |
|
## TODO: attributes => |
|
556 |
base_uri => undef, |
base_uri => undef, |
557 |
manakai_base_uri => undef, |
manakai_base_uri => undef, |
558 |
manakai_expanded_uri => 'http://test/f', |
manakai_expanded_uri => 'http://test/f', |
569 |
parent_node => undef, |
parent_node => undef, |
570 |
prefix => 'e', |
prefix => 'e', |
571 |
previous_sibling => undef, |
previous_sibling => undef, |
572 |
|
tag_name => 'e:f', |
573 |
}, |
}, |
574 |
attr_get_bool => { |
attr_get_bool => { |
575 |
has_attributes => 0, |
has_attributes => 0, |
594 |
node_value => undef, |
node_value => undef, |
595 |
notation_name => undef, |
notation_name => undef, |
596 |
owner_document => $doc, |
owner_document => $doc, |
597 |
|
owner_document_type_definition => undef, |
598 |
parent_node => undef, |
parent_node => undef, |
599 |
previous_sibling => undef, |
previous_sibling => undef, |
600 |
public_id => undef, |
public_id => undef, |
652 |
node_type => 12, |
node_type => 12, |
653 |
node_value => undef, |
node_value => undef, |
654 |
owner_document => $doc, |
owner_document => $doc, |
655 |
|
owner_document_type_definition => undef, |
656 |
parent_node => undef, |
parent_node => undef, |
657 |
prefix => undef, |
prefix => undef, |
658 |
previous_sibling => undef, |
previous_sibling => undef, |
735 |
node_type => 81001, |
node_type => 81001, |
736 |
node_value => undef, |
node_value => undef, |
737 |
owner_document => $doc, |
owner_document => $doc, |
738 |
|
owner_document_type_definition => undef, |
739 |
parent_node => undef, |
parent_node => undef, |
740 |
prefix => undef, |
prefix => undef, |
741 |
previous_sibling => undef, |
previous_sibling => undef, |
762 |
next_sibling => undef, |
next_sibling => undef, |
763 |
node_name => 'e', |
node_name => 'e', |
764 |
node_type => 81002, |
node_type => 81002, |
765 |
node_value => undef, |
node_value => '', |
766 |
owner_document => $doc, |
owner_document => $doc, |
767 |
|
owner_element_type_definition => undef, |
768 |
parent_node => undef, |
parent_node => undef, |
769 |
prefix => undef, |
prefix => undef, |
770 |
previous_sibling => undef, |
previous_sibling => undef, |
771 |
|
text_content => '', |
772 |
}, |
}, |
773 |
attr_get_bool => { |
attr_get_bool => { |
774 |
has_attributes => 0, |
has_attributes => 0, |
805 |
|
|
806 |
## Child node accessors' tests |
## Child node accessors' tests |
807 |
for my $parent (create_parent_nodes ()) { |
for my $parent (create_parent_nodes ()) { |
808 |
|
my $doc = $parent->owner_document || $parent; |
809 |
my $node1; |
my $node1; |
810 |
my $node2; |
my $node2; |
811 |
my $node3; |
my $node3; |
823 |
$node3 = $doc->create_text_node ('text3'); |
$node3 = $doc->create_text_node ('text3'); |
824 |
} |
} |
825 |
|
|
826 |
|
$parent->manakai_set_read_only (0, 1); |
827 |
$parent->append_child ($node1); |
$parent->append_child ($node1); |
828 |
ok $parent->first_child, $node1, $parent->node_name."->first_child [1]"; |
ok $parent->first_child, $node1, $parent->node_name."->first_child [1]"; |
829 |
ok $parent->last_child, $node1, $parent->node_name."->last_child [1]"; |
ok $parent->last_child, $node1, $parent->node_name."->last_child [1]"; |
1151 |
ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]'; |
ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]'; |
1152 |
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]'; |
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]'; |
1153 |
|
|
1154 |
my $er = $doc->create_entity_reference ('er'); |
my $er = ($node->owner_document || $node)->create_entity_reference ('er'); |
1155 |
$node->append_child ($er); |
$node->append_child ($er); |
1156 |
|
|
1157 |
$node->manakai_append_text ('text'); |
$node->manakai_append_text ('text'); |
1270 |
]->[$i]; |
]->[$i]; |
1271 |
|
|
1272 |
my $doc2 = $doc->implementation->create_document; |
my $doc2 = $doc->implementation->create_document; |
1273 |
|
$doc2->strict_error_checking (0); |
1274 |
|
|
1275 |
my $el = $doc2->create_element_ns (undef, 'el'); |
my $el = $doc2->create_element_ns (undef, 'el'); |
1276 |
|
|
1831 |
[unknown => '', 0], |
[unknown => '', 0], |
1832 |
[unknown => undef, 0], |
[unknown => undef, 0], |
1833 |
['+unknown' => undef, 0], |
['+unknown' => undef, 0], |
1834 |
|
[q<http://suika.fam.cx/www/2006/feature/xdoctype> => '', 1], |
1835 |
|
[q<http://suika.fam.cx/www/2006/feature/xdoctype> => '3.0', 1], |
1836 |
) { |
) { |
1837 |
my $label = $node->node_name . ' ' . $_->[0] . ', ' . |
my $label = $node->node_name . ' ' . $_->[0] . ', ' . |
1838 |
(defined $_->[1] ? $_->[1] : 'undef'); |
(defined $_->[1] ? $_->[1] : 'undef'); |
1916 |
ok $node->get_user_data ('key1'), undef, 'set_user_data [7]'; |
ok $node->get_user_data ('key1'), undef, 'set_user_data [7]'; |
1917 |
} |
} |
1918 |
|
|
1919 |
|
## |removeChild| |
1920 |
|
{ |
1921 |
|
my $el = $doc->create_element ('p'); |
1922 |
|
my $c1 = $doc->create_element ('e'); |
1923 |
|
$el->append_child ($c1); |
1924 |
|
my $c2 = $doc->create_element ('f'); |
1925 |
|
$el->append_child ($c2); |
1926 |
|
my $c3 = $doc->create_element ('g'); |
1927 |
|
$el->append_child ($c3); |
1928 |
|
ok $el->can ('remove_child') ? 1 : 0, 1, 'Node->remove_child can [0]'; |
1929 |
|
|
1930 |
|
my $return = $el->remove_child ($c1); |
1931 |
|
ok $return, $c1, 'Node->remove_child return [1]'; |
1932 |
|
ok $c1->parent_node, undef, 'Node->remove_child parent_node [1]'; |
1933 |
|
ok $el->first_child, $c2, 'Node->remove_child first_child [1]'; |
1934 |
|
ok $el->last_child, $c3, 'Node->remove_child last_child [1]'; |
1935 |
|
ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [1]'; |
1936 |
|
} |
1937 |
|
{ |
1938 |
|
my $el = $doc->create_element ('p'); |
1939 |
|
my $c1 = $doc->create_element ('e'); |
1940 |
|
$el->append_child ($c1); |
1941 |
|
my $c2 = $doc->create_element ('f'); |
1942 |
|
$el->append_child ($c2); |
1943 |
|
my $c3 = $doc->create_element ('g'); |
1944 |
|
$el->append_child ($c3); |
1945 |
|
|
1946 |
|
my $return = $el->remove_child ($c2); |
1947 |
|
ok $return, $c2, 'Node->remove_child return [2]'; |
1948 |
|
ok $c2->parent_node, undef, 'Node->remove_child parent_node [2]'; |
1949 |
|
ok $el->first_child, $c1, 'Node->remove_child first_child [2]'; |
1950 |
|
ok $el->last_child, $c3, 'Node->remove_child last_child [2]'; |
1951 |
|
ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [2]'; |
1952 |
|
} |
1953 |
|
{ |
1954 |
|
my $el = $doc->create_element ('p'); |
1955 |
|
my $c1 = $doc->create_element ('e'); |
1956 |
|
$el->append_child ($c1); |
1957 |
|
my $c2 = $doc->create_element ('f'); |
1958 |
|
$el->append_child ($c2); |
1959 |
|
my $c3 = $doc->create_element ('g'); |
1960 |
|
$el->append_child ($c3); |
1961 |
|
|
1962 |
|
my $return = $el->remove_child ($c3); |
1963 |
|
ok $return, $c3, 'Node->remove_child return [3]'; |
1964 |
|
ok $c3->parent_node, undef, 'Node->remove_child parent_node [3]'; |
1965 |
|
ok $el->first_child, $c1, 'Node->remove_child first_child [3]'; |
1966 |
|
ok $el->last_child, $c2, 'Node->remove_child last_child [3]'; |
1967 |
|
ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [3]'; |
1968 |
|
} |
1969 |
|
{ |
1970 |
|
my $el = $doc->create_element ('p'); |
1971 |
|
my $c1 = $doc->create_element ('e'); |
1972 |
|
$el->append_child ($c1); |
1973 |
|
|
1974 |
|
my $return = $el->remove_child ($c1); |
1975 |
|
ok $return, $c1, 'Node->remove_child return [4]'; |
1976 |
|
ok $c1->parent_node, undef, 'Node->remove_child parent_node [4]'; |
1977 |
|
ok $el->first_child, undef, 'Node->remove_child first_child [4]'; |
1978 |
|
ok $el->last_child, undef, 'Node->remove_child last_child [4]'; |
1979 |
|
ok 0+@{$el->child_nodes}, 0, 'Node->remove_child child_nodes [4]'; |
1980 |
|
} |
1981 |
|
|
1982 |
|
## |appendChild|, |insertBefore|, |replaceChild| |
1983 |
|
for my $node (create_leaf_nodes) { |
1984 |
|
for my $method_name (qw/append_child insert_before replace_child/) { |
1985 |
|
ok $node->can ($method_name) ? 1 : 0, 1, |
1986 |
|
$node->node_name . '->can ' . $method_name; |
1987 |
|
|
1988 |
|
for my $node2 (create_nodes) { |
1989 |
|
try { |
1990 |
|
if ($method_name eq 'replace_child') { |
1991 |
|
$node->replace_child ($node2, $node2); |
1992 |
|
} else { |
1993 |
|
$node->$method_name ($node2); |
1994 |
|
} |
1995 |
|
ok 1, 0, |
1996 |
|
$node->node_name . '->' . $method_name . ' ' . $node2->node_name; |
1997 |
|
} catch Message::IF::DOMException with { |
1998 |
|
if ($_[0]->type eq 'HIERARCHY_REQUEST_ERR' or |
1999 |
|
($_[0]->type eq 'WRONG_DOCUMENT_ERR' and |
2000 |
|
($node2->owner_document or $node2) ne $doc) or |
2001 |
|
($_[0]->type eq 'NOT_FOUND_ERR' and |
2002 |
|
$method_name eq 'replace_child')) { |
2003 |
|
ok 1, 1, |
2004 |
|
$node->node_name . '->' . $method_name . ' ' . $node2->node_name; |
2005 |
|
} |
2006 |
|
}; |
2007 |
|
} |
2008 |
|
} |
2009 |
|
} |
2010 |
|
|
2011 |
## TODO: parent_node tests, as with append_child tests |
## TODO: parent_node tests, as with append_child tests |
2012 |
|
|
2013 |
## TODO: text_content tests for CharacterData and PI |
## TODO: text_content tests for CharacterData and PI |