• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python -u
2#
3# this tests the basic APIs of the XmlTextReader interface
4#
5import libxml2
6import sys
7try:
8    import StringIO
9    str_io = StringIO.StringIO
10except:
11    import io
12    str_io = io.StringIO
13
14# Memory debug specific
15libxml2.debugMemory(1)
16
17def tst_reader(s):
18    f = str_io(s)
19    input = libxml2.inputBuffer(f)
20    reader = input.newTextReader("tst")
21    res = ""
22    while reader.Read():
23        res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
24				      reader.Value(), reader.IsEmptyElement())
25        if reader.NodeType() == 1: # Element
26            while reader.MoveToNextAttribute():
27                res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
28						   reader.Name(),reader.Value())
29    return res
30
31expect="""1 (test) [None] 0
321 (b) [None] 1
331 (c) [None] 1
3415 (test) [None] 0
35"""
36
37res = tst_reader("""<test><b/><c/></test>""")
38
39if res != expect:
40    print("Did not get the expected error message:")
41    print(res)
42    sys.exit(1)
43
44# Memory debug specific
45libxml2.cleanupParser()
46if libxml2.debugMemory(1) == 0:
47    print("OK")
48else:
49    print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
50    libxml2.dumpMemory()
51