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/>.
17 from __future__ import print_function
20 sys.path.insert(0, "bin/python")
24 from samba.dcerpc import drsuapi
27 talloc.enable_null_tracking()
29 class RpcTests(object):
30 '''test type behaviour of pidl generated python RPC code'''
32 def check_blocks(self, object, num_expected):
33 '''check that the number of allocated blocks is correct'''
34 nblocks = talloc.total_blocks(object)
36 nblocks -= self.initial_blocks
37 leaked_blocks = (nblocks - num_expected)
38 if leaked_blocks != 0:
39 print("Leaked %d blocks" % leaked_blocks)
41 def check_type(self, interface, typename, type):
42 print("Checking type %s" % typename)
49 except TypeError as errstr:
50 if str(errstr) == "unknown union level":
51 print("ERROR: Unknown union level in %s.%s" % (typename, n))
54 print(str(errstr)[1:21])
55 if str(errstr)[0:21] == "Can not convert C Type":
56 print("ERROR: Unknown C type for %s.%s" % (typename, n))
60 print("ERROR: Failed to instantiate %s.%s" % (typename, n))
64 print("ERROR: Failed to instantiate %s.%s" % (typename, n))
68 # now try setting the value back
70 print("Setting %s.%s" % (typename, n))
72 except Exception as e:
73 if isinstance(e, AttributeError) and str(e).endswith("is read-only"):
77 print("ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e))
81 # and try a comparison
83 if value != getattr(v, n):
84 print("ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n)))
86 except Exception as e:
87 print("ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e))
90 def check_interface(self, interface, iname):
91 errcount = self.errcount
92 for n in dir(interface):
93 if n[0] == '_' or n == iname:
94 # skip the special ones
96 value = getattr(interface, n)
97 if isinstance(value, str):
98 #print "%s=\"%s\"" % (n, value)
100 elif isinstance(value, int) or isinstance(value, long):
101 #print "%s=%d" % (n, value)
103 elif isinstance(value, type):
105 initial_blocks = talloc.total_blocks(None)
106 self.check_type(interface, n, value)
107 self.check_blocks(None, initial_blocks)
108 except Exception as e:
109 print("ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e))
111 elif callable(value):
114 print("UNKNOWN: %s=%s" % (n, value))
115 if self.errcount - errcount != 0:
116 print("Found %d errors in %s" % (self.errcount - errcount, iname))
118 def check_all_interfaces(self):
119 for iname in dir(samba.dcerpc):
122 if iname == 'ClientConnection' or iname == 'base':
124 print("Checking interface %s" % iname)
125 iface = getattr(samba.dcerpc, iname)
126 initial_blocks = talloc.total_blocks(None)
127 self.check_interface(iface, iname)
128 self.check_blocks(None, initial_blocks)
131 self.initial_blocks = talloc.total_blocks(None)
133 self.check_all_interfaces()
137 errcount = tests.run()
141 print("%d failures" % errcount)