VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/sync.py@ 105635

最後變更 在這個檔案從105635是 104106,由 vboxsync 提交於 10 月 前

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 3.8 KB
 
1#!/usr/bin/env python3
2import sys
3import setup_test
4import libxml2
5
6# Memory debug specific
7libxml2.debugMemory(1)
8
9log = ""
10
11class callback:
12 def startDocument(self):
13 global log
14 log = log + "startDocument:"
15
16 def endDocument(self):
17 global log
18 log = log + "endDocument:"
19
20 def startElement(self, tag, attrs):
21 global log
22 log = log + "startElement %s %s:" % (tag, attrs)
23
24 def endElement(self, tag):
25 global log
26 log = log + "endElement %s:" % (tag)
27
28 def characters(self, data):
29 global log
30 log = log + "characters: %s:" % (data)
31
32 def warning(self, msg):
33 global log
34 log = log + "warning: %s:" % (msg)
35
36 def error(self, msg):
37 global log
38 log = log + "error: %s:" % (msg)
39
40 def fatalError(self, msg):
41 global log
42 log = log + "fatalError: %s:" % (msg)
43
44handler = callback()
45
46log=""
47chunk="""<foo><bar2/>"""
48ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
49ctxt.parseChunk(chunk, len(chunk), 0)
50ctxt=None
51
52reference = "startDocument:startElement foo None:startElement bar2 None:endElement bar2:"
53if log != reference:
54 print("Error got: %s" % log)
55 print("Expected: %s" % reference)
56 sys.exit(1)
57
58log=""
59chunk="""<foo><bar2></bar2>"""
60ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
61ctxt.parseChunk(chunk, len(chunk), 0)
62ctxt=None
63
64reference = "startDocument:startElement foo None:startElement bar2 None:endElement bar2:"
65if log != reference:
66 print("Error got: %s" % log)
67 print("Expected: %s" % reference)
68 sys.exit(1)
69
70log=""
71chunk="""<foo><bar2>"""
72ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
73ctxt.parseChunk(chunk, len(chunk), 0)
74ctxt=None
75
76reference = "startDocument:startElement foo None:startElement bar2 None:"
77if log != reference:
78 print("Error got: %s" % log)
79 print("Expected: %s" % reference)
80 sys.exit(1)
81
82log=""
83chunk="""<foo><bar2 a="1" b='2' />"""
84ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
85ctxt.parseChunk(chunk, len(chunk), 0)
86ctxt=None
87
88reference1 = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:endElement bar2:"
89reference2 = "startDocument:startElement foo None:startElement bar2 {'b': '2', 'a': '1'}:endElement bar2:"
90if log not in (reference1, reference2):
91 print("Error got: %s" % log)
92 print("Expected: %s" % reference)
93 sys.exit(1)
94
95log=""
96chunk="""<foo><bar2 a="1" b='2' >"""
97ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
98ctxt.parseChunk(chunk, len(chunk), 0)
99ctxt=None
100
101reference1 = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:"
102reference2 = "startDocument:startElement foo None:startElement bar2 {'b': '2', 'a': '1'}:"
103if log not in (reference1, reference2):
104 print("Error got: %s" % log)
105 print("Expected: %s" % reference)
106 sys.exit(1)
107
108log=""
109chunk="""<foo><bar2 a="1" b='2' ></bar2>"""
110ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
111ctxt.parseChunk(chunk, len(chunk), 0)
112ctxt=None
113
114reference1 = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:endElement bar2:"
115reference2 = "startDocument:startElement foo None:startElement bar2 {'b': '2', 'a': '1'}:endElement bar2:"
116if log not in (reference1, reference2):
117 print("Error got: %s" % log)
118 print("Expected: %s" % reference)
119 sys.exit(1)
120
121log=""
122chunk="""<foo><bar2 a="b='1' />"""
123ctxt = libxml2.createPushParser(handler, None, 0, "test.xml")
124ctxt.parseChunk(chunk, len(chunk), 0)
125ctxt=None
126
127reference = "startDocument:startElement foo None:"
128if log != reference:
129 print("Error got: %s" % log)
130 print("Expected: %s" % reference)
131 sys.exit(1)
132
133# Memory debug specific
134libxml2.cleanupParser()
135if libxml2.debugMemory(1) == 0:
136 print("OK")
137else:
138 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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