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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download) (as text)
Sat Oct 27 13:07:27 2007 UTC (17 years, 1 month ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +2 -1 lines
File MIME type: application/x-troff
++ manakai/lib/Message/DOM/ChangeLog	27 Oct 2007 13:06:39 -0000
2007-10-27  Wakaba  <wakaba@suika.fam.cx>

	* Event.pm (init_event, init_event_ns, init_custom_event_ns):
	The |namespaceURI| attribute was not set correctly.

	* DOMEvents.dis: Removed.

1 #!/usr/bin/perl
2 use strict;
3 use Test;
4 BEGIN { plan tests => 5329 }
5
6 require Message::DOM::DOMImplementation;
7 use Message::Util::Error;
8
9 my $dom = Message::DOM::DOMImplementation->new;
10 my $doc = $dom->create_document;
11
12
13 sub create_nodes () {
14 (
15 $doc->create_attribute ('attr1'),
16 $doc->create_attribute_definition ('at1'),
17 $doc->create_cdata_section ('cdata1'),
18 $doc->create_comment ('comment1'),
19 $doc->create_element ('element1'),
20 $doc->create_element_type_definition ('et1'),
21 $doc->create_general_entity ('entity1'),
22 $doc->create_entity_reference ('entity-reference1'),
23 $doc->implementation->create_document,
24 $doc->create_document_fragment,
25 $doc->create_document_type_definition ('dt1'),
26 $doc->create_notation ('notation1'),
27 $doc->create_processing_instruction ('pi1', 'pi1data'),
28 $doc->create_text_node ('text1'),
29 );
30 } # create_nodes
31
32 sub create_parent_nodes () {
33 (
34 $doc->create_attribute ('attr1'),
35 $doc->create_attribute_definition ('at1'),
36 $doc->create_element ('element1'),
37 $doc->create_general_entity ('entity1'),
38 $doc->create_entity_reference ('entity-reference1'),
39 $doc->implementation->create_document,
40 $doc->create_document_fragment,
41 $doc->create_document_type_definition ('dt1'),
42 );
43 } # 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
56 my $constants = [
57 [ELEMENT_NODE => 1],
58 [ATTRIBUTE_NODE => 2],
59 [TEXT_NODE => 3],
60 [CDATA_SECTION_NODE => 4],
61 [ENTITY_REFERENCE_NODE => 5],
62 [ENTITY_NODE => 6],
63 [PROCESSING_INSTRUCTION_NODE => 7],
64 [COMMENT_NODE => 8],
65 [DOCUMENT_NODE => 9],
66 [DOCUMENT_TYPE_NODE => 10],
67 [DOCUMENT_FRAGMENT_NODE => 11],
68 [NOTATION_NODE => 12],
69 [ELEMENT_TYPE_DEFINITION_NODE => 81001],
70 [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 = {
87 attr1 => {
88 node => sub { return $doc->create_attribute ('a') },
89 attr_get => {
90 manakai_attribute_type => 0,
91 base_uri => undef,
92 manakai_expanded_uri => 'a',
93 first_child => undef,
94 last_child => undef,
95 local_name => 'a',
96 manakai_local_name => 'a',
97 namespace_uri => undef,
98 next_sibling => undef,
99 node_name => 'a',
100 node_type => 2,
101 name => 'a',
102 node_value => '',
103 owner_document => $doc,
104 parent_node => undef,
105 prefix => undef,
106 previous_sibling => undef,
107 value => '',
108 attributes => undef,
109 },
110 attr_get_bool => {
111 has_attributes => 0,
112 has_child_nodes => 0,
113 is_id => 0,
114 manakai_read_only => 0,
115 specified => 1,
116 },
117 },
118 attr2 => {
119 node => sub {
120 my $attr = $doc->create_attribute ('a');
121 $attr->value ('b');
122 return $attr;
123 },
124 attr_get => {
125 manakai_attribute_type => 0,
126 base_uri => undef,
127 manakai_expanded_uri => 'a',
128 local_name => 'a',
129 manakai_local_name => 'a',
130 namespace_uri => undef,
131 next_sibling => undef,
132 node_name => 'a',
133 node_type => 2,
134 name => 'a',
135 node_value => 'b',
136 owner_document => $doc,
137 parent_node => undef,
138 prefix => undef,
139 previous_sibling => undef,
140 value => 'b',
141 attributes => undef,
142 },
143 attr_get_bool => {
144 has_attributes => 0,
145 has_child_nodes => 1,
146 is_id => 0,
147 manakai_read_only => 0,
148 specified => 1,
149 },
150 },
151 attr_ns_default => {
152 node => sub { return $doc->create_attribute_ns (undef, 'a') },
153 attr_get => {
154 base_uri => undef,
155 manakai_expanded_uri => 'a',
156 local_name => 'a',
157 manakai_local_name => 'a',
158 namespace_uri => undef,
159 next_sibling => undef,
160 node_name => 'a',
161 node_type => 2,
162 name => 'a',
163 node_value => '',
164 owner_document => $doc,
165 parent_node => undef,
166 prefix => undef,
167 value => '',
168 attributes => undef,
169 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 => {
180 node => sub { return $doc->create_attribute_ns ('http://test/', 'a:b') },
181 attr_get => {
182 base_uri => undef,
183 manakai_expanded_uri => 'http://test/b',
184 local_name => 'b',
185 manakai_local_name => 'b',
186 namespace_uri => 'http://test/',
187 next_sibling => undef,
188 node_name => 'a:b',
189 node_type => 2,
190 name => 'a:b',
191 node_value => '',
192 owner_document => $doc,
193 parent_node => undef,
194 prefix => 'a',
195 value => '',
196 attributes => undef,
197 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 => {
236 node => sub { return $doc->create_cdata_section ('cdatadata') },
237 attr_get => {
238 base_uri => undef,
239 manakai_expanded_uri => undef,
240 first_child => undef,
241 last_child => undef,
242 local_name => undef,
243 manakai_local_name => undef,
244 namespace_uri => undef,
245 next_sibling => undef,
246 node_name => '#cdata-section',
247 node_type => 4,
248 node_value => 'cdatadata',
249 owner_document => $doc,
250 parent_node => undef,
251 prefix => undef,
252 data => 'cdatadata',
253 attributes => undef,
254 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 => {
264 node => sub { return $doc->create_cdata_section ('cdata]]>data') },
265 attr_get => {
266 base_uri => undef,
267 manakai_expanded_uri => undef,
268 first_child => undef,
269 last_child => undef,
270 local_name => undef,
271 manakai_local_name => undef,
272 namespace_uri => undef,
273 next_sibling => undef,
274 node_name => '#cdata-section',
275 node_type => 4,
276 node_value => 'cdata]]>data',
277 owner_document => $doc,
278 parent_node => undef,
279 prefix => undef,
280 data => 'cdata]]>data',
281 attributes => undef,
282 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 => {
292 node => sub { return $doc->create_comment ('commentdata') },
293 attr_get => {
294 base_uri => undef,
295 manakai_expanded_uri => undef,
296 first_child => undef,
297 last_child => undef,
298 local_name => undef,
299 manakai_local_name => undef,
300 namespace_uri => undef,
301 next_sibling => undef,
302 node_name => '#comment',
303 node_type => 8,
304 node_value => 'commentdata',
305 owner_document => $doc,
306 parent_node => undef,
307 prefix => undef,
308 data => 'commentdata',
309 attributes => undef,
310 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 => {
319 node => sub { return $doc->create_comment ('comment--data') },
320 attr_get => {
321 base_uri => undef,
322 manakai_expanded_uri => undef,
323 first_child => undef,
324 last_child => undef,
325 local_name => undef,
326 manakai_local_name => undef,
327 namespace_uri => undef,
328 next_sibling => undef,
329 node_name => '#comment',
330 node_type => 8,
331 node_value => 'comment--data',
332 owner_document => $doc,
333 parent_node => undef,
334 prefix => undef,
335 data => 'comment--data',
336 attributes => undef,
337 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 => {
346 node => sub { return $doc->create_comment ('commentdata-') },
347 attr_get => {
348 base_uri => undef,
349 manakai_expanded_uri => undef,
350 first_child => undef,
351 last_child => undef,
352 local_name => undef,
353 manakai_local_name => undef,
354 namespace_uri => undef,
355 next_sibling => undef,
356 node_name => '#comment',
357 node_type => 8,
358 node_value => 'commentdata-',
359 owner_document => $doc,
360 parent_node => undef,
361 prefix => undef,
362 data => 'commentdata-',
363 attributes => undef,
364 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 => {
373 node => sub { return $doc },
374 attr_get => {
375 attributes => undef,
376 base_uri => undef,
377 document_uri => undef,
378 manakai_entity_base_uri => undef,
379 manakai_expanded_uri => undef,
380 first_child => undef,
381 implementation => $dom,
382 last_child => undef,
383 local_name => undef,
384 manakai_local_name => undef,
385 namespace_uri => undef,
386 next_sibling => undef,
387 node_name => '#document',
388 node_type => 9,
389 node_value => undef,
390 owner_document => undef,
391 parent_node => undef,
392 prefix => undef,
393 previous_sibling => undef,
394 xml_encoding => undef,
395 xml_version => '1.0',
396 },
397 attr_get_bool => {
398 all_declarations_processed => 0,
399 has_attributes => 0,
400 has_child_nodes => 0,
401 manakai_is_html => 0,
402 manakai_read_only => 0,
403 strict_error_checking => 1,
404 xml_standalone => 0,
405 },
406 },
407 document_fragment => {
408 node => sub { return $doc->create_document_fragment },
409 attr_get => {
410 attributes => undef,
411 base_uri => undef,
412 manakai_expanded_uri => undef,
413 first_child => undef,
414 last_child => undef,
415 local_name => undef,
416 manakai_local_name => undef,
417 namespace_uri => undef,
418 next_sibling => undef,
419 node_name => '#document-fragment',
420 node_type => 11,
421 node_value => undef,
422 owner_document => $doc,
423 parent_node => undef,
424 prefix => undef,
425 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 => {
434 node => sub {
435 return $doc->implementation->create_document_type ('n', '', '');
436 },
437 attr_get => {
438 attributes => undef,
439 base_uri => undef,
440 declaration_base_uri => undef,
441 manakai_declaration_base_uri => undef,
442 manakai_expanded_uri => undef,
443 first_child => undef,
444 implementation => $dom,
445 internal_subset => '',
446 last_child => undef,
447 local_name => undef,
448 manakai_local_name => undef,
449 namespace_uri => undef,
450 next_sibling => undef,
451 node_name => 'n',
452 node_type => 10,
453 node_value => undef,
454 owner_document => undef,
455 parent_node => undef,
456 prefix => undef,
457 previous_sibling => undef,
458 public_id => '',
459 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 => {
468 node => sub { return $doc->create_document_type_definition ('n') },
469 attr_get => {
470 attributes => undef,
471 base_uri => undef,
472 declaration_base_uri => undef,
473 manakai_declaration_base_uri => undef,
474 manakai_expanded_uri => undef,
475 first_child => undef,
476 implementation => $dom,
477 internal_subset => '',
478 last_child => undef,
479 local_name => undef,
480 manakai_local_name => undef,
481 namespace_uri => undef,
482 next_sibling => undef,
483 node_name => 'n',
484 node_type => 10,
485 node_value => undef,
486 owner_document => $doc,
487 parent_node => undef,
488 prefix => undef,
489 previous_sibling => undef,
490 public_id => '',
491 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 => {
500 node => sub { return $doc->create_element ('e') },
501 attr_get => {
502 base_uri => undef,
503 manakai_base_uri => undef,
504 manakai_expanded_uri => 'e',
505 first_child => undef,
506 last_child => undef,
507 local_name => 'e',
508 manakai_local_name => 'e',
509 namespace_uri => undef,
510 next_sibling => undef,
511 node_name => 'e',
512 node_type => 1,
513 node_value => undef,
514 owner_document => $doc,
515 parent_node => undef,
516 prefix => undef,
517 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 => {
527 node => sub { return $doc->create_element_ns ('http://test/', 'f') },
528 attr_get => {
529 base_uri => undef,
530 manakai_base_uri => undef,
531 manakai_expanded_uri => 'http://test/f',
532 first_child => undef,
533 last_child => undef,
534 local_name => 'f',
535 manakai_local_name => 'f',
536 namespace_uri => 'http://test/',
537 next_sibling => undef,
538 node_name => 'f',
539 node_type => 1,
540 node_value => undef,
541 owner_document => $doc,
542 parent_node => undef,
543 prefix => undef,
544 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 => {
554 node => sub { return $doc->create_element_ns ('http://test/', 'e:f') },
555 attr_get => {
556 base_uri => undef,
557 manakai_base_uri => undef,
558 manakai_expanded_uri => 'http://test/f',
559 first_child => undef,
560 last_child => undef,
561 local_name => 'f',
562 manakai_local_name => 'f',
563 namespace_uri => 'http://test/',
564 next_sibling => undef,
565 node_name => 'e:f',
566 node_type => 1,
567 node_value => undef,
568 owner_document => $doc,
569 parent_node => undef,
570 prefix => 'e',
571 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 => {
581 node => sub { return $doc->create_general_entity ('e') },
582 attr_get => {
583 attributes => undef,
584 base_uri => undef,
585 manakai_declaration_base_uri => undef,
586 manakai_entity_base_uri => undef,
587 manakai_entity_uri => undef,
588 manakai_expanded_uri => undef,
589 first_child => undef,
590 last_child => undef,
591 next_sibling => undef,
592 node_name => 'e',
593 node_type => 6,
594 node_value => undef,
595 notation_name => undef,
596 owner_document => $doc,
597 owner_document_type_definition => undef,
598 parent_node => undef,
599 previous_sibling => undef,
600 public_id => undef,
601 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 => {
610 node => sub { return $doc->create_entity_reference ('e') },
611 attr_get => {
612 attributes => undef,
613 base_uri => undef,
614 manakai_entity_base_uri => undef,
615 manakai_expanded_uri => undef,
616 first_child => undef,
617 last_child => undef,
618 local_name => undef,
619 manakai_local_name => undef,
620 namespace_uri => undef,
621 next_sibling => undef,
622 node_name => 'e',
623 node_type => 5,
624 node_value => undef,
625 owner_document => $doc,
626 parent_node => undef,
627 prefix => undef,
628 previous_sibling => undef,
629 },
630 attr_get_bool => {
631 manakai_expanded => 0,
632 manakai_external => 0,
633 has_attributes => 0,
634 has_child_nodes => 0,
635 manakai_read_only => 1,
636 },
637 },
638 notation => {
639 node => sub { return $doc->create_notation ('e') },
640 attr_get => {
641 attributes => undef,
642 base_uri => undef,
643 manakai_declaration_base_uri => undef,
644 manakai_expanded_uri => undef,
645 first_child => undef,
646 last_child => undef,
647 local_name => undef,
648 manakai_local_name => undef,
649 namespace_uri => undef,
650 next_sibling => undef,
651 node_name => 'e',
652 node_type => 12,
653 node_value => undef,
654 owner_document => $doc,
655 owner_document_type_definition => undef,
656 parent_node => undef,
657 prefix => undef,
658 previous_sibling => undef,
659 public_id => undef,
660 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 => {
669 node => sub { return $doc->create_processing_instruction ('t', 'd') },
670 attr_get => {
671 attributes => undef,
672 base_uri => undef,
673 manakai_base_uri => undef,
674 manakai_expanded_uri => undef,
675 first_child => undef,
676 last_child => undef,
677 local_name => undef,
678 manakai_local_name => undef,
679 namespace_uri => undef,
680 next_sibling => undef,
681 node_name => 't',
682 node_type => 7,
683 node_value => 'd',
684 owner_document => $doc,
685 parent_node => undef,
686 prefix => undef,
687 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 => {
696 node => sub { return $doc->create_text_node ('textdata') },
697 attr_get => {
698 attributes => undef,
699 base_uri => undef,
700 manakai_expanded_uri => undef,
701 first_child => undef,
702 last_child => undef,
703 local_name => undef,
704 manakai_local_name => undef,
705 namespace_uri => undef,
706 next_sibling => undef,
707 node_name => '#text',
708 node_type => 3,
709 node_value => 'textdata',
710 owner_document => $doc,
711 parent_node => undef,
712 prefix => undef,
713 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 => {
723 node => sub { return $doc->create_element_type_definition ('e') },
724 attr_get => {
725 attributes => undef,
726 base_uri => undef,
727 manakai_expanded_uri => undef,
728 first_child => undef,
729 last_child => undef,
730 local_name => undef,
731 manakai_local_name => undef,
732 namespace_uri => undef,
733 next_sibling => undef,
734 node_name => 'e',
735 node_type => 81001,
736 node_value => undef,
737 owner_document => $doc,
738 owner_document_type_definition => undef,
739 parent_node => undef,
740 prefix => undef,
741 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 => {
750 node => sub { return $doc->create_attribute_definition ('e') },
751 attr_get => {
752 attributes => undef,
753 base_uri => undef,
754 declared_type => 0,
755 default_type => 0,
756 manakai_expanded_uri => undef,
757 first_child => undef,
758 last_child => undef,
759 local_name => undef,
760 manakai_local_name => undef,
761 namespace_uri => undef,
762 next_sibling => undef,
763 node_name => 'e',
764 node_type => 81002,
765 node_value => '',
766 owner_document => $doc,
767 owner_element_type_definition => undef,
768 parent_node => undef,
769 prefix => undef,
770 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 };
780
781 for my $test_id (sort {$a cmp $b} keys %$tests) {
782 my $test_def = $tests->{$test_id};
783 my $node = $test_def->{node}->();
784
785 for (@$constants) {
786 my $const_name = $_->[0];
787 ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)";
788 ok $node->$const_name, $_->[1], "$test_id.$const_name";
789 }
790
791 for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) {
792 my $expected = $test_def->{attr_get}->{$attr_name};
793 ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)";
794 my $actual = $node->$attr_name;
795 ok $actual, $expected, "$test_id.$attr_name.get";
796 }
797
798 for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get_bool} or {}}) {
799 my $expected = $test_def->{attr_get_bool}->{$attr_name} ? 1 : 0;
800 ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)";
801 my $actual = $node->$attr_name ? 1 : 0;
802 ok $actual, $expected, "$test_id.$attr_name.get";
803 }
804 }
805
806 ## Child node accessors' tests
807 for my $parent (create_parent_nodes ()) {
808 my $doc = $parent->owner_document || $parent;
809 my $node1;
810 my $node2;
811 my $node3;
812 if ($parent->node_type == $parent->DOCUMENT_TYPE_NODE) {
813 $node1 = $doc->create_processing_instruction ('pi1', 'data1');
814 $node2 = $doc->create_processing_instruction ('pi2', 'data2');
815 $node3 = $doc->create_processing_instruction ('pi3', 'data3');
816 } elsif ($parent->node_type == $parent->DOCUMENT_NODE) {
817 $node1 = $doc->create_comment ('comment1');
818 $node2 = $doc->create_comment ('comment2');
819 $node3 = $doc->create_comment ('comment3');
820 } else {
821 $node1 = $doc->create_text_node ('text1');
822 $node2 = $doc->create_text_node ('text2');
823 $node3 = $doc->create_text_node ('text3');
824 }
825
826 $parent->manakai_set_read_only (0, 1);
827 $parent->append_child ($node1);
828 ok $parent->first_child, $node1, $parent->node_name."->first_child [1]";
829 ok $parent->last_child, $node1, $parent->node_name."->last_child [1]";
830 ok $node1->next_sibling, undef, $parent->node_name."->next_sibling [1]";
831 ok $node1->previous_sibling, undef, $parent->node_name."->previous_sibling [1]";
832
833 $parent->append_child ($node2);
834 ok $parent->first_child, $node1, $parent->node_name."->first_child [2]";
835 ok $parent->last_child, $node2, $parent->node_name."->last_child [2]";
836 ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [2]";
837 ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [2]";
838 ok $node2->next_sibling, undef, $parent->node_name."2->next_sibling [2]";
839 ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [2]";
840
841 $parent->append_child ($node3);
842 ok $parent->first_child, $node1, $parent->node_name."->first_child [3]";
843 ok $parent->last_child, $node3, $parent->node_name."->last_child [3]";
844 ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [3]";
845 ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [3]";
846 ok $node2->next_sibling, $node3, $parent->node_name."2->next_sibling [3]";
847 ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [3]";
848 ok $node3->next_sibling, undef, $parent->node_name."3->next_sibling [3]";
849 ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]";
850 }
851
852 ## |prefix| setter
853 for my $node (create_nodes ()) {
854 $node->manakai_set_read_only (0);
855
856 $node->prefix ('non-null');
857 if ($node->node_type == $node->ELEMENT_NODE or
858 $node->node_type == $node->ATTRIBUTE_NODE) {
859 ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)';
860 } else {
861 ok $node->prefix, undef, $node->node_name . '->prefix (non-null)';
862 }
863
864 $node->prefix (undef);
865 if ($node->node_type == $node->ELEMENT_NODE or
866 $node->node_type == $node->ATTRIBUTE_NODE) {
867 ok $node->prefix, undef, $node->node_name . '->prefix (null)';
868 } else {
869 ok $node->prefix, undef, $node->node_name . '->prefix (null)';
870 }
871
872 $node->manakai_set_read_only (1);
873 my $err_type;
874 try {
875 $node->prefix ('non-null');
876 } catch Message::IF::DOMException with {
877 my $err = shift;
878 $err_type = $err->type;
879 };
880 if ($node->node_type == $node->ELEMENT_NODE or
881 $node->node_type == $node->ATTRIBUTE_NODE) {
882 ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR',
883 $node->node_name . '->prefix exception (read-only)';
884 ok $node->prefix, undef, $node->node_name . '->prefix (read-only)';
885 } else {
886 ok $err_type, undef, $node->node_name . '->prefix exception (read-only)';
887 ok $node->prefix, undef, $node->node_name . '->prefix (read-only)';
888 }
889 }
890
891 ## |text_content|
892 {
893 my $doc2 = $doc->implementation->create_document;
894 $doc2->dom_config->set_parameter
895 ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1);
896 for my $node (
897 $doc2,
898 $doc->create_document_type_definition ('dt1'),
899 $doc->implementation->create_document_type ('doctype1'),
900 $doc->create_notation ('notation1'),
901 $doc->create_element_type_definition ('et1'),
902 ) {
903 ok $node->can ('text_content') ? 1 : 0, 1,
904 $node->node_name . '->can text_content';
905
906 ok $node->text_content, undef, $node->node_name . '->text_content';
907
908 $node->manakai_set_read_only (0);
909 $node->text_content ('new-text-content');
910 ok $node->text_content, undef, $node->node_name . '->text_content set';
911
912 $node->manakai_set_read_only (1);
913 $node->text_content ('new-text-content');
914 ok $node->text_content, undef,
915 $node->node_name . '->text_content set (read-only)';
916 }
917
918 $doc2->dom_config->set_parameter
919 ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0);
920 for my $node (
921 $doc2,
922 $doc->create_attribute ('attr1'),
923 $doc->create_attribute_definition ('at1'),
924 $doc->create_element ('element1'),
925 $doc->create_general_entity ('entity1'),
926 $doc->create_entity_reference ('entity-reference1'),
927 $doc->create_document_fragment,
928 ) {
929 ok $node->can ('text_content') ? 1 : 0, 1,
930 $node->node_name . '->can text_content';
931
932 ok $node->text_content, '', $node->node_name . '->text_content';
933
934 $node->manakai_set_read_only (0);
935 $node->text_content ('text1');
936 ok $node->text_content, 'text1', $node->node_name . '->text_content set';
937 ok 0+@{$node->child_nodes}, 1,
938 $node->node_name . '->text_content set child_nodes length';
939
940 $node->text_content ('');
941 ok $node->text_content, '', $node->node_name . '->text_content set empty';
942 ok 0+@{$node->child_nodes}, 0,
943 $node->node_name . '->text_content set empty child_nodes length';
944
945 $node->text_content ('text2');
946 $node->text_content ('');
947 ok $node->text_content, '', $node->node_name . '->text_content set empty';
948 ok 0+@{$node->child_nodes}, 0,
949 $node->node_name . '->text_content set empty child_nodes length';
950
951 $node->text_content ('text3');
952 $node->manakai_set_read_only (1);
953 try {
954 $node->text_content ('new-text-content');
955 ok undef, 'NO_MODIFICATION_ALLOWED_ERR',
956 $node->node_name . '->text_content set (read-only)';
957 } catch Message::IF::DOMException with {
958 my $err = shift;
959 ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR',
960 $node->node_name . '->text_content set (read-only)';
961 };
962 ok $node->text_content, 'text3',
963 $node->node_name . '->text_content set (read-only) text_content';
964 }
965
966
967 for (0..2) {
968 my $el;
969 my $ce;
970
971 [
972 sub {
973 $el = $doc->create_element ('nestingElement');
974 $ce = $doc->create_element ('el2');
975 },
976 sub {
977 $el = $doc->create_element ('elementWithEntityReference');
978 $ce = $doc->create_entity_reference ('ent');
979 $ce->manakai_set_read_only (0, 1);
980 },
981 sub {
982 $el = $doc->create_general_entity ('generalEntityWithChild');
983 $ce = $doc->create_element ('el');
984 $el->manakai_set_read_only (0, 1);
985 },
986 ]->[$_]->();
987 $el->append_child ($ce);
988
989 ok $el->text_content, '', $el->node_name . '->text_content [1]';
990
991 $ce->text_content ('gc');
992 ok $el->text_content, 'gc', $el->node_name . '->text_content [2]';
993
994 $el->manakai_append_text ('cc');
995 ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]';
996
997 $el->text_content ('nc');
998 ok $el->text_content, 'nc', $el->node_name . '->text_content [4]';
999 ok 0+@{$el->child_nodes}, 1,
1000 $el->node_name . '->text_content child_nodes length [4]';
1001 ok $ce->parent_node, undef,
1002 $el->node_name . '->text_content old_child parent_node [4]';
1003 }
1004 }
1005
1006 ## |manakaiReadOnly| and |manakaiSetReadOnly|
1007 {
1008 for my $node (create_nodes ()) {
1009 $node->manakai_set_read_only (1, 0);
1010 ok $node->manakai_read_only ? 1 : 0, 1,
1011 $node->node_name . '->manakai_set_read_only (1, 0) [1]';
1012
1013 $node->manakai_set_read_only (0, 0);
1014 ok $node->manakai_read_only ? 1 : 0, 0,
1015 $node->node_name . '->manakai_set_read_only (0, 0)';
1016
1017 $node->manakai_set_read_only (1, 0);
1018 ok $node->manakai_read_only ? 1 : 0, 1,
1019 $node->node_name . '->manakai_set_read_only (1, 0) [2]';
1020 }
1021
1022 {
1023 my $el = $doc->create_element ('readOnlyElement1');
1024 my $c1 = $doc->create_element ('c1');
1025 $el->append_child ($c1);
1026 my $c2 = $doc->create_text_node ('c2');
1027 $el->append_child ($c2);
1028 my $c3 = $doc->create_element ('c3');
1029 $el->append_child ($c3);
1030 my $c4 = $doc->create_attribute ('c4');
1031 $el->set_attribute_node ($c4);
1032 my $c5 = $doc->create_entity_reference ('c5');
1033 $el->append_child ($c5);
1034
1035 $el->manakai_set_read_only (1, 1);
1036 for ($c1, $c2, $c3, $c4, $c5) {
1037 ok $_->manakai_read_only ? 1 : 0, 1,
1038 $el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1039 }
1040
1041 $el->manakai_set_read_only (0, 1);
1042 for ($c1, $c2, $c3, $c4, $c5) {
1043 ok $_->manakai_read_only ? 1 : 0, 0,
1044 $el->node_name . '->read_only (1, 0) ' . $_->node_name;
1045 }
1046
1047 $el->manakai_set_read_only (1, 1);
1048 for ($c1, $c2, $c3, $c4, $c5) {
1049 ok $_->manakai_read_only ? 1 : 0, 1,
1050 $el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1051 }
1052 }
1053
1054 {
1055 my $dtd = $doc->create_document_type_definition ('readOnlyDTDef1');
1056 my $c1 = $doc->create_processing_instruction ('c1', '');
1057 $dtd->append_child ($c1);
1058 my $c2 = $doc->create_element_type_definition ('c2');
1059 $dtd->set_element_type_definition_node ($c2);
1060 my $c3 = $doc->create_general_entity ('c3');
1061 $dtd->set_general_entity_node ($c3);
1062 my $c4 = $doc->create_notation ('c4');
1063 $dtd->set_notation_node ($c4);
1064 my $c5 = $doc->create_text_node ('c5');
1065 $c3->append_child ($c5);
1066
1067 $dtd->manakai_set_read_only (1, 1);
1068 for ($c1, $c2, $c3, $c4, $c5) {
1069 ok $_->manakai_read_only ? 1 : 0, 1,
1070 $dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1071 }
1072
1073 $dtd->manakai_set_read_only (0, 1);
1074 for ($c1, $c2, $c3, $c4, $c5) {
1075 ok $_->manakai_read_only ? 1 : 0, 0,
1076 $dtd->node_name . '->read_only (1, 0) ' . $_->node_name;
1077 }
1078
1079 $dtd->manakai_set_read_only (1, 1);
1080 for ($c1, $c2, $c3, $c4, $c5) {
1081 ok $_->manakai_read_only ? 1 : 0, 1,
1082 $dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1083 }
1084 }
1085
1086 {
1087 my $et = $doc->create_element_type_definition ('readOnlyETDef1');
1088 my $c1 = $doc->create_element ('c1');
1089 $et->set_attribute_definition_node ($c1);
1090 my $c2 = $doc->create_text_node ('c2');
1091 $c1->append_child ($c2);
1092
1093 $et->manakai_set_read_only (1, 1);
1094 for ($c1, $c2) {
1095 ok $_->manakai_read_only ? 1 : 0, 1,
1096 $et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1097 }
1098
1099 $et->manakai_set_read_only (0, 1);
1100 for ($c1, $c2) {
1101 ok $_->manakai_read_only ? 1 : 0, 0,
1102 $et->node_name . '->read_only (1, 0) ' . $_->node_name;
1103 }
1104
1105 $et->manakai_set_read_only (1, 1);
1106 for ($c1, $c2) {
1107 ok $_->manakai_read_only ? 1 : 0, 1,
1108 $et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1109 }
1110 }
1111 }
1112
1113 ## |manakaiAppendText|
1114 {
1115 my $doc2 = $doc->implementation->create_document;
1116
1117 $doc2->dom_config->set_parameter
1118 ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1);
1119 for my $node (
1120 $doc2,
1121 $doc->create_notation ('Notation_manakaiAppendText'),
1122 $doc->create_document_type_definition ('DT_manakaiAppendText'),
1123 $doc->create_element_type_definition ('ET_manakaiAppendText'),
1124 ) {
1125 ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1126
1127 $node->manakai_append_text ('aaaa');
1128 ok $node->text_content, undef, $node->node_name . ' [1]';
1129 ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1130 }
1131
1132 $doc2->dom_config->set_parameter
1133 ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0);
1134 for my $node (
1135 $doc->create_attribute ('Attr_manakaiAppendText'),
1136 $doc->create_element ('Element_manakaiAppendText'),
1137 $doc2,
1138 $doc->create_document_fragment,
1139 $doc->create_general_entity ('Entity_manakaiAppendText'),
1140 $doc->create_entity_reference ('ER_manakaiAppendText'),
1141 $doc->create_attribute_definition ('AT_manakaiAppendText'),
1142 ) {
1143 $node->manakai_set_read_only (0, 1);
1144 ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1145
1146 $node->manakai_append_text ('string');
1147 ok $node->text_content, 'string', $node->node_name . ' [1]';
1148 ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [1]';
1149
1150 $node->manakai_append_text ('STRING');
1151 ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]';
1152 ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]';
1153
1154 my $er = ($node->owner_document || $node)->create_entity_reference ('er');
1155 $node->append_child ($er);
1156
1157 $node->manakai_append_text ('text');
1158 ok $node->text_content, 'stringSTRINGtext', $node->node_name . ' [3]';
1159 ok 0+@{$node->child_nodes}, 3, $node->node_name . ' childNodes @{} 0+ [3]';
1160 }
1161
1162 for my $node (
1163 $doc->create_text_node (''),
1164 $doc->create_cdata_section (''),
1165 $doc->create_comment (''),
1166 $doc->create_processing_instruction ('PI_manakaiAppendText'),
1167 ) {
1168 ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1169
1170 $node->manakai_append_text ('aaaa');
1171 ok $node->text_content, 'aaaa', $node->node_name . ' [1]';
1172 ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1173
1174 $node->manakai_append_text ('bbbb');
1175 ok $node->text_content, 'aaaabbbb', $node->node_name . ' [1]';
1176 ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1177 }
1178 }
1179
1180 ## |baseURI|
1181 {
1182 my $doc2 = $doc->implementation->create_document;
1183
1184 $doc2->document_uri (q<ftp://suika.fam.cx/>);
1185 ok $doc2->base_uri, q<ftp://suika.fam.cx/>, 'Document->base_uri [1]';
1186
1187 $doc2->document_uri (undef);
1188 ok $doc2->base_uri, undef, 'Document->base_uri [2]';
1189 ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [2]';
1190
1191 $doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>);
1192 ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [3]';
1193 ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>,
1194 'Document->base_uri ebu [3]';
1195
1196 $doc2->manakai_entity_base_uri (undef);
1197 ok $doc2->base_uri, undef, 'Document->base_uri [4]';
1198 ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [4]';
1199
1200 $doc2->document_uri (q<ftp://suika.fam.cx/>);
1201 $doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>);
1202 ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [5]';
1203 ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>,
1204 'Document->base_uri ebu [5]';
1205 }
1206
1207 for my $method (qw/
1208 create_document_fragment
1209 create_element_type_definition
1210 create_attribute_definition
1211 /) {
1212 my $doc2 = $doc->implementation->create_document;
1213
1214 my $node = $doc2->$method ('a');
1215
1216 $doc2->document_uri (q<ftp://doc.test/>);
1217 ok $node->base_uri, q<ftp://doc.test/>, $node->node_name . '->base_uri [1]';
1218
1219 $doc2->manakai_entity_base_uri (q<ftp://suika.fam.cx/>);
1220 ok $node->base_uri, q<ftp://suika.fam.cx/>,
1221 $node->node_name . '->base_uri [2]';
1222 }
1223
1224 {
1225 my $doc2 = $doc->implementation->create_document;
1226
1227 my $attr = $doc2->create_attribute_ns (undef, 'attr');
1228
1229 $doc2->document_uri (q<http://www.example.com/>);
1230 ok $attr->base_uri, q<http://www.example.com/>, 'Attr->base_uri [1]';
1231
1232 my $el = $doc2->create_element_ns (undef, 'element');
1233 $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace',
1234 'xml:base' => q<http://www.example.org/>);
1235 $el->set_attribute_node_ns ($attr);
1236 ok $attr->base_uri, q<http://www.example.org/>, 'Attr->base_uri [2]';
1237 }
1238
1239 for my $i (0..1) {
1240 my $xb = [
1241 ['http://www.w3.org/XML/1998/namespace', 'xml:base'],
1242 [undef, [undef, 'xml:base']],
1243 ]->[$i];
1244
1245 my $doc2 = $doc->implementation->create_document;
1246 $doc2->strict_error_checking (0);
1247
1248 my $attr = $doc2->create_attribute_ns (@$xb);
1249 $attr->value (q<http://attr.test/>);
1250
1251 ok $attr->base_uri, undef, 'xml:base->base_uri [0]' . $i;
1252
1253 $doc2->document_uri (q<http://doc.test/>);
1254 ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [1]' . $i;
1255
1256 my $el = $doc2->create_element_ns (undef, 'e');
1257 $el->set_attribute_node_ns ($attr);
1258 ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [2]' . $i;
1259
1260 my $pel = $doc2->create_element_ns (undef, 'e');
1261 $pel->set_attribute_ns (@$xb, q<http://pel.test/>);
1262 $pel->append_child ($el);
1263 ok $attr->base_uri, q<http://pel.test/>, 'xml:base->base_uri [3]' . $i;
1264 }
1265
1266 for my $i (0..1) {
1267 my $xb = [
1268 ['http://www.w3.org/XML/1998/namespace', 'xml:base'],
1269 [undef, [undef, 'xml:base']],
1270 ]->[$i];
1271
1272 my $doc2 = $doc->implementation->create_document;
1273 $doc2->strict_error_checking (0);
1274
1275 my $el = $doc2->create_element_ns (undef, 'el');
1276
1277 ok $el->base_uri, undef, "Element->base_uri [0]";
1278 ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [0]";
1279
1280 $doc2->document_uri (q<http://foo.example/>);
1281 ok $el->base_uri, q<http://foo.example/>, "Element->base_uri [1]";
1282 ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [1]";
1283
1284 $el->set_attribute_ns (@$xb => q<http://www.example.com/>);
1285 ok $el->base_uri, q<http://www.example.com/>, "Element->base_uri [2]";
1286 ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [2]";
1287
1288 $el->set_attribute_ns (@$xb => q<bar>);
1289 ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [3]";
1290 ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [3]";
1291
1292 $el->manakai_base_uri (q<http://baz.example/>);
1293 ok $el->base_uri, q<http://baz.example/>, "Element->base_uri [4]";
1294 ok $el->manakai_base_uri, q<http://baz.example/>,
1295 "Element->manakai_base_uri [4]";
1296
1297 $el->manakai_base_uri (undef);
1298 ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [5]";
1299 ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [5]";
1300 }
1301
1302 {
1303 my $doc2 = $doc->implementation->create_document;
1304
1305 my $el = $doc2->create_element_ns (undef, 'el');
1306
1307 ok $el->base_uri, undef, "Element->base_uri [6]";
1308
1309 $doc2->document_uri (q<http://doc.test/>);
1310 ok $el->base_uri, q<http://doc.test/>, "Element->base_uri [7]";
1311
1312 my $el0 = $doc2->create_element_ns (undef, 'e');
1313 $el0->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1314 q<http://el.test/>);
1315 $el0->append_child ($el);
1316 ok $el->base_uri, q<http://el.test/>, "Element->base_uri [8]";
1317
1318 my $ent = $doc2->create_entity_reference ('ent');
1319 $ent->manakai_set_read_only (0, 1);
1320 $ent->manakai_external (1);
1321 $ent->manakai_entity_base_uri (q<http://ent.test/>);
1322 $el0->append_child ($ent);
1323 $ent->append_child ($el);
1324 ok $el->base_uri, q<http://ent.test/>, "Element->base_uri [9]";
1325 }
1326
1327 for (qw/create_text_node create_cdata_section create_comment/) {
1328 my $doc2 = $doc->implementation->create_document;
1329 my $node = $doc2->$_ ('');
1330
1331 $doc2->document_uri (q<http://doc.test/>);
1332 ok $node->base_uri, q<http://doc.test/>, $node->node_name . "->base_uri [0]";
1333
1334 my $el = $doc2->create_element_ns (undef, 'e');
1335 $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1336 q<http://el.test/>);
1337 $el->append_child ($node);
1338 ok $node->base_uri, q<http://el.test/>, $node->node_name . "->base_uri [1]";
1339
1340 my $ent = $doc2->create_entity_reference ('ent');
1341 $ent->manakai_set_read_only (0, 1);
1342 $ent->manakai_external (1);
1343 $ent->manakai_entity_base_uri (q<http://ent.test/>);
1344 $el->append_child ($ent);
1345 $ent->append_child ($node);
1346 ok $node->base_uri, q<http://ent.test/>, $node->node_name . "->base_uri [2]";
1347 }
1348
1349 {
1350 my $doc2 = $doc->implementation->create_document;
1351 my $ent = $doc2->create_general_entity ('ent');
1352
1353 $doc2->document_uri (q<http://base.example/>);
1354 ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [1]";
1355
1356 $ent->manakai_entity_base_uri (q<http://www.example.com/>);
1357 ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [2]";
1358
1359 $ent->manakai_declaration_base_uri (q<http://www.example/>);
1360 ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [3]";
1361 }
1362
1363 {
1364 my $doc2 = $doc->implementation->create_document;
1365
1366 my $ent = $doc2->create_entity_reference ('ent');
1367 $ent->manakai_set_read_only (0, 1);
1368
1369 $doc2->document_uri (q<http://base.example/>);
1370 ok $ent->base_uri, q<http://base.example/>, "ER->base_uri [1]";
1371
1372 $ent->manakai_entity_base_uri (q<http://www.example.com/>);
1373 ok $ent->base_uri, q<http://base.example/>;
1374
1375 my $el = $doc2->create_element_ns (undef, 'el');
1376 $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1377 q<http://el.test/>);
1378 $el->append_child ($ent);
1379 ok $ent->base_uri, q<http://el.test/>, "ER->base_uri [2]";
1380
1381 my $xent = $doc2->create_entity_reference ('ext');
1382 $xent->manakai_set_read_only (0, 1);
1383 $xent->manakai_entity_base_uri (q<http://ent.test/>);
1384 $xent->manakai_external (1);
1385 $el->append_child ($xent);
1386 $xent->append_child ($ent);
1387 ok $ent->base_uri, q<http://ent.test/>, "ER->base_uri [3]";
1388 }
1389
1390 {
1391 my $doc2 = $doc->implementation->create_document;
1392
1393 my $pi = $doc2->create_processing_instruction ('i');
1394
1395 ok $pi->base_uri, undef, "PI->base_uri [0]";
1396 ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [0]";
1397
1398 $doc2->document_uri (q<http://doc.test/>);
1399 ok $pi->base_uri, q<http://doc.test/>, "PI->base_uri [1]";
1400 ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [1]";
1401
1402 my $el = $doc2->create_element_ns (undef, 'e');
1403 $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1404 q<http://el.test/>);
1405 $el->append_child ($pi);
1406 ok $pi->base_uri, q<http://el.test/>, "PI->base_uri [2]";
1407 ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [2]";
1408
1409 my $ent = $doc2->create_entity_reference ('ent');
1410 $ent->manakai_set_read_only (0, 1);
1411 $ent->manakai_external (1);
1412 $ent->manakai_entity_base_uri (q<http://ent.test/>);
1413 $el->append_child ($ent);
1414 $ent->append_child ($pi);
1415 ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [3]";
1416 ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [3]";
1417
1418 $pi->manakai_base_uri (q<http://pi.ent/>);
1419 ok $pi->base_uri, q<http://pi.ent/>, "PI->base_uri [4]";
1420 ok $pi->manakai_base_uri, q<http://pi.ent/>, "PI->manakai_base_uri [4]";
1421
1422 $pi->manakai_base_uri (undef);
1423 ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [5]";
1424 ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [5]";
1425 }
1426
1427 {
1428 my $doc2 = $doc->implementation->create_document;
1429
1430 my $pi = $doc2->create_notation ('i');
1431
1432 $doc2->document_uri (q<http://doc.test/>);
1433 ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [1]";
1434
1435 $pi->manakai_declaration_base_uri (q<http://www.example/>);
1436 ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [2]";
1437 }
1438
1439 {
1440 my $dt = $doc->implementation->create_document_type ('name');
1441 ok $dt->base_uri, undef, "DT->base_uri [0]";
1442
1443 my $doc2 = $doc->implementation->create_document;
1444 $doc2->append_child ($dt);
1445 $doc2->document_uri (q<http://doc.test/>);
1446 ok $dt->owner_document, $doc2;
1447 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 [Events => '3.0', 1], ['+Events' => '3.0', 1], ['Events' => '', 1],
1820 [Traversal => '2.0', 1], [Traversal => '', 1], [Traversal => '1.0', 0],
1821 [XML => '1.0', 1],
1822 [XML => '2.0', 1],
1823 [XML => '3.0', 1],
1824 [XML => '', 1],
1825 [XML => undef, 1],
1826 ['+XML' => undef, 1],
1827 [XMLVersion => '1.0', 1],
1828 [XMLVersion => '1.1', 1],
1829 [XMLVersion => '', 1],
1830 [XMLVersion => undef, 1],
1831 ['+XMLVersion' => undef, 1],
1832 [unknown => 3, 0],
1833 [unknown => '', 0],
1834 [unknown => undef, 0],
1835 ['+unknown' => undef, 0],
1836 [q<http://suika.fam.cx/www/2006/feature/xdoctype> => '', 1],
1837 [q<http://suika.fam.cx/www/2006/feature/xdoctype> => '3.0', 1],
1838 [q<http://suika.fam.cx/www/2006/feature/Atom> => '', 1],
1839 [q<http://suika.fam.cx/www/2006/feature/Atom> => '1.0', 1],
1840 [q<http://suika.fam.cx/www/2006/feature/AtomThreading> => '', 1],
1841 [q<http://suika.fam.cx/www/2006/feature/AtomThreading> => '1.0', 1],
1842 ) {
1843 my $label = $node->node_name . ' ' . $_->[0] . ', ' .
1844 (defined $_->[1] ? $_->[1] : 'undef');
1845 ok $node->can ('get_feature') ? 1 : 0, 1, 'can get_feature ' . $label;
1846 ok $node->get_feature ($_->[0], $_->[1]), $_->[2] ? $node : undef,
1847 'get_feature ' . $label;
1848 ok $node->can ('is_supported') ? 1 : 0, 1, 'can is_supported ' . $label;
1849 ok $node->is_supported ($_->[0], $_->[1]) ? 1 : 0, $_->[2],
1850 'is_supported ' . $label;
1851 }
1852 }
1853
1854 ## |isEqualNode|
1855 for my $node (create_nodes ()) {
1856 ok $node->can ('is_equal_node') ? 1 : 0, 1, $node->node_name . '->is_eq_n can';
1857
1858 ok $node->is_equal_node ($node) ? 1 : 0, 1, $node->node_name . '->iseq self';
1859 ok $node == $node ? 1 : 0, 1, $node->node_name . ' == self';
1860 ok $node != $node ? 1 : 0, 0, $node->node_name . ' != self';
1861 ok $node == 'node' ? 1 : 0, 0, $node->node_name . ' == string';
1862 ok $node != 'node' ? 1 : 0, 1, $node->node_name . ' != string';
1863 ok $node == 0 ? 1 : 0, 0, $node->node_name . ' == num';
1864 ok $node != 0 ? 1 : 0, 1, $node->node_name . ' != num';
1865 ok $node == '' ? 1 : 0, 0, $node->node_name . ' == empty';
1866 ok $node != '' ? 1 : 0, 1, $node->node_name . ' != empty';
1867 ok $node == undef () ? 1 : 0, 0, $node->node_name . ' == undef';
1868 ok $node != undef () ? 1 : 0, 1, $node->node_name . ' != undef';
1869 }
1870
1871 {
1872 my $el1 = $doc->create_element_ns (undef, 'type');
1873 my $el2 = $doc->create_element_ns (undef, 'type');
1874 my $el3 = $doc->create_element_ns (undef, 'TYPE');
1875
1876 ok $el1 == $el2 ? 1 : 0, 1, 'Element == [1]';
1877 ok $el1 != $el2 ? 1 : 0, 0, 'Element != [1]';
1878 ok $el1 == $el3 ? 1 : 0, 0, 'Element == [2]';
1879 ok $el1 != $el3 ? 1 : 0, 1, 'Element != [2]';
1880
1881 my $el4 = $doc->create_element_ns ('about:', 'type');
1882 my $el5 = $doc->create_element_ns ('about:', 'type');
1883 my $el6 = $doc->create_element_ns ('about:', 'TYPE');
1884 my $el7 = $doc->create_element_ns ('DAV:', 'type');
1885
1886 ok $el1 == $el4 ? 1 : 0, 0, 'Element == [3]';
1887 ok $el1 != $el4 ? 1 : 0, 1, 'Element != [3]';
1888 ok $el4 == $el5 ? 1 : 0, 1, 'Element == [4]';
1889 ok $el4 != $el5 ? 1 : 0, 0, 'Element != [4]';
1890 ok $el4 == $el6 ? 1 : 0, 0, 'Element == [5]';
1891 ok $el4 != $el6 ? 1 : 0, 1, 'Element != [5]';
1892 ok $el4 == $el7 ? 1 : 0, 0, 'Element == [6]';
1893 ok $el4 != $el7 ? 1 : 0, 1, 'Element != [6]';
1894
1895 $el5->prefix ('prefix');
1896 ok $el4 == $el5 ? 1 : 0, 0, 'Element == [7]';
1897 ok $el4 != $el5 ? 1 : 0, 1, 'Element != [7]';
1898 }
1899
1900 ## |getUserData|, |setUserData|
1901 {
1902 my $node = $dom->create_document;
1903
1904 my $data = ['2'];
1905 my $handler = sub { 1 };
1906
1907 ok $node->set_user_data ('key1', $data, $handler), undef,
1908 'set_user_data [1]';
1909
1910 my $key1_data = $node->get_user_data ('key1');
1911 ok $key1_data, $data, 'set_user_data [2]';
1912 ok $key1_data->[0], $data->[0], 'set_user_data [3]';
1913
1914 my $data2 = ['4'];
1915 ok $node->set_user_data ('key1', $data2, undef), $data, 'set_user_data [4]';
1916 ok $node->get_user_data ('key1'), $data2, 'set_user_data [5]';
1917
1918 $node->set_user_data (key1 => undef, $handler);
1919 ok $node->get_user_data ('key1'), undef, 'set_user_data [6]';
1920
1921 $node->set_user_data (key1 => undef, undef);
1922 ok $node->get_user_data ('key1'), undef, 'set_user_data [7]';
1923 }
1924
1925 ## |removeChild|
1926 {
1927 my $el = $doc->create_element ('p');
1928 my $c1 = $doc->create_element ('e');
1929 $el->append_child ($c1);
1930 my $c2 = $doc->create_element ('f');
1931 $el->append_child ($c2);
1932 my $c3 = $doc->create_element ('g');
1933 $el->append_child ($c3);
1934 ok $el->can ('remove_child') ? 1 : 0, 1, 'Node->remove_child can [0]';
1935
1936 my $return = $el->remove_child ($c1);
1937 ok $return, $c1, 'Node->remove_child return [1]';
1938 ok $c1->parent_node, undef, 'Node->remove_child parent_node [1]';
1939 ok $el->first_child, $c2, 'Node->remove_child first_child [1]';
1940 ok $el->last_child, $c3, 'Node->remove_child last_child [1]';
1941 ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [1]';
1942 }
1943 {
1944 my $el = $doc->create_element ('p');
1945 my $c1 = $doc->create_element ('e');
1946 $el->append_child ($c1);
1947 my $c2 = $doc->create_element ('f');
1948 $el->append_child ($c2);
1949 my $c3 = $doc->create_element ('g');
1950 $el->append_child ($c3);
1951
1952 my $return = $el->remove_child ($c2);
1953 ok $return, $c2, 'Node->remove_child return [2]';
1954 ok $c2->parent_node, undef, 'Node->remove_child parent_node [2]';
1955 ok $el->first_child, $c1, 'Node->remove_child first_child [2]';
1956 ok $el->last_child, $c3, 'Node->remove_child last_child [2]';
1957 ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [2]';
1958 }
1959 {
1960 my $el = $doc->create_element ('p');
1961 my $c1 = $doc->create_element ('e');
1962 $el->append_child ($c1);
1963 my $c2 = $doc->create_element ('f');
1964 $el->append_child ($c2);
1965 my $c3 = $doc->create_element ('g');
1966 $el->append_child ($c3);
1967
1968 my $return = $el->remove_child ($c3);
1969 ok $return, $c3, 'Node->remove_child return [3]';
1970 ok $c3->parent_node, undef, 'Node->remove_child parent_node [3]';
1971 ok $el->first_child, $c1, 'Node->remove_child first_child [3]';
1972 ok $el->last_child, $c2, 'Node->remove_child last_child [3]';
1973 ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [3]';
1974 }
1975 {
1976 my $el = $doc->create_element ('p');
1977 my $c1 = $doc->create_element ('e');
1978 $el->append_child ($c1);
1979
1980 my $return = $el->remove_child ($c1);
1981 ok $return, $c1, 'Node->remove_child return [4]';
1982 ok $c1->parent_node, undef, 'Node->remove_child parent_node [4]';
1983 ok $el->first_child, undef, 'Node->remove_child first_child [4]';
1984 ok $el->last_child, undef, 'Node->remove_child last_child [4]';
1985 ok 0+@{$el->child_nodes}, 0, 'Node->remove_child child_nodes [4]';
1986 }
1987
1988 ## |appendChild|, |insertBefore|, |replaceChild|
1989 for my $node (create_leaf_nodes) {
1990 for my $method_name (qw/append_child insert_before replace_child/) {
1991 ok $node->can ($method_name) ? 1 : 0, 1,
1992 $node->node_name . '->can ' . $method_name;
1993
1994 for my $node2 (create_nodes) {
1995 try {
1996 if ($method_name eq 'replace_child') {
1997 $node->replace_child ($node2, $node2);
1998 } else {
1999 $node->$method_name ($node2);
2000 }
2001 ok 1, 0,
2002 $node->node_name . '->' . $method_name . ' ' . $node2->node_name;
2003 } catch Message::IF::DOMException with {
2004 if ($_[0]->type eq 'HIERARCHY_REQUEST_ERR' or
2005 ($_[0]->type eq 'WRONG_DOCUMENT_ERR' and
2006 ($node2->owner_document or $node2) ne $doc) or
2007 ($_[0]->type eq 'NOT_FOUND_ERR' and
2008 $method_name eq 'replace_child')) {
2009 ok 1, 1,
2010 $node->node_name . '->' . $method_name . ' ' . $node2->node_name;
2011 }
2012 };
2013 }
2014 }
2015 }
2016
2017 ## TODO: parent_node tests, as with append_child tests
2018
2019 ## TODO: text_content tests for CharacterData and PI
2020
2021 ## |UserDataHandler|, |setData|, and |NODE_DELETED|
2022 ## NOTE: This should be the last test, since it does define
2023 ## Node.DESTORY.
2024 {
2025 my $doc = $dom->create_document ('http://test/', 'ex');
2026 my $node = $doc->document_element;
2027
2028 $node->set_user_data (key => {}, sub {
2029 my ($op, $key, $data, $src, $dest) = @_;
2030
2031 ok $op, 3, 'set_user_data operation [8]'; # NODE_DELETED
2032 ok $key, 'key', 'set_user_data key [8]';
2033 ok ref $data, 'HASH', 'set_user_data data [8]';
2034 ok $src, undef, 'set_user_data src [8]';
2035 ok $dest, undef, 'set_user_data dest [8]';
2036 });
2037
2038 undef $node;
2039 undef $doc;
2040
2041 ## NOTE: We cannot control exactly when it is called.
2042 }
2043
2044 ## |manakaiLanguage|
2045 {
2046 my $el = $doc->create_element_ns (undef, 'e');
2047 $doc->strict_error_checking (0);
2048
2049 ok $el->manakai_language, '', 'mlanguage [0]';
2050
2051 my $xml_ns = q<http://www.w3.org/XML/1998/namespace>;
2052
2053 my $parent = $doc->create_element ('e');
2054 $parent->set_attribute_ns ($xml_ns, 'xml:lang', 'en');
2055 $parent->append_child ($el);
2056 ok $el->manakai_language, 'en', 'mlanguage [1]';
2057
2058 my $parent2 = $doc->create_element_ns (undef, 'e');
2059 $parent2->set_attribute_ns (undef, [undef, 'xml:lang'], 'ja');
2060 $parent2->append_child ($el);
2061 ok $el->manakai_language, 'ja', 'mlanguage [2]';
2062
2063 $el->set_attribute_ns ($xml_ns, 'xml:lang', 'en');
2064 ok $el->manakai_language, 'en', 'mlanguage [3]';
2065
2066 $el->set_attribute_ns ($xml_ns, 'xml:lang', 'fr');
2067 $el->set_attribute_ns (undef, [undef, 'xml:lang'], 'es');
2068 ok $el->manakai_language, 'fr', 'mlanguage [4]';
2069
2070 $el->remove_attribute_ns ($xml_ns, 'lang');
2071 ok $el->manakai_language, 'es', 'mlanguage [5]';
2072 }
2073 {
2074 my $el = $doc->create_element_ns (undef, 'e');
2075 my $xml_ns = q<http://www.w3.org/XML/1998/namespace>;
2076
2077 $el->manakai_language ('ja');
2078 ok $el->manakai_language, 'ja', 'mlanguage [6]';
2079
2080 my $attr = $el->get_attribute_node_ns ($xml_ns, 'lang');
2081 ok $attr->value, 'ja', 'mlanguage [7]';
2082 ok $attr->specified ? 1 : 0, 1, 'mlanguage [8]';
2083
2084 $el->manakai_language ('en');
2085 ok $el->manakai_language, 'en', 'mlanguage [9]';
2086 ok $attr->value, 'en', 'mlanguage [a]';
2087
2088 $el->manakai_language ('');
2089 ok $attr->value, '', 'mlanguage [b]';
2090 ok $attr->owner_element, $el, 'mlanguage [c]';
2091 ok $el->get_attribute_ns ($xml_ns, 'lang'), '', 'mlanguage [d]';
2092 ok $el->manakai_language, '', 'mlanguage [e]';
2093
2094 $el->manakai_language (undef);
2095 ok $attr->value, '', 'mlanguage [f]';
2096 ok $attr->owner_element, undef, 'mlanguage [g]';
2097 ok $el->get_attribute_ns ($xml_ns, 'lang'), undef, 'mlanguage [h]';
2098 ok $el->manakai_language, '', 'mlanguage [i]';
2099 }
2100
2101 =head1 LICENSE
2102
2103 Copyright 2007 Wakaba <w@suika.fam.cx>
2104
2105 This program is free software; you can redistribute it and/or
2106 modify it under the same terms as Perl itself.
2107
2108 =cut
2109
2110 ## $Date: 2007/08/25 08:41:01 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24