VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/xpathret.py@ 107065

Last change on this file since 107065 was 105420, checked in by vboxsync, 8 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.3 KB
Line 
1#!/usr/bin/env python3
2import sys
3import setup_test
4import libxml2
5
6#memory debug specific
7libxml2.debugMemory(1)
8
9#
10# A document hosting the nodes returned from the extension function
11#
12mydoc = libxml2.newDoc("1.0")
13
14def foo(ctx, str):
15 global mydoc
16
17 #
18 # test returning a node set works as expected
19 #
20 parent = mydoc.newDocNode(None, 'p', None)
21 mydoc.addChild(parent)
22 node = mydoc.newDocText(str)
23 parent.addChild(node)
24 return [parent]
25
26doc = libxml2.parseFile("tst.xml")
27ctxt = doc.xpathNewContext()
28libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
29res = ctxt.xpathEval("foo('hello')")
30if type(res) != type([]):
31 print("Failed to return a nodeset")
32 sys.exit(1)
33if len(res) != 1:
34 print("Unexpected nodeset size")
35 sys.exit(1)
36node = res[0]
37if node.name != 'p':
38 print("Unexpected nodeset element result")
39 sys.exit(1)
40node = node.children
41if node.type != 'text':
42 print("Unexpected nodeset element children type")
43 sys.exit(1)
44if node.content != 'hello':
45 print("Unexpected nodeset element children content")
46 sys.exit(1)
47
48doc.freeDoc()
49mydoc.freeDoc()
50ctxt.xpathFreeContext()
51
52#memory debug specific
53libxml2.cleanupParser()
54if libxml2.debugMemory(1) == 0:
55 print("OK")
56else:
57 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
Note: See TracBrowser for help on using the repository browser.

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