libxml2 2.9.1 clean sources
[tomato.git] / release / src / router / libxml2 / python / tests / validate.py
blob16c0386f99bc2ac3f55e06a0e4d32cd63817ed0e
1 #!/usr/bin/python -u
2 import sys
3 import libxml2
5 # Memory debug specific
6 libxml2.debugMemory(1)
8 ctxt = libxml2.createFileParserCtxt("valid.xml")
9 ctxt.validate(1)
10 ctxt.parseDocument()
11 doc = ctxt.doc()
12 valid = ctxt.isValid()
14 if doc.name != "valid.xml":
15 print("doc.name failed")
16 sys.exit(1)
17 root = doc.children
18 if root.name != "doc":
19 print("root.name failed")
20 sys.exit(1)
21 if valid != 1:
22 print("validity chec failed")
23 sys.exit(1)
24 doc.freeDoc()
26 i = 1000
27 while 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
39 #desactivate error messages from the validation
40 def noerr(ctx, str):
41 pass
43 libxml2.registerErrorHandler(noerr, None)
45 ctxt = libxml2.createFileParserCtxt("invalid.xml")
46 ctxt.validate(1)
47 ctxt.parseDocument()
48 doc = ctxt.doc()
49 valid = ctxt.isValid()
50 if doc.name != "invalid.xml":
51 print("doc.name failed")
52 sys.exit(1)
53 root = doc.children
54 if root.name != "doc":
55 print("root.name failed")
56 sys.exit(1)
57 if valid != 0:
58 print("validity chec failed")
59 sys.exit(1)
60 doc.freeDoc()
62 i = 1000
63 while 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
74 del ctxt
76 # Memory debug specific
77 libxml2.cleanupParser()
78 if libxml2.debugMemory(1) == 0:
79 print("OK")
80 else:
81 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
82 libxml2.dumpMemory()