VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.14/python/tests/xpath.py@ 98704

最後變更 在這個檔案從98704是 95312,由 vboxsync 提交於 3 年 前

libs/{curl,libxml2}: OSE export fixes, bugref:8515

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.2 KB
 
1#!/usr/bin/python -u
2#
3# this test exercise the XPath basic engine, parser, etc, and
4# allows to detect memory leaks
5#
6import sys
7import libxml2
8
9# Memory debug specific
10libxml2.debugMemory(1)
11
12doc = libxml2.parseFile("tst.xml")
13if doc.name != "tst.xml":
14 print("doc.name error")
15 sys.exit(1);
16
17ctxt = doc.xpathNewContext()
18res = ctxt.xpathEval("//*")
19if len(res) != 2:
20 print("xpath query: wrong node set size")
21 sys.exit(1)
22if res[0].name != "doc" or res[1].name != "foo":
23 print("xpath query: wrong node set value")
24 sys.exit(1)
25ctxt.setContextNode(res[0])
26res = ctxt.xpathEval("foo")
27if len(res) != 1:
28 print("xpath query: wrong node set size")
29 sys.exit(1)
30if res[0].name != "foo":
31 print("xpath query: wrong node set value")
32 sys.exit(1)
33doc.freeDoc()
34ctxt.xpathFreeContext()
35i = 1000
36while i > 0:
37 doc = libxml2.parseFile("tst.xml")
38 ctxt = doc.xpathNewContext()
39 res = ctxt.xpathEval("//*")
40 doc.freeDoc()
41 ctxt.xpathFreeContext()
42 i = i -1
43del ctxt
44
45# Memory debug specific
46libxml2.cleanupParser()
47if libxml2.debugMemory(1) == 0:
48 print("OK")
49else:
50 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
51 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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