Skip to content

Commit 895e736

Browse files
committed
Port image_encodings tests from ROS1.
Signed-off-by: Michael Carroll <[email protected]>
1 parent ce3ff8c commit 895e736

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

sensor_msgs/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ if(BUILD_TESTING)
6565
ament_lint_auto_find_test_dependencies()
6666

6767
include_directories(include)
68-
ament_add_gtest(test_pointcloud
68+
ament_add_gtest(test_sensor_msgs
69+
test/test_image_encodings.cpp
6970
test/test_pointcloud_conversion.cpp
7071
test/test_pointcloud_iterator.cpp)
71-
if(TARGET test_pointcloud)
72-
rosidl_target_interfaces(test_pointcloud ${PROJECT_NAME} "rosidl_typesupport_cpp")
72+
if(TARGET test_sensor_msgs)
73+
rosidl_target_interfaces(test_sensor_msgs ${PROJECT_NAME} "rosidl_typesupport_cpp")
7374
endif()
7475
endif()
7576

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2016, Kentaro Wada
2+
// All rights reserved.
3+
//
4+
// Software License Agreement (BSD License 2.0)
5+
//
6+
// Redistribution and use in source and binary forms, with or without
7+
// modification, are permitted provided that the following conditions
8+
// are met:
9+
//
10+
// * Redistributions of source code must retain the above copyright
11+
// notice, this list of conditions and the following disclaimer.
12+
// * Redistributions in binary form must reproduce the above
13+
// copyright notice, this list of conditions and the following
14+
// disclaimer in the documentation and/or other materials provided
15+
// with the distribution.
16+
// * Neither the name of the copyright holder nor the names of its
17+
// contributors may be used to endorse or promote products derived
18+
// from this software without specific prior written permission.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23+
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24+
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25+
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26+
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30+
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
// POSSIBILITY OF SUCH DAMAGE.
32+
33+
// this file is originally ported from ROS1:
34+
// https://github.com/ros/common_msgs/blob/53579e6bba3d7f692949227fc4fe06cf47689f3a/sensor_msgs/test/test_image_encodings.cpp
35+
36+
#include <gtest/gtest.h>
37+
#include "sensor_msgs/image_encodings.hpp"
38+
39+
TEST(sensor_msgs, NumChannels)
40+
{
41+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("mono8"), 1);
42+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("rgb8"), 3);
43+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("8UC"), 1);
44+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("8UC3"), 3);
45+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("8UC10"), 10);
46+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("16UC"), 1);
47+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("16UC3"), 3);
48+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("16UC10"), 10);
49+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("32SC"), 1);
50+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("32SC3"), 3);
51+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("32SC10"), 10);
52+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC"), 1);
53+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC3"), 3);
54+
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC10"), 10);
55+
}
56+
57+
TEST(sensor_msgs, bitDepth)
58+
{
59+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("mono8"), 8);
60+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("rgb8"), 8);
61+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("8UC"), 8);
62+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("8UC3"), 8);
63+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("8UC10"), 8);
64+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("16UC"), 16);
65+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("16UC3"), 16);
66+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("16UC10"), 16);
67+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("32SC"), 32);
68+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("32SC3"), 32);
69+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("32SC10"), 32);
70+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC"), 64);
71+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC3"), 64);
72+
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC10"), 64);
73+
}

0 commit comments

Comments
 (0)