# -*- coding: ISO-8859-1 -*-
#
# this tests the basic APIs of the XmlTextReader interface
#
import libxml2
import StringIO
import sys
# Memory debug specific
if ret != 1:
print "test1: Error reading to first element"
print "test1: Error reading the first element"
if ret != 1:
print "test1: Error reading to second element"
print "test1: Error reading the second element"
if ret != 1:
print "test1: Error reading to third element"
print "test1: Error reading the third element"
if ret != 1:
print "test1: Error reading to text node"
print "test1: Error reading the text node"
if ret != 1:
print "test1: Error reading to end of third element"
print "test1: Error reading the end of third element"
if ret != 1:
print "test1: Error reading to end of first element"
print "test1: Error reading the end of first element"
if ret != 0:
print "test1: Error reading to end of document"
#
# example from the XmlTextReader docs
#
if ret != 1:
print "Error reading test element"
print "error reading test attributes"
#
# example from the XmlTextReader docs
#
<item>
<ref href="a:b"/>
</item>
</root>""")
while ret == 1:
print "error resolving namespace prefix"
break
if ret != 1:
print "Error finding the ref element"
#
# Home made example for the various attribute access functions
#
if ret != 1:
print "Error reading the testattr element"
#
# Attribute exploration by index
#
print "Failed moveToAttribute(0)"
print "Failed to read attribute(0)"
print "Failed to read attribute(0) name"
print "Failed moveToAttribute(1)"
print "Failed to read attribute(1)"
print "Failed to read attribute(1) name"
print "Failed moveToAttribute(2)"
print "Failed to read attribute(2)"
print "Failed to read attribute(2) name"
print "Failed moveToAttribute(3)"
print "Failed to read attribute(3)"
print "Failed to read attribute(3) name"
#
# Attribute exploration by name
#
print "Failed moveToAttribute('xmlns')"
print "Failed to read attribute('xmlns')"
print "Failed moveToAttribute('xmlns')"
print "Failed to read attribute('xmlns:a')"
print "Failed moveToAttribute('b')"
print "Failed to read attribute('b')"
print "Failed moveToAttribute('a:b')"
print "Failed to read attribute('a:b')"
print "Failed moveToAttribute('b', 'urn:2')"
print "Failed to read attribute('b', 'urn:2')"
#
# Go back and read in sequence
#
print "Failed to move back to element"
print "Failed to move to first attribute"
print "Failed to read attribute(0)"
print "Failed to read attribute(0) name"
print "Failed to move to next attribute"
print "Failed to read attribute(1)"
print "Failed to read attribute(1) name"
print "Failed to move to next attribute"
print "Failed to read attribute(2)"
print "Failed to read attribute(2) name"
print "Failed to move to next attribute"
print "Failed to read attribute(3)"
print "Failed to read attribute(3) name"
print "Failed to detect last attribute"
#
# a couple of tests for namespace nodes
#
if ret != 1:
print "test6: failed to Read()"
if ret != 1:
print "test6: failed to MoveToFirstAttribute()"
print "test6: failed to read the namespace node"
if ret != 1:
print "test7: failed to Read()"
if ret != 1:
print "test7: failed to MoveToFirstAttribute()"
print "test7: failed to read the namespace node"
#
# Test for a limit case:
#
if ret != 1:
print "test8: failed to read the node"
print "test8: failed to analyze the node"
if ret != 0:
print "test8: failed to detect the EOF"
#
# Another test provided by St�phane Bidoul and checked with C#
#
def tst_reader(s):
res = ""
while reader.MoveToNextAttribute():
return res
doc="""<a><b b1="b1"/><c>content of c</c></a>"""
expect="""1 (a) [None] 0 0
1 (b) [None] 1 1
-- 2 (b1) [b1] 0 2
1 (c) [None] 0 1
3 (#text) [content of c] 0 2
15 (c) [None] 0 1
15 (a) [None] 0 0
"""
print "test5 failed"
print res
doc="""<test><b/><c/></test>"""
expect="""1 (test) [None] 0 0
1 (b) [None] 1 1
1 (c) [None] 1 1
15 (test) [None] 0 0
"""
print "test9 failed"
print res
doc="""<a><b>bbb</b><c>ccc</c></a>"""
expect="""1 (a) [None] 0 0
1 (b) [None] 0 1
3 (#text) [bbb] 0 2
15 (b) [None] 0 1
1 (c) [None] 0 1
3 (#text) [ccc] 0 2
15 (c) [None] 0 1
15 (a) [None] 0 0
"""
print "test10 failed"
print res
doc="""<test a="a"/>"""
expect="""1 (test) [None] 1 0
-- 2 (a) [a] 0 1
"""
print "test11 failed"
print res
doc="""<test><a>aaa</a><b/></test>"""
expect="""1 (test) [None] 0 0
1 (a) [None] 0 1
3 (#text) [aaa] 0 2
15 (a) [None] 0 1
1 (b) [None] 1 1
15 (test) [None] 0 0
"""
print "test12 failed"
print res
doc="""<test><p></p></test>"""
expect="""1 (test) [None] 0 0
1 (p) [None] 0 1
15 (p) [None] 0 1
15 (test) [None] 0 0
"""
print "test13 failed"
print res
doc="""<p></p>"""
expect="""1 (p) [None] 0 0
15 (p) [None] 0 0
"""
print "test14 failed"
print res
#
# test from bug #108801
#
doc="""<?xml version="1.0" standalone="no"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
]>
<article>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</article>
"""
expect="""10 (article) [None] 0 0
1 (article) [None] 0 0
3 (#text) [
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
] 0 1
15 (article) [None] 0 0
"""
print "test15 failed"
print res
#
# cleanup for memory allocation counting
#
del f
del input
del reader
# Memory debug specific
print "OK"
else: