Daniel Veillard | 336fc7d | 2002-12-27 19:37:04 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # this tests the validation with the XmlTextReader interface |
| 4 | # |
| 5 | import sys |
| 6 | import glob |
| 7 | import string |
| 8 | import libxml2 |
| 9 | |
| 10 | # Memory debug specific |
| 11 | libxml2.debugMemory(1) |
| 12 | |
| 13 | err="" |
| 14 | expect="""../../test/valid/xlink.xml:450: validity error: ID dt-arc already defined |
| 15 | <p><termdef id="dt-arc" term="Arc"> |
| 16 | ^ |
| 17 | ../../test/valid/xlink.xml:529: validity error: attribute def line 199 references an unknown ID "dt-xlg" |
| 18 | <?Pub *0000052575?> |
| 19 | ^ |
| 20 | ../../test/valid/rss.xml:172: validity error: Element rss does not carry attribute version |
| 21 | </rss> |
| 22 | ^ |
| 23 | """ |
| 24 | def callback(ctx, str): |
| 25 | global err |
| 26 | err = err + "%s" % (str) |
| 27 | libxml2.registerErrorHandler(callback, "") |
| 28 | |
| 29 | valid_files = files = glob.glob("../../test/valid/*.x*") |
| 30 | for file in valid_files: |
| 31 | if string.find(file, "t8") != -1: |
| 32 | continue |
| 33 | reader = libxml2.newTextReaderFilename(file) |
| 34 | #print "%s:" % (file) |
Daniel Veillard | aba976d | 2002-12-28 21:14:18 +0000 | [diff] [blame^] | 35 | reader.SetParserProp(libxml2.PARSER_VALIDATE, 1) |
| 36 | ret = reader.Read() |
Daniel Veillard | 336fc7d | 2002-12-27 19:37:04 +0000 | [diff] [blame] | 37 | while ret == 1: |
Daniel Veillard | aba976d | 2002-12-28 21:14:18 +0000 | [diff] [blame^] | 38 | ret = reader.Read() |
Daniel Veillard | 336fc7d | 2002-12-27 19:37:04 +0000 | [diff] [blame] | 39 | if ret != 0: |
| 40 | print "Error parsing and validating %s" % (file) |
| 41 | #sys.exit(1) |
| 42 | |
| 43 | if err != expect: |
| 44 | print err |
| 45 | |
| 46 | del reader |
| 47 | |
| 48 | # Memory debug specific |
| 49 | libxml2.cleanupParser() |
| 50 | if libxml2.debugMemory(1) == 0: |
| 51 | print "OK" |
| 52 | else: |
| 53 | print "Memory leak %d bytes" % (libxml2.debugMemory(1)) |
| 54 | libxml2.dumpMemory() |