1 # test generated python code from pidl
2 # Copyright (C) Andrew Tridgell August 2010
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 sys.path.insert(0, "bin/python")
23 from samba.dcerpc import drsuapi
26 talloc.enable_null_tracking()
28 class RpcTests(object):
29 '''test type behaviour of pidl generated python RPC code'''
31 def check_blocks(self, object, num_expected):
32 '''check that the number of allocated blocks is correct'''
33 nblocks = talloc.total_blocks(object)
35 nblocks -= self.initial_blocks
36 leaked_blocks = (nblocks - num_expected)
37 if leaked_blocks != 0:
38 print "Leaked %d blocks" % leaked_blocks
40 def check_type(self, interface, typename, type):
41 print "Checking type %s" % typename
48 except TypeError, errstr:
49 if str(errstr) == "unknown union level":
50 print "ERROR: Unknown union level in %s.%s" % (typename, n)
53 print str(errstr)[1:21]
54 if str(errstr)[0:21] == "Can not convert C Type":
55 print "ERROR: Unknown C type for %s.%s" % (typename, n)
59 print "ERROR: Failed to instantiate %s.%s" % (typename, n)
63 print "ERROR: Failed to instantiate %s.%s" % (typename, n)
67 # now try setting the value back
69 print "Setting %s.%s" % (typename, n)
72 if isinstance(e, AttributeError) and str(e).endswith("is read-only"):
76 print "ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e)
80 # and try a comparison
82 if value != getattr(v, n):
83 print "ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n))
86 print "ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e)
89 def check_interface(self, interface, iname):
90 errcount = self.errcount
91 for n in dir(interface):
92 if n[0] == '_' or n == iname:
93 # skip the special ones
95 value = getattr(interface, n)
96 if isinstance(value, str):
97 #print "%s=\"%s\"" % (n, value)
99 elif isinstance(value, int) or isinstance(value, long):
100 #print "%s=%d" % (n, value)
102 elif isinstance(value, type):
104 initial_blocks = talloc.total_blocks(None)
105 self.check_type(interface, n, value)
106 self.check_blocks(None, initial_blocks)
108 print "ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e)
110 elif callable(value):
113 print "UNKNOWN: %s=%s" % (n, value)
114 if self.errcount - errcount != 0:
115 print "Found %d errors in %s" % (self.errcount - errcount, iname)
117 def check_all_interfaces(self):
118 for iname in dir(samba.dcerpc):
121 if iname == 'ClientConnection' or iname == 'base':
123 print "Checking interface %s" % iname
124 iface = getattr(samba.dcerpc, iname)
125 initial_blocks = talloc.total_blocks(None)
126 self.check_interface(iface, iname)
127 self.check_blocks(None, initial_blocks)
130 self.initial_blocks = talloc.total_blocks(None)
132 self.check_all_interfaces()
136 errcount = tests.run()
140 print "%d failures" % errcount