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