Skip to content

Commit 9fd2c27

Browse files
hidmicahcorde
authored andcommitted
Add test_rmw_implementation package. (#106)
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 67f63c8 commit 9fd2c27

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(test_rmw_implementation)
4+
5+
# Default to C++14
6+
if(NOT CMAKE_CXX_STANDARD)
7+
set(CMAKE_CXX_STANDARD 14)
8+
endif()
9+
10+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
11+
add_compile_options(-Wall -Wextra -Wpedantic)
12+
endif()
13+
14+
find_package(ament_cmake REQUIRED)
15+
16+
if(BUILD_TESTING)
17+
find_package(ament_cmake_gtest REQUIRED)
18+
find_package(osrf_testing_tools_cpp REQUIRED)
19+
20+
find_package(rcutils REQUIRED)
21+
find_package(rmw REQUIRED)
22+
find_package(rmw_implementation REQUIRED)
23+
find_package(rmw_implementation_cmake REQUIRED)
24+
25+
macro(test_api)
26+
find_package(${rmw_implementation} REQUIRED)
27+
message(STATUS "Creating API tests for '${rmw_implementation}'")
28+
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})
29+
30+
ament_add_gtest(test_init_shutdown${target_suffix}
31+
test/test_init_shutdown.cpp
32+
ENV ${rmw_implementation_env_var}
33+
)
34+
target_compile_definitions(test_init_shutdown${target_suffix}
35+
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
36+
ament_target_dependencies(test_init_shutdown${target_suffix}
37+
osrf_testing_tools_cpp rcutils rmw rmw_implementation
38+
)
39+
endmacro()
40+
41+
call_for_each_rmw_implementation(test_api)
42+
43+
find_package(ament_lint_auto REQUIRED)
44+
ament_lint_auto_find_test_dependencies()
45+
endif()
46+
47+
ament_package()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>test_rmw_implementation</name>
5+
<version>0.1.0</version>
6+
<description>Test suite for ROS middleware API.</description>
7+
<maintainer email="[email protected]">Michel Hidalgo</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
<buildtool_depend>rmw_implementation_cmake</buildtool_depend>
12+
13+
<test_depend>ament_lint_auto</test_depend>
14+
<test_depend>ament_lint_common</test_depend>
15+
<test_depend>osrf_testing_tools_cpp</test_depend>
16+
<test_depend>rcutils</test_depend>
17+
<test_depend>rmw</test_depend>
18+
<test_depend>rmw_implementation</test_depend>
19+
20+
<export>
21+
<build_type>ament_cmake</build_type>
22+
</export>
23+
</package>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <gtest/gtest.h>
16+
17+
#include "osrf_testing_tools_cpp/scope_exit.hpp"
18+
19+
#include "rcutils/allocator.h"
20+
#include "rcutils/error_handling.h"
21+
22+
#include "rmw/rmw.h"
23+
24+
#ifdef RMW_IMPLEMENTATION
25+
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
26+
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
27+
#else
28+
# define CLASSNAME(NAME, SUFFIX) NAME
29+
#endif
30+
31+
class CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION) : public ::testing::Test {};
32+
33+
TEST_F(CLASSNAME(TestInitShutdown, RMW_IMPLEMENTATION), init_shutdown) {
34+
rmw_context_t context = rmw_get_zero_initialized_context();
35+
rmw_init_options_t options = rmw_get_zero_initialized_init_options();
36+
rmw_ret_t ret = rmw_init_options_init(&options, rcutils_get_default_allocator());
37+
ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str;
38+
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
39+
{
40+
rmw_ret_t ret = rmw_init_options_fini(&options);
41+
EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str;
42+
});
43+
44+
ret = rmw_init(&options, &context);
45+
ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str;
46+
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
47+
{
48+
rmw_ret_t ret = rmw_context_fini(&context);
49+
EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str;
50+
});
51+
52+
ret = rmw_shutdown(&context);
53+
EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str;
54+
}

0 commit comments

Comments
 (0)