test_OutPort.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 #
00005 #  \file test_OutPort.py
00006 #  \brief test for OutPort class
00007 #  \date $Date: 2007/09/19$
00008 #  \author Shinji Kurihara
00009 # 
00010 #  Copyright (C) 2006
00011 #      Noriaki Ando
00012 #      Task-intelligence Research Group,
00013 #      Intelligent Systems Research Institute,
00014 #      National Institute of
00015 #          Advanced Industrial Science and Technology (AIST), Japan
00016 #      All rights reserved.
00017 # 
00018 
00019 import sys
00020 sys.path.insert(1,"../")
00021 
00022 from omniORB import *
00023 from omniORB import any
00024 
00025 import unittest
00026 from OutPort import *
00027 
00028 import RTC, RTC__POA
00029 
00030 import OpenRTM_aist
00031 
00032 class OnRWTest:
00033   def __init__(self):
00034     pass
00035 
00036   def echo(self, value=None):
00037     print "OnRW Called"
00038 
00039 class OnRWConvertTest:
00040   def __init__(self):
00041     pass
00042 
00043   def echo(self, value=None):
00044     print "OnRWConvert Called"
00045     return value
00046 
00047 class ConnectorMock:
00048   def write(self, data):
00049     self._data = data
00050     return OpenRTM_aist.DataPortStatus.PORT_OK
00051 
00052   def read(self, data):
00053     data[0] = self._data
00054     return True
00055 
00056 
00057 class TestOutPort(unittest.TestCase):
00058   def setUp(self):
00059     OpenRTM_aist.Manager.init(sys.argv)
00060     self._op = OutPort("out", RTC.TimedLong(RTC.Time(0,0), 0))
00061     return
00062 
00063   def tearDown(self):
00064     OpenRTM_aist.Manager.instance().shutdownManager()
00065     return
00066 
00067   def test_write(self):
00068     self.assertEqual(self._op.write(RTC.TimedLong(RTC.Time(0,0), 123)), True)
00069     self._connector = ConnectorMock()
00070     self._op._connectors = [self._connector]
00071     self.assertEqual(self._op.write(RTC.TimedLong(RTC.Time(0,0), 123)), True)
00072     read_data = [RTC.TimedLong(RTC.Time(0,0), 0)]
00073     self._connector.read(read_data)
00074     self.assertEqual(read_data[0].data,123)
00075     return
00076 
00077   def test_OnWrite(self):
00078     self._connector = ConnectorMock()
00079     self._op._connectors = [self._connector]
00080     self._op.setOnWrite(OnRWTest().echo)
00081     self._op.setOnWriteConvert(OnRWConvertTest().echo)
00082     self.assertEqual(self._op.write(RTC.TimedLong(RTC.Time(0,0), 123)), True)
00083     return
00084 
00085 
00086   def test_getPortDataType(self):
00087     self.assertEqual(self._op.getPortDataType(),any.to_any(RTC.TimedLong(RTC.Time(0,0),0)).typecode().name())
00088     return
00089 
00090 
00091 ############### test #################
00092 if __name__ == '__main__':
00093   unittest.main()


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