I remember reading a post here that said about the best thing you could do for the perl community was writing module tests. So I've written some tests for XML::LibXML, mainly because I couldn't figure out how to make it do what I want. Does anyone around here know the module and can tell me if I misunderstood the documentation or if there are really bugs in the module? On my system, tests 6, 7, and 11 - 17 break, and I get a segfault with the last method call. I'm using 5.6.1 under Red Hat Linux 7.1.

Here are the tests:

#!/usr/bin/perl -w use Test::More tests => 18; BEGIN { use_ok ('XML::LibXML') }; my $doc = new XML::LibXML::Document; ok (defined $doc, 'Document constructed'); ok ($doc->isa ('XML::LibXML::Document'), 'Document: correct object cla +ss'); my $par = $doc->createElement ('Paragraph'); ok (defined $par, 'XML Element constructed via Document'); ok ($par->isa ('XML::LibXML::Element'), 'Element: correct object class +'); is ($par->ownerDocument (), $doc, 'Element has correct owner'); #explicitly set owner document $par->setOwnerDocument ($doc); is ($par->ownerDocument (), $doc, 'Element has correct owner after exp +licitly setting it'); #add text to Element $par->appendText ('Some text'); is ($par->toString (), '<Paragraph>Some text</Paragraph>', 'Text added + to Element'); #construct Element from scratch $par2 = new XML::LibXML::Element ('Paragraph'); ok (defined $par2, 'XML Element constructed from scratch'); ok ($par2->isa ('XML::LibXML::Element'), 'new Element: correct object +class'); #add text to Element $par2->appendText ('Other text'); is ($par2->toString (), '<Paragraph>Other text</Paragraph>', 'Text add +ed to Element before setting owner document'); #explicitly set owner document $par2->setOwnerDocument ($doc); is ($par2->ownerDocument (), $doc, 'Element has correct owner after ex +plicitly setting it'); #add text to Element after setting owner document $par2->appendText ('Other text'); is ($par2->toString (), '<Paragraph>Other text</Paragraph>', 'Text add +ed to Element after setting owner document'); #add paragraph to document $doc->appendChild ($par); is ($doc->hasChildNodes (), 1, 'Element added to document'); is ($doc->toString (), '<?xml version="1.0" encoding="UTF-8"?> <Paragraph>Some text</Paragraph>', '$doc->toString () works OK'); #attempt with appendChild eval {$doc->insertBefore ($par);}; is ($@, '', '$doc->insertBefore(): OK'); is ($doc->hasChildNodes (), 1, 'Element added to document with appendB +efore'); #attempt to insert DocumentFragment into Document eval {$doc->appendChild ($par->ownerDocument ());}; is ($@, '', 'insert Document Fragment: OK');
Thanks for any feedback

pike


In reply to Problems with XML::LibXML by pike

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.