VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.14/python/tests/xpathleak.py@ 97865

Last change on this file since 97865 was 95312, checked in by vboxsync, 3 years ago

libs/{curl,libxml2}: OSE export fixes, bugref:8515

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/python
2import sys, libxml2
3
4libxml2.debugMemory(True)
5
6expect="""--> Invalid expression
7--> Invalid expression
8--> Invalid expression
9--> Invalid expression
10--> Invalid expression
11--> Invalid expression
12--> Invalid expression
13--> Invalid expression
14--> Invalid expression
15--> Invalid expression
16"""
17err=""
18def callback(ctx, str):
19 global err
20
21 err = err + "%s %s" % (ctx, str)
22
23libxml2.registerErrorHandler(callback, "-->")
24
25doc = libxml2.parseDoc("<fish/>")
26ctxt = doc.xpathNewContext()
27ctxt.setContextNode(doc)
28badexprs = (
29 ":false()", "bad:()", "bad(:)", ":bad(:)", "bad:(:)", "bad:bad(:)",
30 "a:/b", "/c:/d", "//e:/f", "g://h"
31 )
32for expr in badexprs:
33 try:
34 ctxt.xpathEval(expr)
35 except libxml2.xpathError:
36 pass
37 else:
38 print("Unexpectedly legal expression:", expr)
39ctxt.xpathFreeContext()
40doc.freeDoc()
41
42if err != expect:
43 print("error")
44 print("received %s" %(err))
45 print("expected %s" %(expect))
46 sys.exit(1)
47
48libxml2.cleanupParser()
49leakedbytes = libxml2.debugMemory(True)
50if leakedbytes == 0:
51 print("OK")
52else:
53 print("Memory leak", leakedbytes, "bytes")
54 # drop file to .memdump file in cwd, but won't work if not compiled in
55 libxml2.dumpMemory()
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette