Skip to content

Commit

Permalink
Add test coverage for name mangling and namespacing-specific API.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed May 18, 2020
1 parent 6f20a4d commit be31779
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rmw_fastrtps_shared_cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ if(TARGET test_rmw_init_options)
ament_target_dependencies(test_rmw_init_options osrf_testing_tools_cpp rcutils rmw)
target_link_libraries(test_rmw_init_options ${PROJECT_NAME})
endif()

ament_add_gtest(test_names test_names.cpp)
if(TARGET test_names)
ament_target_dependencies(test_names rmw)
target_link_libraries(test_names ${PROJECT_NAME})
endif()
53 changes: 53 additions & 0 deletions rmw_fastrtps_shared_cpp/test/test_names.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020 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 "gtest/gtest.h"

#include "rmw/qos_profiles.h"

#include "rmw_fastrtps_shared_cpp/names.hpp"
#include "rmw_fastrtps_shared_cpp/namespace_prefix.hpp"

TEST(NamespaceTest, get_prefix) {
EXPECT_EQ("", _get_ros_prefix_if_exists(""));
for (const auto & prefix : _get_all_ros_prefixes()) {
EXPECT_EQ(prefix, _get_ros_prefix_if_exists(prefix + "/test"));
}
}

TEST(NamespaceTest, strip_prefix) {
EXPECT_EQ("/no_prefix/test", _strip_ros_prefix_if_exists("/no_prefix/test"));
for (const auto & prefix : _get_all_ros_prefixes()) {
EXPECT_EQ("/test", _strip_ros_prefix_if_exists(prefix + "/test"));
}
}

TEST(NamespaceTest, resolve_prefix) {
EXPECT_EQ("", _resolve_prefix("/test", "some_ros_prefix"));
EXPECT_EQ(
"/test_some_ros_prefix",
_resolve_prefix("some_ros_prefix/test_some_ros_prefix", "some_ros_prefix"));
}

TEST(NamespaceTest, name_mangling) {
rmw_qos_profile_t qos_profile = rmw_qos_profile_unknown;
qos_profile.avoid_ros_namespace_conventions = false;
EXPECT_STREQ(
"some_ros_prefix/test__suffix", _create_topic_name(
&qos_profile, "some_ros_prefix", "/test", "__suffix").c_str());
qos_profile.avoid_ros_namespace_conventions = true;
EXPECT_STREQ(
"/test__suffix", _create_topic_name(
&qos_profile, "some_ros_prefix", "/test", "__suffix").c_str());
}

0 comments on commit be31779

Please sign in to comment.