96bb3923a68b2093efbe1b2da4ebbc90155bf7c3
[ab/samba.git/.git] / source4 / scripting / python / samba / tests / dcerpc / rpcecho.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
5 #   
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #   
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #   
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from samba.dcerpc import echo
21 from samba.ndr import ndr_pack, ndr_unpack
22 import unittest
23 from samba.tests import RpcInterfaceTestCase
24
25 class RpcEchoTests(RpcInterfaceTestCase):
26     def setUp(self):
27         self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm())
28
29     def test_two_contexts(self):
30         self.conn2 = echo.rpcecho("ncalrpc:", self.get_loadparm(), basis_connection=self.conn)
31         self.assertEquals(3, self.conn2.AddOne(2))
32
33     def test_abstract_syntax(self):
34         self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1), 
35                           self.conn.abstract_syntax)
36
37     def test_addone(self):
38         self.assertEquals(2, self.conn.AddOne(1))
39
40     def test_echodata(self):
41         self.assertEquals([1,2,3], self.conn.EchoData([1, 2, 3]))
42
43     def test_call(self):
44         self.assertEquals(u"foobar", self.conn.TestCall(u"foobar"))
45
46     def test_surrounding(self):
47         surrounding_struct = echo.Surrounding()
48         surrounding_struct.x = 4
49         surrounding_struct.surrounding = [1,2,3,4]
50         y = self.conn.TestSurrounding(surrounding_struct)
51         self.assertEquals(8 * [0], y.surrounding)
52
53     def test_manual_request(self):
54         self.assertEquals("\x01\x00\x00\x00", self.conn.request(0, chr(0) * 4))
55
56     def test_server_name(self):
57         self.assertEquals(None, self.conn.server_name)
58
59 class NdrEchoTests(unittest.TestCase):
60     def test_info1_push(self):
61         x = echo.info1()
62         x.v = 42
63         self.assertEquals("\x2a", ndr_pack(x))
64
65     def test_info1_pull(self):
66         x = ndr_unpack(echo.info1, "\x42")
67         self.assertEquals(x.v, 66)