1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
wakaba |
1.6 |
BEGIN { plan tests => 118 } |
5 |
wakaba |
1.1 |
|
6 |
|
|
require Message::DOM::DOMImplementation; |
7 |
|
|
use Message::Util::Error; |
8 |
|
|
|
9 |
wakaba |
1.4 |
my $dom = Message::DOM::DOMImplementation->new; |
10 |
wakaba |
1.1 |
my $doc = $dom->create_document; |
11 |
|
|
|
12 |
wakaba |
1.5 |
for my $v ( |
13 |
|
|
[a => undef], |
14 |
|
|
[abc => undef], |
15 |
|
|
['a:b' => undef], |
16 |
|
|
[1 => 'INVALID_CHARACTER_ERR'], |
17 |
|
|
[1234 => 'INVALID_CHARACTER_ERR'], |
18 |
|
|
["\x{3001}\x{3002}" => 'INVALID_CHARACTER_ERR'], ## XML 1.1 Name |
19 |
|
|
[':aa' => undef], |
20 |
|
|
[':1' => undef], |
21 |
|
|
['a:' => undef], |
22 |
|
|
["a:\x{3005}b" => undef], ## XML 1.0 Name, XML 1.1 QName |
23 |
|
|
) { |
24 |
|
|
$doc->strict_error_checking (1); |
25 |
|
|
if (not defined $v->[1]) { |
26 |
|
|
try { |
27 |
|
|
my $dt = $doc->create_general_entity ($v->[0]); |
28 |
|
|
ok $dt->node_name, $v->[0], 'create_general_entity '.$v->[0]; |
29 |
|
|
} catch Message::IF::DOMException with { |
30 |
|
|
my $e = shift; |
31 |
|
|
ok $e->type, undef, 'create_general_entity '.$v->[0]; |
32 |
|
|
}; |
33 |
|
|
} else { |
34 |
|
|
try { |
35 |
|
|
$doc->create_general_entity ($v->[0]); |
36 |
|
|
ok 0, 1, 'create_general_entity '.$v->[0]; |
37 |
|
|
} catch Message::IF::DOMException with { |
38 |
|
|
my $e = shift; |
39 |
|
|
ok $e->type, $v->[1], 'create_general_entity '.$v->[0]; |
40 |
|
|
}; |
41 |
|
|
} |
42 |
|
|
$doc->strict_error_checking (0); |
43 |
|
|
my $dt = $doc->create_general_entity ($v->[0]); |
44 |
|
|
ok $dt->node_name, $v->[0], 'create_general_entity s '.$v->[0]; |
45 |
|
|
} |
46 |
|
|
$doc->strict_error_checking (1); |
47 |
|
|
|
48 |
wakaba |
1.1 |
my $ent = $doc->create_general_entity ('entity'); |
49 |
|
|
|
50 |
wakaba |
1.6 |
for my $prop (qw/has_replacement_tree is_externally_declared |
51 |
|
|
manakai_has_bom/) { |
52 |
wakaba |
1.1 |
ok $ent->can ($prop) ? 1 : 0, 1, 'can ' . $prop; |
53 |
|
|
|
54 |
|
|
for (1, 0, '') { |
55 |
|
|
$ent->$prop ($_); |
56 |
|
|
ok $ent->$prop ? 1 : 0, $_ ? 1 : 0, $prop . $_; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
$ent->$prop (undef); |
60 |
|
|
ok $ent->$prop ? 1 : 0, 0, $prop . ' undef'; |
61 |
|
|
} |
62 |
|
|
|
63 |
wakaba |
1.6 |
for my $prop (qw/input_encoding notation_name public_id system_id |
64 |
|
|
manakai_charset/) { |
65 |
wakaba |
1.1 |
ok $ent->can ($prop) ? 1 : 0, 1, 'can ' . $prop; |
66 |
|
|
|
67 |
|
|
for ('-//...//EN', 'http://absuri.test/', 'reluri', |
68 |
wakaba |
1.3 |
'utf-8', 'x-sjis', |
69 |
wakaba |
1.2 |
qq('illegal"), qq'\x{4E00}', ' ', 0, '') { |
70 |
wakaba |
1.1 |
$ent->$prop ($_); |
71 |
|
|
ok $ent->$prop, $_, $prop . $_; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
$ent->$prop (undef); |
75 |
|
|
ok $ent->$prop, undef, $prop . ' undef'; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
## |manakaiDeclarationBaseURI| |
79 |
|
|
{ |
80 |
|
|
my $doc2 = $doc->implementation->create_document; |
81 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
82 |
|
|
|
83 |
|
|
ok $ent->can ('manakai_declaration_base_uri') ? 1 : 0, 1, |
84 |
|
|
'can manakai_declaration_base_uri'; |
85 |
|
|
|
86 |
|
|
$doc2->document_uri (q<http://www.example/>); |
87 |
|
|
ok $ent->manakai_declaration_base_uri, q<http://www.example/>, |
88 |
|
|
'manakai_declaration_base_uri document_uri'; |
89 |
|
|
|
90 |
|
|
$ent->manakai_declaration_base_uri (q<ftp://www.example/>); |
91 |
|
|
ok $ent->manakai_declaration_base_uri, q<ftp://www.example/>, |
92 |
|
|
'manakai_declaration_base_uri explicit'; |
93 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
94 |
|
|
'manakai_declaration_base_uri (base_uri)'; |
95 |
|
|
|
96 |
|
|
$ent->manakai_declaration_base_uri (undef); |
97 |
|
|
ok $ent->manakai_declaration_base_uri, q<http://www.example/>, |
98 |
|
|
'manakai_declaration_base_uri reset'; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
## |manakaiEntityBaseURI| |
102 |
|
|
{ |
103 |
|
|
my $doc2 = $doc->implementation->create_document; |
104 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
105 |
|
|
ok $ent->manakai_entity_base_uri, undef, "Entity->manakai_entity_base_uri [0]"; |
106 |
|
|
|
107 |
|
|
$doc2->document_uri (q<http://www.example/>); |
108 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
109 |
|
|
"Entity->manakai_entity_base_uri [1]"; |
110 |
|
|
|
111 |
|
|
$ent->manakai_entity_base_uri (q<ftp://www.example/>); |
112 |
|
|
ok $ent->manakai_entity_base_uri, q<ftp://www.example/>, |
113 |
|
|
"Entity->manakai_entity_base_uri [2]"; |
114 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
115 |
|
|
"Entity->manakai_entity_base_uri base_uri [2]"; |
116 |
|
|
|
117 |
|
|
$ent->manakai_entity_base_uri (undef); |
118 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
119 |
|
|
"Entity->manakai_entity_base_uri [3]"; |
120 |
|
|
|
121 |
|
|
$ent->manakai_entity_uri (q<https://www.example/>); |
122 |
|
|
ok $ent->manakai_entity_base_uri, q<https://www.example/>, |
123 |
|
|
"Entity->manakai_entity_base_uri [4]"; |
124 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
125 |
|
|
"Entity->manakai_entity_base_uri base_uri [4]"; |
126 |
|
|
|
127 |
|
|
$ent->manakai_entity_uri (undef); |
128 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
129 |
|
|
"Entity->manakai_entity_base_uri [5]"; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
## |manakaiEntityURI| |
133 |
|
|
{ |
134 |
|
|
my $doc2 = $doc->implementation->create_document; |
135 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
136 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [0]"; |
137 |
|
|
|
138 |
|
|
$doc2->document_uri (q<http://www.document.example/>); |
139 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [1]"; |
140 |
|
|
|
141 |
|
|
$ent->manakai_declaration_base_uri (q<http://decl.example/>); |
142 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [2]"; |
143 |
|
|
|
144 |
|
|
$ent->system_id (q<sysid>); |
145 |
|
|
ok $ent->manakai_entity_uri, q<http://decl.example/sysid>, |
146 |
|
|
"Entity->manakai_entity_uri [3]"; |
147 |
|
|
|
148 |
|
|
$ent->manakai_entity_uri (q<http://enturi.example/>); |
149 |
|
|
ok $ent->manakai_entity_uri, q<http://enturi.example/>, |
150 |
|
|
"Entity->manakai_entity_uri [4]"; |
151 |
|
|
|
152 |
|
|
$ent->manakai_entity_uri (undef); |
153 |
|
|
ok $ent->manakai_entity_uri, q<http://decl.example/sysid>, |
154 |
|
|
"Entity->manakai_entity_uri [5]"; |
155 |
|
|
} |
156 |
|
|
|
157 |
wakaba |
1.4 |
## |xmlVersion| |
158 |
|
|
{ |
159 |
|
|
my $node = $doc->create_general_entity ('ent'); |
160 |
|
|
ok $node->xml_version, undef, 'xml_version [1]'; |
161 |
|
|
$node->xml_version ('1.0'); |
162 |
|
|
ok $node->xml_version, '1.0', 'xml_version [2]'; |
163 |
|
|
$node->xml_version ('1.1'); |
164 |
|
|
ok $node->xml_version, '1.1', 'xml_version [3]'; |
165 |
|
|
$node->xml_version (undef); |
166 |
|
|
ok $node->xml_version, undef, 'xml_version [4]'; |
167 |
|
|
} |
168 |
|
|
|
169 |
wakaba |
1.1 |
=head1 LICENSE |
170 |
|
|
|
171 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
172 |
|
|
|
173 |
|
|
This program is free software; you can redistribute it and/or |
174 |
|
|
modify it under the same terms as Perl itself. |
175 |
|
|
|
176 |
|
|
=cut |
177 |
|
|
|
178 |
wakaba |
1.6 |
## $Date: 2007/08/22 10:59:43 $ |