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