Skip to content

Commit

Permalink
Modified tests to avoid memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Jaison Titus <jaisontj92@gmail.com>
  • Loading branch information
jaisontj committed Oct 4, 2019
1 parent 36e4a68 commit 25d4236
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
13 changes: 7 additions & 6 deletions rmw/include/rmw/rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,12 @@ rmw_count_subscribers(
size_t * count);

/**
* Retrieves a list of all publishers (described by the rmw_participants_t struct)
* publishing to a specific topic along with its respective qos profile.
* Retrieves a list of all publishers publishing to a specific topic along with its respective qos profile.
*
* None of the parameters provided to this function can be NULL.
* The node parameter must not be `NULL` and must point to a valid node.
*
* Incorrect or non existent topic names are allowed.
* The topic_name parameter must not be `NULL`.
* Incorrect or non existent topic names are allowed. They will return an empty array.
*
* \param[in] node the handle to the node being used to query the ROS graph.
* \param[in] topic_name the name of the topic for which the list of publishers will be retrieved.
Expand All @@ -920,9 +920,10 @@ rmw_get_qos_for_publishers(
* Retrieves a list of all subscribers (described by the rmw_participants_t struct)
* subscribing to a specific topic along with its respective qos profile.
*
* None of the parameters provided to this function can be NULL.
* The node parameter must not be `NULL` and must point to a valid node.
*
* Incorrect or non existent topic names are allowed.
* The topic_name parameter must not be `NULL`.
* Incorrect or non existent topic names are allowed. They will return an empty array.
*
* \param[in] node the handle to the node being used to query the ROS graph.
* \param[in] topic_name the name of the topic for which the list of subscribers will be retrieved.
Expand Down
2 changes: 1 addition & 1 deletion rmw/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<test_depend>osrf_testing_tools_cpp</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down
4 changes: 3 additions & 1 deletion rmw/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
find_package(ament_cmake_gmock REQUIRED)
find_package(osrf_testing_tools_cpp REQUIRED)

ament_add_gmock(test_serialized_message
test_serialized_message.cpp
Expand Down Expand Up @@ -48,5 +49,6 @@ ament_add_gmock(test_rmw_participant_qos_profile_allocator
APPEND_LIBRARY_DIRS "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)
if(TARGET test_rmw_participant_qos_profile_allocator)
target_link_libraries(test_rmw_participant_qos_profile_allocator ${PROJECT_NAME})
target_link_libraries(test_rmw_participant_qos_profile_allocator ${PROJECT_NAME}
osrf_testing_tools_cpp::memory_tools)
endif()
18 changes: 14 additions & 4 deletions rmw/test/test_rmw_participant_qos_profile_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@

#include "gtest/gtest.h"

#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rmw/allocators.h"
#include "rmw/types.h"

TEST(test_rmw_participant_qos_profile_allocator, test_allocate_does_not_return_null) {
rmw_participant_qos_profile_t * qos_profile = rmw_participant_qos_profile_allocate();
ASSERT_TRUE(qos_profile != NULL);
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
delete (qos_profile);
});
EXPECT_NE(qos_profile, nullptr);
}

TEST(test_rmw_participant_qos_profile_allocator, test_allocate_allocates_different_pointers) {
rmw_participant_qos_profile_t * qos_profile1 = rmw_participant_qos_profile_allocate();
rmw_participant_qos_profile_t * qos_profile2 = rmw_participant_qos_profile_allocate();
ASSERT_TRUE(qos_profile1 != qos_profile2);
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
delete (qos_profile1);
delete (qos_profile2);
});
EXPECT_NE(qos_profile1, qos_profile2);
}

TEST(test_rmw_participant_qos_profile_allocator, test_free_null) {
EXPECT_NO_THROW(rmw_participant_qos_profile_free(NULL));
rmw_participant_qos_profile_free(NULL);
SUCCEED();
}

TEST(test_rmw_participant_qos_profile_allocator, test_free_allocated) {
rmw_participant_qos_profile_t * qos_profile = rmw_participant_qos_profile_allocate();
EXPECT_NO_THROW(rmw_participant_qos_profile_free(qos_profile));
rmw_participant_qos_profile_free(qos_profile);
SUCCEED();
}

0 comments on commit 25d4236

Please sign in to comment.