Re: [xml] patch: c14n python bindings



On Tue, Mar 09, 2004 at 04:11:10AM -0500, Daniel Veillard wrote:

Thanks a lot this was commited to CVS.  would you be so kind as
providing some test script which could be integrated in python/tests
subdir, you certainly had to develop some for basic testing and that
would help making sure the feature don't get perturbed by other
developments,

A test script follows. You may want to disable the SaveTo test if it
conflicts with your test policy (it writes a file). I haven't done any
tests with namespaces yet (I'll send an addition when I get to that):


import libxml2
import sys

# Memory debug specific
libxml2.debugMemory(1)

# Test Memory Canonicalization:

buffer = """<?xml version="1.0" encoding="UTF-8" ?>
<e c="c" a="a" b="b"><a><sub-a/></a><b/></e>"""

c14nbuffer = '<e a="a" b="b" c="c"><a><sub-a></sub-a></a><b></b></e>'

doc = libxml2.parseMemory(buffer, len(buffer))

if doc.c14nMemory(None) != c14nbuffer:
    print "error c14n to memory"
    sys.exit(1)

# Test SaveTo Canonicalization:

f = file('test.xml', 'w')
doc.c14nSaveTo(f)
f.close()
f = file('test.xml')
if f.read() !=  c14nbuffer:
    print "error c14n to file"
    sys.exit(1)

f.close()

# Test Canonicalization with nodeset:

c14nbuffer2 = '<e a="a" c="c"><a></a><b></b></e>'

if c14nbuffer2 != doc.c14nMemory((doc.children,
                                  doc.children.get_properties(),
                                  doc.children.get_properties().next,
                                  doc.children.children,
                                  doc.children.children.next,)):
    print "error c14n subset to memory"
    sys.exit(1)

# ISSUE: Just an attribute? This doesn't work.
#c14nbuffer3 = 'c="c"'
#if c14nbuffer3 != doc.c14nMemory((doc.children.get_properties(),)):
#    print "error c14n attribute"
#    sys.exit(1)

doc.freeDoc()

#Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
    print "OK"
else:
    print "Memory leak %d bytes" % (libxml2.debugMemory(1))
    libxml2.dumpMemory()


--
Anthony Carrico



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]