s4-python: Consistently use spaces rather than tabs, fix headers in several places.
[Samba/gebeck_regimport.git] / source4 / scripting / python / samba / tests / messaging.py
blob7f2d4a904b9ab32aa1d451f95c80cbaffc158802
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Unix SMB/CIFS implementation.
5 # Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 """Tests for samba.messaging."""
23 from samba.messaging import Messaging
24 from samba.tests import TestCase
26 class MessagingTests(TestCase):
28 def get_context(self, *args, **kwargs):
29 kwargs["messaging_path"] = "."
30 return Messaging(*args, **kwargs)
32 def test_register(self):
33 x = self.get_context()
34 def callback():
35 pass
36 msg_type = x.register(callback)
37 x.deregister(callback, msg_type)
39 def test_assign_server_id(self):
40 x = self.get_context()
41 self.assertTrue(isinstance(x.server_id, tuple))
42 self.assertEquals(3, len(x.server_id))
44 def test_ping_speed(self):
45 server_ctx = self.get_context((0, 1))
46 def ping_callback(src, data):
47 server_ctx.send(src, data)
48 def exit_callback():
49 print "received exit"
50 msg_ping = server_ctx.register(ping_callback)
51 msg_exit = server_ctx.register(exit_callback)
53 def pong_callback():
54 print "received pong"
55 client_ctx = self.get_context((0, 2))
56 msg_pong = client_ctx.register(pong_callback)
58 client_ctx.send((0, 1), msg_ping, "testing")
59 client_ctx.send((0, 1), msg_ping, "")