diff options
author | Mike Hommey <glandium@debian.org> | 2009-03-01 10:54:34 +0100 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2009-03-01 10:54:34 +0100 |
commit | 0c1d871e4c5e46a2945cccb2ce765f9be2fe01fb (patch) | |
tree | 982382b30eb118c65e1a06b25757dac5c3c69b8d /python/tests | |
parent | d03a853bb0370d89552eceee59df1746da4a37f8 (diff) | |
download | libxml2-0c1d871e4c5e46a2945cccb2ce765f9be2fe01fb.tar.gz |
Import upstream version 2.7.1upstream/2.7.1.dfsg
Diffstat (limited to 'python/tests')
-rw-r--r-- | python/tests/Makefile.am | 3 | ||||
-rw-r--r-- | python/tests/Makefile.in | 3 | ||||
-rwxr-xr-x | python/tests/xpathleak.py | 53 |
3 files changed, 57 insertions, 2 deletions
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am index 8a85075..52c89fc 100644 --- a/python/tests/Makefile.am +++ b/python/tests/Makefile.am @@ -46,7 +46,8 @@ PYTESTS= \ validSchemas.py \ validRNG.py \ compareNodes.py \ - xpathns.py + xpathns.py \ + xpathleak.py XMLS= \ tst.xml \ diff --git a/python/tests/Makefile.in b/python/tests/Makefile.in index d7c00e5..ec3036f 100644 --- a/python/tests/Makefile.in +++ b/python/tests/Makefile.in @@ -317,7 +317,8 @@ PYTESTS = \ validSchemas.py \ validRNG.py \ compareNodes.py \ - xpathns.py + xpathns.py \ + xpathleak.py XMLS = \ tst.xml \ diff --git a/python/tests/xpathleak.py b/python/tests/xpathleak.py new file mode 100755 index 0000000..dcc144c --- /dev/null +++ b/python/tests/xpathleak.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +import sys, libxml2 + +libxml2.debugMemory(True) + +expect="""--> Invalid expression +--> xmlXPathEval: evaluation failed +--> Invalid expression +--> xmlXPathEval: evaluation failed +--> Invalid expression +--> xmlXPathEval: evaluation failed +--> Invalid expression +--> xmlXPathEval: evaluation failed +--> Invalid expression +--> xmlXPathEval: evaluation failed +--> Invalid expression +--> xmlXPathEval: evaluation failed +""" +err="" +def callback(ctx, str): + global err + + err = err + "%s %s" % (ctx, str) + +libxml2.registerErrorHandler(callback, "-->") + +doc = libxml2.parseDoc("<fish/>") +ctxt = doc.xpathNewContext() +ctxt.setContextNode(doc) +for expr in (":false()","bad:()","bad(:)",":bad(:)","bad:(:)","bad:bad(:)"): + try: + ctxt.xpathEval(expr) + except libxml2.xpathError, e: + pass + else: + print "Unexpectedly legal expression:", expr +ctxt.xpathFreeContext() +doc.freeDoc() + +if err != expect: + print "error" + print "received %s" %(err) + print "expected %s" %(expect) + sys.exit(1) + +libxml2.cleanupParser() +leakedbytes = libxml2.debugMemory(True) +if leakedbytes == 0: + print "OK" +else: + print "Memory leak", leakedbytes, "bytes" + # drop file to .memdump file in cwd, but won't work if not compiled in + libxml2.dumpMemory() |