use lib "./lib";
use Test::More tests=>56;
BEGIN{ use_ok( "XML::Stream","Tree", "Node" ); }
my $packetIndex;
my @packets;
$packets[0] = "";
$packets[1] = "
";
$packets[2] = "
This is a test.
";
$packets[3] = "
foo1
foo2
";
$packets[4] = "bar";
$packets[5] = "
";
$packets[6] = "valueA";
$packets[7] = "valueB";
$packets[8] = "valueC";
$packets[9] = "foo1";
$packets[10] = "foo2";
$packets[11] = "foo3
";
$packets[12] = "foo4";
$packets[13] = "foo5";
$packets[14] = "foo6
";
$packets[15] = "
";
$packets[16] = "This is cdata with <tags/> embedded <in>it</in>.";
foreach my $xmlType ("tree","node")
{
$packetIndex = 0;
my $stream = new XML::Stream(style=>$xmlType);
ok( defined($stream), "new() - $xmlType" );
isa_ok( $stream, "XML::Stream" );
$stream->SetCallBacks(node=>sub{ &onPacket($xmlType,@_) });
my $sid = $stream->OpenFile("t/test.xml");
my %status;
while( %status = $stream->Process())
{
last if ($status{$sid} == -1);
}
}
sub onPacket
{
my $xmlType = shift;
my $sid = shift;
if ($xmlType eq "tree")
{
my $tree = shift;
my $test = &XML::Stream::BuildXML($tree,"");
$test =~ s/\r//g;
is( $test, $packets[$packetIndex], "packet[$packetIndex]" );
}
if ($xmlType eq "node")
{
my $node = shift;
my $test = &XML::Stream::BuildXML($node,"");
$test =~ s/\r//g;
is( $test, $packets[$packetIndex], "packet[$packetIndex]" );
$node->add_raw_xml("");
$test = &XML::Stream::BuildXML($node);
$test =~ s/\r//g;
is( $test, $packets[$packetIndex], "packet[$packetIndex]" );
}
$packetIndex++;
}