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 = 'composite_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 Composite
00049
00050 class CompositePassthrough(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('composite_in', Composite, self.cb_from_fixture)
00059 rospy.Subscriber('composite_out', Composite, 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_composite_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 m = self.fixture_curr
00080 self.assertAlmostEquals(m.a.x, m.b.x)
00081 self.assertAlmostEquals(m.a.y, m.b.y)
00082 self.assertAlmostEquals(m.a.z, m.b.z)
00083
00084
00085 timeout_t = time.time() + 20.
00086 print "waiting for 20 seconds for client to verify"
00087 while self.test_curr is None and \
00088 not rospy.is_shutdown() and \
00089 timeout_t > time.time():
00090 time.sleep(0.2)
00091
00092 self.failIf(self.test_curr is None, "no data from test")
00093 m = self.test_curr
00094 self.assertAlmostEquals(m.a.x, m.b.x)
00095 self.assertAlmostEquals(m.a.y, m.b.y)
00096 self.assertAlmostEquals(m.a.z, m.b.z)
00097
00098
00099 a = self.test_curr.a
00100 self.assert_(abs(a.x + a.y + a.z - a.w) < 10.)
00101
00102 if __name__ == '__main__':
00103 import rostest
00104 rostest.run(PKG, NAME, CompositePassthrough, sys.argv)