1#!/usr/bin/python -u
2import libxml2
3import libxml2mod
4import sys
5
6def error(msg, data):
7    pass
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12dtd="""<!ELEMENT foo EMPTY>"""
13instance="""<?xml version="1.0"?>
14<foo></foo>"""
15
16dtd = libxml2.parseDTD(None, 'test.dtd')
17ctxt = libxml2.newValidCtxt()
18libxml2mod.xmlSetValidErrors(ctxt._o, error, error)
19doc = libxml2.parseDoc(instance)
20ret = doc.validateDtd(ctxt, dtd)
21if ret != 1:
22    print("error doing DTD validation")
23    sys.exit(1)
24
25doc.freeDoc()
26dtd.freeDtd()
27del dtd
28del ctxt
29
30# Memory debug specific
31libxml2.cleanupParser()
32if libxml2.debugMemory(1) == 0:
33    print("OK")
34else:
35    print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
36    libxml2.dumpMemory()
37