Hash :
9e395c28
Author :
Date :
2003-01-01T14:50:44
fixed another validity checking in external parsed entities raised by * xmlreader.c python/tests/reader2.py: fixed another validity checking in external parsed entities raised by Stéphane Bidoul and added a specific regression test. * python/tests/reader3.py: cleanup Daniel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
#!/usr/bin/python -u
#
# this tests the validation with the XmlTextReader interface
#
import sys
import StringIO
import libxml2
docstr="""<?xml version='1.0'?>
<!DOCTYPE doc [
<!ENTITY tst "<p>test</p>">
]>
<doc>&tst;</doc>"""
# Memory debug specific
libxml2.debugMemory(1)
#
# First test, normal don't substitute entities.
#
f = StringIO.StringIO(docstr)
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test_noent")
ret = reader.Read()
if ret != 1:
print "Error reading to root"
sys.exit(1)
if reader.Name() != "doc" or reader.NodeType() != 1:
print "test_normal: Error reading the root element"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_normal: Error reading to the entity"
sys.exit(1)
if reader.Name() != "tst" or reader.NodeType() != 5:
print "test_normal: Error reading the entity"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_normal: Error reading to the end of root"
sys.exit(1)
if reader.Name() != "doc" or reader.NodeType() != 15:
print "test_normal: Error reading the end of the root element"
sys.exit(1)
ret = reader.Read()
if ret != 0:
print "test_normal: Error detecting the end"
sys.exit(1)
#
# Second test, completely substitute the entities.
#
f = StringIO.StringIO(docstr)
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test_noent")
reader.SetParserProp(libxml2.PARSER_SUBST_ENTITIES, 1)
ret = reader.Read()
if ret != 1:
print "Error reading to root"
sys.exit(1)
if reader.Name() != "doc" or reader.NodeType() != 1:
print "test_noent: Error reading the root element"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_noent: Error reading to the entity content"
sys.exit(1)
if reader.Name() != "p" or reader.NodeType() != 1:
print "test_noent: Error reading the p element from entity"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_noent: Error reading to the text node"
sys.exit(1)
if reader.NodeType() != 3 or reader.Value() != "test":
print "test_noent: Error reading the text node"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_noent: Error reading to the end of p element"
sys.exit(1)
if reader.Name() != "p" or reader.NodeType() != 15:
print "test_noent: Error reading the end of the p element"
sys.exit(1)
ret = reader.Read()
if ret != 1:
print "test_noent: Error reading to the end of root"
sys.exit(1)
if reader.Name() != "doc" or reader.NodeType() != 15:
print "test_noent: Error reading the end of the root element"
sys.exit(1)
ret = reader.Read()
if ret != 0:
print "test_noent: Error detecting the end"
sys.exit(1)
#
# cleanup
#
del f
del input
del reader
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()