Annotation of embedaddon/libxml2/python/tests/xpathext.py, revision 1.1.1.2

1.1       misho       1: #!/usr/bin/python -u
                      2: import sys
                      3: import libxml2
                      4: 
                      5: # Memory debug specific
                      6: libxml2.debugMemory(1)
                      7: 
                      8: def foo(ctx, x):
                      9:     return x + 1
                     10: 
                     11: def bar(ctx, x):
                     12:     return "%d" % (x + 2)
                     13: 
                     14: doc = libxml2.parseFile("tst.xml")
                     15: ctxt = doc.xpathNewContext()
                     16: res = ctxt.xpathEval("//*")
                     17: if len(res) != 2:
1.1.1.2 ! misho      18:     print("xpath query: wrong node set size")
1.1       misho      19:     sys.exit(1)
                     20: if res[0].name != "doc" or res[1].name != "foo":
1.1.1.2 ! misho      21:     print("xpath query: wrong node set value")
1.1       misho      22:     sys.exit(1)
                     23: 
                     24: libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
                     25: libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
                     26: i = 10000
                     27: while i > 0:
                     28:     res = ctxt.xpathEval("foo(1)")
                     29:     if res != 2:
1.1.1.2 ! misho      30:         print("xpath extension failure")
1.1       misho      31:         sys.exit(1)
                     32:     i = i - 1
                     33: i = 10000
                     34: while i > 0:
                     35:     res = ctxt.xpathEval("bar(1)")
                     36:     if res != "3":
1.1.1.2 ! misho      37:         print("xpath extension failure got %s expecting '3'")
1.1       misho      38:         sys.exit(1)
                     39:     i = i - 1
                     40: doc.freeDoc()
                     41: ctxt.xpathFreeContext()
                     42: 
                     43: # Memory debug specific
                     44: libxml2.cleanupParser()
                     45: if libxml2.debugMemory(1) == 0:
1.1.1.2 ! misho      46:     print("OK")
1.1       misho      47: else:
1.1.1.2 ! misho      48:     print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
1.1       misho      49:     libxml2.dumpMemory()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>