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

Source Code for Module elisa.core.tests.test_input_provider

  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.base_components import input_provider 
 17  from elisa.core import input_event 
 18  from elisa.core.tests.elisa_test_case import ElisaTestCase 
 19   
20 -def create_input_event(data, component_source):
21 source, typ, value, action = data 22 source = getattr(input_event.EventSource, source) 23 value = getattr(input_event.EventValue, value) 24 typ = getattr(input_event.EventType, typ) 25 evt = input_event.InputEvent(input_event.EventSource.MOUSE, typ, 26 action, value, source_id=source) 27 evt.component_source = component_source 28 return evt
29 30 31 EVTS = [ ('MOUSE', 'MOUSE_DOWN', 'MOUSE_LEFT', 'PAUSE'), 32 ('MOUSE', 'MOUSE_UP', 'MOUSE_LEFT', 'PLAY') 33 ] 34 35
36 -class MousePollInputProvider(input_provider.PollInputProvider):
37 name = 'mouse' 38
39 - def create_input_event(self, data):
40 return create_input_event(data, self)
41
42 - def get_input_events(self):
43 return [self.create_input_event(data) for data in EVTS]
44
45 -class MousePushInputProvider(input_provider.PushInputProvider):
46 name = 'push_mouse' 47
48 - def create_input_event(self, data):
49 return create_input_event(data, self)
50
51 - def bind(self):
52 pass
53
54 - def unbind(self):
55 pass
56
57 - def trigger_some_events(self):
58 for evt in [self.create_input_event(data) for data in EVTS]: 59 self.input_manager.process_event(evt, self.path)
60
61 -class FakeManager:
62 63 up_ok = False 64 down_ok = False 65
66 - def process_event(self, event, path):
67 if event.type == input_event.EventType.MOUSE_UP and \ 68 event.value == input_event.EventValue.MOUSE_LEFT: 69 self.up_ok = True 70 71 if event.type == input_event.EventType.MOUSE_DOWN and \ 72 event.value == input_event.EventValue.MOUSE_LEFT: 73 self.down_ok = True
74
75 -class TestInputProvider(ElisaTestCase):
76 """ 77 """ 78
79 - def test_poll_provider(self):
80 """ check poll provider 81 82 Poll some events from a provider and check their value/type. 83 """ 84 c = MousePollInputProvider() 85 events = c.get_input_events() 86 self.failUnless(events) 87 88 self.assertEquals(len(events), 2) 89 down, up = events 90 91 self.assertEquals(up.type, input_event.EventType.MOUSE_UP) 92 self.assertEquals(up.value, input_event.EventValue.MOUSE_LEFT) 93 94 self.assertEquals(down.type, input_event.EventType.MOUSE_DOWN) 95 self.assertEquals(down.value, input_event.EventValue.MOUSE_LEFT)
96
97 - def test_push_provider(self):
98 """ check push_input_provider calls its manager on event trigger 99 100 Attach a fake manager to the component, trigger some events 101 and check some bool attributes of the manager. 102 """ 103 c = MousePushInputProvider() 104 m = FakeManager() 105 c.input_manager = m 106 107 c.trigger_some_events() 108 self.assertEquals(m.up_ok, True) 109 self.assertEquals(m.down_ok, True)
110