line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::XML::SAX; |
2
|
|
|
|
|
|
|
# @(#) $Id$ |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
371249
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
8
|
1
|
|
|
1
|
|
6
|
use Test::More; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
1150
|
use Test::XML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Test::Builder; |
11
|
|
|
|
|
|
|
use XML::SAX; |
12
|
|
|
|
|
|
|
use XML::SAX::ParserFactory; |
13
|
|
|
|
|
|
|
use XML::SAX::Writer; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
my $caller = caller; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
no strict 'refs'; |
22
|
|
|
|
|
|
|
*{ $caller . '::test_sax' } = \&test_sax; |
23
|
|
|
|
|
|
|
*{ $caller . '::test_all_sax_parsers' } = \&test_all_sax_parsers; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
26
|
|
|
|
|
|
|
$Test->exported_to( $caller ); |
27
|
|
|
|
|
|
|
$Test->plan( @_ ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub test_sax { |
31
|
|
|
|
|
|
|
my ( $handler, $input, $expected, $test_name ) = @_; |
32
|
|
|
|
|
|
|
croak "usage: test_sax(handler,input,expected,[test_name])" |
33
|
|
|
|
|
|
|
unless $handler && ref $handler && $input && $expected; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
36
|
|
|
|
|
|
|
my $result = ''; |
37
|
|
|
|
|
|
|
eval { |
38
|
|
|
|
|
|
|
my $w = XML::SAX::Writer->new( Output => \$result ); |
39
|
|
|
|
|
|
|
$handler->set_handler( $w ); |
40
|
|
|
|
|
|
|
my $p = XML::SAX::ParserFactory->parser( Handler => $handler ); |
41
|
|
|
|
|
|
|
$p->parse_string( $input ); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
if ( $@ ) { |
44
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
45
|
|
|
|
|
|
|
$Test->diag( "Error during parse: $@" ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return is_xml( $result, $expected, $test_name ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub test_all_sax_parsers { |
52
|
|
|
|
|
|
|
my ( $sub, $numtests ) = @_; |
53
|
|
|
|
|
|
|
croak "usage: test_all_sax_parsers(sub,[numtests])" |
54
|
|
|
|
|
|
|
unless $sub && ref($sub) eq 'CODE'; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my @parsers = map { $_->{Name} } @{ XML::SAX->parsers }; |
57
|
|
|
|
|
|
|
plan tests => ($numtests * scalar( @parsers ) ) |
58
|
|
|
|
|
|
|
if $numtests; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# NB: Have to sort by shortest parser first so that |
61
|
|
|
|
|
|
|
# XML::SAX::ParserFactory |
62
|
|
|
|
|
|
|
# loads them all in correctly. |
63
|
|
|
|
|
|
|
foreach my $parser ( sort { length $a <=> length $b } @parsers ) { |
64
|
|
|
|
|
|
|
local $XML::SAX::ParserPackage = $parser; |
65
|
|
|
|
|
|
|
$sub->( $parser, $numtests ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |