Annotation of embedaddon/libxml2/python/tests/compareNodes.py, revision 1.1.1.1

1.1       misho       1: #!/usr/bin/python -u
                      2: import sys
                      3: import libxml2
                      4: 
                      5: # Memory debug specific
                      6: libxml2.debugMemory(1)
                      7: 
                      8: #
                      9: # Testing XML Node comparison and Node hash-value
                     10: #
                     11: doc = libxml2.parseDoc("""<root><foo/></root>""")
                     12: root = doc.getRootElement()
                     13: 
                     14: # Create two different objects which point to foo
                     15: foonode1 = root.children
                     16: foonode2 = root.children
                     17: 
                     18: # Now check that [in]equality tests work ok
                     19: if not ( foonode1 == foonode2 ):
                     20:     print "Error comparing nodes with ==, nodes should be equal but are unequal"
                     21:     sys.exit(1)
                     22: if not ( foonode1 != root ):
                     23:     print "Error comparing nodes with ==, nodes should not be equal but are equal"
                     24:     sys.exit(1)
                     25: if not ( foonode1 != root ):
                     26:     print "Error comparing nodes with !=, nodes should not be equal but are equal"
                     27: if ( foonode1 != foonode2 ):
                     28:     print "Error comparing nodes with !=, nodes should be equal but are unequal"
                     29: 
                     30: # Next check that the hash function for the objects also works ok
                     31: if not (hash(foonode1) == hash(foonode2)):
                     32:     print "Error hash values for two equal nodes are different"
                     33:     sys.exit(1)
                     34: if not (hash(foonode1) != hash(root)):
                     35:     print "Error hash values for two unequal nodes are not different"
                     36:     sys.exit(1)
                     37: if hash(foonode1) == hash(root):
                     38:     print "Error hash values for two unequal nodes are equal"
                     39:     sys.exit(1)
                     40: 
                     41: # Basic tests successful
                     42: doc.freeDoc()
                     43: 
                     44: # Memory debug specific
                     45: libxml2.cleanupParser()
                     46: if libxml2.debugMemory(1) == 0:
                     47:     print "OK"
                     48: else:
                     49:     print "Memory leak %d bytes" % (libxml2.debugMemory(1))
                     50:     libxml2.dumpMemory()

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