| 1 |
#!/usr/bin/env python3 |
| 2 |
import setup_test |
| 3 |
import libxml2 |
| 4 |
import sys |
| 5 |
|
| 6 |
# Memory debug specific |
| 7 |
libxml2.debugMemory(1) |
| 8 |
|
| 9 |
schema="""<?xml version="1.0"?> |
| 10 |
<element name="foo" |
| 11 |
xmlns="http://relaxng.org/ns/structure/1.0" |
| 12 |
xmlns:a="http://relaxng.org/ns/annotation/1.0" |
| 13 |
xmlns:ex1="http://www.example.com/n1" |
| 14 |
xmlns:ex2="http://www.example.com/n2"> |
| 15 |
<a:documentation>A foo element.</a:documentation> |
| 16 |
<element name="ex1:bar1"> |
| 17 |
<empty/> |
| 18 |
</element> |
| 19 |
<element name="ex2:bar2"> |
| 20 |
<empty/> |
| 21 |
</element> |
| 22 |
</element> |
| 23 |
""" |
| 24 |
instance="""<?xml version="1.0"?> |
| 25 |
<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>""" |
| 26 |
|
| 27 |
rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema)) |
| 28 |
rngs = rngp.relaxNGParse() |
| 29 |
ctxt = rngs.relaxNGNewValidCtxt() |
| 30 |
doc = libxml2.parseDoc(instance) |
| 31 |
ret = doc.relaxNGValidateDoc(ctxt) |
| 32 |
if ret != 0: |
| 33 |
print("error doing RelaxNG validation") |
| 34 |
sys.exit(1) |
| 35 |
|
| 36 |
doc.freeDoc() |
| 37 |
del rngp |
| 38 |
del rngs |
| 39 |
del ctxt |
| 40 |
libxml2.relaxNGCleanupTypes() |
| 41 |
|
| 42 |
# Memory debug specific |
| 43 |
libxml2.cleanupParser() |
| 44 |
if libxml2.debugMemory(1) == 0: |
| 45 |
print("OK") |
| 46 |
else: |
| 47 |
print("Memory leak %d bytes" % (libxml2.debugMemory(1))) |
| 48 |
|