VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/xpathleak.py

Last change on this file was 105420, checked in by vboxsync, 7 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

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