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