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 dtd="""<!ELEMENT foo EMPTY>"""
10 instance="""<?xml version="1.0"?>
11 <foo></foo>"""
12
13 dtd = libxml2.parseDTD(None, 'test.dtd')
14 ctxt = libxml2.newValidCtxt()
15 doc = libxml2.parseDoc(instance)
16 ret = doc.validateDtd(ctxt, dtd)
17 if ret != 1:
18 print("error doing DTD validation")
19 sys.exit(1)
20
21 doc.freeDoc()
22 dtd.freeDtd()
23 del dtd
24 del ctxt
25
26 # Memory debug specific
27 libxml2.cleanupParser()
28 if libxml2.debugMemory(1) == 0:
29 print("OK")
30 else:
31 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
32