1#!/usr/bin/python -u 2# -*- coding: ISO-8859-1 -*- 3# 4# this tests the next API of the XmlTextReader interface 5# 6import libxml2 7import sys 8try: 9 import StringIO 10 str_io = StringIO.StringIO 11except: 12 import io 13 str_io = io.StringIO 14 15# Memory debug specific 16libxml2.debugMemory(1) 17 18f = str_io("""<a><b><c /></b><d>content of d</d></a>""") 19input = libxml2.inputBuffer(f) 20reader = input.newTextReader("test_next") 21ret = reader.Read() 22if ret != 1: 23 print("test_next: Error reading to first element") 24 sys.exit(1) 25if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ 26 reader.NodeType() != 1 or reader.HasAttributes() != 0: 27 print("test_next: Error reading the first element") 28 sys.exit(1) 29ret = reader.Read() 30if ret != 1: 31 print("test_next: Error reading to second element") 32 sys.exit(1) 33if reader.Name() != "b" or reader.IsEmptyElement() != 0 or \ 34 reader.NodeType() != 1 or reader.HasAttributes() != 0: 35 print("test_next: Error reading the second element") 36 sys.exit(1) 37ret = reader.Read() 38if ret != 1: 39 print("test_next: Error reading to third element") 40 sys.exit(1) 41if reader.Name() != "c" or reader.NodeType() != 1 or \ 42 reader.HasAttributes() != 0: 43 print("test_next: Error reading the third element") 44 sys.exit(1) 45ret = reader.Read() 46if ret != 1: 47 print("test_next: Error reading to end of third element") 48 sys.exit(1) 49if reader.Name() != "b" or reader.NodeType() != 15: 50 print("test_next: Error reading to end of second element") 51 sys.exit(1) 52ret = reader.Next() 53if ret != 1: 54 print("test_next: Error moving to third element") 55 sys.exit(1) 56if reader.Name() != "d" or reader.IsEmptyElement() != 0 or \ 57 reader.NodeType() != 1 or reader.HasAttributes() != 0: 58 print("test_next: Error reading third element") 59 sys.exit(1) 60ret = reader.Next() 61if ret != 1: 62 print("test_next: Error reading to end of first element") 63 sys.exit(1) 64if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ 65 reader.NodeType() != 15 or reader.HasAttributes() != 0: 66 print("test_next: Error reading the end of first element") 67 sys.exit(1) 68ret = reader.Read() 69if ret != 0: 70 print("test_next: Error reading to end of document") 71 sys.exit(1) 72 73# 74# cleanup for memory allocation counting 75# 76del f 77del input 78del reader 79 80# Memory debug specific 81libxml2.cleanupParser() 82if libxml2.debugMemory(1) == 0: 83 print("OK") 84else: 85 print("Memory leak %d bytes" % (libxml2.debugMemory(1))) 86 libxml2.dumpMemory() 87