Annotation of embedaddon/libxml2/python/tests/xpath.py, revision 1.1.1.2
1.1 misho 1: #!/usr/bin/python -u
2: #
3: # this test exercise the XPath basic engine, parser, etc, and
4: # allows to detect memory leaks
5: #
6: import sys
7: import libxml2
8:
9: # Memory debug specific
10: libxml2.debugMemory(1)
11:
12: doc = libxml2.parseFile("tst.xml")
13: if doc.name != "tst.xml":
1.1.1.2 ! misho 14: print("doc.name error")
1.1 misho 15: sys.exit(1);
16:
17: ctxt = doc.xpathNewContext()
18: res = ctxt.xpathEval("//*")
19: if len(res) != 2:
1.1.1.2 ! misho 20: print("xpath query: wrong node set size")
1.1 misho 21: sys.exit(1)
22: if res[0].name != "doc" or res[1].name != "foo":
1.1.1.2 ! misho 23: print("xpath query: wrong node set value")
1.1 misho 24: sys.exit(1)
25: ctxt.setContextNode(res[0])
26: res = ctxt.xpathEval("foo")
27: if len(res) != 1:
1.1.1.2 ! misho 28: print("xpath query: wrong node set size")
1.1 misho 29: sys.exit(1)
30: if res[0].name != "foo":
1.1.1.2 ! misho 31: print("xpath query: wrong node set value")
1.1 misho 32: sys.exit(1)
33: doc.freeDoc()
34: ctxt.xpathFreeContext()
35: i = 1000
36: while i > 0:
37: doc = libxml2.parseFile("tst.xml")
38: ctxt = doc.xpathNewContext()
39: res = ctxt.xpathEval("//*")
40: doc.freeDoc()
41: ctxt.xpathFreeContext()
42: i = i -1
43: del ctxt
44:
45: # Memory debug specific
46: libxml2.cleanupParser()
47: if libxml2.debugMemory(1) == 0:
1.1.1.2 ! misho 48: print("OK")
1.1 misho 49: else:
1.1.1.2 ! misho 50: print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
1.1 misho 51: libxml2.dumpMemory()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>