VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.2/python/tests/xpathext.py@ 64246

最後變更 在這個檔案從64246是 58072,由 vboxsync 提交於 9 年 前

libxml 2.9.2 unmodified

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
檔案大小: 1.1 KB
 
1#!/usr/bin/python -u
2import sys
3import libxml2
4
5# Memory debug specific
6libxml2.debugMemory(1)
7
8def foo(ctx, x):
9 return x + 1
10
11def bar(ctx, x):
12 return "%d" % (x + 2)
13
14doc = libxml2.parseFile("tst.xml")
15ctxt = doc.xpathNewContext()
16res = ctxt.xpathEval("//*")
17if len(res) != 2:
18 print("xpath query: wrong node set size")
19 sys.exit(1)
20if res[0].name != "doc" or res[1].name != "foo":
21 print("xpath query: wrong node set value")
22 sys.exit(1)
23
24libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
25libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
26i = 10000
27while i > 0:
28 res = ctxt.xpathEval("foo(1)")
29 if res != 2:
30 print("xpath extension failure")
31 sys.exit(1)
32 i = i - 1
33i = 10000
34while i > 0:
35 res = ctxt.xpathEval("bar(1)")
36 if res != "3":
37 print("xpath extension failure got %s expecting '3'")
38 sys.exit(1)
39 i = i - 1
40doc.freeDoc()
41ctxt.xpathFreeContext()
42
43# Memory debug specific
44libxml2.cleanupParser()
45if libxml2.debugMemory(1) == 0:
46 print("OK")
47else:
48 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
49 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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