gazebo_ros_pkgs/gazebo_plugins/test/camera/camera.cpp
TEST_F(CameraTest, cameraSubscribeTest)
{
  image_transport::ImageTransport it(nh_);
  cam_sub_ = it.subscribe("camera1/image_raw", 1,
                          &CameraTest::imageCallback,
                          dynamic_cast<CameraTest*>(this));

#if 0
  // wait for gazebo to start publishing
  // TODO(lucasw) this isn't really necessary since this test
  // is purely passive
  bool wait_for_topic = true;
  while (wait_for_topic)
  {
    // @todo this fails without the additional 0.5 second sleep after the
    // publisher comes online, which means on a slower or more heavily
    // loaded system it may take longer than 0.5 seconds, and the test
    // would hang until the timeout is reached and fail.
    if (cam_sub_.getNumPublishers() > 0)
       wait_for_topic = false;
    ros::Duration(0.5).sleep();
  }
#endif

  while (!has_new_image_)
  {
    ros::spinOnce();
    ros::Duration(0.1).sleep();
  }

  // This check depends on the update period being much longer
  // than the expected difference between now and the received image time
  // TODO(lucasw)
  // this likely isn't that robust - what if the testing system is really slow?
  double time_diff = (ros::Time::now() - image_stamp_).toSec();
  ROS_INFO_STREAM(time_diff);
  EXPECT_LT(time_diff, 1.0);
  cam_sub_.shutdown();
}
// Test if the camera image is published at all, and that the timestamp
// is not too long in the past.
Test if the camera image is published at all, and that the timestamp
is not too long in the past.
Test if the camera image is published at all and that the timestamp is not too long in the past .
TEST_F(CameraTest, cameraSubscribeTest)
{
  image_transport::ImageTransport it(nh_);
  cam_sub_ = it.subscribe("camera1/image_raw", 1,
                          &CameraTest::imageCallback,
                          dynamic_cast<CameraTest*>(this));
#if 0
  bool wait_for_topic = true;
  while (wait_for_topic)
  {
    if (cam_sub_.getNumPublishers() > 0)
       wait_for_topic = false;
    ros::Duration(0.5).sleep();
  }
#endif
  while (!has_new_image_)
  {
    ros::spinOnce();
    ros::Duration(0.1).sleep();
  }
  double time_diff = (ros::Time::now() - image_stamp_).toSec();
  ROS_INFO_STREAM(time_diff);
  EXPECT_LT(time_diff, 1.0);
  cam_sub_.shutdown();
}
TEST_F ( CameraTest , cameraSubscribeTest ) { image_transport :: ImageTransport it ( nh_ ) ; cam_sub_ = it . subscribe ( " " , 1 , & CameraTest :: imageCallback , dynamic_cast < CameraTest * > ( this ) ) ; #if 0 bool wait_for_topic = true ; while ( wait_for_topic ) { if ( cam_sub_ . getNumPublishers ( ) > 0 ) wait_for_topic = false ; ros :: Duration ( 0.5 ) . sleep ( ) ; } #endif while ( ! has_new_image_ ) { ros :: spinOnce ( ) ; ros :: Duration ( 0.1 ) . sleep ( ) ; } double time_diff = ( ros :: Time :: now ( ) - image_stamp_ ) . toSec ( ) ; ROS_INFO_STREAM ( time_diff ) ; EXPECT_LT ( time_diff , 1.0 ) ; cam_sub_ . shutdown ( ) ; }
Test if the camera image is published at all, and that the timestamp
is not too long in the past.
Test if the camera image is published at all and that the timestamp is not too long in the past .
// wait for gazebo to start publishing // TODO(lucasw) this isn't really necessary since this test // is purely passive // @todo this fails without the additional 0.5 second sleep after the // publisher comes online, which means on a slower or more heavily // loaded system it may take longer than 0.5 seconds, and the test // would hang until the timeout is reached and fail. // This check depends on the update period being much longer // than the expected difference between now and the received image time // TODO(lucasw) // this likely isn't that robust - what if the testing system is really slow?