Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # This test exercise the redirection of error messages with a |
| 4 | # functions defined in Python. |
| 5 | # |
| 6 | import sys |
| 7 | import libxml2 |
| 8 | |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 9 | # Memory debug specific |
| 10 | libxml2.debugMemory(1) |
| 11 | |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 12 | expect='--> warning: --> failed to load external entity "missing.xml"\n' |
| 13 | err="" |
| 14 | def callback(ctx, str): |
| 15 | global err |
| 16 | |
| 17 | err = err + "%s %s" % (ctx, str) |
| 18 | |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 19 | got_exc = 0 |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 20 | libxml2.registerErrorHandler(callback, "-->") |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 21 | try: |
| 22 | doc = libxml2.parseFile("missing.xml") |
| 23 | except libxml2.parserError: |
| 24 | got_exc = 1 |
| 25 | |
| 26 | if got_exc == 0: |
| 27 | print "Failed to get a parser exception" |
| 28 | sys.exit(1) |
| 29 | |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 30 | if err != expect: |
| 31 | print "error" |
| 32 | print "received %s" %(err) |
| 33 | print "expected %s" %(expect) |
| 34 | sys.exit(1) |
| 35 | |
| 36 | i = 10000 |
| 37 | while i > 0: |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 38 | try: |
| 39 | doc = libxml2.parseFile("missing.xml") |
| 40 | except libxml2.parserError: |
| 41 | got_exc = 1 |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 42 | err = "" |
| 43 | i = i - 1 |
| 44 | |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 45 | # Memory debug specific |
| 46 | libxml2.cleanupParser() |
| 47 | if libxml2.debugMemory(1) == 0: |
| 48 | print "OK" |
| 49 | else: |
| 50 | print "Memory leak %d bytes" % (libxml2.debugMemory(1)) |
| 51 | libxml2.dumpMemory() |