Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Use standard CMake macros for adding gtest/gmock tests (#33)
Browse files Browse the repository at this point in the history
* modify kinesis_video_streamer to use add_rostest_gmock()

Signed-off-by: Miaofei <miaofei@amazon.com>

* update travis.yml to be compatible with specifying multiple package names

Signed-off-by: Miaofei <miaofei@amazon.com>
  • Loading branch information
mm318 authored and ross-desmond committed Jun 27, 2019
1 parent ffc89d1 commit 76a15d7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ notifications:
env:
global:
- GITHUB_ACCOUNT=aws-robotics
# uncomment PACKAGE_NAME to build unit tests - REQUIRED if you'd like to run unit tests using colcon
- PACKAGE_NAME=kinesis_video_streamer
# uncomment PACKAGE_NAMES to build unit tests - REQUIRED if you'd like to run unit tests using colcon
- PACKAGE_NAMES=kinesis_video_streamer
matrix:
# define DOWNSTREAM_GITHUB_REPO=name-of-your-repo if you'd like to trigger downstream repos' travis builds
- ROS_DISTRO=kinetic ROS_VERSION=1
Expand Down
74 changes: 50 additions & 24 deletions kinesis_video_streamer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,55 @@ install(FILES kvs_log_configuration DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATI
#############

if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)

add_rostest_gtest(test_kinesis_video_streamer
test/test_kinesis_video_streamer.test
test/kinesis_video_streamer_test.cpp)
target_include_directories(test_kinesis_video_streamer PRIVATE include ${catkin_INCLUDE_DIRS} ${kinesis_manager_INCLUDE_DIRS})
target_link_libraries(test_kinesis_video_streamer
${PROJECT_NAME}_lib
${catkin_LIBRARIES})
find_package(GMock QUIET)
if(GMOCK_FOUND)
add_rostest_gmock(test_streamer_node
find_package(rostest REQUIRED)
add_rostest_gtest(test_kinesis_video_streamer
test/test_kinesis_video_streamer.test
test/kinesis_video_streamer_test.cpp
)
target_include_directories(test_kinesis_video_streamer PRIVATE
include
${catkin_INCLUDE_DIRS}
${kinesis_manager_INCLUDE_DIRS}
)
target_link_libraries(test_kinesis_video_streamer
${PROJECT_NAME}_lib
${catkin_LIBRARIES}
)

find_package(GMock QUIET)
if(GMOCK_FOUND)
add_rostest_gmock(test_streamer_node
test/test_streamer_node.test
test/streamer_node_test.cpp)
target_include_directories(test_streamer_node PRIVATE include ${catkin_INCLUDE_DIRS} ${kinesis_manager_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS})
target_link_libraries(test_streamer_node ${PROJECT_NAME}_lib ${catkin_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
else()
include_directories(/usr/include/gmock /usr/src/gmock)
add_library(${PROJECT_NAME}_libgmock /usr/src/gmock/src/gmock-all.cc)
add_rostest_gtest(test_streamer_node
test/test_streamer_node.test
test/streamer_node_test.cpp)
target_include_directories(test_streamer_node PRIVATE include ${catkin_INCLUDE_DIRS} ${kinesis_manager_INCLUDE_DIRS})
target_link_libraries(test_streamer_node ${PROJECT_NAME}_lib ${catkin_LIBRARIES} ${PROJECT_NAME}_libgmock)
endif()
test/streamer_node_test.cpp
)
target_include_directories(test_streamer_node PRIVATE
include
${catkin_INCLUDE_DIRS}
${kinesis_manager_INCLUDE_DIRS}
${GMOCK_INCLUDE_DIRS}
)
target_link_libraries(test_streamer_node
${PROJECT_NAME}_lib
${catkin_LIBRARIES}
${GMOCK_BOTH_LIBRARIES}
)
else()
include_directories(/usr/include/gmock /usr/src/gmock)
add_library(${PROJECT_NAME}_libgmock SHARED /usr/src/gmock/src/gmock-all.cc)

add_rostest_gtest(test_streamer_node
test/test_streamer_node.test
test/streamer_node_test.cpp
)
target_include_directories(test_streamer_node PRIVATE
include
${catkin_INCLUDE_DIRS}
${kinesis_manager_INCLUDE_DIRS}
)
target_link_libraries(test_streamer_node
${PROJECT_NAME}_lib
${catkin_LIBRARIES}
${PROJECT_NAME}_libgmock
)
endif()
endif()
7 changes: 5 additions & 2 deletions kinesis_video_streamer/package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<package format="2">
<package format="3">
<name>kinesis_video_streamer</name>
<version>2.0.1</version>
<description>Kinesis Video Streams producer node</description>
Expand All @@ -10,7 +10,6 @@

<license>Apache 2.0</license>


<buildtool_depend>catkin</buildtool_depend>

<depend>aws_common</depend>
Expand All @@ -21,6 +20,10 @@
<depend>image_transport</depend>
<depend>std_msgs</depend>

<test_depend condition="$ROS_VERSION == 1">gtest</test_depend>
<test_depend condition="$ROS_VERSION == 1">google-mock</test_depend>
<test_depend condition="$ROS_VERSION == 2">ament_cmake_gtest</test_depend>
<test_depend condition="$ROS_VERSION == 2">ament_cmake_gmock</test_depend>
<test_depend>rostest</test_depend>
<test_depend>rostopic</test_depend>
</package>

0 comments on commit 76a15d7

Please sign in to comment.