Blame python/tests/compareNodes.py
|
Packit |
423ecb |
#!/usr/bin/python -u
|
|
Packit |
423ecb |
import sys
|
|
Packit |
423ecb |
import libxml2
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Memory debug specific
|
|
Packit |
423ecb |
libxml2.debugMemory(1)
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
#
|
|
Packit |
423ecb |
# Testing XML Node comparison and Node hash-value
|
|
Packit |
423ecb |
#
|
|
Packit |
423ecb |
doc = libxml2.parseDoc("""<root><foo/></root>""")
|
|
Packit |
423ecb |
root = doc.getRootElement()
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Create two different objects which point to foo
|
|
Packit |
423ecb |
foonode1 = root.children
|
|
Packit |
423ecb |
foonode2 = root.children
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Now check that [in]equality tests work ok
|
|
Packit |
423ecb |
if not ( foonode1 == foonode2 ):
|
|
Packit |
423ecb |
print("Error comparing nodes with ==, nodes should be equal but are unequal")
|
|
Packit |
423ecb |
sys.exit(1)
|
|
Packit |
423ecb |
if not ( foonode1 != root ):
|
|
Packit |
423ecb |
print("Error comparing nodes with ==, nodes should not be equal but are equal")
|
|
Packit |
423ecb |
sys.exit(1)
|
|
Packit |
423ecb |
if not ( foonode1 != root ):
|
|
Packit |
423ecb |
print("Error comparing nodes with !=, nodes should not be equal but are equal")
|
|
Packit |
423ecb |
if ( foonode1 != foonode2 ):
|
|
Packit |
423ecb |
print("Error comparing nodes with !=, nodes should be equal but are unequal")
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Next check that the hash function for the objects also works ok
|
|
Packit |
423ecb |
if not (hash(foonode1) == hash(foonode2)):
|
|
Packit |
423ecb |
print("Error hash values for two equal nodes are different")
|
|
Packit |
423ecb |
sys.exit(1)
|
|
Packit |
423ecb |
if not (hash(foonode1) != hash(root)):
|
|
Packit |
423ecb |
print("Error hash values for two unequal nodes are not different")
|
|
Packit |
423ecb |
sys.exit(1)
|
|
Packit |
423ecb |
if hash(foonode1) == hash(root):
|
|
Packit |
423ecb |
print("Error hash values for two unequal nodes are equal")
|
|
Packit |
423ecb |
sys.exit(1)
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Basic tests successful
|
|
Packit |
423ecb |
doc.freeDoc()
|
|
Packit |
423ecb |
|
|
Packit |
423ecb |
# Memory debug specific
|
|
Packit |
423ecb |
libxml2.cleanupParser()
|
|
Packit |
423ecb |
if libxml2.debugMemory(1) == 0:
|
|
Packit |
423ecb |
print("OK")
|
|
Packit |
423ecb |
else:
|
|
Packit |
423ecb |
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
|
Packit |
423ecb |
libxml2.dumpMemory()
|