libxml2 2.9.1 clean sources
[tomato.git] / release / src / router / libxml2 / python / tests / reader7.py
blobc88e37024ae5a38c1beebca0d349b17dde711dba
1 #!/usr/bin/python -u
3 # this tests the entities substitutions with the XmlTextReader interface
5 import sys
6 import libxml2
8 # Memory debug specific
9 libxml2.debugMemory(1)
11 result = ""
12 def processNode(reader):
13 global result
15 result = result + "%d %d %s %d\n" % (reader.Depth(), reader.NodeType(),
16 reader.Name(), reader.IsEmptyElement())
19 # Parse a document testing the readerForxxx API
21 docstr="""<foo>
22 <label>some text</label>
23 <item>100</item>
24 </foo>"""
25 expect="""0 1 foo 0
26 1 14 #text 0
27 1 1 label 0
28 2 3 #text 0
29 1 15 label 0
30 1 14 #text 0
31 1 1 item 0
32 2 3 #text 0
33 1 15 item 0
34 1 14 #text 0
35 0 15 foo 0
36 """
37 result = ""
39 reader = libxml2.readerForDoc(docstr, "test1", None, 0)
40 ret = reader.Read()
41 while ret == 1:
42 processNode(reader)
43 ret = reader.Read()
45 if ret != 0:
46 print("Error parsing the document test1")
47 sys.exit(1)
49 if result != expect:
50 print("Unexpected result for test1")
51 print(result)
52 sys.exit(1)
55 # Reuse the reader for another document testing the ReaderNewxxx API
57 docstr="""<foo>
58 <label>some text</label>
59 <item>1000</item>
60 </foo>"""
61 expect="""0 1 foo 0
62 1 14 #text 0
63 1 1 label 0
64 2 3 #text 0
65 1 15 label 0
66 1 14 #text 0
67 1 1 item 0
68 2 3 #text 0
69 1 15 item 0
70 1 14 #text 0
71 0 15 foo 0
72 """
73 result = ""
75 reader.NewDoc(docstr, "test2", None, 0)
76 ret = reader.Read()
77 while ret == 1:
78 processNode(reader)
79 ret = reader.Read()
81 if ret != 0:
82 print("Error parsing the document test2")
83 sys.exit(1)
85 if result != expect:
86 print("Unexpected result for test2")
87 print(result)
88 sys.exit(1)
91 # cleanup
93 del reader
95 # Memory debug specific
96 libxml2.cleanupParser()
97 if libxml2.debugMemory(1) == 0:
98 print("OK")
99 else:
100 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
101 libxml2.dumpMemory()