Go to the documentation of this file.00001
00002 #include "fitting.h"
00003 #include <gtest/gtest.h>
00004 #include <ros/ros.h>
00005 #include <image_transport/image_transport.h>
00006 #include <geometry_msgs/Pose2D.h>
00007 #include <boost/shared_ptr.hpp>
00008 #include <cv_bridge/cv_bridge.h>
00009
00010 class TestImageResults : public testing::Test
00011 {
00012 protected:
00013 boost::shared_ptr<ros::NodeHandle> nh_;
00014 ros::Subscriber posesub_;
00015 geometry_msgs::Pose2D realpose_;
00016 bool receivedpose_;
00017
00018 virtual void SetUp() {
00019 receivedpose_ = false;
00020 nh_.reset(new ros::NodeHandle());
00021 posesub_ = nh_->subscribe("ellipse",1,&TestImageResults::posecb, this);
00022 }
00023 virtual void TearDown() {
00024 posesub_.shutdown();
00025 nh_.reset();
00026 }
00027 void posecb(const geometry_msgs::Pose2DConstPtr msg) {
00028 ASSERT_NEAR(msg->x,realpose_.x,0.5);
00029 ASSERT_NEAR(msg->y,realpose_.y,0.5);
00030 EXPECT_NEAR(msg->theta, realpose_.theta,0.2);
00031 receivedpose_ = true;
00032 }
00033 };
00034
00035 TEST_F(TestImageResults, SendImage) {
00036 image_transport::ImageTransport imgtrans(*nh_);
00037 image_transport::Publisher image_pub = imgtrans.advertise("image", 1);
00038 realpose_.x = 100;
00039 realpose_.y = 200;
00040 realpose_.theta = 0;
00041 receivedpose_ = false;
00042 cv_bridge::CvImagePtr cv_ptr;
00043
00044 image_pub.publish(cv_ptr->toImageMsg());
00045
00046 for(int i = 0; i < 1000; ++i) {
00047 if( receivedpose_ ) {
00048 break;
00049 }
00050 ros::spinOnce();
00051 usleep(1000);
00052 }
00053 ASSERT_TRUE(receivedpose_);
00054 }
00055
00056 int main(int argc, char **argv)
00057 {
00058 testing::InitGoogleTest(&argc, argv);
00059 ros::init(argc, argv, "testfitting");
00060 if( !ros::master::check() ) {
00061 return 1;
00062 }
00063 return RUN_ALL_TESTS();
00064 }