VirtualBox

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

最後變更 在這個檔案從55391是 39915,由 vboxsync 提交於 13 年 前

libxml-2.6.31 unmodified

  • 屬性 svn:eol-style 設為 native
檔案大小: 1.3 KB
 
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()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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