3 # test generated python code from pidl
4 # Andrew Tridgell August 2010
8 sys.path.insert(0, "bin/python")
12 from samba.dcerpc import drsuapi
15 talloc.enable_null_tracking()
17 class RpcTests(object):
18 '''test type behaviour of pidl generated python RPC code'''
20 def check_blocks(self, object, num_expected):
21 '''check that the number of allocated blocks is correct'''
22 nblocks = talloc.total_blocks(object)
24 nblocks -= self.initial_blocks
25 leaked_blocks = (nblocks - num_expected)
26 if leaked_blocks != 0:
27 print "Leaked %d blocks" % leaked_blocks
29 def check_type(self, interface, typename, type):
30 print "Checking type %s" % typename
37 except TypeError, errstr:
38 if str(errstr) == "unknown union level":
39 print "ERROR: Unknown union level in %s.%s" % (typename, n)
42 print str(errstr)[1:21]
43 if str(errstr)[0:21] == "Can not convert C Type":
44 print "ERROR: Unknown C type for %s.%s" % (typename, n)
48 print "ERROR: Failed to instantiate %s.%s" % (typename, n)
52 print "ERROR: Failed to instantiate %s.%s" % (typename, n)
56 # now try setting the value back
58 print "Setting %s.%s" % (typename, n)
61 if isinstance(e, AttributeError) and str(e).endswith("is read-only"):
65 print "ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e)
69 # and try a comparison
71 if value != getattr(v, n):
72 print "ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n))
75 print "ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e)
78 def check_interface(self, interface, iname):
79 errcount = self.errcount
80 for n in dir(interface):
81 if n[0] == '_' or n == iname:
82 # skip the special ones
84 value = getattr(interface, n)
85 if isinstance(value, str):
86 #print "%s=\"%s\"" % (n, value)
88 elif isinstance(value, int) or isinstance(value, long):
89 #print "%s=%d" % (n, value)
91 elif isinstance(value, type):
93 initial_blocks = talloc.total_blocks(None)
94 self.check_type(interface, n, value)
95 self.check_blocks(None, initial_blocks)
97 print "ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e)
102 print "UNKNOWN: %s=%s" % (n, value)
103 if self.errcount - errcount != 0:
104 print "Found %d errors in %s" % (self.errcount - errcount, iname)
106 def check_all_interfaces(self):
107 for iname in dir(samba.dcerpc):
110 if iname == 'ClientConnection' or iname == 'base':
112 print "Checking interface %s" % iname
113 iface = getattr(samba.dcerpc, iname)
114 initial_blocks = talloc.total_blocks(None)
115 self.check_interface(iface, iname)
116 self.check_blocks(None, initial_blocks)
119 self.initial_blocks = talloc.total_blocks(None)
121 self.check_all_interfaces()
125 errcount = tests.run()
129 print "%d failures" % errcount