Annotation of embedaddon/libxml2/python/tests/readernext.py, revision 1.1

1.1     ! misho       1: #!/usr/bin/python -u
        !             2: # -*- coding: ISO-8859-1 -*-
        !             3: #
        !             4: # this tests the next API of the XmlTextReader interface
        !             5: #
        !             6: import libxml2
        !             7: import StringIO
        !             8: import sys
        !             9: 
        !            10: # Memory debug specific
        !            11: libxml2.debugMemory(1)
        !            12: 
        !            13: f = StringIO.StringIO("""<a><b><c /></b><d>content of d</d></a>""")
        !            14: input = libxml2.inputBuffer(f)
        !            15: reader = input.newTextReader("test_next")
        !            16: ret = reader.Read()
        !            17: if ret != 1:
        !            18:     print "test_next: Error reading to first element"
        !            19:     sys.exit(1)
        !            20: if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \
        !            21:    reader.NodeType() != 1 or reader.HasAttributes() != 0:
        !            22:     print "test_next: Error reading the first element"
        !            23:     sys.exit(1)
        !            24: ret = reader.Read()
        !            25: if ret != 1:
        !            26:     print "test_next: Error reading to second element"
        !            27:     sys.exit(1)
        !            28: if reader.Name() != "b" or reader.IsEmptyElement() != 0 or \
        !            29:    reader.NodeType() != 1 or reader.HasAttributes() != 0:
        !            30:     print "test_next: Error reading the second element"
        !            31:     sys.exit(1)
        !            32: ret = reader.Read()
        !            33: if ret != 1:
        !            34:     print "test_next: Error reading to third element"
        !            35:     sys.exit(1)
        !            36: if reader.Name() != "c" or reader.NodeType() != 1 or \
        !            37:    reader.HasAttributes() != 0:
        !            38:     print "test_next: Error reading the third element"
        !            39:     sys.exit(1)
        !            40: ret = reader.Read()
        !            41: if ret != 1:
        !            42:     print "test_next: Error reading to end of third element"
        !            43:     sys.exit(1)
        !            44: if reader.Name() != "b" or reader.NodeType() != 15:
        !            45:     print "test_next: Error reading to end of second element"
        !            46:     sys.exit(1)
        !            47: ret = reader.Next()
        !            48: if ret != 1:
        !            49:     print "test_next: Error moving to third element"
        !            50:     sys.exit(1)
        !            51: if reader.Name() != "d" or reader.IsEmptyElement() != 0 or \
        !            52:    reader.NodeType() != 1 or reader.HasAttributes() != 0:
        !            53:     print "test_next: Error reading third element"
        !            54:     sys.exit(1)
        !            55: ret = reader.Next()
        !            56: if ret != 1:
        !            57:     print "test_next: Error reading to end of first element"
        !            58:     sys.exit(1)
        !            59: if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \
        !            60:    reader.NodeType() != 15 or reader.HasAttributes() != 0:
        !            61:     print "test_next: Error reading the end of first element"
        !            62:     sys.exit(1)
        !            63: ret = reader.Read()
        !            64: if ret != 0:
        !            65:     print "test_next: Error reading to end of document"
        !            66:     sys.exit(1)
        !            67: 
        !            68: #
        !            69: # cleanup for memory allocation counting
        !            70: #
        !            71: del f
        !            72: del input
        !            73: del reader
        !            74: 
        !            75: # Memory debug specific
        !            76: libxml2.cleanupParser()
        !            77: if libxml2.debugMemory(1) == 0:
        !            78:     print "OK"
        !            79: else:
        !            80:     print "Memory leak %d bytes" % (libxml2.debugMemory(1))
        !            81:     libxml2.dumpMemory()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>