Go to the documentation of this file.00001
00002 """
00003 @file check_camera_transforms_publish_tf.py
00004 """
00005 import os
00006 import sys
00007 import unittest
00008 import time
00009 import rospy
00010 import rostest
00011 from rs_general.rs_general import get_camera_params_and_values, \
00012 is_log_contains_keyword, LOGFILE, shell_cmd_timeout
00013
00014 PKG = "realsense_camera"
00015 NAME = "test_camera_transforms_publish_tf"
00016
00017
00018 class CheckCameraTransformsPublishTf(unittest.TestCase):
00019 """
00020 @class CheckCameraTransformsPublishTf: check whether message exist
00021 or not based on disable/enable publish tf
00022 """
00023 def test_camera_transforms_publish_tf(self):
00024 """
00025 @fn test_camera_transforms_publish_tf
00026 @param self
00027 @return
00028 """
00029 rospy.init_node(NAME, anonymous=True, log_level=rospy.DEBUG)
00030 time.sleep(10)
00031 messages = expected_message.split(',')
00032 indicator = 0
00033 cmd = "rm ~/.ros/test_rostopic.log >/dev/null 2>&1"
00034 os.system(cmd)
00035 cmd = "rostopic echo /tf_static > ~/.ros/test_rostopic.log"
00036 shell_cmd_timeout(cmd, 5)
00037 for message in messages:
00038 if is_log_contains_keyword("~/.ros/test_rostopic.log", message):
00039 indicator = indicator + 1
00040 rospy.loginfo("***transforms publish info***: " + str(indicator))
00041 if indicator == len(messages) and is_log_contains_keyword(LOGFILE, publish_info):
00042 self.assertEqual('true', expected)
00043 elif indicator == 0 and not is_log_contains_keyword(LOGFILE, publish_info):
00044 self.assertEqual('false', expected)
00045 else:
00046 self.assertTrue(False)
00047
00048 if __name__ == '__main__':
00049 param_dict = get_camera_params_and_values(sys.argv)
00050 expected_message = param_dict['expected_messages']
00051 expected = param_dict['expected']
00052 publish_info = param_dict['info'].replace('*', ' ')
00053 rostest.rosrun(PKG, NAME, CheckCameraTransformsPublishTf, sys.argv)