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