Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00092 if __name__ == '__main__':
00093 unittest.main()