VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/xpath.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.2 KB
 
1#!/usr/bin/env python3
2#
3# this test exercise the XPath basic engine, parser, etc, and
4# allows to detect memory leaks
5#
6import sys
7import setup_test
8import libxml2
9
10# Memory debug specific
11libxml2.debugMemory(1)
12
13doc = libxml2.parseFile("tst.xml")
14if doc.name != "tst.xml":
15 print("doc.name error")
16 sys.exit(1);
17
18ctxt = doc.xpathNewContext()
19res = ctxt.xpathEval("//*")
20if len(res) != 2:
21 print("xpath query: wrong node set size")
22 sys.exit(1)
23if res[0].name != "doc" or res[1].name != "foo":
24 print("xpath query: wrong node set value")
25 sys.exit(1)
26ctxt.setContextNode(res[0])
27res = ctxt.xpathEval("foo")
28if len(res) != 1:
29 print("xpath query: wrong node set size")
30 sys.exit(1)
31if res[0].name != "foo":
32 print("xpath query: wrong node set value")
33 sys.exit(1)
34doc.freeDoc()
35ctxt.xpathFreeContext()
36i = 1000
37while i > 0:
38 doc = libxml2.parseFile("tst.xml")
39 ctxt = doc.xpathNewContext()
40 res = ctxt.xpathEval("//*")
41 doc.freeDoc()
42 ctxt.xpathFreeContext()
43 i = i -1
44del ctxt
45
46# Memory debug specific
47libxml2.cleanupParser()
48if libxml2.debugMemory(1) == 0:
49 print("OK")
50else:
51 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