test_composite_passthrough.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2011, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 # Revision $Id: test_empty_service.py 3803 2009-02-11 02:04:39Z rob_wheeler $
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         # 20 seconds to validate fixture
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         # another 20 seconds to validate client
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         # a.w = a.x + a.y + a.z.  Just make sure we're in the ballpark
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)


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49