1*7c568831SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*7c568831SAndroid Build Coastguard Worker# 3*7c568831SAndroid Build Coastguard Worker# this tests the basic APIs of the XmlTextReader interface 4*7c568831SAndroid Build Coastguard Worker# 5*7c568831SAndroid Build Coastguard Workerimport setup_test 6*7c568831SAndroid Build Coastguard Workerimport libxml2 7*7c568831SAndroid Build Coastguard Workerimport sys 8*7c568831SAndroid Build Coastguard Workertry: 9*7c568831SAndroid Build Coastguard Worker import StringIO 10*7c568831SAndroid Build Coastguard Worker str_io = StringIO.StringIO 11*7c568831SAndroid Build Coastguard Workerexcept: 12*7c568831SAndroid Build Coastguard Worker import io 13*7c568831SAndroid Build Coastguard Worker str_io = io.StringIO 14*7c568831SAndroid Build Coastguard Worker 15*7c568831SAndroid Build Coastguard Worker# Memory debug specific 16*7c568831SAndroid Build Coastguard Workerlibxml2.debugMemory(1) 17*7c568831SAndroid Build Coastguard Worker 18*7c568831SAndroid Build Coastguard Workerdef tst_reader(s): 19*7c568831SAndroid Build Coastguard Worker f = str_io(s) 20*7c568831SAndroid Build Coastguard Worker input = libxml2.inputBuffer(f) 21*7c568831SAndroid Build Coastguard Worker reader = input.newTextReader("tst") 22*7c568831SAndroid Build Coastguard Worker res = "" 23*7c568831SAndroid Build Coastguard Worker while reader.Read(): 24*7c568831SAndroid Build Coastguard Worker res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(), 25*7c568831SAndroid Build Coastguard Worker reader.Value(), reader.IsEmptyElement()) 26*7c568831SAndroid Build Coastguard Worker if reader.NodeType() == 1: # Element 27*7c568831SAndroid Build Coastguard Worker while reader.MoveToNextAttribute(): 28*7c568831SAndroid Build Coastguard Worker res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(), 29*7c568831SAndroid Build Coastguard Worker reader.Name(),reader.Value()) 30*7c568831SAndroid Build Coastguard Worker return res 31*7c568831SAndroid Build Coastguard Worker 32*7c568831SAndroid Build Coastguard Workerexpect="""1 (test) [None] 0 33*7c568831SAndroid Build Coastguard Worker1 (b) [None] 1 34*7c568831SAndroid Build Coastguard Worker1 (c) [None] 1 35*7c568831SAndroid Build Coastguard Worker15 (test) [None] 0 36*7c568831SAndroid Build Coastguard Worker""" 37*7c568831SAndroid Build Coastguard Worker 38*7c568831SAndroid Build Coastguard Workerres = tst_reader("""<test><b/><c/></test>""") 39*7c568831SAndroid Build Coastguard Worker 40*7c568831SAndroid Build Coastguard Workerif res != expect: 41*7c568831SAndroid Build Coastguard Worker print("Did not get the expected error message:") 42*7c568831SAndroid Build Coastguard Worker print(res) 43*7c568831SAndroid Build Coastguard Worker sys.exit(1) 44*7c568831SAndroid Build Coastguard Worker 45*7c568831SAndroid Build Coastguard Worker# Memory debug specific 46*7c568831SAndroid Build Coastguard Workerlibxml2.cleanupParser() 47*7c568831SAndroid Build Coastguard Workerif libxml2.debugMemory(1) == 0: 48*7c568831SAndroid Build Coastguard Worker print("OK") 49*7c568831SAndroid Build Coastguard Workerelse: 50*7c568831SAndroid Build Coastguard Worker print("Memory leak %d bytes" % (libxml2.debugMemory(1))) 51