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