diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index 9db174e..b8b630f 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -100,6 +100,14 @@ function(test_target_function) LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries} AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs" ) + + rcl_add_custom_gtest(test_wait${target_suffix} + SRCS rcl/test_wait.cpp + ENV ${extra_test_env} + APPEND_LIBRARY_DIRS ${extra_lib_dirs} + LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries} + AMENT_DEPENDENCIES ${rmw_implementation} + ) endfunction() call_for_each_rmw_implementation(test_target) diff --git a/rcl/test/rcl/test_wait.cpp b/rcl/test/rcl/test_wait.cpp new file mode 100644 index 0000000..28e96db --- /dev/null +++ b/rcl/test/rcl/test_wait.cpp @@ -0,0 +1,43 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#include + +#include "rcl/rcl.h" +#include "rcl/error_handling.h" +#include "rcl/wait.h" + +#ifdef RMW_IMPLEMENTATION +# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX +# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) +#else +# define CLASSNAME(NAME, SUFFIX) NAME +#endif + + +TEST(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_resize_to_zero) { + // Initialize a waitset with a subscription and then resize it to zero. + rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); + rcl_ret_t ret = rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, rcl_get_default_allocator()); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); + + ret = rcl_wait_set_resize_subscriptions(&wait_set, 0); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); + + EXPECT_EQ(wait_set.size_of_subscriptions, 0); + + ret = rcl_wait_set_fini(&wait_set); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); +}