Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | import libxml2 |
| 3 | import sys |
| 4 | |
| 5 | # Memory debug specific |
| 6 | libxml2.debugMemory(1) |
| 7 | |
| 8 | dtd="""<!ELEMENT foo EMPTY>""" |
| 9 | instance="""<?xml version="1.0"?> |
| 10 | <foo></foo>""" |
| 11 | |
| 12 | dtd = libxml2.parseDTD(None, 'test.dtd') |
| 13 | ctxt = libxml2.newValidCtxt() |
| 14 | doc = libxml2.parseDoc(instance) |
| 15 | ret = doc.validateDtd(ctxt, dtd) |
| 16 | if ret != 1: |
Daniel Veillard | 2cb6bf8 | 2013-03-30 21:38:20 +0800 | [diff] [blame] | 17 | print("error doing DTD validation") |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 18 | sys.exit(1) |
| 19 | |
| 20 | doc.freeDoc() |
| 21 | dtd.freeDtd() |
| 22 | del dtd |
| 23 | del ctxt |
| 24 | |
| 25 | # Memory debug specific |
| 26 | libxml2.cleanupParser() |
| 27 | if libxml2.debugMemory(1) == 0: |
Daniel Veillard | 2cb6bf8 | 2013-03-30 21:38:20 +0800 | [diff] [blame] | 28 | print("OK") |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 29 | else: |
Daniel Veillard | 2cb6bf8 | 2013-03-30 21:38:20 +0800 | [diff] [blame] | 30 | print("Memory leak %d bytes" % (libxml2.debugMemory(1))) |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 31 | libxml2.dumpMemory() |
| 32 | |