/[suikacvs]/messaging/manakai/t/DOM-Node.t
Suika

Diff of /messaging/manakai/t/DOM-Node.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by wakaba, Sat Jul 7 09:11:05 2007 UTC revision 1.17 by wakaba, Sat Jul 14 10:28:52 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2  use strict;  use strict;
3  use Test;  use Test;
4  BEGIN { plan tests => 2754 }  BEGIN { plan tests => 4918 }
5    
6  require Message::DOM::DOMImplementation;  require Message::DOM::DOMImplementation;
7  use Message::Util::Error;  use Message::Util::Error;
# Line 42  sub create_parent_nodes () { Line 42  sub create_parent_nodes () {
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],
# Line 65  my $constants = [ Line 75  my $constants = [
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 = {
# Line 94  my $tests = { Line 110  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,
115        specified => 1,        specified => 1,
116      },      },
117    },    },
# Line 125  my $tests = { Line 143  my $tests = {
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,
148        specified => 1,        specified => 1,
149      },      },
150    },    },
# Line 151  my $tests = { Line 171  my $tests = {
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,
176        specified => 1,        specified => 1,
177      },      },
178    },    },
# Line 177  my $tests = { Line 199  my $tests = {
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,
204        specified => 1,        specified => 1,
205      },      },
206    },    },
# Line 203  my $tests = { Line 227  my $tests = {
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,
232        specified => 1,        specified => 1,
233      },      },
234    },    },
# Line 230  my $tests = { Line 256  my $tests = {
256      attr_get_bool => {      attr_get_bool => {
257        has_attributes => 0,        has_attributes => 0,
258        has_child_nodes => 0,        has_child_nodes => 0,
259          is_element_content_whitespace => 0,
260          manakai_read_only => 0,
261      },      },
262    },    },
263    cdatasectionmde => {    cdatasectionmde => {
# Line 256  my $tests = { Line 284  my $tests = {
284      attr_get_bool => {      attr_get_bool => {
285        has_attributes => 0,        has_attributes => 0,
286        has_child_nodes => 0,        has_child_nodes => 0,
287          is_element_content_whitespace => 0,
288          manakai_read_only => 0,
289      },      },
290    },    },
291    comment => {    comment => {
# Line 282  my $tests = { Line 312  my $tests = {
312      attr_get_bool => {      attr_get_bool => {
313        has_attributes => 0,        has_attributes => 0,
314        has_child_nodes => 0,        has_child_nodes => 0,
315          manakai_read_only => 0,
316      },      },
317    },    },
318    commentcom1 => {    commentcom1 => {
# Line 308  my $tests = { Line 339  my $tests = {
339      attr_get_bool => {      attr_get_bool => {
340        has_attributes => 0,        has_attributes => 0,
341        has_child_nodes => 0,        has_child_nodes => 0,
342          manakai_read_only => 0,
343      },      },
344    },    },
345    commentcom2 => {    commentcom2 => {
# Line 334  my $tests = { Line 366  my $tests = {
366      attr_get_bool => {      attr_get_bool => {
367        has_attributes => 0,        has_attributes => 0,
368        has_child_nodes => 0,        has_child_nodes => 0,
369          manakai_read_only => 0,
370      },      },
371    },    },
372    document => {    document => {
# Line 366  my $tests = { Line 399  my $tests = {
399        has_attributes => 0,        has_attributes => 0,
400        has_child_nodes => 0,        has_child_nodes => 0,
401        manakai_is_html => 0,        manakai_is_html => 0,
402          manakai_read_only => 0,
403        strict_error_checking => 1,        strict_error_checking => 1,
404        xml_standalone => 0,        xml_standalone => 0,
405      },      },
# Line 393  my $tests = { Line 427  my $tests = {
427      attr_get_bool => {      attr_get_bool => {
428        has_attributes => 0,        has_attributes => 0,
429        has_child_nodes => 0,        has_child_nodes => 0,
430          manakai_read_only => 0,
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,
# Line 405  my $tests = { Line 442  my $tests = {
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,
# Line 417  my $tests = { Line 455  my $tests = {
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,
463        has_child_nodes => 0,        has_child_nodes => 0,
464          manakai_read_only => 1,
465      },      },
466    },    },
467    document_type_definition => {    document_type_definition => {
# Line 435  my $tests = { Line 474  my $tests = {
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,
# Line 447  my $tests = { Line 487  my $tests = {
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,
495        has_child_nodes => 0,        has_child_nodes => 0,
496          manakai_read_only => 0,
497      },      },
498    },    },
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',
# Line 475  my $tests = { Line 515  my $tests = {
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,
522        has_child_nodes => 0,        has_child_nodes => 0,
523          manakai_read_only => 0,
524      },      },
525    },    },
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',
# Line 501  my $tests = { Line 542  my $tests = {
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,
549        has_child_nodes => 0,        has_child_nodes => 0,
550          manakai_read_only => 0,
551      },      },
552    },    },
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',
# Line 527  my $tests = { Line 569  my $tests = {
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,
576        has_child_nodes => 0,        has_child_nodes => 0,
577          manakai_read_only => 0,
578      },      },
579    },    },
580    entity => {    entity => {
# Line 550  my $tests = { Line 594  my $tests = {
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,
# Line 558  my $tests = { Line 603  my $tests = {
603      attr_get_bool => {      attr_get_bool => {
604        has_attributes => 0,        has_attributes => 0,
605        has_child_nodes => 0,        has_child_nodes => 0,
606          manakai_read_only => 0,
607      },      },
608    },    },
609    entity_reference => {    entity_reference => {
# Line 586  my $tests = { Line 632  my $tests = {
632        manakai_external => 0,        manakai_external => 0,
633        has_attributes => 0,        has_attributes => 0,
634        has_child_nodes => 0,        has_child_nodes => 0,
635          manakai_read_only => 1,
636      },      },
637    },    },
638    notation => {    notation => {
# Line 605  my $tests = { Line 652  my $tests = {
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,
# Line 614  my $tests = { Line 662  my $tests = {
662      attr_get_bool => {      attr_get_bool => {
663        has_attributes => 0,        has_attributes => 0,
664        has_child_nodes => 0,        has_child_nodes => 0,
665          manakai_read_only => 0,
666      },      },
667    },    },
668    processing_instruction => {    processing_instruction => {
# Line 640  my $tests = { Line 689  my $tests = {
689      attr_get_bool => {      attr_get_bool => {
690        has_attributes => 0,        has_attributes => 0,
691        has_child_nodes => 0,        has_child_nodes => 0,
692          manakai_read_only => 0,
693      },      },
694    },    },
695    text => {    text => {
# Line 665  my $tests = { Line 715  my $tests = {
715      attr_get_bool => {      attr_get_bool => {
716        has_attributes => 0,        has_attributes => 0,
717        has_child_nodes => 0,        has_child_nodes => 0,
718          is_element_content_whitespace => 0,
719          manakai_read_only => 0,
720      },      },
721    },    },
722    element_type_definition => {    element_type_definition => {
# Line 683  my $tests = { Line 735  my $tests = {
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,
# Line 690  my $tests = { Line 743  my $tests = {
743      attr_get_bool => {      attr_get_bool => {
744        has_attributes => 0,        has_attributes => 0,
745        has_child_nodes => 0,        has_child_nodes => 0,
746          manakai_read_only => 0,
747      },      },
748    },    },
749    attribute_definition => {    attribute_definition => {
# Line 708  my $tests = { Line 762  my $tests = {
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,
775        has_child_nodes => 0,        has_child_nodes => 0,
776          manakai_read_only => 0,
777      },      },
778    },    },
779  };  };
# Line 748  for my $test_id (sort {$a cmp $b} keys % Line 805  for my $test_id (sort {$a cmp $b} keys %
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;
# Line 765  for my $parent (create_parent_nodes ()) Line 823  for my $parent (create_parent_nodes ())
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]";
# Line 1092  for my $node (create_nodes ()) { Line 1151  for my $node (create_nodes ()) {
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');
# Line 1211  for my $i (0..1) { Line 1270  for my $i (0..1) {
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    
# Line 1745  for (qw/create_text_node create_cdata_se Line 1805  for (qw/create_text_node create_cdata_se
1805    ok 0+@{$el->child_nodes}, 1, 'normalize [21]';    ok 0+@{$el->child_nodes}, 1, 'normalize [21]';
1806  }  }
1807    
1808    ## |getFeature| and |isSupported|
1809    for my $node (create_nodes ()) {
1810      for (
1811           [Core => '1.0', 1],
1812           [Core => '2.0', 1],
1813           [Core => '3.0', 1],
1814           ['+Core' => '3.0', 1],
1815           ['++Core' => '3.0', 0],
1816           [Core => '', 1],
1817           [Core => undef, 1],
1818           [Core => 3, 0],
1819           [XML => '1.0', 1],
1820           [XML => '2.0', 1],
1821           [XML => '3.0', 1],
1822           [XML => '', 1],
1823           [XML => undef, 1],
1824           ['+XML' => undef, 1],
1825           [XMLVersion => '1.0', 1],
1826           [XMLVersion => '1.1', 1],
1827           [XMLVersion => '', 1],
1828           [XMLVersion => undef, 1],
1829           ['+XMLVersion' => undef, 1],
1830           [unknown => 3, 0],
1831           [unknown => '', 0],
1832           [unknown => undef, 0],
1833           ['+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] . ', ' .
1838            (defined $_->[1] ? $_->[1] : 'undef');
1839        ok $node->can ('get_feature') ? 1 : 0, 1, 'can get_feature ' . $label;
1840        ok $node->get_feature ($_->[0], $_->[1]), $_->[2] ? $node : undef,
1841            'get_feature ' . $label;
1842        ok $node->can ('is_supported') ? 1 : 0, 1, 'can is_supported ' . $label;
1843        ok $node->is_supported ($_->[0], $_->[1]) ? 1 : 0, $_->[2],
1844            'is_supported ' . $label;
1845      }
1846    }
1847    
1848    ## |isEqualNode|
1849    for my $node (create_nodes ()) {
1850      ok $node->can ('is_equal_node') ? 1 : 0, 1, $node->node_name . '->is_eq_n can';
1851    
1852      ok $node->is_equal_node ($node) ? 1 : 0, 1, $node->node_name . '->iseq self';
1853      ok $node == $node ? 1 : 0, 1, $node->node_name . ' == self';
1854      ok $node != $node ? 1 : 0, 0, $node->node_name . ' != self';
1855      ok $node == 'node' ? 1 : 0, 0, $node->node_name . ' == string';
1856      ok $node != 'node' ? 1 : 0, 1, $node->node_name . ' != string';
1857      ok $node == 0 ? 1 : 0, 0, $node->node_name . ' == num';
1858      ok $node != 0 ? 1 : 0, 1, $node->node_name . ' != num';
1859      ok $node == '' ? 1 : 0, 0, $node->node_name . ' == empty';
1860      ok $node != '' ? 1 : 0, 1, $node->node_name . ' != empty';
1861      ok $node == undef () ? 1 : 0, 0, $node->node_name . ' == undef';
1862      ok $node != undef () ? 1 : 0, 1, $node->node_name . ' != undef';
1863    }
1864    
1865    {
1866      my $el1 = $doc->create_element_ns (undef, 'type');
1867      my $el2 = $doc->create_element_ns (undef, 'type');
1868      my $el3 = $doc->create_element_ns (undef, 'TYPE');
1869    
1870      ok $el1 == $el2 ? 1 : 0, 1, 'Element == [1]';
1871      ok $el1 != $el2 ? 1 : 0, 0, 'Element != [1]';
1872      ok $el1 == $el3 ? 1 : 0, 0, 'Element == [2]';
1873      ok $el1 != $el3 ? 1 : 0, 1, 'Element != [2]';
1874    
1875      my $el4 = $doc->create_element_ns ('about:', 'type');
1876      my $el5 = $doc->create_element_ns ('about:', 'type');
1877      my $el6 = $doc->create_element_ns ('about:', 'TYPE');
1878      my $el7 = $doc->create_element_ns ('DAV:', 'type');
1879    
1880      ok $el1 == $el4 ? 1 : 0, 0, 'Element == [3]';
1881      ok $el1 != $el4 ? 1 : 0, 1, 'Element != [3]';
1882      ok $el4 == $el5 ? 1 : 0, 1, 'Element == [4]';
1883      ok $el4 != $el5 ? 1 : 0, 0, 'Element != [4]';
1884      ok $el4 == $el6 ? 1 : 0, 0, 'Element == [5]';
1885      ok $el4 != $el6 ? 1 : 0, 1, 'Element != [5]';
1886      ok $el4 == $el7 ? 1 : 0, 0, 'Element == [6]';
1887      ok $el4 != $el7 ? 1 : 0, 1, 'Element != [6]';
1888    
1889      $el5->prefix ('prefix');
1890      ok $el4 == $el5 ? 1 : 0, 0, 'Element == [7]';
1891      ok $el4 != $el5 ? 1 : 0, 1, 'Element != [7]';
1892    }
1893    
1894    ## |getUserData|, |setUserData|
1895    {
1896      my $node = $dom->create_document;
1897    
1898      my $data = ['2'];
1899      my $handler = sub { 1 };
1900    
1901      ok $node->set_user_data ('key1', $data, $handler), undef,
1902          'set_user_data [1]';
1903      
1904      my $key1_data = $node->get_user_data ('key1');
1905      ok $key1_data, $data, 'set_user_data [2]';
1906      ok $key1_data->[0], $data->[0], 'set_user_data [3]';
1907    
1908      my $data2 = ['4'];
1909      ok $node->set_user_data ('key1', $data2, undef), $data, 'set_user_data [4]';
1910      ok $node->get_user_data ('key1'), $data2, 'set_user_data [5]';
1911    
1912      $node->set_user_data (key1 => undef, $handler);
1913      ok $node->get_user_data ('key1'), undef, 'set_user_data [6]';
1914    
1915      $node->set_user_data (key1 => undef, undef);
1916      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
2014    
2015    ## |UserDataHandler|, |setData|, and |NODE_DELETED|
2016    ## NOTE: This should be the last test, since it does define
2017    ## Node.DESTORY.
2018    {
2019      my $doc = $dom->create_document ('http://test/', 'ex');
2020      my $node = $doc->document_element;
2021      
2022      $node->set_user_data (key => {}, sub {
2023        my ($op, $key, $data, $src, $dest) = @_;
2024    
2025        ok $op, 3, 'set_user_data operation [8]'; # NODE_DELETED
2026        ok $key, 'key', 'set_user_data key [8]';
2027        ok ref $data, 'HASH', 'set_user_data data [8]';
2028        ok $src, undef, 'set_user_data src [8]';
2029        ok $dest, undef, 'set_user_data dest [8]';
2030      });
2031    
2032      undef $node;
2033      undef $doc;
2034    
2035      ## NOTE: We cannot control exactly when it is called.
2036    }
2037    
2038  =head1 LICENSE  =head1 LICENSE
2039    
2040  Copyright 2007 Wakaba <w@suika.fam.cx>  Copyright 2007 Wakaba <w@suika.fam.cx>

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.17

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24