push.py 765 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/python -u
  2. import sys
  3. import libxml2
  4. # Memory debug specific
  5. libxml2.debugMemory(1)
  6. ctxt = libxml2.createPushParser(None, "<foo", 4, "test.xml")
  7. ctxt.parseChunk("/>", 2, 1)
  8. doc = ctxt.doc()
  9. ctxt=None
  10. if doc.name != "test.xml":
  11. print "document name error"
  12. sys.exit(1)
  13. root = doc.children
  14. if root.name != "foo":
  15. print "root element name error"
  16. sys.exit(1)
  17. doc.freeDoc()
  18. i = 10000
  19. while i > 0:
  20. ctxt = libxml2.createPushParser(None, "<foo", 4, "test.xml")
  21. ctxt.parseChunk("/>", 2, 1)
  22. doc = ctxt.doc()
  23. doc.freeDoc()
  24. i = i -1
  25. ctxt=None
  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. libxml2.dumpMemory()