/[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.4 by wakaba, Sun Jun 17 13:37:42 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 => 1921 }  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 58  my $constants = [ Line 68  my $constants = [
68    [NOTATION_NODE => 12],    [NOTATION_NODE => 12],
69    [ELEMENT_TYPE_DEFINITION_NODE => 81001],    [ELEMENT_TYPE_DEFINITION_NODE => 81001],
70    [ATTRIBUTE_DEFINITION_NODE => 81002],    [ATTRIBUTE_DEFINITION_NODE => 81002],
71    
72      [DOCUMENT_POSITION_DISCONNECTED => 0x01],
73      [DOCUMENT_POSITION_PRECEDING => 0x02],
74      [DOCUMENT_POSITION_FOLLOWING => 0x04],
75      [DOCUMENT_POSITION_CONTAINS => 0x08],
76      [DOCUMENT_POSITION_CONTAINED_BY => 0x10],
77      [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 66  my $tests = { Line 89  my $tests = {
89      attr_get => {      attr_get => {
90        manakai_attribute_type => 0,        manakai_attribute_type => 0,
91        base_uri => undef,        base_uri => undef,
92          manakai_expanded_uri => 'a',
93        first_child => undef,        first_child => undef,
94        last_child => undef,        last_child => undef,
95        local_name => 'a',        local_name => 'a',
# Line 73  my $tests = { Line 97  my $tests = {
97        namespace_uri => undef,        namespace_uri => undef,
98        next_sibling => undef,        next_sibling => undef,
99        node_name => 'a',        node_name => 'a',
100          node_type => 2,
101        name => 'a',        name => 'a',
102        node_value => '',        node_value => '',
103        owner_document => $doc,        owner_document => $doc,
# Line 83  my $tests = { Line 108  my $tests = {
108        attributes => undef,        attributes => undef,
109      },      },
110      attr_get_bool => {      attr_get_bool => {
111          has_attributes => 0,
112          has_child_nodes => 0,
113          is_id => 0,
114          manakai_read_only => 0,
115        specified => 1,        specified => 1,
116      },      },
117    },    },
# Line 95  my $tests = { Line 124  my $tests = {
124      attr_get => {      attr_get => {
125        manakai_attribute_type => 0,        manakai_attribute_type => 0,
126        base_uri => undef,        base_uri => undef,
127          manakai_expanded_uri => 'a',
128        local_name => 'a',        local_name => 'a',
129        manakai_local_name => 'a',        manakai_local_name => 'a',
130        namespace_uri => undef,        namespace_uri => undef,
131        next_sibling => undef,        next_sibling => undef,
132        node_name => 'a',        node_name => 'a',
133          node_type => 2,
134        name => 'a',        name => 'a',
135        node_value => 'b',        node_value => 'b',
136        owner_document => $doc,        owner_document => $doc,
# Line 110  my $tests = { Line 141  my $tests = {
141        attributes => undef,        attributes => undef,
142      },      },
143      attr_get_bool => {      attr_get_bool => {
144          has_attributes => 0,
145          has_child_nodes => 1,
146          is_id => 0,
147          manakai_read_only => 0,
148        specified => 1,        specified => 1,
149      },      },
150    },    },
# Line 117  my $tests = { Line 152  my $tests = {
152      node => sub { return $doc->create_attribute_ns (undef, 'a') },      node => sub { return $doc->create_attribute_ns (undef, 'a') },
153      attr_get => {      attr_get => {
154        base_uri => undef,        base_uri => undef,
155          manakai_expanded_uri => 'a',
156        local_name => 'a',        local_name => 'a',
157        manakai_local_name => 'a',        manakai_local_name => 'a',
158        namespace_uri => undef,        namespace_uri => undef,
159        next_sibling => undef,        next_sibling => undef,
160        node_name => 'a',        node_name => 'a',
161          node_type => 2,
162        name => 'a',        name => 'a',
163        node_value => '',        node_value => '',
164        owner_document => $doc,        owner_document => $doc,
# Line 131  my $tests = { Line 168  my $tests = {
168        attributes => undef,        attributes => undef,
169        previous_sibling => undef,        previous_sibling => undef,
170      },      },
171        attr_get_bool => {
172          has_attributes => 0,
173          has_child_nodes => 0,
174          is_id => 0,
175          manakai_read_only => 0,
176          specified => 1,
177        },
178    },    },
179    attr_ns_prefixed => {    attr_ns_prefixed => {
180      node => sub { return $doc->create_attribute_ns ('http://test/', 'a:b') },      node => sub { return $doc->create_attribute_ns ('http://test/', 'a:b') },
181      attr_get => {      attr_get => {
182        base_uri => undef,        base_uri => undef,
183          manakai_expanded_uri => 'http://test/b',
184        local_name => 'b',        local_name => 'b',
185        manakai_local_name => 'b',        manakai_local_name => 'b',
186        namespace_uri => 'http://test/',        namespace_uri => 'http://test/',
187        next_sibling => undef,        next_sibling => undef,
188        node_name => 'a:b',        node_name => 'a:b',
189          node_type => 2,
190        name => 'a:b',        name => 'a:b',
191        node_value => '',        node_value => '',
192        owner_document => $doc,        owner_document => $doc,
# Line 150  my $tests = { Line 196  my $tests = {
196        attributes => undef,        attributes => undef,
197        previous_sibling => undef,        previous_sibling => undef,
198      },      },
199        attr_get_bool => {
200          has_attributes => 0,
201          has_child_nodes => 0,
202          is_id => 0,
203          manakai_read_only => 0,
204          specified => 1,
205        },
206      },
207      attr_ns_prefixed_array => {
208        node => sub { $doc->create_attribute_ns ('http://test/', ['a', 'b']) },
209        attr_get => {
210          base_uri => undef,
211          manakai_expanded_uri => 'http://test/b',
212          local_name => 'b',
213          manakai_local_name => 'b',
214          namespace_uri => 'http://test/',
215          next_sibling => undef,
216          node_name => 'a:b',
217          node_type => 2,
218          name => 'a:b',
219          node_value => '',
220          owner_document => $doc,
221          parent_node => undef,
222          prefix => 'a',
223          value => '',
224          attributes => undef,
225          previous_sibling => undef,
226        },
227        attr_get_bool => {
228          has_attributes => 0,
229          has_child_nodes => 0,
230          is_id => 0,
231          manakai_read_only => 0,
232          specified => 1,
233        },
234    },    },
235    cdatasection => {    cdatasection => {
236      node => sub { return $doc->create_cdata_section ('cdatadata') },      node => sub { return $doc->create_cdata_section ('cdatadata') },
237      attr_get => {      attr_get => {
238        base_uri => undef,        base_uri => undef,
239          manakai_expanded_uri => undef,
240        first_child => undef,        first_child => undef,
241        last_child => undef,        last_child => undef,
242        local_name => undef,        local_name => undef,
# Line 162  my $tests = { Line 244  my $tests = {
244        namespace_uri => undef,        namespace_uri => undef,
245        next_sibling => undef,        next_sibling => undef,
246        node_name => '#cdata-section',        node_name => '#cdata-section',
247          node_type => 4,
248        node_value => 'cdatadata',        node_value => 'cdatadata',
249        owner_document => $doc,        owner_document => $doc,
250        parent_node => undef,        parent_node => undef,
# Line 170  my $tests = { Line 253  my $tests = {
253        attributes => undef,        attributes => undef,
254        previous_sibling => undef,        previous_sibling => undef,
255      },      },
256        attr_get_bool => {
257          has_attributes => 0,
258          has_child_nodes => 0,
259          is_element_content_whitespace => 0,
260          manakai_read_only => 0,
261        },
262    },    },
263    cdatasectionmde => {    cdatasectionmde => {
264      node => sub { return $doc->create_cdata_section ('cdata]]>data') },      node => sub { return $doc->create_cdata_section ('cdata]]>data') },
265      attr_get => {      attr_get => {
266        base_uri => undef,        base_uri => undef,
267          manakai_expanded_uri => undef,
268        first_child => undef,        first_child => undef,
269        last_child => undef,        last_child => undef,
270        local_name => undef,        local_name => undef,
# Line 182  my $tests = { Line 272  my $tests = {
272        namespace_uri => undef,        namespace_uri => undef,
273        next_sibling => undef,        next_sibling => undef,
274        node_name => '#cdata-section',        node_name => '#cdata-section',
275          node_type => 4,
276        node_value => 'cdata]]>data',        node_value => 'cdata]]>data',
277        owner_document => $doc,        owner_document => $doc,
278        parent_node => undef,        parent_node => undef,
# Line 190  my $tests = { Line 281  my $tests = {
281        attributes => undef,        attributes => undef,
282        previous_sibling => undef,        previous_sibling => undef,
283      },      },
284        attr_get_bool => {
285          has_attributes => 0,
286          has_child_nodes => 0,
287          is_element_content_whitespace => 0,
288          manakai_read_only => 0,
289        },
290    },    },
291    comment => {    comment => {
292      node => sub { return $doc->create_comment ('commentdata') },      node => sub { return $doc->create_comment ('commentdata') },
293      attr_get => {      attr_get => {
294        base_uri => undef,        base_uri => undef,
295          manakai_expanded_uri => undef,
296        first_child => undef,        first_child => undef,
297        last_child => undef,        last_child => undef,
298        local_name => undef,        local_name => undef,
# Line 202  my $tests = { Line 300  my $tests = {
300        namespace_uri => undef,        namespace_uri => undef,
301        next_sibling => undef,        next_sibling => undef,
302        node_name => '#comment',        node_name => '#comment',
303          node_type => 8,
304        node_value => 'commentdata',        node_value => 'commentdata',
305        owner_document => $doc,        owner_document => $doc,
306        parent_node => undef,        parent_node => undef,
# Line 209  my $tests = { Line 308  my $tests = {
308        data => 'commentdata',        data => 'commentdata',
309        attributes => undef,        attributes => undef,
310        previous_sibling => undef,        previous_sibling => undef,
311        },
312        attr_get_bool => {
313          has_attributes => 0,
314          has_child_nodes => 0,
315          manakai_read_only => 0,
316      },      },
317    },    },
318    commentcom1 => {    commentcom1 => {
319      node => sub { return $doc->create_comment ('comment--data') },      node => sub { return $doc->create_comment ('comment--data') },
320      attr_get => {      attr_get => {
321        base_uri => undef,        base_uri => undef,
322          manakai_expanded_uri => undef,
323        first_child => undef,        first_child => undef,
324        last_child => undef,        last_child => undef,
325        local_name => undef,        local_name => undef,
# Line 222  my $tests = { Line 327  my $tests = {
327        namespace_uri => undef,        namespace_uri => undef,
328        next_sibling => undef,        next_sibling => undef,
329        node_name => '#comment',        node_name => '#comment',
330          node_type => 8,
331        node_value => 'comment--data',        node_value => 'comment--data',
332        owner_document => $doc,        owner_document => $doc,
333        parent_node => undef,        parent_node => undef,
# Line 230  my $tests = { Line 336  my $tests = {
336        attributes => undef,        attributes => undef,
337        previous_sibling => undef,        previous_sibling => undef,
338      },      },
339        attr_get_bool => {
340          has_attributes => 0,
341          has_child_nodes => 0,
342          manakai_read_only => 0,
343        },
344    },    },
345    commentcom2 => {    commentcom2 => {
346      node => sub { return $doc->create_comment ('commentdata-') },      node => sub { return $doc->create_comment ('commentdata-') },
347      attr_get => {      attr_get => {
348        base_uri => undef,        base_uri => undef,
349          manakai_expanded_uri => undef,
350        first_child => undef,        first_child => undef,
351        last_child => undef,        last_child => undef,
352        local_name => undef,        local_name => undef,
# Line 242  my $tests = { Line 354  my $tests = {
354        namespace_uri => undef,        namespace_uri => undef,
355        next_sibling => undef,        next_sibling => undef,
356        node_name => '#comment',        node_name => '#comment',
357          node_type => 8,
358        node_value => 'commentdata-',        node_value => 'commentdata-',
359        owner_document => $doc,        owner_document => $doc,
360        parent_node => undef,        parent_node => undef,
# Line 250  my $tests = { Line 363  my $tests = {
363        attributes => undef,        attributes => undef,
364        previous_sibling => undef,        previous_sibling => undef,
365      },      },
366        attr_get_bool => {
367          has_attributes => 0,
368          has_child_nodes => 0,
369          manakai_read_only => 0,
370        },
371    },    },
372    document => {    document => {
373      node => sub { return $doc },      node => sub { return $doc },
# Line 258  my $tests = { Line 376  my $tests = {
376        base_uri => undef,        base_uri => undef,
377        document_uri => undef,        document_uri => undef,
378        manakai_entity_base_uri => undef,        manakai_entity_base_uri => undef,
379          manakai_expanded_uri => undef,
380        first_child => undef,        first_child => undef,
381        implementation => $dom,        implementation => $dom,
382        last_child => undef,        last_child => undef,
# Line 266  my $tests = { Line 385  my $tests = {
385        namespace_uri => undef,        namespace_uri => undef,
386        next_sibling => undef,        next_sibling => undef,
387        node_name => '#document',        node_name => '#document',
388          node_type => 9,
389        node_value => undef,        node_value => undef,
390        owner_document => undef,        owner_document => undef,
391        parent_node => undef,        parent_node => undef,
# Line 276  my $tests = { Line 396  my $tests = {
396      },      },
397      attr_get_bool => {      attr_get_bool => {
398        all_declarations_processed => 0,        all_declarations_processed => 0,
399          has_attributes => 0,
400          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 286  my $tests = { Line 409  my $tests = {
409      attr_get => {      attr_get => {
410        attributes => undef,        attributes => undef,
411        base_uri => undef,        base_uri => undef,
412          manakai_expanded_uri => undef,
413        first_child => undef,        first_child => undef,
414        last_child => undef,        last_child => undef,
415        local_name => undef,        local_name => undef,
# Line 293  my $tests = { Line 417  my $tests = {
417        namespace_uri => undef,        namespace_uri => undef,
418        next_sibling => undef,        next_sibling => undef,
419        node_name => '#document-fragment',        node_name => '#document-fragment',
420          node_type => 11,
421        node_value => undef,        node_value => undef,
422        owner_document => $doc,        owner_document => $doc,
423        parent_node => undef,        parent_node => undef,
424        prefix => undef,        prefix => undef,
425        previous_sibling => undef,        previous_sibling => undef,
426      },      },
427        attr_get_bool => {
428          has_attributes => 0,
429          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,
440        declaration_base_uri => undef,        declaration_base_uri => undef,
441        manakai_declaration_base_uri => undef,        manakai_declaration_base_uri => undef,
442          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,
449        namespace_uri => undef,        namespace_uri => undef,
450        next_sibling => undef,        next_sibling => undef,
451        node_name => 'n',        node_name => 'n',
452          node_type => 10,
453        node_value => undef,        node_value => undef,
454        owner_document => undef,        owner_document => 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 => {
462          has_attributes => 0,
463          has_child_nodes => 0,
464          manakai_read_only => 1,
465      },      },
466    },    },
467    document_type_definition => {    document_type_definition => {
# Line 331  my $tests = { Line 471  my $tests = {
471        base_uri => undef,        base_uri => undef,
472        declaration_base_uri => undef,        declaration_base_uri => undef,
473        manakai_declaration_base_uri => undef,        manakai_declaration_base_uri => undef,
474          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,
481        namespace_uri => undef,        namespace_uri => undef,
482        next_sibling => undef,        next_sibling => undef,
483        node_name => 'n',        node_name => 'n',
484          node_type => 10,
485        node_value => undef,        node_value => undef,
486        owner_document => $doc,        owner_document => $doc,
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 => {
494          has_attributes => 0,
495          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',
505        first_child => undef,        first_child => undef,
506        last_child => undef,        last_child => undef,
507        local_name => 'e',        local_name => 'e',
# Line 361  my $tests = { Line 509  my $tests = {
509        namespace_uri => undef,        namespace_uri => undef,
510        next_sibling => undef,        next_sibling => undef,
511        node_name => 'e',        node_name => 'e',
512          node_type => 1,
513        node_value => undef,        node_value => undef,
514        owner_document => $doc,        owner_document => $doc,
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 => {
521          has_attributes => 0,
522          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',
532        first_child => undef,        first_child => undef,
533        last_child => undef,        last_child => undef,
534        local_name => 'f',        local_name => 'f',
# Line 381  my $tests = { Line 536  my $tests = {
536        namespace_uri => 'http://test/',        namespace_uri => 'http://test/',
537        next_sibling => undef,        next_sibling => undef,
538        node_name => 'f',        node_name => 'f',
539          node_type => 1,
540        node_value => undef,        node_value => undef,
541        owner_document => $doc,        owner_document => $doc,
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 => {
548          has_attributes => 0,
549          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',
559        first_child => undef,        first_child => undef,
560        last_child => undef,        last_child => undef,
561        local_name => 'f',        local_name => 'f',
# Line 401  my $tests = { Line 563  my $tests = {
563        namespace_uri => 'http://test/',        namespace_uri => 'http://test/',
564        next_sibling => undef,        next_sibling => undef,
565        node_name => 'e:f',        node_name => 'e:f',
566          node_type => 1,
567        node_value => undef,        node_value => undef,
568        owner_document => $doc,        owner_document => $doc,
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 => {
575          has_attributes => 0,
576          has_child_nodes => 0,
577          manakai_read_only => 0,
578      },      },
579    },    },
580    entity => {    entity => {
# Line 416  my $tests = { Line 585  my $tests = {
585        manakai_declaration_base_uri => undef,        manakai_declaration_base_uri => undef,
586        manakai_entity_base_uri => undef,        manakai_entity_base_uri => undef,
587        manakai_entity_uri => undef,        manakai_entity_uri => undef,
588          manakai_expanded_uri => undef,
589        first_child => undef,        first_child => undef,
590        last_child => undef,        last_child => undef,
591        next_sibling => undef,        next_sibling => undef,
592        node_name => 'e',        node_name => 'e',
593          node_type => 6,
594        node_value => undef,        node_value => undef,
595          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,
601        system_id => undef,        system_id => undef,
602      },      },
603        attr_get_bool => {
604          has_attributes => 0,
605          has_child_nodes => 0,
606          manakai_read_only => 0,
607        },
608    },    },
609    entity_reference => {    entity_reference => {
610      node => sub { return $doc->create_entity_reference ('e') },      node => sub { return $doc->create_entity_reference ('e') },
# Line 434  my $tests = { Line 612  my $tests = {
612        attributes => undef,        attributes => undef,
613        base_uri => undef,        base_uri => undef,
614        manakai_entity_base_uri => undef,        manakai_entity_base_uri => undef,
615          manakai_expanded_uri => undef,
616        first_child => undef,        first_child => undef,
617        last_child => undef,        last_child => undef,
618        local_name => undef,        local_name => undef,
# Line 441  my $tests = { Line 620  my $tests = {
620        namespace_uri => undef,        namespace_uri => undef,
621        next_sibling => undef,        next_sibling => undef,
622        node_name => 'e',        node_name => 'e',
623          node_type => 5,
624        node_value => undef,        node_value => undef,
625        owner_document => $doc,        owner_document => $doc,
626        parent_node => undef,        parent_node => undef,
# Line 450  my $tests = { Line 630  my $tests = {
630      attr_get_bool => {      attr_get_bool => {
631        manakai_expanded => 0,        manakai_expanded => 0,
632        manakai_external => 0,        manakai_external => 0,
633          has_attributes => 0,
634          has_child_nodes => 0,
635          manakai_read_only => 1,
636      },      },
637    },    },
638    notation => {    notation => {
# Line 458  my $tests = { Line 641  my $tests = {
641        attributes => undef,        attributes => undef,
642        base_uri => undef,        base_uri => undef,
643        manakai_declaration_base_uri => undef,        manakai_declaration_base_uri => undef,
644          manakai_expanded_uri => undef,
645        first_child => undef,        first_child => undef,
646        last_child => undef,        last_child => undef,
647        local_name => undef,        local_name => undef,
# Line 465  my $tests = { Line 649  my $tests = {
649        namespace_uri => undef,        namespace_uri => undef,
650        next_sibling => undef,        next_sibling => undef,
651        node_name => 'e',        node_name => 'e',
652          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,
659        public_id => undef,        public_id => undef,
660        system_id => undef,        system_id => undef,
661      },      },
662        attr_get_bool => {
663          has_attributes => 0,
664          has_child_nodes => 0,
665          manakai_read_only => 0,
666        },
667    },    },
668    processing_instruction => {    processing_instruction => {
669      node => sub { return $doc->create_processing_instruction ('t', 'd') },      node => sub { return $doc->create_processing_instruction ('t', 'd') },
# Line 480  my $tests = { Line 671  my $tests = {
671        attributes => undef,        attributes => undef,
672        base_uri => undef,        base_uri => undef,
673        manakai_base_uri => undef,        manakai_base_uri => undef,
674          manakai_expanded_uri => undef,
675        first_child => undef,        first_child => undef,
676        last_child => undef,        last_child => undef,
677        local_name => undef,        local_name => undef,
# Line 487  my $tests = { Line 679  my $tests = {
679        namespace_uri => undef,        namespace_uri => undef,
680        next_sibling => undef,        next_sibling => undef,
681        node_name => 't',        node_name => 't',
682          node_type => 7,
683        node_value => 'd',        node_value => 'd',
684        owner_document => $doc,        owner_document => $doc,
685        parent_node => undef,        parent_node => undef,
686        prefix => undef,        prefix => undef,
687        previous_sibling => undef,        previous_sibling => undef,
688      },      },
689        attr_get_bool => {
690          has_attributes => 0,
691          has_child_nodes => 0,
692          manakai_read_only => 0,
693        },
694    },    },
695    text => {    text => {
696      node => sub { return $doc->create_text_node ('textdata') },      node => sub { return $doc->create_text_node ('textdata') },
697      attr_get => {      attr_get => {
698        attributes => undef,        attributes => undef,
699        base_uri => undef,        base_uri => undef,
700          manakai_expanded_uri => undef,
701        first_child => undef,        first_child => undef,
702        last_child => undef,        last_child => undef,
703        local_name => undef,        local_name => undef,
# Line 506  my $tests = { Line 705  my $tests = {
705        namespace_uri => undef,        namespace_uri => undef,
706        next_sibling => undef,        next_sibling => undef,
707        node_name => '#text',        node_name => '#text',
708          node_type => 3,
709        node_value => 'textdata',        node_value => 'textdata',
710        owner_document => $doc,        owner_document => $doc,
711        parent_node => undef,        parent_node => undef,
712        prefix => undef,        prefix => undef,
713        previous_sibling => undef,        previous_sibling => undef,
714      },      },
715        attr_get_bool => {
716          has_attributes => 0,
717          has_child_nodes => 0,
718          is_element_content_whitespace => 0,
719          manakai_read_only => 0,
720        },
721    },    },
722    element_type_definition => {    element_type_definition => {
723      node => sub { return $doc->create_element_type_definition ('e') },      node => sub { return $doc->create_element_type_definition ('e') },
724      attr_get => {      attr_get => {
725        attributes => undef,        attributes => undef,
726        base_uri => undef,        base_uri => undef,
727          manakai_expanded_uri => undef,
728        first_child => undef,        first_child => undef,
729        last_child => undef,        last_child => undef,
730        local_name => undef,        local_name => undef,
# Line 525  my $tests = { Line 732  my $tests = {
732        namespace_uri => undef,        namespace_uri => undef,
733        next_sibling => undef,        next_sibling => undef,
734        node_name => 'e',        node_name => 'e',
735          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,
742      },      },
743        attr_get_bool => {
744          has_attributes => 0,
745          has_child_nodes => 0,
746          manakai_read_only => 0,
747        },
748    },    },
749    attribute_definition => {    attribute_definition => {
750      node => sub { return $doc->create_attribute_definition ('e') },      node => sub { return $doc->create_attribute_definition ('e') },
# Line 539  my $tests = { Line 753  my $tests = {
753        base_uri => undef,        base_uri => undef,
754        declared_type => 0,        declared_type => 0,
755        default_type => 0,        default_type => 0,
756          manakai_expanded_uri => undef,
757        first_child => undef,        first_child => undef,
758        last_child => undef,        last_child => undef,
759        local_name => undef,        local_name => undef,
# Line 546  my $tests = { Line 761  my $tests = {
761        namespace_uri => undef,        namespace_uri => undef,
762        next_sibling => undef,        next_sibling => undef,
763        node_name => 'e',        node_name => 'e',
764        node_value => undef,        node_type => 81002,
765          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 => {
774          has_attributes => 0,
775          has_child_nodes => 0,
776          manakai_read_only => 0,
777      },      },
778    },    },
779  };  };
# Line 582  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 599  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 926  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 1018  for my $i (0..1) { Line 1243  for my $i (0..1) {
1243             ]->[$i];             ]->[$i];
1244    
1245    my $doc2 = $doc->implementation->create_document;    my $doc2 = $doc->implementation->create_document;
1246      $doc2->strict_error_checking (0);
1247    
1248    my $attr = $doc2->create_attribute_ns (@$xb);    my $attr = $doc2->create_attribute_ns (@$xb);
1249    $attr->value (q<http://attr.test/>);    $attr->value (q<http://attr.test/>);
# Line 1044  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 1220  for (qw/create_text_node create_cdata_se Line 1447  for (qw/create_text_node create_cdata_se
1447    ok $dt->base_uri, q<http://doc.test/>, "DT->base_uri [1]";    ok $dt->base_uri, q<http://doc.test/>, "DT->base_uri [1]";
1448  }  }
1449    
1450    ## |hasAttribute|
1451    {
1452      my $el = $doc->create_element ('e');
1453      ok $el->has_attributes ? 1 : 0, 0, "Element->has_attributes [0]";
1454    
1455      $el->set_attribute (a => 'b');
1456      ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [1]";
1457    
1458      $el->set_attribute (c => 'd');
1459      ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [2]";
1460    
1461      $el->remove_attribute ('c');
1462      ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [3]";
1463    
1464      $el->get_attribute_node ('a')->specified (0);
1465      ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [4]";
1466    
1467      $el->remove_attribute ('a');
1468      ok $el->has_attributes ? 1 : 0, 0, "Element->has_attributes [5]";
1469    }
1470    
1471    ## |hasChildNodes|
1472    {
1473      my $doc2 = $doc->implementation->create_document;
1474      
1475      ok $doc2->has_child_nodes ? 1 : 0, 0, "Document->has_child_nodes [0]";
1476    
1477      $doc2->append_child ($doc2->create_comment (''));
1478      ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [1]";
1479    
1480      $doc2->append_child ($doc2->create_comment (''));
1481      ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [2]";
1482    
1483      $doc2->remove_child ($doc2->first_child);
1484      ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [3]";
1485    
1486      $doc2->remove_child ($doc2->first_child);
1487      ok $doc2->has_child_nodes ? 1 : 0, 0, "Document->has_child_nodes [4]";
1488    }
1489    
1490    ## |compareDocumentPosition|
1491    {
1492      my $e1 = $doc->create_element ('e1');
1493      my $e2 = $doc->create_element ('e2');
1494      
1495      my $dp2 = $e1->compare_document_position ($e2);
1496      
1497      ok $dp2 & $e1->DOCUMENT_POSITION_DISCONNECTED ? 1 : 0, 1, "cdp [1]";
1498      ok $dp2 & $e1->DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ? 1 : 0, 1, "edp [2]";
1499      ok (($dp2 & $e1->DOCUMENT_POSITION_PRECEDING ||
1500           $dp2 & $e1->DOCUMENT_POSITION_FOLLOWING) ? 1 : 0, 1, "cdp [3]");
1501    
1502      my $dp1 = $e2->compare_document_position ($e1);
1503      
1504      ok $dp1 & $e1->DOCUMENT_POSITION_DISCONNECTED ? 1 : 0, 1, "cdp [4]";
1505      ok $dp1 & $e1->DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ? 1 : 0, 1, "cdp [5]";
1506      ok (($dp1 & $e1->DOCUMENT_POSITION_PRECEDING ||
1507           $dp1 & $e1->DOCUMENT_POSITION_FOLLOWING) ? 1 : 0, 1, "cdp [6]");
1508    }
1509    
1510    {
1511      my $e1 = $doc->create_element ('e1');
1512      my $e2 = $doc->create_element ('e2');
1513    
1514      my $pe = $doc->create_element ('pe');
1515      $pe->append_child ($e1);
1516      $pe->append_child ($e2);
1517    
1518      my $dp2 = $e1->compare_document_position ($e2);
1519    
1520      ok $dp2 & $e1->DOCUMENT_POSITION_FOLLOWING ? 1 : 0, 1, "cde [7]";
1521    
1522      my $dp1 = $e2->compare_document_position ($e1);
1523    
1524      ok $dp1 & $e1->DOCUMENT_POSITION_PRECEDING ? 1 : 0, 1, "cde [8]";
1525    }
1526    ## TODO: Apparently compare_document_position requires more tests.
1527    
1528    ## |lookupNamespaceURI|
1529    {
1530      for my $node (create_nodes ()) {
1531        ok $node->lookup_namespace_uri ('ns1'), undef, $node->node_name . " lnu [0]";
1532        ok $node->lookup_namespace_uri ('xml'), undef, $node->node_name . " lnu [1]";
1533        ok $node->lookup_namespace_uri ('xmlns'), undef, $node->node_name . " lnu [2]";
1534        ok $node->lookup_namespace_uri (''), undef, $node->node_name . " lnu [3]";
1535        ok $node->lookup_namespace_uri (undef), undef, $node->node_name . " lnu [4]";
1536      }
1537    
1538      my $el = $doc->create_element_ns ('about:', 'el');
1539      ok $el->lookup_namespace_uri ('ns1'), undef, 'Element->lnu [0]';
1540    
1541      $el->prefix ('ns1');
1542      ok $el->lookup_namespace_uri ('ns1'), 'about:', 'Element->lnu [1]';
1543    
1544      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns:ns1', 'DAV:');
1545      ok $el->lookup_namespace_uri ('ns1'), 'about:', 'Element->lnu [2]';
1546    
1547      $el->prefix (undef);
1548      ok $el->lookup_namespace_uri ('ns1'), 'DAV:', 'Element->lnu [3]';
1549    }
1550    
1551    ## |lookupPrefix|
1552    {
1553      for my $node (create_nodes ()) {
1554        ok $node->lookup_prefix ('http://test/'), undef, $node->node_name . "lp [0]";
1555        ok $node->lookup_prefix ('http://www.w3.org/XML/1998/namespace'), undef, $node->node_name . "lp [1]";
1556        ok $node->lookup_prefix ('http://www.w3.org/2000/xmlns/'), undef, $node->node_name . "lp [2]";
1557        ok $node->lookup_prefix ('http://www.w3.org/1999/xhtml'), undef, $node->node_name . "lp [3]";
1558        ok $node->lookup_prefix (''), undef, $node->node_name . "lp [4]";
1559        ok $node->lookup_prefix (undef), undef, $node->node_name . "lp [5]";
1560      }
1561    
1562      my $el = $doc->create_element_ns ('http://test/', 'e');
1563      ok $el->lookup_prefix ('ns'), undef, "Element->lp [0]";;
1564    
1565      my $el2 = $doc->create_element_ns ('http://test/', 'f');
1566      $el2->append_child ($el);
1567      $el2->prefix ('ns');
1568      ok $el->lookup_prefix ('http://test/'), 'ns', "Element->lp [1]";
1569    
1570      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns:a',
1571                             'http://test/');
1572      ok $el->lookup_prefix ('http://test/'), 'a', "Element->lp [2]";
1573    
1574      $el->prefix ('b');
1575      ok $el->lookup_prefix ('http://test/'), 'b', "Element->lp [3]";
1576    }
1577    
1578    ## |isDefaultNamespace|
1579    {
1580      for my $node (create_nodes ()) {
1581        next if $node->node_type == 1;
1582        ok $node->is_default_namespace ('about:') ? 1 : 0, 0, $node->node_name."idn[0]";
1583        ok $node->is_default_namespace ('http://www.w3.org/XML/1998/namespace') ? 1 : 0, 0, $node->node_name."idn[2]";
1584        ok $node->is_default_namespace ('http://www.w3.org/2000/xmlns/') ? 1 : 0, 0, $node->node_name."idn[3]";
1585        ok $node->is_default_namespace ('') ? 1 : 0, 0, $node->node_name."idn[4]";
1586        ok $node->is_default_namespace (undef) ? 1 : 0, 0, $node->node_name."idn[5]";
1587      }
1588      
1589      my $el = $doc->create_element_ns ('about:', 'el');
1590      ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [0]";
1591      
1592      $el->prefix ('ns1');
1593      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [1]";
1594    
1595      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1596      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [2]";
1597      
1598      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'about:');
1599      ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [3]";
1600    
1601      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1602      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [4]";
1603    }
1604    
1605    {
1606      my $el = $doc->create_element_ns ('about:', 'p:el');
1607      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [5]";
1608      
1609      $el->prefix ('ns1');
1610      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [6]";
1611    
1612      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1613      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [7]";
1614      
1615      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'about:');
1616      ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [8]";
1617    
1618      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1619      ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [9]";
1620    }
1621    
1622    {
1623      my $el = $doc->create_element ('e');
1624    
1625      ## NOTE: This might look like strange, but it is how it is defined!
1626      ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [10]";
1627      ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [11]";
1628    
1629      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1630      ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [12]";
1631      ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [13]";
1632    
1633      $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1634      ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [14]";
1635      ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [15]";
1636    }
1637    
1638    ## |manakaiParentElement|
1639    {
1640      my $el = $doc->create_element ('el');
1641      ok $el->manakai_parent_element, undef, "mpe [0]";
1642    
1643      my $el2 = $doc->create_element ('el2');
1644      $el->append_child ($el2);
1645      ok $el2->manakai_parent_element, $el, "mpe [1]";
1646      
1647      my $er1 = $doc->create_entity_reference ('er1');
1648      $er1->manakai_set_read_only (0, 1);
1649      $el->append_child ($er1);
1650      $er1->append_child ($el2);
1651      ok $el2->manakai_parent_element, $el, "mpe [1]";
1652    }
1653    
1654    {
1655      my $el = $doc->create_element ('el');
1656      my $t1 = $doc->create_text_node ('t1');
1657      my $t2 = $doc->create_text_node ('t2');
1658      $el->append_child ($t1);
1659      $el->append_child ($t2);
1660      $el->normalize;
1661      
1662      ok $el->text_content, 't1t2', 'normalize [0]';
1663      ok 0+@{$el->child_nodes}, 1, 'normalize [1]';
1664    }
1665    
1666    {
1667      my $el = $doc->create_element ('el');
1668      my $t1 = $doc->create_text_node ('t1');
1669      my $t2 = $doc->create_text_node ('t2');
1670      my $t3 = $doc->create_text_node ('t3');
1671      my $t4 = $doc->create_text_node ('t4');
1672      $el->append_child ($t1);
1673      $el->append_child ($t2);
1674      $el->append_child ($t3);
1675      $el->append_child ($t4);
1676      $el->normalize;
1677      
1678      ok $el->text_content, 't1t2t3t4', 'normalize [2]';
1679      ok 0+@{$el->child_nodes}, 1, 'normalize [3]';
1680    }
1681    
1682    {
1683      my $el = $doc->create_element ('el');
1684      my $t1 = $doc->create_text_node ('t1');
1685      my $t2 = $doc->create_text_node ('t2');
1686      my $c1 = $doc->create_cdata_section ('c1');
1687      my $t3 = $doc->create_text_node ('t3');
1688      my $t4 = $doc->create_text_node ('t4');
1689      $el->append_child ($t1);
1690      $el->append_child ($t2);
1691      $el->append_child ($c1);
1692      $el->append_child ($t3);
1693      $el->append_child ($t4);
1694      $el->normalize;
1695      
1696      ok $el->text_content, 't1t2c1t3t4', 'normalize [4]';
1697      ok 0+@{$el->child_nodes}, 3, 'normalize [5]';
1698      ok $el->first_child->text_content, 't1t2', 'normalize [6]';
1699      ok $el->last_child->text_content, 't3t4', 'normalize [7]';
1700    }
1701    
1702    {
1703      my $el = $doc->create_element ('el');
1704      my $t1 = $doc->create_text_node ('t1');
1705      my $t2 = $doc->create_text_node ('');
1706      $el->append_child ($t1);
1707      $el->append_child ($t2);
1708      $el->normalize;
1709      
1710      ok $el->text_content, 't1', 'normalize [8]';
1711      ok 0+@{$el->child_nodes}, 1, 'normalize [9]';
1712    }
1713    
1714    {
1715      my $el = $doc->create_element ('el');
1716      my $t1 = $doc->create_text_node ('');
1717      my $t2 = $doc->create_text_node ('t2');
1718      $el->append_child ($t1);
1719      $el->append_child ($t2);
1720      $el->normalize;
1721      
1722      ok $el->text_content, 't2', 'normalize [10]';
1723      ok 0+@{$el->child_nodes}, 1, 'normalize [11]';
1724    }
1725    
1726    {
1727      my $el = $doc->create_element ('el');
1728      my $t1 = $doc->create_text_node ('');
1729      $el->append_child ($t1);
1730      $el->normalize;
1731      
1732      ok $el->text_content, '', 'normalize [12]';
1733      ok 0+@{$el->child_nodes}, 0, 'normalize [13]';
1734    }
1735    
1736    {
1737      my $pe = $doc->create_element ('pe');
1738      my $el = $doc->create_element ('el');
1739      my $t1 = $doc->create_text_node ('t1');
1740      my $t2 = $doc->create_text_node ('t2');
1741      $el->append_child ($t1);
1742      $el->append_child ($t2);
1743      $pe->append_child ($el);
1744      $pe->normalize;
1745      
1746      ok $el->text_content, 't1t2', 'normalize [14]';
1747      ok 0+@{$el->child_nodes}, 1, 'normalize [15]';
1748    }
1749    
1750    {
1751      my $pe = $doc->create_element ('pe');
1752      my $el = $doc->create_attribute ('a');
1753      my $t1 = $doc->create_text_node ('t1');
1754      my $t2 = $doc->create_text_node ('t2');
1755      $el->append_child ($t1);
1756      $el->append_child ($t2);
1757      $pe->set_attribute_node ($el);
1758      $pe->normalize;
1759      
1760      ok $el->text_content, 't1t2', 'normalize [16]';
1761      ok 0+@{$el->child_nodes}, 1, 'normalize [17]';
1762    }
1763    
1764    {
1765      my $pe = $doc->create_element_type_definition ('pe');
1766      my $el = $doc->create_attribute_definition ('a');
1767      my $t1 = $doc->create_text_node ('t1');
1768      my $t2 = $doc->create_text_node ('t2');
1769      $el->append_child ($t1);
1770      $el->append_child ($t2);
1771      $pe->set_attribute_definition_node ($el);
1772      $pe->normalize;
1773      
1774      ok $el->text_content, 't1t2', 'normalize [16]';
1775      ok 0+@{$el->child_nodes}, 1, 'normalize [17]';
1776    }
1777    
1778    {
1779      my $dt = $doc->create_document_type_definition ('dt');
1780      my $pe = $doc->create_element_type_definition ('pe');
1781      my $el = $doc->create_attribute_definition ('a');
1782      my $t1 = $doc->create_text_node ('t1');
1783      my $t2 = $doc->create_text_node ('t2');
1784      $el->append_child ($t1);
1785      $el->append_child ($t2);
1786      $pe->set_attribute_definition_node ($el);
1787      $dt->set_element_type_definition_node ($pe);
1788      $dt->normalize;
1789      
1790      ok $el->text_content, 't1t2', 'normalize [18]';
1791      ok 0+@{$el->child_nodes}, 1, 'normalize [19]';
1792    }
1793    
1794    {
1795      my $pe = $doc->create_document_type_definition ('pe');
1796      my $el = $doc->create_general_entity ('a');
1797      my $t1 = $doc->create_text_node ('t1');
1798      my $t2 = $doc->create_text_node ('t2');
1799      $el->append_child ($t1);
1800      $el->append_child ($t2);
1801      $pe->set_general_entity_node ($el);
1802      $pe->normalize;
1803      
1804      ok $el->text_content, 't1t2', 'normalize [20]';
1805      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.4  
changed lines
  Added in v.1.17

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24