From 35a201cc8ef0c3f5b2df88d2e528aabee1048348 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 30 Apr 2021 18:47:09 +0200 Subject: Initial/Final commit --- libxml2-2.9.10/python/tests/indexes.py | 113 +++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 libxml2-2.9.10/python/tests/indexes.py (limited to 'libxml2-2.9.10/python/tests/indexes.py') diff --git a/libxml2-2.9.10/python/tests/indexes.py b/libxml2-2.9.10/python/tests/indexes.py new file mode 100755 index 0000000..e41a0d9 --- /dev/null +++ b/libxml2-2.9.10/python/tests/indexes.py @@ -0,0 +1,113 @@ +#!/usr/bin/python -u +# -*- coding: ISO-8859-1 -*- +import sys +import libxml2 + +# Memory debug specific +libxml2.debugMemory(1) + +ctxt = None + +class callback: + def __init__(self, startd, starte, ende, delta, endd): + self.startd = startd + self.starte = starte + self.ende = ende + self.endd = endd + self.delta = delta + self.count = 0 + + def startDocument(self): + global ctxt + if ctxt.byteConsumed() != self.startd: + print("document start at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), self.startd)) + sys.exit(1) + + def endDocument(self): + global ctxt + expect = self.ende + self.delta * (self.count - 1) + self.endd + if ctxt.byteConsumed() != expect: + print("document end at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect)) + sys.exit(1) + + def startElement(self, tag, attrs): + global ctxt + if tag == "bar1": + expect = self.starte + self.delta * self.count + if ctxt.byteConsumed() != expect: + print("element start at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect)) + sys.exit(1) + + + def endElement(self, tag): + global ctxt + if tag == "bar1": + expect = self.ende + self.delta * self.count + if ctxt.byteConsumed() != expect: + print("element end at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect)) + sys.exit(1) + self.count = self.count + 1 + + def characters(self, data): + pass + +# +# First run a pure UTF-8 test +# +handler = callback(0, 13, 27, 198, 183) +ctxt = libxml2.createPushParser(handler, "\n", 6, "test.xml") +chunk = """ chars1 + chars2 + chars3 + chars4 + chars5 + <s6 + chars7 + &8 + chars9 +""" +i = 0 +while i < 10000: + ctxt.parseChunk(chunk, len(chunk), 0) + i = i + 1 +chunk = "" +ctxt.parseChunk(chunk, len(chunk), 1) +ctxt=None + +# +# Then run a test relying on ISO-Latin-1 +# +handler = callback(43, 57, 71, 198, 183) +chunk=""" + +""" +ctxt = libxml2.createPushParser(handler, chunk, len(chunk), "test.xml") +chunk = """ chars1 + chars2 + chars3 + chàrs4 + chars5 + <s6 + chars7 + &8 + très 9 +""" +i = 0 +while i < 10000: + ctxt.parseChunk(chunk, len(chunk), 0) + i = i + 1 +chunk = "" +ctxt.parseChunk(chunk, len(chunk), 1) +ctxt=None + +# Memory debug specific +libxml2.cleanupParser() +if libxml2.debugMemory(1) == 0: + print("OK") +else: + print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + libxml2.dumpMemory() -- cgit v1.2.3