build.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/python -u
  2. import libxml2
  3. import sys
  4. # Memory debug specific
  5. libxml2.debugMemory(1)
  6. doc = libxml2.newDoc("1.0")
  7. comment = doc.newDocComment("This is a generated document")
  8. doc.addChild(comment)
  9. pi = libxml2.newPI("test", "PI content")
  10. doc.addChild(pi)
  11. root = doc.newChild(None, "doc", None)
  12. ns = root.newNs("http://example.com/doc", "my")
  13. root.setNs(ns)
  14. elem = root.newChild(None, "foo", "bar")
  15. elem.setBase("http://example.com/imgs")
  16. elem.setProp("img", "image.gif")
  17. doc.saveFile("tmp.xml")
  18. doc.freeDoc()
  19. doc = libxml2.parseFile("tmp.xml")
  20. comment = doc.children
  21. if comment.type != "comment" or \
  22. comment.content != "This is a generated document":
  23. print "error rereading comment"
  24. sys.exit(1)
  25. pi = comment.next
  26. if pi.type != "pi" or pi.name != "test" or pi.content != "PI content":
  27. print "error rereading PI"
  28. sys.exit(1)
  29. root = pi.next
  30. if root.name != "doc":
  31. print "error rereading root"
  32. sys.exit(1)
  33. ns = root.ns()
  34. if ns.name != "my" or ns.content != "http://example.com/doc":
  35. print "error rereading namespace"
  36. sys.exit(1)
  37. elem = root.children
  38. if elem.name != "foo":
  39. print "error rereading elem"
  40. sys.exit(1)
  41. if elem.getBase(None) != "http://example.com/imgs":
  42. print "error rereading base"
  43. sys.exit(1)
  44. if elem.prop("img") != "image.gif":
  45. print "error rereading property"
  46. sys.exit(1)
  47. doc.freeDoc()
  48. # Memory debug specific
  49. libxml2.cleanupParser()
  50. if libxml2.debugMemory(1) == 0:
  51. print "OK"
  52. else:
  53. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  54. libxml2.dumpMemory()