aboutsummaryrefslogtreecommitdiff
path: root/libxml2-2.9.10/python/tests/validate.py
blob: 16c0386f99bc2ac3f55e06a0e4d32cd63817ed0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python -u
import sys
import libxml2

# Memory debug specific
libxml2.debugMemory(1)

ctxt = libxml2.createFileParserCtxt("valid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()

if doc.name != "valid.xml":
    print("doc.name failed")
    sys.exit(1)
root = doc.children
if root.name != "doc":
    print("root.name failed")
    sys.exit(1)
if valid != 1:
    print("validity chec failed")
    sys.exit(1)
doc.freeDoc()

i = 1000
while i > 0:
    ctxt = libxml2.createFileParserCtxt("valid.xml")
    ctxt.validate(1)
    ctxt.parseDocument()
    doc = ctxt.doc()
    valid = ctxt.isValid()
    doc.freeDoc()
    if valid != 1:
        print("validity check failed")
        sys.exit(1)
    i = i - 1

#desactivate error messages from the validation
def noerr(ctx, str):
    pass

libxml2.registerErrorHandler(noerr, None)

ctxt = libxml2.createFileParserCtxt("invalid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()
if doc.name != "invalid.xml":
    print("doc.name failed")
    sys.exit(1)
root = doc.children
if root.name != "doc":
    print("root.name failed")
    sys.exit(1)
if valid != 0:
    print("validity chec failed")
    sys.exit(1)
doc.freeDoc()

i = 1000
while i > 0:
    ctxt = libxml2.createFileParserCtxt("invalid.xml")
    ctxt.validate(1)
    ctxt.parseDocument()
    doc = ctxt.doc()
    valid = ctxt.isValid()
    doc.freeDoc()
    if valid != 0:
        print("validity check failed")
        sys.exit(1)
    i = i - 1
del ctxt

# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
    print("OK")
else:
    print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
    libxml2.dumpMemory()