Skip to content

Commit

Permalink
Added rmw_logging tests (#442)
Browse files Browse the repository at this point in the history
* Added rmw_logging tests

Signed-off-by: ahcorde <ahcorde@gmail.com>

* Added feedback

Signed-off-by: ahcorde <ahcorde@gmail.com>

* Added feedback

Signed-off-by: ahcorde <ahcorde@gmail.com>
  • Loading branch information
ahcorde committed Oct 15, 2020
1 parent a2e3bfb commit 4fcffe3
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 45 additions & 0 deletions rmw_fastrtps_cpp/test/test_logging.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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_t>(RMW_LOG_SEVERITY_FATAL + 1));
EXPECT_EQ(ret, RMW_RET_ERROR);
}
4 changes: 4 additions & 0 deletions rmw_fastrtps_dynamic_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 45 additions & 0 deletions rmw_fastrtps_dynamic_cpp/test/test_logging.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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_t>(RMW_LOG_SEVERITY_FATAL + 1));
EXPECT_EQ(ret, RMW_RET_ERROR);
}
7 changes: 7 additions & 0 deletions rmw_fastrtps_shared_cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
48 changes: 48 additions & 0 deletions rmw_fastrtps_shared_cpp/test/test_logging.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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_t>(RMW_LOG_SEVERITY_FATAL + 1));
EXPECT_EQ(ret, RMW_RET_ERROR);
}

0 comments on commit 4fcffe3

Please sign in to comment.