test_ComponentActionListener.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file test_ComponentActionListener.py
00006 # @brief test for ComponentActionListener class
00007 # @date $Date$
00008 # @author Shinji Kurihara
00009 #
00010 # Copyright (C) 2011
00011 #     Intelligent Systems Research Institute,
00012 #     National Institute of
00013 #         Advanced Industrial Science and Technology (AIST), Japan
00014 #     All rights reserved.
00015 
00016 
00017 import sys
00018 sys.path.insert(1,"../")
00019 
00020 import unittest
00021 
00022 from ComponentActionListener import *
00023 import OpenRTM_aist
00024 
00025 class MockPreComponentActionListener(PreComponentActionListener):
00026   def __init__(self):
00027     PreComponentActionListener.__init__(self)
00028     return
00029 
00030   def __call__(self,id):
00031     return id
00032 
00033 
00034 class MockPostComponentActionListener(PostComponentActionListener):
00035   def __init__(self):
00036     PostComponentActionListener.__init__(self)
00037     return
00038 
00039   def __call__(self,id,ret):
00040     return id,ret
00041 
00042 
00043 class MockPortActionListener(PortActionListener):
00044   def __init__(self):
00045     PortActionListener.__init__(self)
00046     return
00047 
00048   def __call__(self, pprof):
00049     return pprof
00050 
00051 
00052 class MockExecutionContextActionListener(ExecutionContextActionListener):
00053   def __init__(self):
00054     ExecutionContextActionListener.__init__(self)
00055     return
00056 
00057   def __call__(self, ec_id):
00058     return ec_id
00059 
00060 
00061 class TestListener(unittest.TestCase):
00062   def setUp(self):
00063     return
00064 
00065   def tearDown(self):
00066     OpenRTM_aist.Manager.instance().shutdownManager()
00067     return
00068 
00069   def test_PreComponentActionListener_toString(self):
00070     self.assertEqual("PRE_ON_INITIALIZE",
00071                     PreComponentActionListener.toString(
00072         PreComponentActionListenerType.PRE_ON_INITIALIZE))
00073     
00074     self.assertEqual("PRE_ON_FINALIZE",
00075                     PreComponentActionListener.toString(
00076         PreComponentActionListenerType.PRE_ON_FINALIZE))
00077 
00078     self.assertEqual("PRE_ON_STARTUP",
00079                     PreComponentActionListener.toString(
00080         PreComponentActionListenerType.PRE_ON_STARTUP))
00081 
00082     self.assertEqual("PRE_ON_SHUTDOWN",
00083                     PreComponentActionListener.toString(
00084         PreComponentActionListenerType.PRE_ON_SHUTDOWN))
00085 
00086     self.assertEqual("PRE_ON_ACTIVATED",
00087                     PreComponentActionListener.toString(
00088         PreComponentActionListenerType.PRE_ON_ACTIVATED))
00089 
00090     self.assertEqual("PRE_ON_DEACTIVATED",
00091                     PreComponentActionListener.toString(
00092         PreComponentActionListenerType.PRE_ON_DEACTIVATED))
00093 
00094     self.assertEqual("PRE_ON_ABORTING",
00095                     PreComponentActionListener.toString(
00096         PreComponentActionListenerType.PRE_ON_ABORTING))
00097 
00098     self.assertEqual("PRE_ON_ERROR",
00099                     PreComponentActionListener.toString(
00100         PreComponentActionListenerType.PRE_ON_ERROR))
00101 
00102     self.assertEqual("PRE_ON_RESET",
00103                     PreComponentActionListener.toString(
00104         PreComponentActionListenerType.PRE_ON_RESET))
00105 
00106     self.assertEqual("PRE_ON_EXECUTE",
00107                     PreComponentActionListener.toString(
00108         PreComponentActionListenerType.PRE_ON_EXECUTE))
00109 
00110     self.assertEqual("PRE_ON_STATE_UPDATE",
00111                     PreComponentActionListener.toString(
00112         PreComponentActionListenerType.PRE_ON_STATE_UPDATE))
00113 
00114     self.assertEqual("PRE_ON_RATE_CHANGED",
00115                     PreComponentActionListener.toString(
00116         PreComponentActionListenerType.PRE_ON_RATE_CHANGED))
00117 
00118     return
00119 
00120   def test_PostComponentActionListener_toString(self):
00121     self.assertEqual("POST_ON_INITIALIZE",
00122                     PostComponentActionListener.toString(
00123         PostComponentActionListenerType.POST_ON_INITIALIZE))
00124     
00125     self.assertEqual("POST_ON_FINALIZE",
00126                     PostComponentActionListener.toString(
00127         PostComponentActionListenerType.POST_ON_FINALIZE))
00128 
00129     self.assertEqual("POST_ON_STARTUP",
00130                     PostComponentActionListener.toString(
00131         PostComponentActionListenerType.POST_ON_STARTUP))
00132 
00133     self.assertEqual("POST_ON_SHUTDOWN",
00134                     PostComponentActionListener.toString(
00135         PostComponentActionListenerType.POST_ON_SHUTDOWN))
00136 
00137     self.assertEqual("POST_ON_ACTIVATED",
00138                     PostComponentActionListener.toString(
00139         PostComponentActionListenerType.POST_ON_ACTIVATED))
00140 
00141     self.assertEqual("POST_ON_DEACTIVATED",
00142                     PostComponentActionListener.toString(
00143         PostComponentActionListenerType.POST_ON_DEACTIVATED))
00144 
00145     self.assertEqual("POST_ON_ABORTING",
00146                     PostComponentActionListener.toString(
00147         PostComponentActionListenerType.POST_ON_ABORTING))
00148 
00149     self.assertEqual("POST_ON_ERROR",
00150                     PostComponentActionListener.toString(
00151         PostComponentActionListenerType.POST_ON_ERROR))
00152 
00153     self.assertEqual("POST_ON_RESET",
00154                     PostComponentActionListener.toString(
00155         PostComponentActionListenerType.POST_ON_RESET))
00156 
00157     self.assertEqual("POST_ON_EXECUTE",
00158                     PostComponentActionListener.toString(
00159         PostComponentActionListenerType.POST_ON_EXECUTE))
00160 
00161     self.assertEqual("POST_ON_STATE_UPDATE",
00162                     PostComponentActionListener.toString(
00163         PostComponentActionListenerType.POST_ON_STATE_UPDATE))
00164 
00165     self.assertEqual("POST_ON_RATE_CHANGED",
00166                     PostComponentActionListener.toString(
00167         PostComponentActionListenerType.POST_ON_RATE_CHANGED))
00168 
00169     return
00170 
00171   def test_PortActionListener_toString(self):
00172     self.assertEqual("ADD_PORT",
00173                     PortActionListener.toString(
00174         PortActionListenerType.ADD_PORT))
00175 
00176     self.assertEqual("REMOVE_PORT",
00177                     PortActionListener.toString(
00178         PortActionListenerType.REMOVE_PORT))
00179 
00180     return
00181 
00182   def test_ExecutionContextActionListener_toString(self):
00183     self.assertEqual("ATTACH_EC",
00184                     ExecutionContextActionListener.toString(
00185         ExecutionContextActionListenerType.EC_ATTACHED))
00186 
00187     self.assertEqual("DETACH_EC",
00188                     ExecutionContextActionListener.toString(
00189         ExecutionContextActionListenerType.EC_DETACHED))
00190 
00191     return
00192 
00193 
00194   def test_PreComponentActionListenerHolder(self):
00195     preactions = ComponentActionListeners()
00196     listener = MockPreComponentActionListener()
00197     preactions.preaction_[0].addListener(listener,True)
00198     preactions.preaction_[0].notify("test precomp ec_id")
00199     preactions.preaction_[0].removeListener(listener)
00200     return
00201 
00202   def test_PostComponentActionListenerHolder(self):
00203     postactions = ComponentActionListeners()
00204     listener = MockPostComponentActionListener()
00205     postactions.postaction_[0].addListener(listener,True)
00206     postactions.postaction_[0].notify("test postcomp ec_id",True)
00207     postactions.postaction_[0].removeListener(listener)
00208     return
00209 
00210   def test_PortActionListenerHolder(self):
00211     portactions = ComponentActionListeners()
00212     listener = MockPortActionListener()
00213     portactions.portaction_[0].addListener(listener,True)
00214     portactions.portaction_[0].notify("test port pprof")
00215     portactions.portaction_[0].removeListener(listener)
00216     return
00217 
00218   def test_ExecutionContextActionListenerHolder(self):
00219     ecactions = ComponentActionListeners()
00220     listener = MockExecutionContextActionListener()
00221     ecactions.ecaction_[0].addListener(listener,True)
00222     ecactions.ecaction_[0].notify("test ec ec_id")
00223     ecactions.ecaction_[0].removeListener(listener)
00224     return
00225 
00226 
00227 ############### test #################
00228 if __name__ == '__main__':
00229   unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28