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 6143c32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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 6143c32

Please sign in to comment.