1 | #!/usr/bin/env python3
|
---|
2 | import sys
|
---|
3 | import setup_test
|
---|
4 | import libxml2
|
---|
5 |
|
---|
6 | # Memory debug specific
|
---|
7 | libxml2.debugMemory(1)
|
---|
8 |
|
---|
9 | log = ""
|
---|
10 |
|
---|
11 | class callback:
|
---|
12 | def startDocument(self):
|
---|
13 | global log
|
---|
14 | log = log + "startDocument:"
|
---|
15 |
|
---|
16 | def endDocument(self):
|
---|
17 | global log
|
---|
18 | log = log + "endDocument:"
|
---|
19 |
|
---|
20 | def startElement(self, tag, attrs):
|
---|
21 | global log
|
---|
22 | log = log + "startElement %s %s:" % (tag, attrs)
|
---|
23 |
|
---|
24 | def endElement(self, tag):
|
---|
25 | global log
|
---|
26 | log = log + "endElement %s:" % (tag)
|
---|
27 |
|
---|
28 | def characters(self, data):
|
---|
29 | global log
|
---|
30 | log = log + "characters: %s:" % (data)
|
---|
31 |
|
---|
32 | def warning(self, msg):
|
---|
33 | global log
|
---|
34 | log = log + "warning: %s:" % (msg)
|
---|
35 |
|
---|
36 | def error(self, msg):
|
---|
37 | global log
|
---|
38 | log = log + "error: %s:" % (msg)
|
---|
39 |
|
---|
40 | def fatalError(self, msg):
|
---|
41 | global log
|
---|
42 | log = log + "fatalError: %s:" % (msg)
|
---|
43 |
|
---|
44 | handler = callback()
|
---|
45 |
|
---|
46 | ctxt = libxml2.createPushParser(handler, "<foo", 4, "test.xml")
|
---|
47 | chunk = " url='tst'>b"
|
---|
48 | ctxt.parseChunk(chunk, len(chunk), 0)
|
---|
49 | chunk = "ar</foo>"
|
---|
50 | ctxt.parseChunk(chunk, len(chunk), 1)
|
---|
51 | ctxt=None
|
---|
52 |
|
---|
53 | reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:"
|
---|
54 | if log != reference:
|
---|
55 | print("Error got: %s" % log)
|
---|
56 | print("Exprected: %s" % reference)
|
---|
57 | sys.exit(1)
|
---|
58 |
|
---|
59 | # Memory debug specific
|
---|
60 | libxml2.cleanupParser()
|
---|
61 | if libxml2.debugMemory(1) == 0:
|
---|
62 | print("OK")
|
---|
63 | else:
|
---|
64 | print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
---|