VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/validDTD.py

Last change on this file was 105420, checked in by vboxsync, 7 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/env python3
2import setup_test
3import libxml2
4import sys
5
6ARG = 'test string'
7
8class ErrorHandler:
9
10 def __init__(self):
11 self.errors = []
12
13 def handler(self, msg, data):
14 if data != ARG:
15 raise Exception("Error handler did not receive correct argument")
16 self.errors.append(msg)
17
18
19# Memory debug specific
20libxml2.debugMemory(1)
21
22dtd="""<!ELEMENT foo EMPTY>"""
23valid="""<?xml version="1.0"?>
24<foo></foo>"""
25
26invalid="""<?xml version="1.0"?>
27<foo><bar/></foo>"""
28
29dtd = libxml2.parseDTD(None, 'test.dtd')
30ctxt = libxml2.newValidCtxt()
31e = ErrorHandler()
32ctxt.setValidityErrorHandler(e.handler, e.handler, ARG)
33
34# Test valid document
35doc = libxml2.parseDoc(valid)
36ret = doc.validateDtd(ctxt, dtd)
37if ret != 1 or e.errors:
38 print("error doing DTD validation")
39 sys.exit(1)
40doc.freeDoc()
41
42# Test invalid document
43doc = libxml2.parseDoc(invalid)
44ret = doc.validateDtd(ctxt, dtd)
45if ret != 0 or not e.errors:
46 print("Error: document supposed to be invalid")
47doc.freeDoc()
48
49dtd.freeDtd()
50del dtd
51del ctxt
52
53# Memory debug specific
54libxml2.cleanupParser()
55if libxml2.debugMemory(1) == 0:
56 print("OK")
57else:
58 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
59
Note: See TracBrowser for help on using the repository browser.

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