Skip to content

Commit

Permalink
iox-eclipse-iceoryx#841 Remove workaround for mock due to GMock 1.8 l…
Browse files Browse the repository at this point in the history
…imitation
  • Loading branch information
elBoberido committed Jan 4, 2022
1 parent e17da2d commit add8ed1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 65 deletions.
31 changes: 4 additions & 27 deletions iceoryx_posh/test/mocks/roudi_memory_block_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,10 @@
class MemoryBlockMock final : public iox::roudi::MemoryBlock
{
public:
/// @note with gmock 1.8 it is not possible to mock functions with the noexcept specifier, therefore this
/// interesting mock implementation

uint64_t size() const noexcept override
{
return sizeMock();
}

uint64_t alignment() const noexcept override
{
return alignmentMock();
}

void onMemoryAvailable(iox::cxx::not_null<void*> memory) noexcept override
{
onMemoryAvailableMock(memory);
}

void destroy() noexcept override
{
destroyMock();
}

MOCK_CONST_METHOD0(sizeMock, uint64_t());
MOCK_CONST_METHOD0(alignmentMock, uint64_t());
MOCK_METHOD1(onMemoryAvailableMock, void(iox::cxx::not_null<void*>));
MOCK_METHOD0(destroyMock, void());
MOCK_METHOD(uint64_t, size, (), (const, noexcept, override));
MOCK_METHOD(uint64_t, alignment, (), (const, noexcept, override));
MOCK_METHOD(void, onMemoryAvailable, (iox::cxx::not_null<void*>), (noexcept, override));
MOCK_METHOD(void, destroy, (), (noexcept, override));
};

#endif // IOX_POSH_MOCKS_ROUDI_MEMORY_BLOCK_MOCK_HPP
4 changes: 2 additions & 2 deletions iceoryx_posh/test/moduletests/test_roudi_memory_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class MemoryBlock_Test : public Test
public:
void SetUp() override
{
EXPECT_CALL(sut, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(sut, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
EXPECT_CALL(sut, size()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(sut, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
}

void TearDown() override
Expand Down
26 changes: 13 additions & 13 deletions iceoryx_posh/test/moduletests/test_roudi_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ TEST_F(RouDiMemoryManager_Test, CallingCreateMemoryWithMemoryProviderSucceeds)
uint64_t MEMORY_ALIGNMENT_1{8};
uint64_t MEMORY_SIZE_2{32};
uint64_t MEMORY_ALIGNMENT_2{16};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock1, onMemoryAvailableMock(_));
EXPECT_CALL(memoryBlock2, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE_2));
EXPECT_CALL(memoryBlock2, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT_2));
EXPECT_CALL(memoryBlock2, onMemoryAvailableMock(_));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock1, onMemoryAvailable(_));
EXPECT_CALL(memoryBlock2, size()).WillRepeatedly(Return(MEMORY_SIZE_2));
EXPECT_CALL(memoryBlock2, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT_2));
EXPECT_CALL(memoryBlock2, onMemoryAvailable(_));

IOX_DISCARD_RESULT(memoryProvider1.addMemoryBlock(&memoryBlock1));
IOX_DISCARD_RESULT(memoryProvider2.addMemoryBlock(&memoryBlock2));
Expand All @@ -93,8 +93,8 @@ TEST_F(RouDiMemoryManager_Test, CallingCreateMemoryWithMemoryProviderSucceeds)

EXPECT_THAT(sut.createAndAnnounceMemory().has_error(), Eq(false));

EXPECT_CALL(memoryBlock1, destroyMock());
EXPECT_CALL(memoryBlock2, destroyMock());
EXPECT_CALL(memoryBlock1, destroy());
EXPECT_CALL(memoryBlock2, destroy());
}

TEST_F(RouDiMemoryManager_Test, CallingCreateMemoryWithMemoryProviderError)
Expand All @@ -112,19 +112,19 @@ TEST_F(RouDiMemoryManager_Test, RouDiMemoryManagerDTorTriggersMemoryProviderDest
{
uint64_t MEMORY_SIZE_1{16};
uint64_t MEMORY_ALIGNMENT_1{8};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock1, onMemoryAvailableMock(_));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock1, onMemoryAvailable(_));

IOX_DISCARD_RESULT(memoryProvider1.addMemoryBlock(&memoryBlock1));

{
RouDiMemoryManager sutDestroy;
ASSERT_FALSE(sutDestroy.addMemoryProvider(&memoryProvider1).has_error());
ASSERT_FALSE(sutDestroy.createAndAnnounceMemory().has_error());
EXPECT_CALL(memoryBlock1, destroyMock()).Times(1);
EXPECT_CALL(memoryBlock1, destroy()).Times(1);
}
EXPECT_CALL(memoryBlock1, destroyMock()).Times(0);
EXPECT_CALL(memoryBlock1, destroy()).Times(0);
}

TEST_F(RouDiMemoryManager_Test, AddMemoryProviderExceedsCapacity)
Expand Down
30 changes: 15 additions & 15 deletions iceoryx_posh/test/moduletests/test_roudi_memory_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class MemoryProvider_Test : public Test
iox::cxx::expected<MemoryProviderError> commonSetup()
{
EXPECT_FALSE(sut.addMemoryBlock(&memoryBlock1).has_error());
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(COMMON_SETUP_MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(COMMON_SETUP_MEMORY_ALIGNMENT));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(COMMON_SETUP_MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(COMMON_SETUP_MEMORY_ALIGNMENT));
EXPECT_CALL(sut, createMemoryMock(COMMON_SETUP_MEMORY_SIZE, COMMON_SETUP_MEMORY_ALIGNMENT)).Times(1);

EXPECT_CALL(sut, destroyMemoryMock());
EXPECT_CALL(memoryBlock1, destroyMock());
EXPECT_CALL(memoryBlock1, destroy());

return sut.create();
}
Expand Down Expand Up @@ -178,8 +178,8 @@ TEST_F(MemoryProvider_Test, CreationFailed)
ASSERT_FALSE(sutFailure.addMemoryBlock(&memoryBlock1).has_error());
uint64_t MEMORY_SIZE{16};
uint64_t MEMORY_ALIGNMENT{8};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT));

auto expectError = sutFailure.create();
ASSERT_THAT(expectError.has_error(), Eq(true));
Expand All @@ -193,7 +193,7 @@ TEST_F(MemoryProvider_Test, CreateAndAnnounceWithOneMemoryBlock)
{
ASSERT_FALSE(commonSetup().has_error());

EXPECT_CALL(memoryBlock1, onMemoryAvailableMock(_)).Times(1);
EXPECT_CALL(memoryBlock1, onMemoryAvailable(_)).Times(1);
sut.announceMemoryAvailable();

EXPECT_THAT(sut.isAvailableAnnounced(), Eq(true));
Expand All @@ -207,23 +207,23 @@ TEST_F(MemoryProvider_Test, CreateAndAnnounceWithMultipleMemoryBlocks)
uint64_t MEMORY_ALIGNMENT_1{8};
uint64_t MEMORY_SIZE_2{32};
uint64_t MEMORY_ALIGNMENT_2{16};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock2, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE_2));
EXPECT_CALL(memoryBlock2, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT_2));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE_1));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT_1));
EXPECT_CALL(memoryBlock2, size()).WillRepeatedly(Return(MEMORY_SIZE_2));
EXPECT_CALL(memoryBlock2, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT_2));
EXPECT_CALL(sut, createMemoryMock(MEMORY_SIZE_1 + MEMORY_SIZE_2, std::max(MEMORY_ALIGNMENT_1, MEMORY_ALIGNMENT_2)))
.Times(1);
EXPECT_THAT(sut.create().has_error(), Eq(false));

EXPECT_CALL(memoryBlock1, onMemoryAvailableMock(_)).Times(1);
EXPECT_CALL(memoryBlock2, onMemoryAvailableMock(_)).Times(1);
EXPECT_CALL(memoryBlock1, onMemoryAvailable(_)).Times(1);
EXPECT_CALL(memoryBlock2, onMemoryAvailable(_)).Times(1);
sut.announceMemoryAvailable();

EXPECT_THAT(sut.isAvailableAnnounced(), Eq(true));

EXPECT_CALL(sut, destroyMemoryMock());
EXPECT_CALL(memoryBlock1, destroyMock());
EXPECT_CALL(memoryBlock2, destroyMock());
EXPECT_CALL(memoryBlock1, destroy());
EXPECT_CALL(memoryBlock2, destroy());
}

TEST_F(MemoryProvider_Test, AddMemoryBlockAfterCreation)
Expand All @@ -248,7 +248,7 @@ TEST_F(MemoryProvider_Test, MultipleAnnouncesAreSuppressed)
{
ASSERT_FALSE(commonSetup().has_error());

EXPECT_CALL(memoryBlock1, onMemoryAvailableMock(_)).Times(1);
EXPECT_CALL(memoryBlock1, onMemoryAvailable(_)).Times(1);
sut.announceMemoryAvailable();
sut.announceMemoryAvailable(); // this shouldn't trigger a second memoryAvailable call on memoryBlock1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ TEST_F(PosixShmMemoryProvider_Test, CreateMemory)
ASSERT_FALSE(sut.addMemoryBlock(&memoryBlock1).has_error());
uint64_t MEMORY_SIZE{16};
uint64_t MEMORY_ALIGNMENT{8};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT));

EXPECT_THAT(sut.create().has_error(), Eq(false));

EXPECT_THAT(shmExists(), Eq(true));

EXPECT_CALL(memoryBlock1, destroyMock());
EXPECT_CALL(memoryBlock1, destroy());
}

TEST_F(PosixShmMemoryProvider_Test, DestroyMemory)
Expand All @@ -87,12 +87,12 @@ TEST_F(PosixShmMemoryProvider_Test, DestroyMemory)
ASSERT_FALSE(sut.addMemoryBlock(&memoryBlock1).has_error());
uint64_t MEMORY_SIZE{16};
uint64_t MEMORY_ALIGNMENT{8};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT));

ASSERT_FALSE(sut.create().has_error());

EXPECT_CALL(memoryBlock1, destroyMock());
EXPECT_CALL(memoryBlock1, destroy());

ASSERT_FALSE(sut.destroy().has_error());

Expand All @@ -106,8 +106,8 @@ TEST_F(PosixShmMemoryProvider_Test, CreationFailedWithAlignmentExceedingPageSize
ASSERT_FALSE(sut.addMemoryBlock(&memoryBlock1).has_error());
uint64_t MEMORY_SIZE{16};
uint64_t MEMORY_ALIGNMENT{iox::posix::pageSize() + 8U};
EXPECT_CALL(memoryBlock1, sizeMock()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignmentMock()).WillRepeatedly(Return(MEMORY_ALIGNMENT));
EXPECT_CALL(memoryBlock1, size()).WillRepeatedly(Return(MEMORY_SIZE));
EXPECT_CALL(memoryBlock1, alignment()).WillRepeatedly(Return(MEMORY_ALIGNMENT));

auto expectFailed = sut.create();
ASSERT_THAT(expectFailed.has_error(), Eq(true));
Expand Down

0 comments on commit add8ed1

Please sign in to comment.