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