2 # test generated python code from pidl
3 # Andrew Tridgell August 2010
5 # to run this test, use one of these:
7 # python -m testtools.run samba.tests.dcerpc.rpc_talloc
9 # or if you have trial installed (from twisted), use
11 # trial samba.tests.dcerpc.rpc_talloc
15 sys.path.insert(0, "bin/python")
19 from samba.dcerpc import drsuapi
22 talloc.enable_null_tracking()
24 class TallocTests(samba.tests.TestCase):
25 '''test talloc behaviour of pidl generated python code'''
27 def check_blocks(self, object, num_expected):
28 '''check that the number of allocated blocks is correct'''
29 nblocks = talloc.total_blocks(object)
31 nblocks -= self.initial_blocks
32 self.assertEquals(nblocks, num_expected)
34 def get_rodc_partial_attribute_set(self):
35 '''get a list of attributes for RODC replication'''
36 partial_attribute_set = drsuapi.DsPartialAttributeSet()
38 # we expect one block for the object, and one for the structure
39 self.check_blocks(partial_attribute_set, 2)
42 partial_attribute_set.version = 1
43 partial_attribute_set.attids = attids
44 partial_attribute_set.num_attids = len(attids)
46 # we expect one block object, a structure, an ARRAY, and a
47 # reference to the array
48 self.check_blocks(partial_attribute_set, 3)
50 return partial_attribute_set
53 pas = self.get_rodc_partial_attribute_set()
54 self.check_blocks(pas, 3)
55 req8 = drsuapi.DsGetNCChangesRequest8()
56 self.check_blocks(req8, 2)
57 self.check_blocks(None, 5)
58 req8.partial_attribute_set = pas
59 if req8.partial_attribute_set.attids[1] != 2:
60 raise Exception("Wrong value in attids[2]")
61 # we now get an additional reference
62 self.check_blocks(None, 6)
65 self.initial_blocks = talloc.total_blocks(None)
66 self.check_blocks(None, 0)
68 self.check_blocks(None, 0)