Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1121 Remove converting ctors
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
  • Loading branch information
MatthiasKillat committed Feb 25, 2022
1 parent 3363741 commit 47a092a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ class RelativePointer : public BaseRelativePointer
/// @param[in] ptr the pointer whose pointee shall be the same for this
RelativePointer(ptr_t ptr) noexcept;

/// @brief creates a RelativePointer from a BaseRelativePointer
/// @param[in] other is the BaseRelativePointer
RelativePointer(const BaseRelativePointer& other) noexcept;

/// @brief assign this to point to the same pointee as the BaseRelativePointer other
/// @param[in] other the pointer whose pointee shall be the same for this
/// @return reference to self
RelativePointer& operator=(const BaseRelativePointer& other) noexcept;

/// @brief assigns the RelativePointer to point to the same pointee as ptr
/// @param[in] ptr the pointer whose pointee shall be the same for this
/// @return reference to self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ inline RelativePointer<T>::RelativePointer(ptr_t ptr) noexcept
{
}


template <typename T>
inline RelativePointer<T>::RelativePointer(const BaseRelativePointer& other) noexcept
: BaseRelativePointer(other)
{
}

template <typename T>
inline RelativePointer<T>& RelativePointer<T>::operator=(const BaseRelativePointer& other) noexcept
{
BaseRelativePointer::operator=(other);

return *this;
}

template <typename T>
inline RelativePointer<T>& RelativePointer<T>::operator=(ptr_t ptr) noexcept
{
Expand Down
90 changes: 40 additions & 50 deletions iceoryx_hoofs/test/moduletests/test_relative_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,67 +76,74 @@ typedef testing::Types<uint8_t, int8_t, double> Types;
TYPED_TEST_SUITE(RelativePointer_test, Types);


/// @todo the tests should be reworked in a reworked in a refactoring of relative pointers
TYPED_TEST(RelativePointer_test, ConstrTests)
{
::testing::Test::RecordProperty("TEST_ID", "cae7b4d4-86eb-42f6-b938-90a76f01bea5");
EXPECT_EQ(BaseRelativePointer::registerPtr(1, this->memoryPartition[0], SHARED_MEMORY_SIZE), true);
EXPECT_EQ(BaseRelativePointer::registerPtr(2, this->memoryPartition[1], SHARED_MEMORY_SIZE), true);

auto ptr0 = this->partitionPtr(0);
auto ptr1 = this->partitionPtr(1);

{
auto offset = SHARED_MEMORY_SIZE / 2;
void* adr = this->memoryPartition[0] + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0 + offset);

RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
RelativePointer<TypeParam> rp(this->memoryPartition[0]);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), 0);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE / 2;
void* adr = this->memoryPartition[0] + offset;
RelativePointer<TypeParam> rp(adr);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0 + offset);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE - 1;
void* adr = this->memoryPartition[0] + offset;
RelativePointer<TypeParam> rp(adr);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0 + offset);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
RelativePointer<TypeParam> rp(this->memoryPartition[1]);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), 0);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE / 2;
void* adr = this->memoryPartition[1] + offset;
RelativePointer<TypeParam> rp(adr);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE - 1;
void* adr = this->memoryPartition[1] + offset;
RelativePointer<TypeParam> rp(adr);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
Expand All @@ -149,85 +156,74 @@ TYPED_TEST(RelativePointer_test, ConstrTests)

{
auto offset = SHARED_MEMORY_SIZE + 1;
void* adr = static_cast<uint8_t*>(this->memoryPartition[1]) + offset;
RelativePointer<TypeParam> rp(adr);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp(typedPtr);
EXPECT_NE(rp, nullptr);
}
}

TYPED_TEST(RelativePointer_test, AssignmentOperatorTests)
{
::testing::Test::RecordProperty("TEST_ID", "cd0c4a6a-7779-4dc3-97dc-58ef40a58715");
EXPECT_EQ(BaseRelativePointer::registerPtr(1, this->memoryPartition[0], SHARED_MEMORY_SIZE), true);
EXPECT_EQ(BaseRelativePointer::registerPtr(2, this->memoryPartition[1], SHARED_MEMORY_SIZE), true);
auto ptr0 = this->partitionPtr(0);
auto ptr1 = this->partitionPtr(1);

EXPECT_EQ(BaseRelativePointer::registerPtr(1, ptr0, SHARED_MEMORY_SIZE), true);
EXPECT_EQ(BaseRelativePointer::registerPtr(2, ptr1, SHARED_MEMORY_SIZE), true);

{
RelativePointer<TypeParam> rp;
rp = this->memoryPartition[0];
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0);
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), 0);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
RelativePointer<TypeParam> rp;
rp = this->memoryPartition[0];
BaseRelativePointer basePointer(rp);
RelativePointer<TypeParam> recovered(basePointer);

EXPECT_EQ(rp, recovered);
EXPECT_EQ(rp.getOffset(), recovered.getOffset());
EXPECT_EQ(rp.getId(), recovered.getId());

recovered = basePointer;
EXPECT_EQ(rp, recovered);
EXPECT_EQ(rp.getOffset(), recovered.getOffset());
EXPECT_EQ(rp.getId(), recovered.getId());
}

{
auto offset = SHARED_MEMORY_SIZE / 2;
void* adr = this->memoryPartition[0] + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0 + offset);
RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE - 1;
void* adr = this->memoryPartition[0] + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr0 + offset);
RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 1);
EXPECT_NE(rp, nullptr);
}

{
RelativePointer<TypeParam> rp;
rp = this->memoryPartition[1];
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1);
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), 0);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE / 2;
void* adr = this->memoryPartition[1] + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
}

{
auto offset = SHARED_MEMORY_SIZE - 1;
void* adr = this->memoryPartition[1] + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_EQ(rp.getOffset(), offset);
EXPECT_EQ(rp.getId(), 2);
EXPECT_NE(rp, nullptr);
Expand All @@ -241,9 +237,9 @@ TYPED_TEST(RelativePointer_test, AssignmentOperatorTests)

{
auto offset = SHARED_MEMORY_SIZE + 1;
void* adr = static_cast<uint8_t*>(this->memoryPartition[1]) + offset;
auto typedPtr = reinterpret_cast<TypeParam*>(ptr1 + offset);
RelativePointer<TypeParam> rp;
rp = adr;
rp = typedPtr;
EXPECT_NE(rp, nullptr);
}
}
Expand Down Expand Up @@ -288,7 +284,6 @@ TYPED_TEST(RelativePointer_test, getPtr)
::testing::Test::RecordProperty("TEST_ID", "4fadf89f-69c0-4058-8995-a98e2e3334b2");
auto ptr = this->partitionPtr(0);
auto typedPtr = reinterpret_cast<TypeParam*>(ptr);

RelativePointer<TypeParam> rp1(typedPtr, 1);
EXPECT_EQ(rp1.registerPtr(1, typedPtr), true);
EXPECT_EQ(BaseRelativePointer::getPtr(1, 0), ptr);
Expand Down Expand Up @@ -491,11 +486,6 @@ TYPED_TEST(RelativePointer_test, defaultConstructedRelativePtrIsNull)

EXPECT_EQ(rp1, nullptr);
EXPECT_EQ(rp2, nullptr);

float f;
int* p = &f;

RelativePointer<int> rp(&f);
}

} // namespace

0 comments on commit 47a092a

Please sign in to comment.