blob: 2e036e1f4a41f7f22c58cfc9a6d4d3c79649cb23 [file] [log] [blame]
Daniel Veillard253aa2c2002-02-02 09:17:16 +00001#!/usr/bin/python -u
2#
3# this test exercise the XPath basic engine, parser, etc, and
4# allows to detect memory leaks
5#
Daniel Veillard5d819032002-02-02 21:49:17 +00006import sys
Daniel Veillard253aa2c2002-02-02 09:17:16 +00007import libxml2
8
Daniel Veillard4e1b26c2002-02-03 20:13:06 +00009# Memory debug specific
10libxml2.debugMemory(1)
11
Daniel Veillard253aa2c2002-02-02 09:17:16 +000012doc = libxml2.parseFile("tst.xml")
Daniel Veillard5d819032002-02-02 21:49:17 +000013if doc.name != "tst.xml":
14 print "doc.name error"
15 sys.exit(1);
16
17ctxt = doc.xpathNewContext()
18res = ctxt.xpathEval("//*")
19if len(res) != 2:
20 print "xpath query: wrong node set size"
21 sys.exit(1)
22if res[0].name != "doc" or res[1].name != "foo":
23 print "xpath query: wrong node set value"
24 sys.exit(1)
Daniel Veillard8d24cc12002-03-05 15:41:29 +000025ctxt.setContextNode(res[0])
26res = ctxt.xpathEval("foo")
27if len(res) != 1:
28 print "xpath query: wrong node set size"
29 sys.exit(1)
30if res[0].name != "foo":
31 print "xpath query: wrong node set value"
32 sys.exit(1)
Daniel Veillard5d819032002-02-02 21:49:17 +000033doc.freeDoc()
Daniel Veillardc575b992002-02-08 13:28:40 +000034ctxt.xpathFreeContext()
Daniel Veillard253aa2c2002-02-02 09:17:16 +000035i = 1000
36while i > 0:
37 doc = libxml2.parseFile("tst.xml")
38 ctxt = doc.xpathNewContext()
39 res = ctxt.xpathEval("//*")
40 doc.freeDoc()
Daniel Veillardc575b992002-02-08 13:28:40 +000041 ctxt.xpathFreeContext()
Daniel Veillard253aa2c2002-02-02 09:17:16 +000042 i = i -1
Daniel Veillard4e1b26c2002-02-03 20:13:06 +000043del ctxt
44
45# Memory debug specific
46libxml2.cleanupParser()
47if libxml2.debugMemory(1) == 0:
48 print "OK"
49else:
50 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
51 libxml2.dumpMemory()