File: 16docnodes.t

package info (click to toggle)
libxml-libxml-perl 2.0116%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,420 kB
  • sloc: perl: 6,139; ansic: 3,752; xml: 182; sh: 64; makefile: 8
file content (72 lines) | stat: -rw-r--r-- 1,630 bytes parent folder | download | duplicates (7)
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
use strict;
use warnings;

use XML::LibXML;
# Should be 11.
use Test::More tests => 11;

# this test fails under XML-LibXML-1.00 with a segfault after the
# second parsing.  it was fixed by putting in code in getChildNodes
# to handle the special case where the node was the document node

  my $input = <<EOD;
<doc>
   <clean>   </clean>
   <dirty>   A   B   </dirty>
   <mixed>
      A
      <clean>   </clean>
      B
      <dirty>   A   B   </dirty>
      C
   </mixed>
</doc>
EOD

for my $time (0 .. 2) {
    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_string($input);
    my @a = $doc->getChildnodes;
    # TEST*3
    is(scalar(@a), 1, "1 Child node - time $time");
}

my $parser = XML::LibXML->new();
my $doc = $parser->parse_string($input);
for my $time (0 .. 2) {
    my $e = $doc->getFirstChild;
    # TEST*3
    isa_ok ($e, 'XML::LibXML::Element',
        "first child is an Element - time No. $time"
    );
}

for my $time (0 .. 2) {
    my $e = $doc->getLastChild;
    # TEST*3
    isa_ok($e,'XML::LibXML::Element',
        "last child is an element - time No. $time"
    );
}

##
# Test Ticket 7645
{
    my $in = pack('U', 0x00e4);
    my $doc = XML::LibXML::Document->new();

    my $node = XML::LibXML::Element->new('test');
    $node->setAttribute(contents => $in);
    $doc->setDocumentElement($node);

    # TEST
    is( $node->serialize(), '<test contents="&#xE4;"/>', 'Node serialise works.' );

    $doc->setEncoding('utf-8');
    # Second output
    # TEST
    is( $node->serialize(),
        encodeToUTF8( 'iso-8859-1', '<test contents=""/>' ),
        'UTF-8 node serialize',
    );
}