blob: cc771de13470bf6958cfb65e70f018ef761d7b2a [file] [log] [blame]
Daniel Veillard26f1dcc2002-02-03 16:53:19 +00001#!/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
Daniel Veillard4e1b26c2002-02-03 20:13:06 +00009# Memory debug specific
10libxml2.debugMemory(1)
11
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000012expect='--> warning: --> failed to load external entity "missing.xml"\n'
13err=""
14def callback(ctx, str):
15 global err
16
17 err = err + "%s %s" % (ctx, str)
18
Daniel Veillard8d24cc12002-03-05 15:41:29 +000019got_exc = 0
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000020libxml2.registerErrorHandler(callback, "-->")
Daniel Veillard8d24cc12002-03-05 15:41:29 +000021try:
22 doc = libxml2.parseFile("missing.xml")
23except libxml2.parserError:
24 got_exc = 1
25
26if got_exc == 0:
27 print "Failed to get a parser exception"
28 sys.exit(1)
29
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000030if err != expect:
31 print "error"
32 print "received %s" %(err)
33 print "expected %s" %(expect)
34 sys.exit(1)
35
36i = 10000
37while i > 0:
Daniel Veillard8d24cc12002-03-05 15:41:29 +000038 try:
39 doc = libxml2.parseFile("missing.xml")
40 except libxml2.parserError:
41 got_exc = 1
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000042 err = ""
43 i = i - 1
44
Daniel Veillard4e1b26c2002-02-03 20:13:06 +000045# Memory debug specific
46libxml2.cleanupParser()
47if libxml2.debugMemory(1) == 0:
48 print "OK"
49else:
50 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
51 libxml2.dumpMemory()