summaryrefslogtreecommitdiff
path: root/python/tests
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-02-11 13:25:26 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-02-11 13:25:26 +0000
commit3671190b546760a9e10d2e683257c3a86c680816 (patch)
treece15fac5cbe6b2db5c36f2d6035e65fb66a98d97 /python/tests
parent6f108a1d0b388bbe26b2b169bce1434c15efca49 (diff)
downloadlibxml2-3671190b546760a9e10d2e683257c3a86c680816.tar.gz
added xmlByteConsumed() interface updated the benchmark rebuilt the docs
* parserInternals.c xmlIO.c encoding.c include/libxml/parser.h include/libxml/xmlIO.h: added xmlByteConsumed() interface * doc/*: updated the benchmark rebuilt the docs * python/tests/Makefile.am python/tests/indexes.py: added a specific regression test for xmlByteConsumed() * include/libxml/encoding.h rngparser.c tree.c: small cleanups Daniel
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/Makefile.am3
-rwxr-xr-xpython/tests/indexes.py112
2 files changed, 114 insertions, 1 deletions
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index c496dc88..a07497e1 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -32,7 +32,8 @@ PYTESTS= \
readererr.py\
relaxng.py \
thread2.py \
- tstLastError.py
+ tstLastError.py \
+ indexes.py
XMLS= \
tst.xml \
diff --git a/python/tests/indexes.py b/python/tests/indexes.py
new file mode 100755
index 00000000..18c85c7f
--- /dev/null
+++ b/python/tests/indexes.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python -u
+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, "<foo>\n", 6, "test.xml")
+chunk = """ <bar1>chars1</bar1>
+ <bar2>chars2</bar2>
+ <bar3>chars3</bar3>
+ <bar4>chars4</bar4>
+ <bar5>chars5</bar5>
+ <bar6>&lt;s6</bar6>
+ <bar7>chars7</bar7>
+ <bar8>&#38;8</bar8>
+ <bar9>chars9</bar9>
+"""
+i = 0
+while i < 10000:
+ ctxt.parseChunk(chunk, len(chunk), 0)
+ i = i + 1
+chunk = "</foo>"
+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="""<?xml version="1.0" encoding="ISO-8859-1"?>
+<foo>
+"""
+ctxt = libxml2.createPushParser(handler, chunk, len(chunk), "test.xml")
+chunk = """ <bar1>chars1</bar1>
+ <bar2>chars2</bar2>
+ <bar3>chars3</bar3>
+ <bar4>chàrs4</bar4>
+ <bar5>chars5</bar5>
+ <bar6>&lt;s6</bar6>
+ <bar7>chars7</bar7>
+ <bar8>&#38;8</bar8>
+ <bar9>très 9</bar9>
+"""
+i = 0
+while i < 10000:
+ ctxt.parseChunk(chunk, len(chunk), 0)
+ i = i + 1
+chunk = "</foo>"
+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()