tstmem.py 717 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/python -u
  2. import libxml2
  3. import libxml2mod
  4. import sys
  5. def error(msg, data):
  6. pass
  7. # Memory debug specific
  8. libxml2.debugMemory(1)
  9. dtd="""<!ELEMENT foo EMPTY>"""
  10. instance="""<?xml version="1.0"?>
  11. <foo></foo>"""
  12. dtd = libxml2.parseDTD(None, 'test.dtd')
  13. ctxt = libxml2.newValidCtxt()
  14. libxml2mod.xmlSetValidErrors(ctxt._o, error, error)
  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. doc.freeDoc()
  21. dtd.freeDtd()
  22. del dtd
  23. del ctxt
  24. # Memory debug specific
  25. libxml2.cleanupParser()
  26. if libxml2.debugMemory(1) == 0:
  27. print "OK"
  28. else:
  29. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  30. libxml2.dumpMemory()