aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-02-02 09:17:16 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-02-02 09:17:16 +0000
commit253aa2c33bb4d781b5120dd82b404e0416abd79f (patch)
tree499c5922cf62188bd54aba35991414da455a70f5 /python/tests
parenta7340c830e4bddd86201cfdb97ac81e30b0dee62 (diff)
downloadandroid_external_libxml2-253aa2c33bb4d781b5120dd82b404e0416abd79f.tar.gz
android_external_libxml2-253aa2c33bb4d781b5120dd82b404e0416abd79f.tar.bz2
android_external_libxml2-253aa2c33bb4d781b5120dd82b404e0416abd79f.zip
added more informations in the libxml2-python package including docs.
* configure.in libxml.spec.in python/Makefile.am python/TODO python/generator.py python/libxml2class.txt: added more informations in the libxml2-python package including docs. Slightly changed the class hierarchy * python/tests/*: added basic regression tests infrastructure too Daniel
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/Makefile.am26
-rwxr-xr-xpython/tests/tst.py10
-rw-r--r--python/tests/tst.xml1
-rwxr-xr-xpython/tests/tstxpath.py29
-rwxr-xr-xpython/tests/xpath.py21
-rwxr-xr-xpython/tests/xpathext.py33
6 files changed, 120 insertions, 0 deletions
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
new file mode 100644
index 00000000..366ad066
--- /dev/null
+++ b/python/tests/Makefile.am
@@ -0,0 +1,26 @@
+EXAMPLE_DIR = $(prefix)/share/doc/libxml2-python-$(LIBXML_VERSION)/examples
+
+TESTS= \
+ tst.py \
+ tstxpath.py \
+ xpathext.py \
+ xpath.py
+
+XMLS= \
+ tst.xml
+
+EXTRA_DIST = $(TESTS) $(XMLS)
+
+if WITH_PYTHON
+tests: $(TESTS)
+ -@(CLASSPATH=".." ; export CLASSPATH; \
+ for test in $(TESTS) ; do echo "-- $$test" ; $(PYTHON) $$test ; done)
+else
+tests:
+endif
+
+install-data-local:
+ $(mkinstalldirs) $(DESTDIR)$(EXAMPLE_DIR)
+ -(for test in $(TESTS) $(XMLS); \
+ do @INSTALL@ -m 0644 $$test $(DESTDIR)$(EXAMPLE_DIR) ; done)
+
diff --git a/python/tests/tst.py b/python/tests/tst.py
new file mode 100755
index 00000000..86ac64ba
--- /dev/null
+++ b/python/tests/tst.py
@@ -0,0 +1,10 @@
+#!/usr/bin/python -u
+import libxml2
+
+doc = libxml2.parseFile("tst.xml")
+print doc.name
+root = doc.children
+print root.name
+child = root.children
+print child.name
+doc.freeDoc()
diff --git a/python/tests/tst.xml b/python/tests/tst.xml
new file mode 100644
index 00000000..751d46d8
--- /dev/null
+++ b/python/tests/tst.xml
@@ -0,0 +1 @@
+<doc><foo>bar</foo></doc>
diff --git a/python/tests/tstxpath.py b/python/tests/tstxpath.py
new file mode 100755
index 00000000..f6c675a1
--- /dev/null
+++ b/python/tests/tstxpath.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python -u
+import libxml2
+
+def foo(x):
+ # print "foo called %s" % (x)
+ return x + 1
+
+def bar(x):
+ # print "foo called %s" % (x)
+ return "%s" % (x + 1)
+
+doc = libxml2.parseFile("tst.xml")
+ctxt = doc.xpathNewContext()
+res = ctxt.xpathEval("//*")
+print res
+
+libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
+libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
+i = 10000
+while i > 0:
+ res = ctxt.xpathEval("foo(1)")
+ i = i - 1
+print res
+i = 10000
+while i > 0:
+ res = ctxt.xpathEval("bar(1)")
+ i = i - 1
+print res
+doc.freeDoc()
diff --git a/python/tests/xpath.py b/python/tests/xpath.py
new file mode 100755
index 00000000..fdbd8395
--- /dev/null
+++ b/python/tests/xpath.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python -u
+#
+# this test exercise the XPath basic engine, parser, etc, and
+# allows to detect memory leaks
+#
+import libxml2
+
+doc = libxml2.parseFile("tst.xml")
+print doc
+i = 1000
+while i > 0:
+ doc = libxml2.parseFile("tst.xml")
+ ctxt = doc.xpathNewContext()
+ res = ctxt.xpathEval("//*")
+ doc.freeDoc()
+ i = i -1
+doc = libxml2.parseFile("tst.xml")
+ctxt = doc.xpathNewContext()
+res = ctxt.xpathEval("//*")
+print res
+doc.freeDoc()
diff --git a/python/tests/xpathext.py b/python/tests/xpathext.py
new file mode 100755
index 00000000..d6f0455b
--- /dev/null
+++ b/python/tests/xpathext.py
@@ -0,0 +1,33 @@
+#!/usr/bin/python -u
+#
+# This test exercise the extension of the XPath engine with
+# functions defined in Python.
+#
+import libxml2
+
+def foo(x):
+ # print "foo called %s" % (x)
+ return x + 1
+
+def bar(x):
+ # print "foo called %s" % (x)
+ return "%s" % (x + 1)
+
+doc = libxml2.parseFile("tst.xml")
+ctxt = doc.xpathNewContext()
+res = ctxt.xpathEval("//*")
+print res
+
+libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
+libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
+i = 10000
+while i > 0:
+ res = ctxt.xpathEval("foo(1)")
+ i = i - 1
+print res
+i = 10000
+while i > 0:
+ res = ctxt.xpathEval("bar(1)")
+ i = i - 1
+print res
+doc.freeDoc()