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