37 #include <gtest/gtest.h> 54 TEST(ConvertTest, setupLibrary)
57 const float scan_time = 1.0/30.0;
59 const float range_min = 0.45;
60 const float range_max = 10.0;
62 const int scan_height = 1;
64 const std::string output_frame =
"camera_depth_frame";
76 uint16_t value = 0x0F;
79 info_msg_.reset(
new sensor_msgs::CameraInfo);
83 info_msg_->distortion_model =
"plumb_bob";
102 EXPECT_EQ(scan_msg->scan_time, scan_time);
103 EXPECT_EQ(scan_msg->range_min, range_min);
104 EXPECT_EQ(scan_msg->range_max, range_max);
105 EXPECT_EQ(scan_msg->header.frame_id, output_frame);
106 EXPECT_EQ(scan_msg->ranges.size(),
depth_msg_->width);
110 TEST(ConvertTest, testExceptions)
123 TEST(ConvertTest, testScanHeight)
125 for(
int scan_height = 1; scan_height <= 100; scan_height++){
126 uint16_t low_value = 500;
127 uint16_t high_value = 3000;
130 uint16_t* data =
reinterpret_cast<uint16_t*
>(&
depth_msg_->data[0]);
131 int row_step =
depth_msg_->step /
sizeof(uint16_t);
135 int offset = (int)(
info_msg_->K[5]-scan_height/2);
136 data += offset*row_step;
138 for(
int v = 0; v < scan_height; v++, data += row_step){
139 for (
int u = 0; u < data_len; u++)
141 if(v % scan_height == u % scan_height){
144 data[u] = high_value;
153 float high_float_thresh = (float)high_value * 1.0
f/1000.0
f * 0.9
f;
154 for(
size_t i = 0; i < scan_msg->ranges.size(); i++){
156 if(scan_msg->range_min <= scan_msg->ranges[i] && scan_msg->ranges[i] <= scan_msg->range_max){
158 ASSERT_LT(scan_msg->ranges[i], high_float_thresh);
174 uint16_t* data =
reinterpret_cast<uint16_t*
>(&
depth_msg_->data[0]);
176 data[i] = rand() % 500;
183 for(
size_t i = 0; i < scan_msg->ranges.size(); i++){
184 if(std::isfinite(scan_msg->ranges[i])){
185 ASSERT_GE(scan_msg->ranges[i], scan_msg->range_min);
186 ASSERT_LE(scan_msg->ranges[i], scan_msg->range_max);
195 sensor_msgs::ImagePtr float_msg(
new sensor_msgs::Image(*
depth_msg_));
197 float_msg->step = float_msg->width*4;
198 float_msg->data.resize(float_msg->step * float_msg->height);
200 float* data =
reinterpret_cast<float*
>(&float_msg->data[0]);
201 for(
size_t i = 0; i < float_msg->width*float_msg->height; i++){
202 data[i] = std::numeric_limits<float>::quiet_NaN();
209 for(
size_t i = 0; i < scan_msg->ranges.size(); i++){
210 if(std::isfinite(scan_msg->ranges[i])){
211 ADD_FAILURE() <<
"Non-NaN value produced from NaN test.";
217 TEST(ConvertTest, testPositiveInf)
220 sensor_msgs::ImagePtr float_msg(
new sensor_msgs::Image(*
depth_msg_));
222 float_msg->step = float_msg->width*4;
223 float_msg->data.resize(float_msg->step * float_msg->height);
225 float* data =
reinterpret_cast<float*
>(&float_msg->data[0]);
226 for(
size_t i = 0; i < float_msg->width*float_msg->height; i++){
227 data[i] = std::numeric_limits<float>::infinity();
234 size_t nan_count = 0;
235 for(
size_t i = 0; i < scan_msg->ranges.size(); i++){
236 if(std::isfinite(scan_msg->ranges[i])){
237 ADD_FAILURE() <<
"Non-finite value produced from postive infniity test.";
238 }
else if(std::isnan(scan_msg->ranges[i])){
240 }
else if(scan_msg->ranges[i] < 0){
241 ADD_FAILURE() <<
"Negative value produced from postive infinity test.";
245 ASSERT_LE(nan_count, scan_msg->ranges.size() * 0.80);
249 TEST(ConvertTest, testNegativeInf)
252 sensor_msgs::ImagePtr float_msg(
new sensor_msgs::Image(*
depth_msg_));
254 float_msg->step = float_msg->width*4;
255 float_msg->data.resize(float_msg->step * float_msg->height);
257 float* data =
reinterpret_cast<float*
>(&float_msg->data[0]);
258 for(
size_t i = 0; i < float_msg->width*float_msg->height; i++){
259 data[i] = -std::numeric_limits<float>::infinity();
266 size_t nan_count = 0;
267 for(
size_t i = 0; i < scan_msg->ranges.size(); i++){
268 if(std::isfinite(scan_msg->ranges[i])){
269 ADD_FAILURE() <<
"Non-finite value produced from postive infniity test.";
270 }
else if(std::isnan(scan_msg->ranges[i])){
272 }
else if(scan_msg->ranges[i] > 0){
273 ADD_FAILURE() <<
"Postive value produced from negative infinity test.";
277 ASSERT_LE(nan_count, scan_msg->ranges.size() * 0.80);
282 int main(
int argc,
char **argv){
283 testing::InitGoogleTest(&argc, argv);
284 return RUN_ALL_TESTS();
int main(int argc, char **argv)
sensor_msgs::LaserScanPtr convert_msg(const sensor_msgs::ImageConstPtr &depth_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
void set_output_frame(const std::string output_frame_id)
void set_scan_height(const int scan_height)
const std::string TYPE_32FC1
const std::string TYPE_16UC1
TEST(ConvertTest, setupLibrary)
sensor_msgs::CameraInfoPtr info_msg_
depthimage_to_laserscan::DepthImageToLaserScan dtl_
void set_scan_time(const float scan_time)
void set_range_limits(const float range_min, const float range_max)
sensor_msgs::ImagePtr depth_msg_