VirtualBox

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

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

libxml 2.9.2 unmodified

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
檔案大小: 1.7 KB
 
1#!/usr/bin/python -u
2import sys
3import libxml2
4
5# Memory debug specific
6libxml2.debugMemory(1)
7
8ctxt = libxml2.createFileParserCtxt("valid.xml")
9ctxt.validate(1)
10ctxt.parseDocument()
11doc = ctxt.doc()
12valid = ctxt.isValid()
13
14if doc.name != "valid.xml":
15 print("doc.name failed")
16 sys.exit(1)
17root = doc.children
18if root.name != "doc":
19 print("root.name failed")
20 sys.exit(1)
21if valid != 1:
22 print("validity chec failed")
23 sys.exit(1)
24doc.freeDoc()
25
26i = 1000
27while i > 0:
28 ctxt = libxml2.createFileParserCtxt("valid.xml")
29 ctxt.validate(1)
30 ctxt.parseDocument()
31 doc = ctxt.doc()
32 valid = ctxt.isValid()
33 doc.freeDoc()
34 if valid != 1:
35 print("validity check failed")
36 sys.exit(1)
37 i = i - 1
38
39#desactivate error messages from the validation
40def noerr(ctx, str):
41 pass
42
43libxml2.registerErrorHandler(noerr, None)
44
45ctxt = libxml2.createFileParserCtxt("invalid.xml")
46ctxt.validate(1)
47ctxt.parseDocument()
48doc = ctxt.doc()
49valid = ctxt.isValid()
50if doc.name != "invalid.xml":
51 print("doc.name failed")
52 sys.exit(1)
53root = doc.children
54if root.name != "doc":
55 print("root.name failed")
56 sys.exit(1)
57if valid != 0:
58 print("validity chec failed")
59 sys.exit(1)
60doc.freeDoc()
61
62i = 1000
63while i > 0:
64 ctxt = libxml2.createFileParserCtxt("invalid.xml")
65 ctxt.validate(1)
66 ctxt.parseDocument()
67 doc = ctxt.doc()
68 valid = ctxt.isValid()
69 doc.freeDoc()
70 if valid != 0:
71 print("validity check failed")
72 sys.exit(1)
73 i = i - 1
74del ctxt
75
76# Memory debug specific
77libxml2.cleanupParser()
78if libxml2.debugMemory(1) == 0:
79 print("OK")
80else:
81 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
82 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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