| 1 |
#!/usr/bin/env python3 |
| 2 |
import setup_test |
| 3 |
import libxml2 |
| 4 |
import sys |
| 5 |
|
| 6 |
# Memory debug specific |
| 7 |
libxml2.debugMemory(1) |
| 8 |
|
| 9 |
doc = libxml2.newDoc("1.0") |
| 10 |
comment = doc.newDocComment("This is a generated document") |
| 11 |
doc.addChild(comment) |
| 12 |
pi = libxml2.newPI("test", "PI content") |
| 13 |
doc.addChild(pi) |
| 14 |
root = doc.newChild(None, "doc", None) |
| 15 |
ns = root.newNs("http://example.com/doc", "my") |
| 16 |
root.setNs(ns) |
| 17 |
elem = root.newChild(None, "foo", "bar") |
| 18 |
elem.setBase("http://example.com/imgs") |
| 19 |
elem.setProp("img", "image.gif") |
| 20 |
doc.saveFile("tmp.xml") |
| 21 |
doc.freeDoc() |
| 22 |
|
| 23 |
doc = libxml2.parseFile("tmp.xml") |
| 24 |
comment = doc.children |
| 25 |
if comment.type != "comment" or \ |
| 26 |
comment.content != "This is a generated document": |
| 27 |
print("error rereading comment") |
| 28 |
sys.exit(1) |
| 29 |
pi = comment.next |
| 30 |
if pi.type != "pi" or pi.name != "test" or pi.content != "PI content": |
| 31 |
print("error rereading PI") |
| 32 |
sys.exit(1) |
| 33 |
root = pi.next |
| 34 |
if root.name != "doc": |
| 35 |
print("error rereading root") |
| 36 |
sys.exit(1) |
| 37 |
ns = root.ns() |
| 38 |
if ns.name != "my" or ns.content != "http://example.com/doc": |
| 39 |
print("error rereading namespace") |
| 40 |
sys.exit(1) |
| 41 |
elem = root.children |
| 42 |
if elem.name != "foo": |
| 43 |
print("error rereading elem") |
| 44 |
sys.exit(1) |
| 45 |
if elem.getBase(None) != "http://example.com/imgs": |
| 46 |
print("error rereading base") |
| 47 |
sys.exit(1) |
| 48 |
if elem.prop("img") != "image.gif": |
| 49 |
print("error rereading property") |
| 50 |
sys.exit(1) |
| 51 |
|
| 52 |
doc.freeDoc() |
| 53 |
|
| 54 |
# Memory debug specific |
| 55 |
libxml2.cleanupParser() |
| 56 |
if libxml2.debugMemory(1) == 0: |
| 57 |
print("OK") |
| 58 |
else: |
| 59 |
print("Memory leak %d bytes" % (libxml2.debugMemory(1))) |