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