• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 libxml2
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12expect='--> I/O --> 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
19got_exc = 0
20libxml2.registerErrorHandler(callback, "-->")
21try:
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
30if 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:
38    try:
39        doc = libxml2.parseFile("missing.xml")
40    except libxml2.parserError:
41        got_exc = 1
42    err = ""
43    i = i - 1
44
45# 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()
52