From 0e88af01ca12ce1dd48e1e3401a2914ccf41482c Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Thu, 15 Sep 2022 16:08:49 +0200 Subject: [PATCH] iox-#1104 unique_ptr is no longer nullable - full integration into iceoryx_hoofs Signed-off-by: Christian Eltzschig --- .../source/posix_wrapper/access_control.cpp | 2 +- .../test/moduletests/test_cxx_unique_ptr.cpp | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/iceoryx_hoofs/source/posix_wrapper/access_control.cpp b/iceoryx_hoofs/source/posix_wrapper/access_control.cpp index a81feb234c..8684b96a23 100644 --- a/iceoryx_hoofs/source/posix_wrapper/access_control.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/access_control.cpp @@ -98,7 +98,7 @@ AccessController::createACL(const int32_t numEntries) noexcept cxx::Ensures(!aclFreeCall.has_error() && "Could not free ACL memory"); }; - return cxx::success(aclInitCall->value, freeACL); + return cxx::success(*aclInitCall->value, freeACL); } bool AccessController::addUserPermission(const Permission permission, const PosixUser::userName_t& name) noexcept diff --git a/iceoryx_hoofs/test/moduletests/test_cxx_unique_ptr.cpp b/iceoryx_hoofs/test/moduletests/test_cxx_unique_ptr.cpp index 16bddcd8e0..ae4cc22b13 100644 --- a/iceoryx_hoofs/test/moduletests/test_cxx_unique_ptr.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cxx_unique_ptr.cpp @@ -207,6 +207,28 @@ TEST_F(UniquePtrTest, SwapTwoValidUniquePtrsWithDifferentDeletersSucceeds) EXPECT_TRUE(m_anotherDeleterCalled); } +TEST_F(UniquePtrTest, SwapUniquePtrWithUniquePtrLeadsToCleanupOfBothInReverseOrder) +{ + ::testing::Test::RecordProperty("TEST_ID", "9017ba22-ff18-41d4-8590-ccb0d7729435"); + { + auto sut = iox::cxx::unique_ptr(&object, deleter); + { + auto anotherSut = iox::cxx::unique_ptr(&anotherObject, anotherDeleter); + + sut.swap(anotherSut); + + // no deleter calls during swap + EXPECT_FALSE(m_deleterCalled); + EXPECT_EQ(anotherSut.get(), &object); + } + // anotherSUT is out of scope and calls its deleter, which has been swapped and is now 'deleter' + EXPECT_TRUE(m_deleterCalled); + EXPECT_FALSE(m_anotherDeleterCalled); + } + // SUT is out of scope and calling anotherDeleter + EXPECT_TRUE(m_anotherDeleterCalled); +} + TEST_F(UniquePtrTest, CompareAUniquePtrWithItselfIsTrue) { ::testing::Test::RecordProperty("TEST_ID", "d12f8cf6-e37e-424a-9ed5-aea580b8bdc9");