1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
wakaba |
1.5 |
BEGIN { plan tests => 101 } |
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.3 |
for my $prop (qw/has_replacement_tree is_externally_declared/) { |
51 |
wakaba |
1.1 |
ok $ent->can ($prop) ? 1 : 0, 1, 'can ' . $prop; |
52 |
|
|
|
53 |
|
|
for (1, 0, '') { |
54 |
|
|
$ent->$prop ($_); |
55 |
|
|
ok $ent->$prop ? 1 : 0, $_ ? 1 : 0, $prop . $_; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
$ent->$prop (undef); |
59 |
|
|
ok $ent->$prop ? 1 : 0, 0, $prop . ' undef'; |
60 |
|
|
} |
61 |
|
|
|
62 |
wakaba |
1.3 |
for my $prop (qw/input_encoding notation_name public_id system_id/) { |
63 |
wakaba |
1.1 |
ok $ent->can ($prop) ? 1 : 0, 1, 'can ' . $prop; |
64 |
|
|
|
65 |
|
|
for ('-//...//EN', 'http://absuri.test/', 'reluri', |
66 |
wakaba |
1.3 |
'utf-8', 'x-sjis', |
67 |
wakaba |
1.2 |
qq('illegal"), qq'\x{4E00}', ' ', 0, '') { |
68 |
wakaba |
1.1 |
$ent->$prop ($_); |
69 |
|
|
ok $ent->$prop, $_, $prop . $_; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
$ent->$prop (undef); |
73 |
|
|
ok $ent->$prop, undef, $prop . ' undef'; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
## |manakaiDeclarationBaseURI| |
77 |
|
|
{ |
78 |
|
|
my $doc2 = $doc->implementation->create_document; |
79 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
80 |
|
|
|
81 |
|
|
ok $ent->can ('manakai_declaration_base_uri') ? 1 : 0, 1, |
82 |
|
|
'can manakai_declaration_base_uri'; |
83 |
|
|
|
84 |
|
|
$doc2->document_uri (q<http://www.example/>); |
85 |
|
|
ok $ent->manakai_declaration_base_uri, q<http://www.example/>, |
86 |
|
|
'manakai_declaration_base_uri document_uri'; |
87 |
|
|
|
88 |
|
|
$ent->manakai_declaration_base_uri (q<ftp://www.example/>); |
89 |
|
|
ok $ent->manakai_declaration_base_uri, q<ftp://www.example/>, |
90 |
|
|
'manakai_declaration_base_uri explicit'; |
91 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
92 |
|
|
'manakai_declaration_base_uri (base_uri)'; |
93 |
|
|
|
94 |
|
|
$ent->manakai_declaration_base_uri (undef); |
95 |
|
|
ok $ent->manakai_declaration_base_uri, q<http://www.example/>, |
96 |
|
|
'manakai_declaration_base_uri reset'; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
## |manakaiEntityBaseURI| |
100 |
|
|
{ |
101 |
|
|
my $doc2 = $doc->implementation->create_document; |
102 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
103 |
|
|
ok $ent->manakai_entity_base_uri, undef, "Entity->manakai_entity_base_uri [0]"; |
104 |
|
|
|
105 |
|
|
$doc2->document_uri (q<http://www.example/>); |
106 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
107 |
|
|
"Entity->manakai_entity_base_uri [1]"; |
108 |
|
|
|
109 |
|
|
$ent->manakai_entity_base_uri (q<ftp://www.example/>); |
110 |
|
|
ok $ent->manakai_entity_base_uri, q<ftp://www.example/>, |
111 |
|
|
"Entity->manakai_entity_base_uri [2]"; |
112 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
113 |
|
|
"Entity->manakai_entity_base_uri base_uri [2]"; |
114 |
|
|
|
115 |
|
|
$ent->manakai_entity_base_uri (undef); |
116 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
117 |
|
|
"Entity->manakai_entity_base_uri [3]"; |
118 |
|
|
|
119 |
|
|
$ent->manakai_entity_uri (q<https://www.example/>); |
120 |
|
|
ok $ent->manakai_entity_base_uri, q<https://www.example/>, |
121 |
|
|
"Entity->manakai_entity_base_uri [4]"; |
122 |
|
|
ok $ent->base_uri, q<http://www.example/>, |
123 |
|
|
"Entity->manakai_entity_base_uri base_uri [4]"; |
124 |
|
|
|
125 |
|
|
$ent->manakai_entity_uri (undef); |
126 |
|
|
ok $ent->manakai_entity_base_uri, q<http://www.example/>, |
127 |
|
|
"Entity->manakai_entity_base_uri [5]"; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
## |manakaiEntityURI| |
131 |
|
|
{ |
132 |
|
|
my $doc2 = $doc->implementation->create_document; |
133 |
|
|
my $ent = $doc2->create_general_entity ('entity'); |
134 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [0]"; |
135 |
|
|
|
136 |
|
|
$doc2->document_uri (q<http://www.document.example/>); |
137 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [1]"; |
138 |
|
|
|
139 |
|
|
$ent->manakai_declaration_base_uri (q<http://decl.example/>); |
140 |
|
|
ok $ent->manakai_entity_uri, undef, "Entity->manakai_entity_uri [2]"; |
141 |
|
|
|
142 |
|
|
$ent->system_id (q<sysid>); |
143 |
|
|
ok $ent->manakai_entity_uri, q<http://decl.example/sysid>, |
144 |
|
|
"Entity->manakai_entity_uri [3]"; |
145 |
|
|
|
146 |
|
|
$ent->manakai_entity_uri (q<http://enturi.example/>); |
147 |
|
|
ok $ent->manakai_entity_uri, q<http://enturi.example/>, |
148 |
|
|
"Entity->manakai_entity_uri [4]"; |
149 |
|
|
|
150 |
|
|
$ent->manakai_entity_uri (undef); |
151 |
|
|
ok $ent->manakai_entity_uri, q<http://decl.example/sysid>, |
152 |
|
|
"Entity->manakai_entity_uri [5]"; |
153 |
|
|
} |
154 |
|
|
|
155 |
wakaba |
1.4 |
## |xmlVersion| |
156 |
|
|
{ |
157 |
|
|
my $node = $doc->create_general_entity ('ent'); |
158 |
|
|
ok $node->xml_version, undef, 'xml_version [1]'; |
159 |
|
|
$node->xml_version ('1.0'); |
160 |
|
|
ok $node->xml_version, '1.0', 'xml_version [2]'; |
161 |
|
|
$node->xml_version ('1.1'); |
162 |
|
|
ok $node->xml_version, '1.1', 'xml_version [3]'; |
163 |
|
|
$node->xml_version (undef); |
164 |
|
|
ok $node->xml_version, undef, 'xml_version [4]'; |
165 |
|
|
} |
166 |
|
|
|
167 |
wakaba |
1.1 |
=head1 LICENSE |
168 |
|
|
|
169 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
170 |
|
|
|
171 |
|
|
This program is free software; you can redistribute it and/or |
172 |
|
|
modify it under the same terms as Perl itself. |
173 |
|
|
|
174 |
|
|
=cut |
175 |
|
|
|
176 |
wakaba |
1.5 |
## $Date: 2007/07/29 03:49:00 $ |