VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/xpathret.py@ 105635

最後變更 在這個檔案從105635是 104106,由 vboxsync 提交於 10 月 前

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.3 KB
 
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)))
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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