VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/ctxterror.py@ 105420

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