Skip to content

Commit f3b5b72

Browse files
committed
Modified tests to avoid memory leak
Signed-off-by: Jaison Titus <[email protected]>
1 parent 36e4a68 commit f3b5b72

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

rmw/include/rmw/rmw.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,12 @@ rmw_count_subscribers(
894894
size_t * count);
895895

896896
/**
897-
* Retrieves a list of all publishers (described by the rmw_participants_t struct)
898-
* publishing to a specific topic along with its respective qos profile.
897+
* Retrieves a list of all publishers publishing to a specific topic along with its respective qos profile.
899898
*
900-
* None of the parameters provided to this function can be NULL.
899+
* The node parameter must not be `NULL` and must point to a valid node.
901900
*
902-
* Incorrect or non existent topic names are allowed.
901+
* The topic_name parameter must not be `NULL`.
902+
* Incorrect or non existent topic names are allowed. They will return an empty array.
903903
*
904904
* \param[in] node the handle to the node being used to query the ROS graph.
905905
* \param[in] topic_name the name of the topic for which the list of publishers will be retrieved.
@@ -920,9 +920,10 @@ rmw_get_qos_for_publishers(
920920
* Retrieves a list of all subscribers (described by the rmw_participants_t struct)
921921
* subscribing to a specific topic along with its respective qos profile.
922922
*
923-
* None of the parameters provided to this function can be NULL.
923+
* The node parameter must not be `NULL` and must point to a valid node.
924924
*
925-
* Incorrect or non existent topic names are allowed.
925+
* The topic_name parameter must not be `NULL`.
926+
* Incorrect or non existent topic names are allowed. They will return an empty array.
926927
*
927928
* \param[in] node the handle to the node being used to query the ROS graph.
928929
* \param[in] topic_name the name of the topic for which the list of subscribers will be retrieved.

rmw/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<test_depend>ament_cmake_gmock</test_depend>
2020
<test_depend>ament_lint_auto</test_depend>
2121
<test_depend>ament_lint_common</test_depend>
22-
22+
<test_depend>osrf_testing_tools_cpp</test_depend>
2323
<export>
2424
<build_type>ament_cmake</build_type>
2525
</export>

rmw/test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
find_package(ament_cmake_gmock REQUIRED)
2+
find_package(osrf_testing_tools_cpp REQUIRED)
23

34
ament_add_gmock(test_serialized_message
45
test_serialized_message.cpp
@@ -48,5 +49,6 @@ ament_add_gmock(test_rmw_participant_qos_profile_allocator
4849
APPEND_LIBRARY_DIRS "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
4950
)
5051
if(TARGET test_rmw_participant_qos_profile_allocator)
51-
target_link_libraries(test_rmw_participant_qos_profile_allocator ${PROJECT_NAME})
52+
target_link_libraries(test_rmw_participant_qos_profile_allocator ${PROJECT_NAME}
53+
osrf_testing_tools_cpp::memory_tools)
5254
endif()

rmw/test/test_rmw_participant_qos_profile_allocator.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Open Source Robotics Foundation, Inc.
1+
// Copyright 2019 Open Source Robotics Foundation, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,25 +14,35 @@
1414

1515
#include "gtest/gtest.h"
1616

17+
#include "osrf_testing_tools_cpp/scope_exit.hpp"
1718
#include "rmw/allocators.h"
1819
#include "rmw/types.h"
1920

2021
TEST(test_rmw_participant_qos_profile_allocator, test_allocate_does_not_return_null) {
2122
rmw_participant_qos_profile_t * qos_profile = rmw_participant_qos_profile_allocate();
22-
ASSERT_TRUE(qos_profile != NULL);
23+
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
24+
delete (qos_profile);
25+
});
26+
EXPECT_NE(qos_profile, nullptr);
2327
}
2428

2529
TEST(test_rmw_participant_qos_profile_allocator, test_allocate_allocates_different_pointers) {
2630
rmw_participant_qos_profile_t * qos_profile1 = rmw_participant_qos_profile_allocate();
2731
rmw_participant_qos_profile_t * qos_profile2 = rmw_participant_qos_profile_allocate();
28-
ASSERT_TRUE(qos_profile1 != qos_profile2);
32+
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
33+
delete (qos_profile1);
34+
delete (qos_profile2);
35+
});
36+
EXPECT_NE(qos_profile1, qos_profile2);
2937
}
3038

3139
TEST(test_rmw_participant_qos_profile_allocator, test_free_null) {
32-
EXPECT_NO_THROW(rmw_participant_qos_profile_free(NULL));
40+
rmw_participant_qos_profile_free(NULL);
41+
SUCCEED();
3342
}
3443

3544
TEST(test_rmw_participant_qos_profile_allocator, test_free_allocated) {
3645
rmw_participant_qos_profile_t * qos_profile = rmw_participant_qos_profile_allocate();
37-
EXPECT_NO_THROW(rmw_participant_qos_profile_free(qos_profile));
46+
rmw_participant_qos_profile_free(qos_profile);
47+
SUCCEED();
3848
}

0 commit comments

Comments
 (0)