Move python modules from source4/scripting/python/ to python/.
[bbaumbach/samba-autobuild/.git] / python / samba / tests / dcerpc / rpc_talloc.py
1 # test generated python code from pidl
2 # Copyright (C) Andrew Tridgell August 2010
3 #
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.
8 #
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.
13 #
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/>.
16 #
17 #
18 # to run this test, use one of these:
19 #
20 #    python -m testtools.run samba.tests.dcerpc.rpc_talloc
21 #
22 # or if you have trial installed (from twisted), use
23 #
24 #    trial samba.tests.dcerpc.rpc_talloc
25
26 """Tests for the talloc handling in the generated Python DCE/RPC bindings."""
27
28 import sys
29
30 sys.path.insert(0, "bin/python")
31
32 import samba
33 import samba.tests
34 from samba.dcerpc import drsuapi
35 import talloc
36
37 talloc.enable_null_tracking()
38
39
40 class TallocTests(samba.tests.TestCase):
41     '''test talloc behaviour of pidl generated python code'''
42
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)
49
50     def get_rodc_partial_attribute_set(self):
51         '''get a list of attributes for RODC replication'''
52         partial_attribute_set = drsuapi.DsPartialAttributeSet()
53
54         # we expect one block for the object, and one for the structure
55         self.check_blocks(partial_attribute_set, 2)
56
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)
61
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)
65
66         return partial_attribute_set
67
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)
79
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)