Move python modules from source4/scripting/python/ to python/.
[bbaumbach/samba-autobuild/.git] / python / samba / tests / dcerpc / rpcecho.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
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 """Tests for samba.dceprc.rpcecho."""
19
20 from samba.dcerpc import echo
21 from samba.ndr import ndr_pack, ndr_unpack
22 from samba.tests import RpcInterfaceTestCase, TestCase
23
24
25 class RpcEchoTests(RpcInterfaceTestCase):
26
27     def setUp(self):
28         super(RpcEchoTests, self).setUp()
29         self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm())
30
31     def test_two_contexts(self):
32         self.conn2 = echo.rpcecho("ncalrpc:", self.get_loadparm(), basis_connection=self.conn)
33         self.assertEquals(3, self.conn2.AddOne(2))
34
35     def test_abstract_syntax(self):
36         self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1),
37                           self.conn.abstract_syntax)
38
39     def test_addone(self):
40         self.assertEquals(2, self.conn.AddOne(1))
41
42     def test_echodata(self):
43         self.assertEquals([1,2,3], self.conn.EchoData([1, 2, 3]))
44
45     def test_call(self):
46         self.assertEquals(u"foobar", self.conn.TestCall(u"foobar"))
47
48     def test_surrounding(self):
49         surrounding_struct = echo.Surrounding()
50         surrounding_struct.x = 4
51         surrounding_struct.surrounding = [1,2,3,4]
52         y = self.conn.TestSurrounding(surrounding_struct)
53         self.assertEquals(8 * [0], y.surrounding)
54
55     def test_manual_request(self):
56         self.assertEquals("\x01\x00\x00\x00", self.conn.request(0, chr(0) * 4))
57
58     def test_server_name(self):
59         self.assertEquals(None, self.conn.server_name)
60
61
62 class NdrEchoTests(TestCase):
63
64     def test_info1_push(self):
65         x = echo.info1()
66         x.v = 42
67         self.assertEquals("\x2a", ndr_pack(x))
68
69     def test_info1_pull(self):
70         x = ndr_unpack(echo.info1, "\x42")
71         self.assertEquals(x.v, 66)