From 4cad05b43fe0a3e18bc37ce56b9f7f37d079a31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 25 Sep 2020 16:34:54 +0200 Subject: [PATCH] Added rmw_logging tests (#442) * Added rmw_logging tests Signed-off-by: ahcorde * Added feedback Signed-off-by: ahcorde * Added feedback Signed-off-by: ahcorde --- rmw_fastrtps_cpp/CMakeLists.txt | 4 ++ rmw_fastrtps_cpp/test/test_logging.cpp | 45 +++++++++++++++++ rmw_fastrtps_dynamic_cpp/CMakeLists.txt | 4 ++ .../test/test_logging.cpp | 45 +++++++++++++++++ rmw_fastrtps_shared_cpp/test/CMakeLists.txt | 7 +++ rmw_fastrtps_shared_cpp/test/test_logging.cpp | 48 +++++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 rmw_fastrtps_cpp/test/test_logging.cpp create mode 100644 rmw_fastrtps_dynamic_cpp/test/test_logging.cpp create mode 100644 rmw_fastrtps_shared_cpp/test/test_logging.cpp diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 86dd0bf88..f92952380 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -145,6 +145,10 @@ if(BUILD_TESTING) osrf_testing_tools_cpp rcutils rmw test_msgs ) target_link_libraries(test_get_native_entities rmw_fastrtps_cpp) + + ament_add_gtest(test_logging test/test_logging.cpp) + ament_target_dependencies(test_logging rmw) + target_link_libraries(test_logging rmw_fastrtps_cpp) endif() ament_package( diff --git a/rmw_fastrtps_cpp/test/test_logging.cpp b/rmw_fastrtps_cpp/test/test_logging.cpp new file mode 100644 index 000000000..cd1068094 --- /dev/null +++ b/rmw_fastrtps_cpp/test/test_logging.cpp @@ -0,0 +1,45 @@ +// 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 + +#include "fastrtps/log/Log.h" + +#include "rmw/rmw.h" +#include "rmw/error_handling.h" + +TEST(TestLogging, rmw_logging) +{ + rmw_ret_t ret = rmw_set_log_severity(RMW_LOG_SEVERITY_DEBUG); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_INFO); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_WARN); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Warning, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_ERROR); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_FATAL); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); +} + +TEST(TestLogging, rmw_logging_bad_verbosity) +{ + rmw_ret_t ret = rmw_set_log_severity(static_cast(RMW_LOG_SEVERITY_FATAL + 1)); + EXPECT_EQ(ret, RMW_RET_ERROR); +} diff --git a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt index 4854050c3..44517187f 100644 --- a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt +++ b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt @@ -155,6 +155,10 @@ if(BUILD_TESTING) osrf_testing_tools_cpp rcutils rmw test_msgs ) target_link_libraries(test_get_native_entities rmw_fastrtps_dynamic_cpp) + + ament_add_gtest(test_logging test/test_logging.cpp) + ament_target_dependencies(test_logging rmw) + target_link_libraries(test_logging rmw_fastrtps_dynamic_cpp) endif() ament_package( diff --git a/rmw_fastrtps_dynamic_cpp/test/test_logging.cpp b/rmw_fastrtps_dynamic_cpp/test/test_logging.cpp new file mode 100644 index 000000000..cd1068094 --- /dev/null +++ b/rmw_fastrtps_dynamic_cpp/test/test_logging.cpp @@ -0,0 +1,45 @@ +// 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 + +#include "fastrtps/log/Log.h" + +#include "rmw/rmw.h" +#include "rmw/error_handling.h" + +TEST(TestLogging, rmw_logging) +{ + rmw_ret_t ret = rmw_set_log_severity(RMW_LOG_SEVERITY_DEBUG); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_INFO); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_WARN); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Warning, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_ERROR); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_set_log_severity(RMW_LOG_SEVERITY_FATAL); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); +} + +TEST(TestLogging, rmw_logging_bad_verbosity) +{ + rmw_ret_t ret = rmw_set_log_severity(static_cast(RMW_LOG_SEVERITY_FATAL + 1)); + EXPECT_EQ(ret, RMW_RET_ERROR); +} diff --git a/rmw_fastrtps_shared_cpp/test/CMakeLists.txt b/rmw_fastrtps_shared_cpp/test/CMakeLists.txt index 3db9b12e6..0c71dc1dc 100644 --- a/rmw_fastrtps_shared_cpp/test/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/test/CMakeLists.txt @@ -29,3 +29,10 @@ if(TARGET test_names) ament_target_dependencies(test_names rmw) target_link_libraries(test_names ${PROJECT_NAME}) endif() + +ament_add_gtest(test_logging test_logging.cpp) +if(TARGET test_logging) + ament_target_dependencies(test_logging + osrf_testing_tools_cpp rcutils rmw) + target_link_libraries(test_logging rmw_fastrtps_shared_cpp) +endif() diff --git a/rmw_fastrtps_shared_cpp/test/test_logging.cpp b/rmw_fastrtps_shared_cpp/test/test_logging.cpp new file mode 100644 index 000000000..4401d290b --- /dev/null +++ b/rmw_fastrtps_shared_cpp/test/test_logging.cpp @@ -0,0 +1,48 @@ +// 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 + +#include "fastrtps/log/Log.h" + +#include "rmw/rmw.h" +#include "rmw/error_handling.h" + +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + +TEST(TestLogging, rmw_logging) +{ + rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity(RMW_LOG_SEVERITY_DEBUG); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity(RMW_LOG_SEVERITY_INFO); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Info, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity(RMW_LOG_SEVERITY_WARN); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Warning, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity(RMW_LOG_SEVERITY_ERROR); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); + ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity(RMW_LOG_SEVERITY_FATAL); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(eprosima::fastrtps::Log::Kind::Error, eprosima::fastrtps::Log::GetVerbosity()); +} + +TEST(TestLogging, rmw_logging_bad_verbosity) +{ + rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_set_log_severity( + static_cast(RMW_LOG_SEVERITY_FATAL + 1)); + EXPECT_EQ(ret, RMW_RET_ERROR); +}