1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2015
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 """Tests for integer handling in PIDL generated bindings samba.dcerpc.*"""
20 from samba.dcerpc import server_id, misc, srvsvc
23 class IntegerTests(samba.tests.TestCase):
25 def test_uint32_into_hyper(self):
26 s = server_id.server_id()
27 s.unique_id = server_id.NONCLUSTER_VNN
28 self.assertEquals(s.unique_id, 0xFFFFFFFFL)
30 def test_int_into_hyper(self):
31 s = server_id.server_id()
34 def test_negative_int_into_hyper(self):
35 s = server_id.server_id()
38 self.assertRaises(OverflowError, assign)
40 def test_hyper_into_uint32(self):
41 s = server_id.server_id()
43 s.vnn = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
44 self.assertRaises(OverflowError, assign)
46 def test_hyper_into_int32(self):
47 s = srvsvc.NetRemoteTODInfo()
49 s.timezone = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
50 self.assertRaises(OverflowError, assign)
52 def test_int_into_int32(self):
53 s = srvsvc.NetRemoteTODInfo()
56 def test_uint32_into_int32(self):
57 s = srvsvc.NetRemoteTODInfo()
59 s.timezone = server_id.NONCLUSTER_VNN
60 self.assertRaises(OverflowError, assign)
62 def test_long_into_int32(self):
63 s = srvsvc.NetRemoteTODInfo()
66 def test_larger_long_int_into_int32(self):
67 s = srvsvc.NetRemoteTODInfo()
69 s.timezone = 2147483648
70 self.assertRaises(OverflowError, assign)
72 def test_larger_int_into_int32(self):
73 s = srvsvc.NetRemoteTODInfo()
74 s.timezone = 2147483647
76 def test_float_into_int32(self):
77 s = srvsvc.NetRemoteTODInfo()
80 self.assertRaises(TypeError, assign)
82 def test_int_float_into_int32(self):
83 s = srvsvc.NetRemoteTODInfo()
86 self.assertRaises(TypeError, assign)
88 def test_negative_int_into_int32(self):
89 s = srvsvc.NetRemoteTODInfo()
90 s.timezone = -2147483648
92 def test_negative_into_uint32(self):
93 s = server_id.server_id()
96 self.assertRaises(OverflowError, assign)
98 def test_hyper_into_uint16(self):
101 g.time_mid = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
102 self.assertRaises(OverflowError, assign)
104 def test_int_into_uint16(self):
108 self.assertRaises(OverflowError, assign)
110 def test_negative_int_into_uint16(self):
114 self.assertRaises(OverflowError, assign)
116 def test_int_into_uint16(self):
120 self.assertRaises(OverflowError, assign)
122 def test_negative_int_into_uint16(self):
126 self.assertRaises(OverflowError, assign)
128 def test_enum_into_uint16(self):
130 g.time_mid = misc.SEC_CHAN_DOMAIN
132 def test_bitmap_into_uint16(self):
134 g.time_mid = misc.SV_TYPE_WFW
135 self.assertEqual(g.time_mid, misc.SV_TYPE_WFW)
137 def test_overflow_bitmap_into_uint16(self):
140 g.time_mid = misc.SV_TYPE_LOCAL_LIST_ONLY
141 self.assertRaises(OverflowError, assign)
143 def test_overflow_bitmap_into_uint16_2(self):
146 g.time_mid = misc.SV_TYPE_DOMAIN_ENUM
147 self.assertRaises(OverflowError, assign)
149 def test_int_list_over_list(self):
151 g.node = [5, 0, 5, 0, 7, 4]
152 self.assertEqual(g.node[0], 5)
154 def test_long_int_list_over_uint8_list(self):
156 g.node = [5L, 0, 5, 0, 7, 4]
157 self.assertEqual(g.node[0], 5)
159 def test_negative_list_over_uint8_list(self):
162 g.node = [-1, 0, 5, 0, 7, 4]
163 self.assertRaises(OverflowError, assign)
165 def test_overflow_list_over_uint8_list(self):
168 g.node = [256, 0, 5, 0, 7, 4]
169 self.assertRaises(OverflowError, assign)
171 def test_short_list_over_uint8_list(self):
175 self.assertRaises(TypeError, assign)
177 def test_long_list_over_uint8_list(self):
180 g.node = [5, 0, 5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
181 self.assertRaises(TypeError, assign)
183 # Due to our PIDL bindings generating a python List, modifications
184 # to a list of non-objects are not reflected in the C list
185 # (modifications objects in lists of objects work because the
186 # objects are modified), so changes essentially vanish and are not
187 # type checked either.
188 def test_assign_into_uint8_list(self):
191 self.assertEqual(g.node[1], 5)
193 def test_negative_into_uint8_list(self):
197 self.assertRaises(OverflowError, assign)
199 def test_overflow_into_uint8_list(self):
203 self.assertRaises(OverflowError, assign)