blob: 0dc86f4cb1c12c6c49eb08c18d40eac04bb82ead [file] [log] [blame]
Daniel Veillard26f1dcc2002-02-03 16:53:19 +00001#!/usr/bin/python -u
2import sys
3import libxml2
4
Daniel Veillard4e1b26c2002-02-03 20:13:06 +00005# Memory debug specific
6libxml2.debugMemory(1)
7
Daniel Veillard26f1dcc2002-02-03 16:53:19 +00008ctxt = 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:
Daniel Veillard09b792b2004-02-23 10:53:52 +000035 print "validity check failed"
36 sys.exit(1)
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000037 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:
Daniel Veillard09b792b2004-02-23 10:53:52 +000071 print "validity check failed"
72 sys.exit(1)
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000073 i = i - 1
Daniel Veillard4e1b26c2002-02-03 20:13:06 +000074del ctxt
Daniel Veillard26f1dcc2002-02-03 16:53:19 +000075
Daniel Veillard4e1b26c2002-02-03 20:13:06 +000076# 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()