summaryrefslogtreecommitdiff
path: root/python/tests
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2003-04-17 12:55:35 +0000
committerDaniel Veillard <veillard@src.gnome.org>2003-04-17 12:55:35 +0000
commitac297930c24964cfa1bde996d837081a74f57eea (patch)
treeebeda86ba98bffc56c5a052bc605875729e15035 /python/tests
parent621636042b200e70c410f3112e89bc0f8b6203c0 (diff)
downloadlibxml2-ac297930c24964cfa1bde996d837081a74f57eea.tar.gz
some cleanups extended the document to cover RelaxNG and tree operations
* relaxng.c: some cleanups * doc/xmlreader.html: extended the document to cover RelaxNG and tree operations * python/tests/Makefile.am python/tests/reader[46].py: added some xmlReader example/regression tests * result/relaxng/tutor*.err: updated the output of a number of tests Daniel
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/Makefile.am3
-rwxr-xr-xpython/tests/reader4.py45
-rwxr-xr-xpython/tests/reader6.py118
3 files changed, 166 insertions, 0 deletions
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index 761046a5..0c16acf0 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -23,6 +23,9 @@ PYTESTS= \
reader.py \
reader2.py \
reader3.py \
+ reader4.py \
+ reader5.py \
+ reader6.py \
ctxterror.py\
readererr.py\
relaxng.py
diff --git a/python/tests/reader4.py b/python/tests/reader4.py
new file mode 100755
index 00000000..0269cb0c
--- /dev/null
+++ b/python/tests/reader4.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python -u
+#
+# this tests the basic APIs of the XmlTextReader interface
+#
+import libxml2
+import StringIO
+import sys
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+def tst_reader(s):
+ f = StringIO.StringIO(s)
+ input = libxml2.inputBuffer(f)
+ reader = input.newTextReader("tst")
+ res = ""
+ while reader.Read():
+ res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
+ reader.Value(), reader.IsEmptyElement())
+ if reader.NodeType() == 1: # Element
+ while reader.MoveToNextAttribute():
+ res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
+ reader.Name(),reader.Value())
+ return res
+
+expect="""1 (test) [None] 0
+1 (b) [None] 1
+1 (c) [None] 1
+15 (test) [None] 0
+"""
+
+res = tst_reader("""<test><b/><c/></test>""")
+
+if res != expect:
+ print "Did not get the expected error message:"
+ print res
+ 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()
diff --git a/python/tests/reader6.py b/python/tests/reader6.py
new file mode 100755
index 00000000..fe22079f
--- /dev/null
+++ b/python/tests/reader6.py
@@ -0,0 +1,118 @@
+#!/usr/bin/python -u
+#
+# this tests the entities substitutions with the XmlTextReader interface
+#
+import sys
+import StringIO
+import libxml2
+
+schema="""<element name="foo" xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <oneOrMore>
+ <element name="label">
+ <text/>
+ </element>
+ <optional>
+ <element name="opt">
+ <empty/>
+ </element>
+ </optional>
+ <element name="item">
+ <data type="byte"/>
+ </element>
+ </oneOrMore>
+</element>
+"""
+# Memory debug specific
+libxml2.debugMemory(1)
+
+#
+# Parse the Relax NG Schemas
+#
+rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
+rngs = rngp.relaxNGParse()
+del rngp
+
+#
+# Parse and validate the correct document
+#
+docstr="""<foo>
+<label>some text</label>
+<item>100</item>
+</foo>"""
+
+f = StringIO.StringIO(docstr)
+input = libxml2.inputBuffer(f)
+reader = input.newTextReader("correct")
+reader.RelaxNGSetSchema(rngs)
+ret = reader.Read()
+while ret == 1:
+ ret = reader.Read()
+
+if ret != 0:
+ print "Error parsing the document"
+ sys.exit(1)
+
+if reader.IsValid() != 1:
+ print "Document failed to validate"
+ sys.exit(1)
+
+#
+# Parse and validate the incorrect document
+#
+docstr="""<foo>
+<label>some text</label>
+<item>1000</item>
+</foo>"""
+
+err=""
+expect="""RNG validity error: file error line 3 element text
+Type byte doesn't allow value '1000'
+RNG validity error: file error line 3 element text
+Error validating datatype byte
+RNG validity error: file error line 3 element text
+Element item failed to validate content
+"""
+
+def callback(ctx, str):
+ global err
+ err = err + "%s" % (str)
+libxml2.registerErrorHandler(callback, "")
+
+f = StringIO.StringIO(docstr)
+input = libxml2.inputBuffer(f)
+reader = input.newTextReader("error")
+reader.RelaxNGSetSchema(rngs)
+ret = reader.Read()
+while ret == 1:
+ ret = reader.Read()
+
+if ret != 0:
+ print "Error parsing the document"
+ sys.exit(1)
+
+if reader.IsValid() != 0:
+ print "Document failed to detect the validation error"
+ sys.exit(1)
+
+if err != expect:
+ print "Did not get the expected error message:"
+ print err
+ sys.exit(1)
+
+#
+# cleanup
+#
+del f
+del input
+del reader
+del rngs
+libxml2.relaxNGCleanupTypes()
+
+# Memory debug specific
+libxml2.cleanupParser()
+if libxml2.debugMemory(1) == 0:
+ print "OK"
+else:
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+ libxml2.dumpMemory()