1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
# -*-perl-*-
use strict;
use Test::More tests => 34;
my $die_problem = 1; # XML::LibXML (or my usage of it) has a problem, mask out some tests
use XTM;
use Data::Dumper;
$Data::Dumper::Indent = 1;
require_ok( 'XTM::XML');
my $xtm = new XTM::XML (text => q|<?xml version="1.0"?><topicMap xmlns = 'http://www.topicmaps.org/xtm/1.0/'></topicMap>|);
like ( $xtm->{url}, qr/^inline/, 'creating handle');
my $tm;
#-- experimental space
#----
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap xmlns = 'http://www.topicmaps.org/xtm/1.0/'>
</topicMap>|)))->associations}, 0, 'empty map, assocs');
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap xmlns = 'http://www.topicmaps.org/xtm/1.0/'>
</topicMap>|)))->topics}, 0, 'empty map, topics');
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
</topic>
</topicMap>|)))->topics}, 1, 'singleton map, empty topics, default namespace');
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<xx:topicMap id="xtm"
xmlns:xx = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<xx:topic id="t1">
</xx:topic>
</xx:topicMap>|)))->topics}, 1, 'singleton map, empty topic, explicit namespace');
if (!$die_problem) {
eval {
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topic id="t1" xmlns = 'http://www.topicmaps.org/xtm/1.0/'>
</topic>
|)))->topics}, 123, 'broken map 5');
}; if ($@) {
ok (1, "broken map 5, XTM conformance, raises exception");
print $@;
};
}
#if (!$die_problem) {
eval {
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="t1" xmlns = 'http://www.topicmaps.org/xtm/1.0/'>
</topicMap>
<topicMap id="t2" xmlns = 'http://www.topicmaps.org/xtm/1.0/'>
</topicMap>
|)))->topics}, 123, 'broken map 6');
}; if ($@) {
ok (1, "broken map 6, XTM conformance, raises exception");
print $@;
};
#}
if (!$die_problem) {
eval {
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
</baseName>
</toxxxxpic>
</topicMap>|)))->topics}, 123, 'broken map 1');
}; if ($@) {
ok (1, "broken map 1, XML conformance, raises exception");
# print $@;
};
}
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
</baseName>
</topic>
</topicMap>|)))->topics ('baseName regexps /test/ and is-a tt1')}, 1, 'singleton map, baseName, instanceOf');
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
</baseName>
</topic>
<association>
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<member>
<roleSpec><topicRef xlink:href="#rt1"/></roleSpec>
<topicRef xlink:href="#t1"/>
</member>
<member>
<roleSpec><topicRef xlink:href="#rt2"/></roleSpec>
<topicRef xlink:href="#tustes"/>
</member>
</association>
</topicMap>|)))->topics ()}, 5, 'auto complete on');
is (@{($tm = new XTM (tie => new XTM::XML (auto_complete => 0,
text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
</baseName>
</topic>
<association>
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<member>
<roleSpec><topicRef xlink:href="#rt1"/></roleSpec>
<topicRef xlink:href="#t1"/>
</member>
<member>
<roleSpec><topicRef xlink:href="#rt2"/></roleSpec>
<topicRef xlink:href="#tustes"/>
</member>
</association>
</topicMap>|)))->topics ()}, 1, 'auto complete off');
$tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="testus">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
</baseName>
</topic>
<topic id="tustes">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Tustes</baseNameString>
</baseName>
<baseName>
<scope><topicRef xlink:href="http://www.topicmaps.org/xtm/language.xtm#en"/></scope>
<baseNameString>Tustes</baseNameString>
</baseName>
<occurrence>
<instanceOf><topicRef xlink:href="#ot"/></instanceOf>
<resourceRef xlink:href="http://www.someexample.com.au/path?xxx=yyy&aaa=bbb"/>
</occurrence>
<occurrence>
<instanceOf><topicRef xlink:href="#ot"/></instanceOf>
<resourceRef xlink:href="http://www.someexample.com.au/path?xxx=yyy&aaa=bbb"/>
</occurrence>
</topic>
<association>
<instanceOf><topicRef xlink:href="#at1"/></instanceOf>
<member>
<roleSpec><topicRef xlink:href="#rt1"/></roleSpec>
<topicRef xlink:href="#testus"/>
</member>
<member>
<roleSpec><topicRef xlink:href="#rt2"/></roleSpec>
<topicRef xlink:href="#tustes"/>
</member>
</association>
</topicMap>|));
is (@{$tm->topics ('baseName regexps /test/ and is-a tt1')}, 1, 'small map, baseName, instanceOf 1');
is (@{$tm->topics ('baseName regexps /tust/ and is-a tt1')}, 1, 'small map, baseName, instanceOf 2');
is (@{$tm->topics ('occurrence regexps /example/')}, 1, 'small map, baseName, occurrence 1');
is (@{$tm->topics ('assocs with testus')}[0], 'tustes', 'small map, baseName, assoc 1');
is (@{$tm->topics ('assocs with tustes')}[0], 'testus', 'small map, baseName, assoc 2');
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
</topic>
</topicMap>|)))->topics ('is-a http://www.topicmaps.org/xtm/1.0/#psi-topic')}, 1, 'singleton map, empty topics, default topic type');
if (!$die_problem) {
eval {
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<resourceData>Testus</resourceData>
</baseName>
</topic>
</topicMap>|)))->topics}, 123, 'broken map 2');
}; if ($@) {
ok (1, "broken map 2, XTM conformance, raises exception");
# print $@;
};
}
if (!$die_problem) {
eval {
# print "before 4 $@";
is (@{($tm = new XTM (tie => new XTM::XML (text => q|<?xml version="1.0"?>
<topicMap id="xtm"
xmlns = 'http://www.topicmaps.org/xtm/1.0/'
xmlns:xlink = 'http://www.w3.org/1999/xlink'>
<topic id="t1">
<instanceOf><topicRef xlink:href="#tt1"/></instanceOf>
<baseName>
<baseNameString>Testus</baseNameString>
<baseNameString>Testus</baseNameString>
</baseName>
<occurrence>
<instanceOf><topicRef xlink:href="#ot"/></instanceOf>
<resourceRef xlink:href="http://example.org/"/>
</occurrence>
</topic>
</topicMap>|)))->topics}, 0, 'broken map 4');
}; if ($@) {
ok (1, "broken map 4, duplicate baseNameString, raises exception");
print "after 4 $@";
};
}
$tm = new XTM (tie => new XTM::XML (url => "file:maps/test.xtm", auto_complete => 0));
is (@{$tm->topics()}, 8, 'single map, nr topics');
is (@{$tm->topics('occurrence regexps /example/')}, 3, 'single map, occurrences');
is (@{$tm->topics('text regexps /any text/')}, 1, 'single map, data');
is (@{$tm->topics('assocs with t-topic4')}, 2, 'single map, assocs 1');
is (@{$tm->topics('assocs with t-topic2')}, 3, 'single map, assocs 2');
is (@{$tm->topics('is-a tt-type1')}, 3, 'single map, is-a 1');
is (@{$tm->topics('is-a tt-type2')}, 1, 'single map, is-a 2');
is (@{$tm->associations()}, 4, 'single map, nr assocs');
is (@{$tm->associations('is-a at-is-associated-with')}, 2, 'single map, is-a 3');
$tm = new XTM (tie => new XTM::XML (file => 'maps/test.xtm'));
is (@{$tm->topics()}, 14, 'mergeMap, nr topics');
is (@{$tm->topics('occurrence regexps /example/')}, 3, 'mergeMap, occurrences');
is (@{$tm->topics('text regexps /any text/')}, 1, 'mergeMap, data');
is (@{$tm->topics('assocs with t-topic4')}, 2, 'mergeMap, assocs 1');
is (@{$tm->topics('assocs with t-topic2')}, 3, 'mergeMap, assocs 2');
is (@{$tm->topics('is-a tt-type1')}, 3, 'mergeMap, is-a 1');
is (@{$tm->topics('is-a tt-type2')}, 1, 'mergeMap, is-a 2');
is (@{$tm->associations()}, 4, 'mergeMap, nr assocs');
is (@{$tm->associations('is-a at-is-associated-with')}, 2, 'mergeMap, is-a 3');
__END__
exit;
use Data::Dumper;
print Dumper $tm;
exit;
exit;
# test file for Bizarre copy of HASH problem
package MyMemoryBuilder;
use base qw(XML::SAX::Base);
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->{xxx} = {
yyy => {},
};
return $self;
}
sub start_element {
print "at a start element\n";
die "A good place to die?";
}
1;
my $xml = q|<?xml version="1.0"?><topicMap></topicMap>|;
use XML::SAX::ParserFactory;
my $builder;
my $parser;
foreach (1..3) {
eval {
$builder = new MyMemoryBuilder ();
$parser = XML::SAX::ParserFactory->parser(Handler => $builder);
print "I'm a ".ref ($parser), "\n";
$parser->parse_string($xml);
}; if ($@) {
print "$@";
};
}
exit;
exit;
__END__
|