VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/compareNodes.py@ 105635

最後變更 在這個檔案從105635是 104106,由 vboxsync 提交於 10 月 前

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.5 KB
 
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)))
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette