diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2022-07-25 08:44:28 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2022-07-25 08:44:28 +0900 |
commit | 386653a5f530a4e00811bacc50ae734d5610695d (patch) | |
tree | c6f6c4e3d74f202bd65a80e06992debe83e4e1ab /t | |
parent | bed2f52e9348362135cc7cc4e6cedfe306744b20 (diff) | |
download | perl-XML-LibXML-386653a5f530a4e00811bacc50ae734d5610695d.tar.gz perl-XML-LibXML-386653a5f530a4e00811bacc50ae734d5610695d.tar.bz2 perl-XML-LibXML-386653a5f530a4e00811bacc50ae734d5610695d.zip |
Imported Upstream version 2.0202upstream/2.0202
Diffstat (limited to 't')
-rw-r--r-- | t/00-report-prereqs.t | 1 | ||||
-rw-r--r-- | t/02parse.t | 6 | ||||
-rw-r--r-- | t/13dtd.t | 2 | ||||
-rw-r--r-- | t/17callbacks.t | 2 | ||||
-rw-r--r-- | t/18docfree.t | 3 | ||||
-rw-r--r-- | t/25relaxng.t | 32 | ||||
-rw-r--r-- | t/26schema.t | 23 | ||||
-rw-r--r-- | t/35huge_mode.t | 5 | ||||
-rw-r--r-- | t/40reader.t | 1 | ||||
-rw-r--r-- | t/43options.t | 21 | ||||
-rw-r--r-- | t/48_SAX_Builder_rt_91433.t | 3 | ||||
-rw-r--r-- | t/48_rt123379_setNamespace.t | 8 | ||||
-rw-r--r-- | t/48_rt93429_recover_2_in_html_parsing.t | 1 | ||||
-rw-r--r-- | t/62overload.t | 12 | ||||
-rw-r--r-- | t/91unique_key.t | 1 |
15 files changed, 104 insertions, 17 deletions
diff --git a/t/00-report-prereqs.t b/t/00-report-prereqs.t index c72183a..259894e 100644 --- a/t/00-report-prereqs.t +++ b/t/00-report-prereqs.t @@ -188,6 +188,7 @@ if ( @dep_errors ) { ); } +# TEST pass; # vim: ts=4 sts=4 sw=4 et: diff --git a/t/02parse.t b/t/02parse.t index 929654d..b111507 100644 --- a/t/02parse.t +++ b/t/02parse.t @@ -25,6 +25,8 @@ use constant XML_DECL => "<?xml version=\"1.0\"?>\n"; use Errno qw(ENOENT); +# TEST*533 + ## # test values my @goodWFStrings = ( @@ -720,7 +722,7 @@ my $badXInclude = q{ my %badstrings = ( SIMPLE => '<?xml version="1.0"?>'."\n<A/>\n", ); - my $parser = XML::LibXML->new; + my $parser = XML::LibXML->new(expand_entities => 1); $parser->validation(1); my $doc; @@ -745,7 +747,7 @@ EOXML <bar/> EOXML - my $parser = XML::LibXML->new; + my $parser = XML::LibXML->new(expand_entities => 1); $parser->validation(1); eval { $parser->parse_string( $badxml ); }; @@ -69,7 +69,7 @@ ok($dtdstr, "DTD String read"); # TEST ok ($@, '->validate throws an exception'); - my $parser = XML::LibXML->new(); + my $parser = XML::LibXML->new(load_ext_dtd => 1); # TEST ok ($parser->validation(1), '->validation returns 1'); # this one is OK as it's well formed (no DTD) diff --git a/t/17callbacks.t b/t/17callbacks.t index dafaee0..e2d9859 100644 --- a/t/17callbacks.t +++ b/t/17callbacks.t @@ -276,7 +276,7 @@ $XML::LibXML::close_cb = $close1_global_counter->cb(); { # tests if global callbacks are working - my $parser = XML::LibXML->new(); + my $parser = XML::LibXML->new(load_ext_dtd => 1); # TEST ok($parser, '$parser was init'); diff --git a/t/18docfree.t b/t/18docfree.t index fb559d5..9a2cff6 100644 --- a/t/18docfree.t +++ b/t/18docfree.t @@ -9,5 +9,6 @@ use XML::LibXML; $doc = XML::LibXML::Document->new(); } # used to get "Attempt to free unreferenced scalar" here -ok(1, 'docfree Out of scope is OK - no "Attempt to free unreferenced scalar"'); +# TEST +pass('docfree Out of scope is OK - no "Attempt to free unreferenced scalar"'); diff --git a/t/25relaxng.t b/t/25relaxng.t index dd579ee..93e6188 100644 --- a/t/25relaxng.t +++ b/t/25relaxng.t @@ -16,7 +16,7 @@ BEGIN { use XML::LibXML; if ( XML::LibXML::LIBXML_VERSION >= 20510 ) { - plan tests => 13; + plan tests => 17; } else { plan skip_all => 'Skip No RNG Support compiled'; @@ -32,6 +32,7 @@ my $badfile = "test/relaxng/badschema.rng"; my $validfile = "test/relaxng/demo.xml"; my $invalidfile = "test/relaxng/invaliddemo.xml"; my $demo4 = "test/relaxng/demo4.rng"; +my $netfile = "test/relaxng/net.rng"; print "# 1 parse schema from a file\n"; { @@ -127,5 +128,34 @@ EOXML } +print "# 6 check that no_network => 1 works\n"; +{ + my $rng = eval { XML::LibXML::RelaxNG->new( location => $netfile, no_network => 1 ) }; + # TEST + like( $@, qr{I/O error : Attempt to load network entity}, 'RNG from file location with external import and no_network => 1 throws an exception.' ); + # TEST + ok( !defined $rng, 'RNG from file location with external import and no_network => 1 is not loaded.' ); +} +{ + my $rng = eval { XML::LibXML::RelaxNG->new( string => <<'EOF', no_network => 1 ) }; +<?xml version="1.0" encoding="iso-8859-1"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <include href="http://example.com/xml.rng"/> + <start> + <ref name="include"/> + </start> + <define name="include"> + <element name="include"> + <text/> + </element> + </define> +</grammar> +EOF + # TEST + like( $@, qr{I/O error : Attempt to load network entity}, 'RNG from buffer with external import and no_network => 1 throws an exception.' ); + # TEST + ok( !defined $rng, 'RNG from buffer with external import and no_network => 1 is not loaded.' ); +} + } # Version >= 20510 test diff --git a/t/26schema.t b/t/26schema.t index 90831ab..17f641e 100644 --- a/t/26schema.t +++ b/t/26schema.t @@ -15,7 +15,7 @@ use Test::More; use XML::LibXML; if ( XML::LibXML::LIBXML_VERSION >= 20510 ) { - plan tests => 8; + plan tests => 12; } else { plan skip_all => 'No Schema Support compiled.'; @@ -27,6 +27,7 @@ my $file = "test/schema/schema.xsd"; my $badfile = "test/schema/badschema.xsd"; my $validfile = "test/schema/demo.xml"; my $invalidfile = "test/schema/invaliddemo.xml"; +my $netfile = "test/schema/net.xsd"; # 1 parse schema from a file @@ -112,3 +113,23 @@ EOF is( $result, 0, 'validate() with element returns 0' ); } +# 5 check that no_network => 1 works +{ + my $schema = eval { XML::LibXML::Schema->new( location => $netfile, no_network => 1 ) }; + # TEST + like( $@, qr{I/O error : Attempt to load network entity}, 'Schema from file location with external import and no_network => 1 throws an exception.' ); + # TEST + ok( !defined $schema, 'Schema from file location with external import and no_network => 1 is not loaded.' ); +} +{ + my $schema = eval { XML::LibXML::Schema->new( string => <<'EOF', no_network => 1 ) }; +<?xml version="1.0" encoding="UTF-8"?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:import namespace="http://example.com/namespace" schemaLocation="http://example.com/xml.xsd"/> +</xsd:schema> +EOF + # TEST + like( $@, qr{I/O error : Attempt to load network entity}, 'Schema from buffer with external import and no_network => 1 throws an exception.' ); + # TEST + ok( !defined $schema, 'Schema from buffer with external import and no_network => 1 is not loaded.' ); +} diff --git a/t/35huge_mode.t b/t/35huge_mode.t index adf03da..1ccb334 100644 --- a/t/35huge_mode.t +++ b/t/35huge_mode.t @@ -49,11 +49,14 @@ my($parser, $doc); $parser = XML::LibXML->new; #$parser->set_option(huge => 0); +# TEST ok(!$parser->get_option('huge'), "huge mode disabled by default"); $doc = eval { $parser->parse_string($evil_xml); }; +# TEST isnt("$@", "", "exception thrown during parse"); +# TEST like($@, qr/entity.*loop/si, "exception refers to entity reference loop"); @@ -61,9 +64,11 @@ $parser = XML::LibXML->new; $doc = eval { $parser->parse_string($benign_xml); }; +# TEST is("$@", "", "no exception thrown during parse"); my $body = $doc->findvalue( '/lolz' ); +# TEST is($body, 'haha', 'entity was parsed and expanded correctly'); exit; diff --git a/t/40reader.t b/t/40reader.t index 4b75b22..f08c2ab 100644 --- a/t/40reader.t +++ b/t/40reader.t @@ -19,6 +19,7 @@ BEGIN{ use_ok('XML::LibXML::Reader'); }; +# TEST*100 my $file = "test/textReader/countries.xml"; { my $reader = XML::LibXML::Reader->new(location => $file, {expand_entities => 1}); diff --git a/t/43options.t b/t/43options.t index 826f0ad..d46fe23 100644 --- a/t/43options.t +++ b/t/43options.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 290; +use Test::More tests => 291; use XML::LibXML; @@ -50,7 +50,7 @@ no_network { my $p = XML::LibXML->new(); for my $opt (@all) { - my $ret = (($opt =~ /^(?:load_ext_dtd|expand_entities)$/) ? 1 : 0); + my $ret = 0; # TEST*$all ok( ($p->get_option($opt)||0) == $ret @@ -110,18 +110,21 @@ no_network ok( $p->get_option('recover') == 2, ' TODO : Add test name' ); # TEST - ok( $p->expand_entities() == 1, ' TODO : Add test name' ); + ok( $p->expand_entities() == 0, 'expand_entities should default to false' ); # TEST - ok( $p->load_ext_dtd() == 1, ' TODO : Add test name' ); + ok( $p->load_ext_dtd() == 0, 'load_ext_dtd should default to false' ); + $p->load_ext_dtd(1); + # TEST + ok( $p->load_ext_dtd() == 1, 'load_ext_dtd should be true after being set to true' ); $p->load_ext_dtd(0); + $p->expand_entities(1); # TEST - ok( $p->load_ext_dtd() == 0, ' TODO : Add test name' ); - $p->expand_entities(0); + ok( $p->expand_entities() == 1, 'expand_entities should be true after being set to true' ); # TEST - ok( $p->expand_entities() == 0, ' TODO : Add test name' ); - $p->expand_entities(1); + ok( $p->load_ext_dtd() == 1, 'load_ext_dtd should be true after expand_entities is set to true' ); + $p->expand_entities(0); # TEST - ok( $p->expand_entities() == 1, ' TODO : Add test name' ); + ok( $p->expand_entities() == 0, 'expand_entities should be false after being set to false' ); } { diff --git a/t/48_SAX_Builder_rt_91433.t b/t/48_SAX_Builder_rt_91433.t index 3422d42..808c0ec 100644 --- a/t/48_SAX_Builder_rt_91433.t +++ b/t/48_SAX_Builder_rt_91433.t @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl use strict; use warnings; @@ -50,6 +50,7 @@ $parser->parse_string(<<'END_OF_XML'); </rdf:RDF></metadata></record></GetRecord></OAI-PMH> END_OF_XML +# TEST eq_or_diff( \@got_warnings, [], diff --git a/t/48_rt123379_setNamespace.t b/t/48_rt123379_setNamespace.t index 45bf5e8..bf396f7 100644 --- a/t/48_rt123379_setNamespace.t +++ b/t/48_rt123379_setNamespace.t @@ -4,12 +4,20 @@ use warnings; use XML::LibXML; use Test::More tests => 8; +# TEST ok(my $doc = XML::LibXML::Document->new(), 'new document'); +# TEST ok(my $elm = $doc->createElement('D:element'), 'create element'); +# TEST ok($elm->setAttribute('xmlns:D', 'attribute'), 'set attribute'); $doc->setDocumentElement($elm); # XXX does not return true if successful +# TEST ok(my $str = $doc->toString(0), 'to string'); +# TEST ok(my $par = XML::LibXML->new(), 'new parser'); +# TEST ok( eval { $par->parse_string($str) } , 'parse string'); +# TEST is($@, "", 'parse error'); +# TEST like($str, qr{<D:element xmlns:D="attribute"/>}, 'xml element'); diff --git a/t/48_rt93429_recover_2_in_html_parsing.t b/t/48_rt93429_recover_2_in_html_parsing.t index d684fa4..c1c06be 100644 --- a/t/48_rt93429_recover_2_in_html_parsing.t +++ b/t/48_rt93429_recover_2_in_html_parsing.t @@ -27,6 +27,7 @@ use XML::LibXML; close($fh); + # TEST is($buf, '', 'No warning emitted on load_html with recover => 2.'); } diff --git a/t/62overload.t b/t/62overload.t index 24ee7be..98b9032 100644 --- a/t/62overload.t +++ b/t/62overload.t @@ -16,23 +16,35 @@ $e2->setAttribute('attr' => 'value2'); my $h1 = \%{ $e1 }; my $h2 = \%{ $e2 }; +# TEST isnt $h1,$h2, 'different references'; +# TEST is $h1->{attr}, 'value1', 'affr for el 1'; +# TEST is $h2->{attr}, 'value2', 'affr for el 2'; +# TEST is "$e1", '<test1 attr="value1"/>', 'stringify for el 1'; +# TEST is "$e2", '<test2 attr="value2"/>', 'stringify for el 2'; +# TEST cmp_ok 0+$e1, '>', 1, 'num for el 1'; +# TEST cmp_ok 0+$e2, '>', 1, 'num for el 2'; +# TEST isnt 0+$e1,0+$e2, 'num for e1 and e2 differs'; my $e3 = $e1; +# TEST ok $e3 eq $e1, 'eq'; +# TEST ok $e3 == $e1, '=='; +# TEST ok $e1 ne $e2, 'ne'; +# TEST ok $e1 != $e2, '!='; diff --git a/t/91unique_key.t b/t/91unique_key.t index 19ad9e5..fd5a0bb 100644 --- a/t/91unique_key.t +++ b/t/91unique_key.t @@ -23,6 +23,7 @@ my $foo = $doc->documentElement; my @children_1 = $foo->childNodes;
my @children_2 = $foo->childNodes;
+# TEST
ok($children_1[0]->can('unique_key'), 'unique_key method available')
or exit -1;
|