# -*- cperl -*-
# $Id$
##
# these testcases are for xml canonization interfaces.
#
# should be 23.
use Test::More tests => 23;
use strict;
use warnings;
use XML::LibXML;
use XML::LibXML::Common qw(:libxml);
my $parser = XML::LibXML->new;
{
my $doc = $parser->parse_string( " " );
my $c14n_res = $doc->toStringC14N();
# TEST
is( $c14n_res, " ", ' TODO : Add test name' );
$c14n_res = $doc->toStringC14N(1);
# TEST
is( $c14n_res, " ", ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( 'e&f<]]> ' );
my $c14n_res = $doc->toStringC14N();
# TEST
is( $c14n_res, ' >e&f< ', ' TODO : Add test name' );
$c14n_res = $doc->toStringC14N(1);
# TEST
is( $c14n_res, ' >e&f< ', ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( '' );
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( '' );
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
# ----------------------------------------------------------------- #
# The C14N says: remove unused namespaces, libxml2 just orders them
# ----------------------------------------------------------------- #
{
my $doc = $parser->parse_string( '' );
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
# would be correct, but will not work.
# ok( $c14n_res, '' );
}
# ----------------------------------------------------------------- #
# The C14N says: remove redundant namespaces
# ----------------------------------------------------------------- #
{
my $doc = $parser->parse_string( '' );
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( '' );
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( <
EOX
my $c14n_res;
$c14n_res = $doc->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
# canonize with xpath expressions
{
my $doc = $parser->parse_string( <
EOX
my $c14n_res;
$c14n_res = $doc->toStringC14N(0, "//d" );
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
{
my $doc = $parser->parse_string( <
EOX
my $rootnode=$doc->documentElement;
my $c14n_res;
$c14n_res = $rootnode->toStringC14N(0, "//*[local-name()='d']");
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
($rootnode) = $doc->findnodes("//*[local-name()='d']");
$c14n_res = $rootnode->toStringC14N();
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
$rootnode = $doc->documentElement->firstChild;
$c14n_res = $rootnode->toStringC14N(0);
# TEST
is( $c14n_res, '', ' TODO : Add test name' );
}
# exclusive canonicalization
if (20620 > XML::LibXML::LIBXML_VERSION) {
skip("skipping Exclusive C14N tests for libxml2 < 2.6.17") for 15..20;
} else {
my $xml1 = <
EOX
my $xml2 = <
EOX
my $xpath = "(//. | //@* | //namespace::*)[ancestor-or-self::*[name()='n1:elem2']]";
my $result = qq(\n \n );
my $result_n0n2 = qq(\n \n );
my $doc1 = $parser->parse_string( $xml1 );
my $doc2 = $parser->parse_string( $xml2 );
{
my $c14n_res = $doc1->toStringEC14N(0, $xpath);
# TEST
is( $c14n_res, $result, ' TODO : Add test name');
}
{
my $c14n_res = $doc2->toStringEC14N(0, $xpath);
# TEST
is( $c14n_res, $result, ' TODO : Add test name');
}
{
my $c14n_res = $doc1->toStringEC14N(0, $xpath,[]);
# TEST
is( $c14n_res, $result, ' TODO : Add test name');
}
{
my $c14n_res = $doc2->toStringEC14N(0, $xpath,[]);
# TEST
is( $c14n_res, $result, ' TODO : Add test name');
}
{
my $c14n_res = $doc2->toStringEC14N(0, $xpath,['n1','n3']);
# TEST
is( $c14n_res, $result, ' TODO : Add test name');
}
{
my $c14n_res = $doc2->toStringEC14N(0, $xpath,['n0','n2']);
# TEST
is( $c14n_res, $result_n0n2, ' TODO : Add test name');
}
}
{
my $xml = <<'EOF';
http://www.behealth.be/webservices/tsa/TSConsultTSBagRequesthttps://www.ehealth.fgov.be/timestampauthority_1_5/timestampauthorityurn:www.sve.man.ac.uk-54690551758351720271010843310http://www.w3.org/2005/08/addressing/anonymoustsa_0406798006_01803002317537321226995312781
EOF
my $xpath = q{(//. | //@* | //namespace::*)[ancestor-or-self::x:MessageID]};
my $xpath2 = q{(//. | //@* | //namespace::*)[ancestor-or-self::*[local-name()='MessageID' and namespace-uri()='http://www.w3.org/2005/08/addressing']]};
my $doc = XML::LibXML->load_xml(string=>$xml);
my $xpc = XML::LibXML::XPathContext->new($doc);
$xpc->registerNs(x => "http://www.w3.org/2005/08/addressing");
my $expect = 'urn:www.sve.man.ac.uk-54690551758351720271010843310';
# TEST
is( $doc->toStringEC14N( 0, $xpath2, [qw(soap)] ), $expect, ' TODO : Add test name' );
# TEST
is( $doc->toStringEC14N( 0, $xpath, $xpc, [qw(soap)] ), $expect, ' TODO : Add test name' );
# TEST
is( $doc->toStringEC14N( 0, $xpath2, $xpc, [qw(soap)] ), $expect, ' TODO : Add test name' );
}