VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.31/python/tests/reader4.py@ 55391

最後變更 在這個檔案從55391是 39915,由 vboxsync 提交於 13 年 前

libxml-2.6.31 unmodified

  • 屬性 svn:eol-style 設為 native
檔案大小: 1.1 KB
 
1#!/usr/bin/python -u
2#
3# this tests the basic APIs of the XmlTextReader interface
4#
5import libxml2
6import StringIO
7import sys
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12def tst_reader(s):
13 f = StringIO.StringIO(s)
14 input = libxml2.inputBuffer(f)
15 reader = input.newTextReader("tst")
16 res = ""
17 while reader.Read():
18 res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
19 reader.Value(), reader.IsEmptyElement())
20 if reader.NodeType() == 1: # Element
21 while reader.MoveToNextAttribute():
22 res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
23 reader.Name(),reader.Value())
24 return res
25
26expect="""1 (test) [None] 0
271 (b) [None] 1
281 (c) [None] 1
2915 (test) [None] 0
30"""
31
32res = tst_reader("""<test><b/><c/></test>""")
33
34if res != expect:
35 print "Did not get the expected error message:"
36 print res
37 sys.exit(1)
38
39# Memory debug specific
40libxml2.cleanupParser()
41if libxml2.debugMemory(1) == 0:
42 print "OK"
43else:
44 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
45 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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