diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2015-10-19 15:37:26 +0300 |
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2015-10-19 15:37:26 +0300 |
| commit | 6c6e567eb34ad0f5a3bd90f6585c521543106401 (patch) | |
| tree | 7f8dc62f12dd2b720ffdc738d393cd1a8f82921c /python/tests/pushSAXhtml.py | |
| parent | 7421ae696c1ef2fb48adc73ba8564ef2f276d618 (diff) | |
| parent | 218d404f34d79a8837f9c0230dd9d9f1180b4068 (diff) | |
| download | libxml2-pristine-tar.tar.gz | |
Merge branch 'pristine-tar' of git://anonscm.debian.org/debian-xml-sgml/libxml2 into pristine-tarpristine-tar
Diffstat (limited to 'python/tests/pushSAXhtml.py')
| -rwxr-xr-x | python/tests/pushSAXhtml.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/python/tests/pushSAXhtml.py b/python/tests/pushSAXhtml.py new file mode 100755 index 0000000..159d308 --- /dev/null +++ b/python/tests/pushSAXhtml.py @@ -0,0 +1,65 @@ +#!/usr/bin/python -u +import sys +import libxml2 + +# Memory debug specific +libxml2.debugMemory(1) + +log = "" + +class callback: + def startDocument(self): + global log + log = log + "startDocument:" + + def endDocument(self): + global log + log = log + "endDocument:" + + def startElement(self, tag, attrs): + global log + log = log + "startElement %s %s:" % (tag, attrs) + + def endElement(self, tag): + global log + log = log + "endElement %s:" % (tag) + + def characters(self, data): + global log + log = log + "characters: %s:" % (data) + + def warning(self, msg): + global log + log = log + "warning: %s:" % (msg) + + def error(self, msg): + global log + log = log + "error: %s:" % (msg) + + def fatalError(self, msg): + global log + log = log + "fatalError: %s:" % (msg) + +handler = callback() + +ctxt = libxml2.htmlCreatePushParser(handler, "<foo", 4, "test.xml") +chunk = " url='tst'>b" +ctxt.htmlParseChunk(chunk, len(chunk), 0) +chunk = "ar</foo>" +ctxt.htmlParseChunk(chunk, len(chunk), 1) +ctxt=None + +reference = """startDocument:startElement html None:startElement body None:startElement foo {'url': 'tst'}:error: Tag foo invalid +:characters: bar:endElement foo:endElement body:endElement html:endDocument:""" +if log != reference: + print("Error got: %s" % log) + print("Exprected: %s" % reference) + sys.exit(1) + +# Memory debug specific +libxml2.cleanupParser() +if libxml2.debugMemory(1) == 0: + print("OK") +else: + print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + libxml2.dumpMemory() |
