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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 PKG = 'rosjava'
00037 NAME = 'testheader_passthrough'
00038 import roslib; roslib.load_manifest(PKG)
00039
00040 from ros import rospy
00041 from ros import rosjava_test_msgs
00042 from ros import rostest
00043
00044 import sys
00045 import time
00046 import unittest
00047
00048 from rosjava_test_msgs.msg import TestHeader
00049
00050 class TestHeaderPassthrough(unittest.TestCase):
00051
00052 def setUp(self):
00053 rospy.init_node(NAME)
00054
00055 self.fixture_curr = None
00056 self.test_curr = None
00057
00058 rospy.Subscriber('test_header_in', TestHeader, self.cb_from_fixture)
00059 rospy.Subscriber('test_header_out', TestHeader, self.cb_from_test)
00060
00061 def cb_from_fixture(self, msg):
00062 self.fixture_curr = msg
00063
00064 def cb_from_test(self, msg):
00065 self.test_curr = msg
00066
00067 def test_testheader_passthrough(self):
00068
00069 timeout_t = time.time() + 20.
00070 print "waiting for 20 seconds for fixture to verify"
00071 while self.fixture_curr is None and \
00072 not rospy.is_shutdown() and \
00073 timeout_t > time.time():
00074 time.sleep(0.2)
00075
00076 self.failIf(timeout_t < time.time(), "timeout exceeded")
00077 self.failIf(rospy.is_shutdown(), "node shutdown")
00078 self.failIf(self.fixture_curr is None, "no data from fixture")
00079 self.assertEquals('/node0', self.fixture_curr.caller_id)
00080 self.assertEquals('', self.fixture_curr.orig_caller_id)
00081
00082
00083 timeout_t = time.time() + 20.
00084 print "waiting for 20 seconds for client to verify"
00085 while self.test_curr is None and \
00086 not rospy.is_shutdown() and \
00087 timeout_t > time.time():
00088 time.sleep(0.2)
00089
00090 self.failIf(self.test_curr is None, "no data from test")
00091 self.assertEquals('/rosjava_node', self.test_curr.caller_id)
00092 self.assertEquals('/node0', self.test_curr.orig_caller_id)
00093 t = self.test_curr.header.stamp.to_sec()
00094
00095 self.assert_(abs(time.time() - t) < 60.)
00096
00097 if __name__ == '__main__':
00098 import rostest
00099 rostest.run(PKG, NAME, TestHeaderPassthrough, sys.argv)