1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
|
|
BEGIN { plan tests => 258 } |
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 |
|
|
## |manakai_create_serial_walker| and attributes |
13 |
|
|
{ |
14 |
|
|
ok $doc->can ('manakai_create_serial_walker') ? 1 : 0, 1, 'create_sw can'; |
15 |
|
|
|
16 |
|
|
my $el = $doc->create_element ('e'); |
17 |
|
|
my $tw = $doc->manakai_create_serial_walker ($el); |
18 |
|
|
|
19 |
|
|
ok $tw->isa ('Message::IF::SerialWalker') ? 1 : 0, 1, 'create_sw [1] if'; |
20 |
|
|
ok $tw->what_to_show, 0, 'create_sw [1] what_to_show'; |
21 |
|
|
ok $tw->filter, undef, 'create_sw [1] filter'; |
22 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 0, 'create_sw [1] xent'; |
23 |
|
|
ok $tw->current_node, $el, 'create_sw [1] current_node'; |
24 |
|
|
ok $tw->root, $el, 'create_sw [1] root'; |
25 |
|
|
} |
26 |
|
|
{ |
27 |
|
|
my $el = $doc->create_element ('e'); |
28 |
|
|
my $filter = sub { }; |
29 |
|
|
my $tw = $doc->manakai_create_serial_walker ($el, 0xFFFFFFFF, $filter, 1); |
30 |
|
|
|
31 |
|
|
ok $tw->isa ('Message::IF::SerialWalker') ? 1 : 0, 1, 'create_sw [2] if'; |
32 |
|
|
ok $tw->what_to_show, 0xFFFFFFFF, 'create_sw [2] what_to_show'; |
33 |
|
|
ok $tw->filter, $filter, 'create_sw [2] filter'; |
34 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 1, 'create_sw [2] xent'; |
35 |
|
|
ok $tw->current_node, $el, 'create_sw [2] current_node'; |
36 |
|
|
ok $tw->root, $el, 'create_sw [2] root'; |
37 |
|
|
} |
38 |
|
|
{ |
39 |
|
|
my $el = $doc->create_element ('e'); |
40 |
|
|
my $filter = sub { }; |
41 |
|
|
my $tw = $doc->manakai_create_serial_walker ($el, 0xFFFFFFFF, $filter, 0); |
42 |
|
|
|
43 |
|
|
ok $tw->isa ('Message::IF::SerialWalker') ? 1 : 0, 1, 'create_sw [3] if'; |
44 |
|
|
ok $tw->what_to_show, 0xFFFFFFFF, 'create_sw [3] what_to_show'; |
45 |
|
|
ok $tw->filter, $filter, 'create_sw [3] filter'; |
46 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 0, 'create_sw [3] xent'; |
47 |
|
|
ok $tw->current_node, $el, 'create_sw [3] current_node'; |
48 |
|
|
ok $tw->root, $el, 'create_sw [3] root'; |
49 |
|
|
} |
50 |
|
|
try { |
51 |
|
|
$doc->manakai_create_serial_walker; |
52 |
|
|
ok 1, 0, 'create_sw [4]'; |
53 |
|
|
} catch Message::IF::DOMException with { |
54 |
|
|
ok $_[0]->type, 'NOT_SUPPORTED_ERR', 'create_sw [4]'; |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
my %tree3; |
58 |
|
|
$tree3{el1} = $doc->create_element ('el1'); |
59 |
|
|
$tree3{el2} = $doc->create_element ('el2'); |
60 |
|
|
$tree3{el3} = $doc->create_element ('el3'); |
61 |
|
|
$tree3{el4} = $doc->create_element ('el4'); |
62 |
|
|
$tree3{el5} = $doc->create_element ('el5'); |
63 |
|
|
$tree3{el1}->append_child ($tree3{el2}); |
64 |
|
|
$tree3{el1}->append_child ($tree3{el3}); |
65 |
|
|
$tree3{el3}->append_child ($tree3{el4}); |
66 |
|
|
$tree3{el1}->append_child ($tree3{el5}); |
67 |
|
|
|
68 |
|
|
ok $doc->can ('manakai_create_serial_walker') ? 1 : 0, 1, 'can create_sw'; |
69 |
|
|
|
70 |
|
|
## |nextNode| |
71 |
|
|
{ |
72 |
|
|
my $sw = $doc->manakai_create_serial_walker |
73 |
|
|
($tree3{el1}, 0xFFFFFFFF); |
74 |
|
|
|
75 |
|
|
ok $sw->can ('next_node') ? 1 : 0, 1, 'can next_node'; |
76 |
|
|
|
77 |
|
|
for ( |
78 |
|
|
[1, 'el1', 'el1', $sw->PRE_PHASE, 0], |
79 |
|
|
[2, 'el2', 'el2', $sw->PRE_PHASE, 0], |
80 |
|
|
[3, 'el2', 'el2', $sw->POST_PHASE, 1], |
81 |
|
|
[4, 'el1', 'el1', $sw->IN_PHASE, 1], |
82 |
|
|
[5, 'el3', 'el3', $sw->PRE_PHASE, 0], |
83 |
|
|
[6, 'el4', 'el4', $sw->PRE_PHASE, 0], |
84 |
|
|
[7, 'el4', 'el4', $sw->POST_PHASE, 1], |
85 |
|
|
[8, 'el3', 'el3', $sw->POST_PHASE, 1], |
86 |
|
|
[9, 'el1', 'el1', $sw->IN_PHASE, 2], |
87 |
|
|
[10, 'el5', 'el5', $sw->PRE_PHASE, 0], |
88 |
|
|
[11, 'el5', 'el5', $sw->POST_PHASE, 1], |
89 |
|
|
[12, 'el1', 'el1', $sw->POST_PHASE, 3], |
90 |
|
|
[13, undef, 'el1', $sw->POST_PHASE, 3], |
91 |
|
|
[14, undef, 'el1', $sw->POST_PHASE, 3], |
92 |
|
|
) { |
93 |
|
|
ok $sw->next_node, $_->[1] ? $tree3{$_->[1]} : undef, |
94 |
|
|
$_->[0] . ' next_node [0] next_node'; |
95 |
|
|
ok $sw->current_node, $tree3{$_->[2]}, |
96 |
|
|
$_->[0] . ' next_node [0] current_node'; |
97 |
|
|
ok $sw->current_phase, $_->[3], |
98 |
|
|
$_->[0] . ' next_node [0] current_phase'; |
99 |
|
|
ok $sw->current_index, $_->[4], |
100 |
|
|
$_->[0] . ' next_node [0] current_index'; |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
{ |
104 |
|
|
my $sw = $doc->manakai_create_serial_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
105 |
|
|
$_[0]->local_name ne 'el3' ? 1 : 3; # ACCEPT : SKIP |
106 |
|
|
}); |
107 |
|
|
|
108 |
|
|
for ( |
109 |
|
|
[1, 'el1', 'el1', $sw->PRE_PHASE, 0], |
110 |
|
|
[2, 'el2', 'el2', $sw->PRE_PHASE, 0], |
111 |
|
|
[3, 'el2', 'el2', $sw->POST_PHASE, 1], |
112 |
|
|
[4, 'el1', 'el1', $sw->IN_PHASE, 1], |
113 |
|
|
[6, 'el4', 'el4', $sw->PRE_PHASE, 0], |
114 |
|
|
[7, 'el4', 'el4', $sw->POST_PHASE, 1], |
115 |
|
|
[9, 'el1', 'el1', $sw->IN_PHASE, 2], |
116 |
|
|
[10, 'el5', 'el5', $sw->PRE_PHASE, 0], |
117 |
|
|
[11, 'el5', 'el5', $sw->POST_PHASE, 1], |
118 |
|
|
[12, 'el1', 'el1', $sw->POST_PHASE, 3], |
119 |
|
|
[13, undef, 'el1', $sw->POST_PHASE, 3], |
120 |
|
|
[14, undef, 'el1', $sw->POST_PHASE, 3], |
121 |
|
|
) { |
122 |
|
|
ok $sw->next_node, $_->[1] ? $tree3{$_->[1]} : undef, |
123 |
|
|
$_->[0] . ' next_node [1] next_node'; |
124 |
|
|
ok $sw->current_node, $tree3{$_->[2]}, |
125 |
|
|
$_->[0] . ' next_node [1] current_node'; |
126 |
|
|
ok $sw->current_phase, $_->[3], |
127 |
|
|
$_->[0] . ' next_node [1] current_phase'; |
128 |
|
|
ok $sw->current_index, $_->[4], |
129 |
|
|
$_->[0] . ' next_node [1] current_index'; |
130 |
|
|
} |
131 |
|
|
} |
132 |
|
|
{ |
133 |
|
|
my $sw = $doc->manakai_create_serial_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
134 |
|
|
$_[0]->local_name eq 'el3' ? 12101 : 1; |
135 |
|
|
}); |
136 |
|
|
|
137 |
|
|
for ( |
138 |
|
|
[1, 'el1', 'el1', $sw->PRE_PHASE, 0], |
139 |
|
|
[2, 'el2', 'el2', $sw->PRE_PHASE, 0], |
140 |
|
|
[3, 'el2', 'el2', $sw->POST_PHASE, 1], |
141 |
|
|
[4, 'el1', 'el1', $sw->IN_PHASE, 1], |
142 |
|
|
[3, 'el3', 'el3', $sw->PRE_PHASE, 0], |
143 |
|
|
[8, 'el3', 'el3', $sw->POST_PHASE, 1], |
144 |
|
|
[9, 'el1', 'el1', $sw->IN_PHASE, 2], |
145 |
|
|
[10, 'el5', 'el5', $sw->PRE_PHASE, 0], |
146 |
|
|
[11, 'el5', 'el5', $sw->POST_PHASE, 1], |
147 |
|
|
[12, 'el1', 'el1', $sw->POST_PHASE, 3], |
148 |
|
|
[13, undef, 'el1', $sw->POST_PHASE, 3], |
149 |
|
|
[14, undef, 'el1', $sw->POST_PHASE, 3], |
150 |
|
|
) { |
151 |
|
|
ok $sw->next_node, $_->[1] ? $tree3{$_->[1]} : undef, |
152 |
|
|
$_->[0] . ' next_node [2] next_node'; |
153 |
|
|
ok $sw->current_node, $tree3{$_->[2]}, |
154 |
|
|
$_->[0] . ' next_node [2] current_node'; |
155 |
|
|
ok $sw->current_phase, $_->[3], |
156 |
|
|
$_->[0] . ' next_node [2] current_phase'; |
157 |
|
|
ok $sw->current_index, $_->[4], |
158 |
|
|
$_->[0] . ' next_node [2] current_index'; |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
{ |
162 |
|
|
my $sw = $doc->manakai_create_serial_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
163 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1; # REJECT : ACCEPT |
164 |
|
|
}); |
165 |
|
|
|
166 |
|
|
for ( |
167 |
|
|
[1, 'el1', 'el1', $sw->PRE_PHASE, 0], |
168 |
|
|
[2, 'el2', 'el2', $sw->PRE_PHASE, 0], |
169 |
|
|
[3, 'el2', 'el2', $sw->POST_PHASE, 1], |
170 |
|
|
[4, 'el1', 'el1', $sw->IN_PHASE, 1], |
171 |
|
|
[10, 'el5', 'el5', $sw->PRE_PHASE, 0], |
172 |
|
|
[11, 'el5', 'el5', $sw->POST_PHASE, 1], |
173 |
|
|
[12, 'el1', 'el1', $sw->POST_PHASE, 2], |
174 |
|
|
[13, undef, 'el1', $sw->POST_PHASE, 2], |
175 |
|
|
[14, undef, 'el1', $sw->POST_PHASE, 2], |
176 |
|
|
) { |
177 |
|
|
ok $sw->next_node, $_->[1] ? $tree3{$_->[1]} : undef, |
178 |
|
|
$_->[0] . ' next_node [3] next_node'; |
179 |
|
|
ok $sw->current_node, $tree3{$_->[2]}, |
180 |
|
|
$_->[0] . ' next_node [3] current_node'; |
181 |
|
|
ok $sw->current_phase, $_->[3], |
182 |
|
|
$_->[0] . ' next_node [3] current_phase'; |
183 |
|
|
ok $sw->current_index, $_->[4], |
184 |
|
|
$_->[0] . ' next_node [3] current_index'; |
185 |
|
|
} |
186 |
|
|
} |
187 |
|
|
{ |
188 |
|
|
my $sw = $doc->manakai_create_serial_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
189 |
|
|
$_[0]->local_name eq 'el4' ? 2 : 1; # REJECT : ACCEPT |
190 |
|
|
}); |
191 |
|
|
|
192 |
|
|
for ( |
193 |
|
|
[1, 'el1', 'el1', $sw->PRE_PHASE, 0], |
194 |
|
|
[2, 'el2', 'el2', $sw->PRE_PHASE, 0], |
195 |
|
|
[3, 'el2', 'el2', $sw->POST_PHASE, 1], |
196 |
|
|
[4, 'el1', 'el1', $sw->IN_PHASE, 1], |
197 |
|
|
[5, 'el3', 'el3', $sw->PRE_PHASE, 0], |
198 |
|
|
[8, 'el3', 'el3', $sw->POST_PHASE, 1], |
199 |
|
|
[9, 'el1', 'el1', $sw->IN_PHASE, 2], |
200 |
|
|
[10, 'el5', 'el5', $sw->PRE_PHASE, 0], |
201 |
|
|
[11, 'el5', 'el5', $sw->POST_PHASE, 1], |
202 |
|
|
[12, 'el1', 'el1', $sw->POST_PHASE, 3], |
203 |
|
|
[13, undef, 'el1', $sw->POST_PHASE, 3], |
204 |
|
|
[14, undef, 'el1', $sw->POST_PHASE, 3], |
205 |
|
|
) { |
206 |
|
|
ok $sw->next_node, $_->[1] ? $tree3{$_->[1]} : undef, |
207 |
|
|
$_->[0] . ' next_node [4] next_node'; |
208 |
|
|
ok $sw->current_node, $tree3{$_->[2]}, |
209 |
|
|
$_->[0] . ' next_node [4] current_node'; |
210 |
|
|
ok $sw->current_phase, $_->[3], |
211 |
|
|
$_->[0] . ' next_node [4] current_phase'; |
212 |
|
|
ok $sw->current_index, $_->[4], |
213 |
|
|
$_->[0] . ' next_node [4] current_index'; |
214 |
|
|
} |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
=head1 LICENSE |
218 |
|
|
|
219 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
220 |
|
|
|
221 |
|
|
This program is free software; you can redistribute it and/or |
222 |
|
|
modify it under the same terms as Perl itself. |
223 |
|
|
|
224 |
|
|
=cut |
225 |
|
|
|
226 |
|
|
## $Date: 2007/07/14 09:19:11 $ |