test_ComponentActionListener.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
15 
16 
17 import sys
18 sys.path.insert(1,"../")
19 
20 import unittest
21 
22 from ComponentActionListener import *
23 import OpenRTM_aist
24 
25 class MockPreComponentActionListener(PreComponentActionListener):
26  def __init__(self):
27  PreComponentActionListener.__init__(self)
28  return
29 
30  def __call__(self,id):
31  return id
32 
33 
34 class MockPostComponentActionListener(PostComponentActionListener):
35  def __init__(self):
36  PostComponentActionListener.__init__(self)
37  return
38 
39  def __call__(self,id,ret):
40  return id,ret
41 
42 
43 class MockPortActionListener(PortActionListener):
44  def __init__(self):
45  PortActionListener.__init__(self)
46  return
47 
48  def __call__(self, pprof):
49  return pprof
50 
51 
52 class MockExecutionContextActionListener(ExecutionContextActionListener):
53  def __init__(self):
54  ExecutionContextActionListener.__init__(self)
55  return
56 
57  def __call__(self, ec_id):
58  return ec_id
59 
60 
61 class TestListener(unittest.TestCase):
62  def setUp(self):
63  return
64 
65  def tearDown(self):
66  OpenRTM_aist.Manager.instance().shutdownManager()
67  return
68 
70  self.assertEqual("PRE_ON_INITIALIZE",
71  PreComponentActionListener.toString(
72  PreComponentActionListenerType.PRE_ON_INITIALIZE))
73 
74  self.assertEqual("PRE_ON_FINALIZE",
75  PreComponentActionListener.toString(
76  PreComponentActionListenerType.PRE_ON_FINALIZE))
77 
78  self.assertEqual("PRE_ON_STARTUP",
79  PreComponentActionListener.toString(
80  PreComponentActionListenerType.PRE_ON_STARTUP))
81 
82  self.assertEqual("PRE_ON_SHUTDOWN",
83  PreComponentActionListener.toString(
84  PreComponentActionListenerType.PRE_ON_SHUTDOWN))
85 
86  self.assertEqual("PRE_ON_ACTIVATED",
87  PreComponentActionListener.toString(
88  PreComponentActionListenerType.PRE_ON_ACTIVATED))
89 
90  self.assertEqual("PRE_ON_DEACTIVATED",
91  PreComponentActionListener.toString(
92  PreComponentActionListenerType.PRE_ON_DEACTIVATED))
93 
94  self.assertEqual("PRE_ON_ABORTING",
95  PreComponentActionListener.toString(
96  PreComponentActionListenerType.PRE_ON_ABORTING))
97 
98  self.assertEqual("PRE_ON_ERROR",
99  PreComponentActionListener.toString(
100  PreComponentActionListenerType.PRE_ON_ERROR))
101 
102  self.assertEqual("PRE_ON_RESET",
103  PreComponentActionListener.toString(
104  PreComponentActionListenerType.PRE_ON_RESET))
105 
106  self.assertEqual("PRE_ON_EXECUTE",
107  PreComponentActionListener.toString(
108  PreComponentActionListenerType.PRE_ON_EXECUTE))
109 
110  self.assertEqual("PRE_ON_STATE_UPDATE",
111  PreComponentActionListener.toString(
112  PreComponentActionListenerType.PRE_ON_STATE_UPDATE))
113 
114  self.assertEqual("PRE_ON_RATE_CHANGED",
115  PreComponentActionListener.toString(
116  PreComponentActionListenerType.PRE_ON_RATE_CHANGED))
117 
118  return
119 
121  self.assertEqual("POST_ON_INITIALIZE",
122  PostComponentActionListener.toString(
123  PostComponentActionListenerType.POST_ON_INITIALIZE))
124 
125  self.assertEqual("POST_ON_FINALIZE",
126  PostComponentActionListener.toString(
127  PostComponentActionListenerType.POST_ON_FINALIZE))
128 
129  self.assertEqual("POST_ON_STARTUP",
130  PostComponentActionListener.toString(
131  PostComponentActionListenerType.POST_ON_STARTUP))
132 
133  self.assertEqual("POST_ON_SHUTDOWN",
134  PostComponentActionListener.toString(
135  PostComponentActionListenerType.POST_ON_SHUTDOWN))
136 
137  self.assertEqual("POST_ON_ACTIVATED",
138  PostComponentActionListener.toString(
139  PostComponentActionListenerType.POST_ON_ACTIVATED))
140 
141  self.assertEqual("POST_ON_DEACTIVATED",
142  PostComponentActionListener.toString(
143  PostComponentActionListenerType.POST_ON_DEACTIVATED))
144 
145  self.assertEqual("POST_ON_ABORTING",
146  PostComponentActionListener.toString(
147  PostComponentActionListenerType.POST_ON_ABORTING))
148 
149  self.assertEqual("POST_ON_ERROR",
150  PostComponentActionListener.toString(
151  PostComponentActionListenerType.POST_ON_ERROR))
152 
153  self.assertEqual("POST_ON_RESET",
154  PostComponentActionListener.toString(
155  PostComponentActionListenerType.POST_ON_RESET))
156 
157  self.assertEqual("POST_ON_EXECUTE",
158  PostComponentActionListener.toString(
159  PostComponentActionListenerType.POST_ON_EXECUTE))
160 
161  self.assertEqual("POST_ON_STATE_UPDATE",
162  PostComponentActionListener.toString(
163  PostComponentActionListenerType.POST_ON_STATE_UPDATE))
164 
165  self.assertEqual("POST_ON_RATE_CHANGED",
166  PostComponentActionListener.toString(
167  PostComponentActionListenerType.POST_ON_RATE_CHANGED))
168 
169  return
170 
172  self.assertEqual("ADD_PORT",
173  PortActionListener.toString(
174  PortActionListenerType.ADD_PORT))
175 
176  self.assertEqual("REMOVE_PORT",
177  PortActionListener.toString(
178  PortActionListenerType.REMOVE_PORT))
179 
180  return
181 
183  self.assertEqual("ATTACH_EC",
184  ExecutionContextActionListener.toString(
185  ExecutionContextActionListenerType.EC_ATTACHED))
186 
187  self.assertEqual("DETACH_EC",
188  ExecutionContextActionListener.toString(
189  ExecutionContextActionListenerType.EC_DETACHED))
190 
191  return
192 
193 
195  preactions = ComponentActionListeners()
196  listener = MockPreComponentActionListener()
197  preactions.preaction_[0].addListener(listener,True)
198  preactions.preaction_[0].notify("test precomp ec_id")
199  preactions.preaction_[0].removeListener(listener)
200  return
201 
203  postactions = ComponentActionListeners()
205  postactions.postaction_[0].addListener(listener,True)
206  postactions.postaction_[0].notify("test postcomp ec_id",True)
207  postactions.postaction_[0].removeListener(listener)
208  return
209 
211  portactions = ComponentActionListeners()
212  listener = MockPortActionListener()
213  portactions.portaction_[0].addListener(listener,True)
214  portactions.portaction_[0].notify("test port pprof")
215  portactions.portaction_[0].removeListener(listener)
216  return
217 
219  ecactions = ComponentActionListeners()
221  ecactions.ecaction_[0].addListener(listener,True)
222  ecactions.ecaction_[0].notify("test ec ec_id")
223  ecactions.ecaction_[0].removeListener(listener)
224  return
225 
226 
227 ############### test #################
228 if __name__ == '__main__':
229  unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34