2 # test generated python code from pidl
3 # Copyright (C) Andrew Tridgell August 2010
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # to run this test, use one of these:
21 # python -m testtools.run samba.tests.dcerpc.rpc_talloc
23 # or if you have trial installed (from twisted), use
25 # trial samba.tests.dcerpc.rpc_talloc
27 """Tests for the talloc handling in the generated Python DCE/RPC bindings."""
31 sys.path.insert(0, "bin/python")
35 from samba.dcerpc import drsuapi
38 talloc.enable_null_tracking()
40 class TallocTests(samba.tests.TestCase):
41 '''test talloc behaviour of pidl generated python code'''
43 def check_blocks(self, object, num_expected):
44 '''check that the number of allocated blocks is correct'''
45 nblocks = talloc.total_blocks(object)
47 nblocks -= self.initial_blocks
48 self.assertEquals(nblocks, num_expected)
50 def get_rodc_partial_attribute_set(self):
51 '''get a list of attributes for RODC replication'''
52 partial_attribute_set = drsuapi.DsPartialAttributeSet()
54 # we expect one block for the object, and one for the structure
55 self.check_blocks(partial_attribute_set, 2)
58 partial_attribute_set.version = 1
59 partial_attribute_set.attids = attids
60 partial_attribute_set.num_attids = len(attids)
62 # we expect one block object, a structure, an ARRAY, and a
63 # reference to the array
64 self.check_blocks(partial_attribute_set, 3)
66 return partial_attribute_set
69 pas = self.get_rodc_partial_attribute_set()
70 self.check_blocks(pas, 3)
71 req8 = drsuapi.DsGetNCChangesRequest8()
72 self.check_blocks(req8, 2)
73 self.check_blocks(None, 5)
74 req8.partial_attribute_set = pas
75 if req8.partial_attribute_set.attids[1] != 2:
76 raise Exception("Wrong value in attids[2]")
77 # we now get an additional reference
78 self.check_blocks(None, 6)
81 self.initial_blocks = talloc.total_blocks(None)
82 self.check_blocks(None, 0)
84 self.check_blocks(None, 0)