test_cv_camera_no_yaml.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <sensor_msgs/CameraInfo.h>
00003 #include <sensor_msgs/Image.h>
00004 #include <gtest/gtest.h>
00005 
00006 sensor_msgs::Image g_image;
00007 sensor_msgs::CameraInfo g_camera_info;
00008 
00009 void ImageCallback(const sensor_msgs::Image::ConstPtr& image)
00010 {
00011   g_image = *image;
00012 }
00013 
00014 void InfoCallback(const sensor_msgs::CameraInfo::ConstPtr& info)
00015 {
00016   g_camera_info = *info;
00017 }
00018 
00019 TEST(CvCameraNode, getImage)
00020 {
00021   ros::NodeHandle node;
00022   ros::Subscriber sub = node.subscribe("/cv_camera_no_yaml/image_raw",
00023                                        1,
00024                                        &ImageCallback);
00025   ros::Rate r(10.0);
00026   while (sub.getNumPublishers() == 0) {
00027     r.sleep();
00028   }
00029   while (g_image.header.frame_id == "") {
00030     ros::spinOnce();
00031     r.sleep();
00032   }
00033   EXPECT_EQ("camera2", g_image.header.frame_id);
00034   EXPECT_EQ(480, g_image.height);
00035   EXPECT_EQ(640, g_image.width);
00036   EXPECT_EQ("bgr8", g_image.encoding);
00037 }
00038 
00039 TEST(CvCameraNode, getCameraInfo)
00040 {
00041   ros::NodeHandle node;
00042   ros::Subscriber sub = node.subscribe("/cv_camera_no_yaml/camera_info",
00043                                        1,
00044                                        &InfoCallback);
00045   ros::Rate r(10.0);
00046   while (sub.getNumPublishers() == 0) {
00047     r.sleep();
00048   }
00049   while (g_camera_info.header.frame_id == "") {
00050     ros::spinOnce();
00051     r.sleep();
00052   }
00053   EXPECT_EQ("camera2", g_camera_info.header.frame_id);
00054   // K
00055   EXPECT_EQ(9, g_camera_info.K.size());
00056   EXPECT_NEAR(0.0, g_camera_info.K.at(0), 0.001);
00057   EXPECT_NEAR(0.0, g_camera_info.K.at(1), 0.001);
00058   EXPECT_NEAR(0.0, g_camera_info.K.at(2), 0.001);
00059   // D
00060   EXPECT_EQ(0, g_camera_info.D.size());
00061 
00062   EXPECT_EQ("", g_camera_info.distortion_model);
00063 
00064   // width
00065   EXPECT_EQ(640, g_camera_info.width);
00066   EXPECT_EQ(480, g_camera_info.height);
00067 }
00068 
00069 int main(int argc, char **argv){
00070   ros::init(argc, argv, "test_cv_camera_no_yaml");
00071   testing::InitGoogleTest(&argc, argv);
00072   return RUN_ALL_TESTS();
00073 }


cv_camera
Author(s): Takashi Ogura
autogenerated on Wed Aug 26 2015 11:13:42