VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/xpathext.py

Last change on this file was 105420, checked in by vboxsync, 7 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette