Package elisa :: Package core :: Package tests :: Module test_input_manager
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.tests.test_input_manager

 1  # Elisa - Home multimedia server 
 2  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 3  # All rights reserved. 
 4  # 
 5  # This file is available under one of two license agreements. 
 6  # 
 7  # This file is licensed under the GPL version 3. 
 8  # See "LICENSE.GPL" in the root of this distribution including a special 
 9  # exception to use Elisa with Fluendo's plugins. 
10  # 
11  # The GPL part of Elisa is also available under a commercial licensing 
12  # agreement from Fluendo. 
13  # See "LICENSE.Elisa" in the root directory of this distribution package 
14  # for details on that license. 
15   
16  from elisa.core.tests.elisa_test_case import ElisaTestCase 
17  from elisa.base_components import input_provider 
18  from elisa.core import input_manager, input_event 
19  from elisa.core import plugin, plugin_registry, config 
20  from elisa.core import common 
21  from twisted.internet import reactor 
22  from elisa.core.tests.test_input_provider import MousePollInputProvider, \ 
23       MousePushInputProvider 
24   
25 -class TestInputManager(ElisaTestCase):
26
27 - def setUp(self):
28 ElisaTestCase.setUp(self) 29 self._input_manager = input_manager.InputManager() 30 #self._input_manager.start() 31 self._called = {self.mouse_upped:False, 32 self.mouse_down: False}
33
34 - def mouse_triggerred(self, event):
35 if event.type == input_event.EventType.MOUSE_UP: 36 self.mouse_upped(event) 37 elif event.type == input_event.EventType.MOUSE_DOWN: 38 self.mouse_down(event)
39
40 - def mouse_upped(self, event):
41 self.assertEquals(event.type, input_event.EventType.MOUSE_UP) 42 self.assertEquals(event.value, input_event.EventValue.MOUSE_LEFT) 43 self._called[self.mouse_upped] = True
44
45 - def mouse_down(self, event):
46 self.assertEquals(event.type, input_event.EventType.MOUSE_DOWN) 47 self.assertEquals(event.value, input_event.EventValue.MOUSE_LEFT) 48 self._called[self.mouse_down] = True
49
50 - def _connect(self, component):
51 #import pdb; pdb.set_trace() 52 self._called[self.mouse_upped] = False 53 self._called[self.mouse_down] = False 54 self._input_manager.subscribe(component.path, self.mouse_triggerred)
55
56 - def _disconnect(self, component):
57 self._input_manager.unsubscribe(component.path, self.mouse_triggerred)
58
59 - def test_poll_events(self):
60 """ 61 """ 62 mouse_poll = MousePollInputProvider() 63 mouse_poll.path = 'mouse_poll_input_provider' 64 self._input_manager.register_component(mouse_poll) 65 66 self._connect(mouse_poll) 67 68 self._input_manager._poll_events() 69 self.assertEquals(self._called[self.mouse_upped], True) 70 self.assertEquals(self._called[self.mouse_down], True) 71 72 self._disconnect(mouse_poll) 73 self._input_manager.unregister_component(mouse_poll)
74
75 - def test_push_events(self):
76 """ 77 """ 78 mouse_push = MousePushInputProvider() 79 mouse_push.path = 'mouse_push_input_provider' 80 self._input_manager.register_component(mouse_push) 81 82 self._connect(mouse_push) 83 84 mouse_push.trigger_some_events() 85 self.assertEquals(self._called[self.mouse_upped], True) 86 self.assertEquals(self._called[self.mouse_down], True) 87 88 self._disconnect(mouse_push) 89 self._input_manager.unregister_component(mouse_push)
90