VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.31/python/tests/ctxterror.py@ 39915

Last change on this file since 39915 was 39915, checked in by vboxsync, 13 years ago

libxml-2.6.31 unmodified

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1#!/usr/bin/python -u
2#
3# This test exercise the redirection of error messages with a
4# functions defined in Python.
5#
6import sys
7import libxml2
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12expect="""--> (3) xmlns: URI foo is not absolute
13--> (4) Opening and ending tag mismatch: x line 0 and y
14"""
15
16err=""
17def callback(arg,msg,severity,reserved):
18 global err
19 err = err + "%s (%d) %s" % (arg,severity,msg)
20
21s = """<x xmlns="foo"></y>"""
22
23parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
24parserCtxt.setErrorHandler(callback, "-->")
25if parserCtxt.getErrorHandler() != (callback,"-->"):
26 print "getErrorHandler failed"
27 sys.exit(1)
28parserCtxt.parseChunk(s,len(s),1)
29doc = parserCtxt.doc()
30doc.freeDoc()
31parserCtxt = None
32
33if err != expect:
34 print "error"
35 print "received %s" %(err)
36 print "expected %s" %(expect)
37 sys.exit(1)
38
39i = 10000
40while i > 0:
41 parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
42 parserCtxt.setErrorHandler(callback, "-->")
43 parserCtxt.parseChunk(s,len(s),1)
44 doc = parserCtxt.doc()
45 doc.freeDoc()
46 parserCtxt = None
47 err = ""
48 i = i - 1
49
50# Memory debug specific
51libxml2.cleanupParser()
52if libxml2.debugMemory(1) == 0:
53 print "OK"
54else:
55 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
56 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