build: Change bin/default/python -> bin/python symlink to bin/default/python_modules
[Samba.git] / source4 / scripting / python / samba / tests / dcerpc / rpc_talloc.py
blobc091f26c1b92b1cb7bd6b4dfb990f89ac3e5d061
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/>.
18 # to run this test, use one of these:
20 # python -m testtools.run samba.tests.dcerpc.rpc_talloc
22 # or if you have trial installed (from twisted), use
24 # trial samba.tests.dcerpc.rpc_talloc
26 """Tests for the talloc handling in the generated Python DCE/RPC bindings."""
28 import sys
30 sys.path.insert(0, "bin/python")
32 import samba
33 import samba.tests
34 from samba.dcerpc import drsuapi
35 import talloc
37 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)
46 if object is None:
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)
57 attids = [1, 2, 3]
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
68 def pas_test(self):
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)
80 def test_run(self):
81 self.initial_blocks = talloc.total_blocks(None)
82 self.check_blocks(None, 0)
83 self.pas_test()
84 self.check_blocks(None, 0)