1 #!/usr/bin/env python3
2 import sys
3 import setup_test
4 import libxml2
5 try:
6 import StringIO
7 str_io = StringIO.StringIO
8 except:
9 import io
10 str_io = io.StringIO
11
12 # Memory debug specific
13 libxml2.debugMemory(1)
14
15 def myResolver(URL, ID, ctxt):
16 return(str_io("<foo/>"))
17
18 libxml2.setEntityLoader(myResolver)
19
20 doc = libxml2.parseFile("doesnotexist.xml")
21 root = doc.children
22 if root.name != "foo":
23 print("root element name error")
24 sys.exit(1)
25 doc.freeDoc()
26
27 i = 0
28 while i < 5000:
29 doc = libxml2.parseFile("doesnotexist.xml")
30 root = doc.children
31 if root.name != "foo":
32 print("root element name error")
33 sys.exit(1)
34 doc.freeDoc()
35 i = i + 1
36
37
38 # Memory debug specific
39 libxml2.cleanupParser()
40 if libxml2.debugMemory(1) == 0:
41 print("OK")
42 else:
43 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
44