Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_topic_tools] Test warnNoRemap #1244

Merged
merged 2 commits into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions jsk_topic_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,23 @@ add_library(jsk_topic_tools SHARED
add_dependencies(jsk_topic_tools ${PROJECT_NAME}_gencpp)
target_link_libraries(jsk_topic_tools ${catkin_LIBRARIES})

catkin_add_gtest(test_rosparam_utils src/tests/test_rosparam_utils.cpp)
target_link_libraries(test_rosparam_utils ${PROJECT_NAME})

add_rostest(test/test_topic_buffer.test)
add_rostest(test/test_topic_buffer_close_wait.test)
add_rostest(test/test_topic_buffer_fixed_rate.test)
add_rostest(test/test_topic_buffer_fixed_rate_and_update_rate.test)
add_rostest(test/test_topic_buffer_update_rate.test)
add_rostest(test/test_lightweight_throttle.test)
add_rostest(test/test_topic_compare.test)
add_rostest(test/test_hz_measure.test)
add_rostest(test/test_block.test)
add_rostest(test/test_connection_based_nodelet.test)
add_rostest(test/test_connection_based_transport.test)
if (CATKIN_ENABLE_TESTING)
add_rostest(test/test_topic_buffer.test)
add_rostest(test/test_topic_buffer_close_wait.test)
add_rostest(test/test_topic_buffer_fixed_rate.test)
add_rostest(test/test_topic_buffer_fixed_rate_and_update_rate.test)
add_rostest(test/test_topic_buffer_update_rate.test)
add_rostest(test/test_lightweight_throttle.test)
add_rostest(test/test_topic_compare.test)
add_rostest(test/test_hz_measure.test)
add_rostest(test/test_block.test)
add_rostest(test/test_connection_based_nodelet.test)
add_rostest(test/test_connection_based_transport.test)
catkin_add_nosetests(src/jsk_topic_tools/tests)
catkin_add_gtest(test_rosparam_utils src/tests/test_rosparam_utils.cpp)
target_link_libraries(test_rosparam_utils ${PROJECT_NAME})
add_rostest_gtest(test_log_utils test/test_log_utils.launch src/tests/test_log_utils.cpp)
target_link_libraries(test_log_utils ${PROJECT_NAME})
endif()

install(TARGETS topic_buffer_server topic_buffer_client jsk_topic_tools
Expand Down
3 changes: 2 additions & 1 deletion jsk_topic_tools/include/jsk_topic_tools/log_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ namespace jsk_topic_tools
/** @brief warn if there are expected remappings.
*
* @param[in] names Names which are expected to remapped.
* @return false if there is at least a topic which is not remapped, else true;
*/
void warnNoRemap(const std::vector<std::string> names);
bool warnNoRemap(const std::vector<std::string> names);

}
5 changes: 4 additions & 1 deletion jsk_topic_tools/src/log_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@
namespace jsk_topic_tools
{

void warnNoRemap(const std::vector<std::string> names)
bool warnNoRemap(const std::vector<std::string> names)
{
bool no_warning = true;
ros::M_string remappings = ros::names::getRemappings();
for (size_t i = 0; i < names.size(); i++) {
std::string resolved_name = ros::names::resolve(/*name=*/names[i],
/*_remap=*/false);
if (remappings.find(resolved_name) == remappings.end()) {
ROS_WARN("[%s] '%s' has not been remapped.",
ros::this_node::getName().c_str(), names[i].c_str());
no_warning = false;
}
}
return no_warning;
}

}
29 changes: 29 additions & 0 deletions jsk_topic_tools/src/tests/test_log_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "jsk_topic_tools/log_utils.h"
#include <ros/ros.h>
#include <std_msgs/Header.h>
#include <gtest/gtest.h>


TEST(LogUtils, testWarnNoRemap){
ros::NodeHandle pnh = ros::NodeHandle("~");
ros::Publisher pub_remap = pnh.advertise<std_msgs::Header>(
/*topic=*/"remap", /*queue_size=*/10);
ros::Publisher pub_noremap = pnh.advertise<std_msgs::Header>(
/*topic=*/"noremap", /*queue_size=*/10);

std::vector<std::string> topics;
topics.push_back(std::string("~remap"));
bool actual;
actual = jsk_topic_tools::warnNoRemap(topics);
EXPECT_EQ(true, actual);

topics.push_back(std::string("~noremap"));
actual = jsk_topic_tools::warnNoRemap(topics);
EXPECT_EQ(false, actual);
}

int main(int argc, char **argv){
ros::init(argc, argv, "simple_lookup_transform");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
12 changes: 12 additions & 0 deletions jsk_topic_tools/test/test_log_utils.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<launch>
<!--
This file should not be called from rostest but ``catkin run_tests``.
So the extension is .launch
-->

<test test-name="test_log_utils"
pkg="jsk_topic_tools" type="test_log_utils">
<remap from="~remap" to="~remapped" />
</test>

</launch>