VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/validate.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.7 KB
 
1#!/usr/bin/env python3
2import sys
3import setup_test
4import libxml2
5
6# Memory debug specific
7libxml2.debugMemory(1)
8
9ctxt = libxml2.createFileParserCtxt("valid.xml")
10ctxt.validate(1)
11ctxt.parseDocument()
12doc = ctxt.doc()
13valid = ctxt.isValid()
14
15if doc.name != "valid.xml":
16 print("doc.name failed")
17 sys.exit(1)
18root = doc.children
19if root.name != "doc":
20 print("root.name failed")
21 sys.exit(1)
22if valid != 1:
23 print("validity chec failed")
24 sys.exit(1)
25doc.freeDoc()
26
27i = 1000
28while i > 0:
29 ctxt = libxml2.createFileParserCtxt("valid.xml")
30 ctxt.validate(1)
31 ctxt.parseDocument()
32 doc = ctxt.doc()
33 valid = ctxt.isValid()
34 doc.freeDoc()
35 if valid != 1:
36 print("validity check failed")
37 sys.exit(1)
38 i = i - 1
39
40#deactivate error messages from the validation
41def noerr(ctx, str):
42 pass
43
44libxml2.registerErrorHandler(noerr, None)
45
46ctxt = libxml2.createFileParserCtxt("invalid.xml")
47ctxt.validate(1)
48ctxt.parseDocument()
49doc = ctxt.doc()
50valid = ctxt.isValid()
51if doc.name != "invalid.xml":
52 print("doc.name failed")
53 sys.exit(1)
54root = doc.children
55if root.name != "doc":
56 print("root.name failed")
57 sys.exit(1)
58if valid != 0:
59 print("validity chec failed")
60 sys.exit(1)
61doc.freeDoc()
62
63i = 1000
64while i > 0:
65 ctxt = libxml2.createFileParserCtxt("invalid.xml")
66 ctxt.validate(1)
67 ctxt.parseDocument()
68 doc = ctxt.doc()
69 valid = ctxt.isValid()
70 doc.freeDoc()
71 if valid != 0:
72 print("validity check failed")
73 sys.exit(1)
74 i = i - 1
75del ctxt
76
77# Memory debug specific
78libxml2.cleanupParser()
79if libxml2.debugMemory(1) == 0:
80 print("OK")
81else:
82 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