diff --git a/iceoryx_posh/test/moduletests/test_gw_channel.cpp b/iceoryx_posh/test/moduletests/test_gw_channel.cpp index 43857a607e..6e34f7f68d 100644 --- a/iceoryx_posh/test/moduletests/test_gw_channel.cpp +++ b/iceoryx_posh/test/moduletests/test_gw_channel.cpp @@ -55,4 +55,5 @@ TEST_F(ChannelTest, ReturnsEmptyOptionalIfObjectPoolExhausted) { auto channel = iox::gw::Channel::create( {"", "", ""}, StubbedIceoryxTerminal::Options()); + EXPECT_FALSE(channel.has_error()); } diff --git a/iceoryx_posh/test/moduletests/test_mepoo_typed_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_typed_mempool.cpp index 08204b3e74..46ebc0b323 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_typed_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_typed_mempool.cpp @@ -87,6 +87,7 @@ TEST_F(TypedMemPool_test, ReleaseChunkWhenGoingOutOfScope) { { auto object = sut.createObject(1, 234); + EXPECT_FALSE(object.has_error()); EXPECT_THAT(sut.getUsedChunks(), Eq(1)); } EXPECT_THAT(sut.getUsedChunks(), Eq(0)); @@ -99,6 +100,10 @@ TEST_F(TypedMemPool_test, OutOfChunksErrorWhenFull) auto object3 = sut.createObject(0xaffe, 0xdead); auto object4 = sut.createObject(0xaffe, 0xdead); + EXPECT_FALSE(object1.has_error()); + EXPECT_FALSE(object2.has_error()); + EXPECT_FALSE(object3.has_error()); + EXPECT_THAT(object4.has_error(), Eq(true)); EXPECT_THAT(object4.get_error(), Eq(TypedMemPoolError::OutOfChunks)); } diff --git a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp index bbe160e154..31ed5e763a 100644 --- a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp @@ -511,10 +511,13 @@ TEST_F(PublisherPort_test, cleanupReleasesAllChunks) // allocate some samples auto maybeChunkHeader1 = m_sutWithHistoryUserSide.tryAllocateChunk( sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + EXPECT_FALSE(maybeChunkHeader1.has_error()); auto maybeChunkHeader2 = m_sutWithHistoryUserSide.tryAllocateChunk( sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + EXPECT_FALSE(maybeChunkHeader2.has_error()); auto maybeChunkHeader3 = m_sutWithHistoryUserSide.tryAllocateChunk( sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + EXPECT_FALSE(maybeChunkHeader3.has_error()); m_sutWithHistoryRouDiSide.releaseAllChunks(); diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoyx_roudi_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoyx_roudi_memory_manager.cpp index ed6e66b73a..b3d06409be 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoyx_roudi_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoyx_roudi_memory_manager.cpp @@ -26,7 +26,6 @@ namespace iox { namespace test { - /// @brief This test file verifies that the BaseClass IceoryxRouDiMemoryManager is tested class IceoryxRoudiMemoryManager_test : public Test { @@ -35,8 +34,8 @@ class IceoryxRoudiMemoryManager_test : public Test void SetUp() override { - auto config = iox::RouDiConfig_t().setDefaults(); - m_roudiMemoryManagerTest = std::unique_ptr(new IceOryxRouDiMemoryManager(config)); + auto config = iox::RouDiConfig_t().setDefaults(); + m_roudiMemoryManagerTest = std::unique_ptr(new IceOryxRouDiMemoryManager(config)); } void TearDown() override @@ -112,6 +111,7 @@ TEST_F(IceoryxRoudiMemoryManager_test, AcquiringPortPoolAfterCreateAndAnnounceMe TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryReturnNoError) { auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory(); + EXPECT_FALSE(testResult.has_error()); auto result = m_roudiMemoryManagerTest->destroyMemory(); @@ -121,8 +121,10 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryReturnNoError) TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryIntrospectionMemoryManagerReturnNullOpt) { auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory(); + ASSERT_FALSE(testResult.has_error()); auto result = m_roudiMemoryManagerTest->destroyMemory(); + ASSERT_FALSE(result.has_error()); auto res = m_roudiMemoryManagerTest->introspectionMemoryManager(); EXPECT_THAT(res, Eq(iox::cxx::nullopt_t())); @@ -131,8 +133,10 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryIntrospectionMemoryManagerRe TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemorySegmentManagerReturnNullOpt) { auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory(); + ASSERT_FALSE(testResult.has_error()); auto result = m_roudiMemoryManagerTest->destroyMemory(); + ASSERT_FALSE(result.has_error()); auto resultTest = m_roudiMemoryManagerTest->segmentManager(); EXPECT_THAT(resultTest, Eq(iox::cxx::nullopt_t())); @@ -141,6 +145,7 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemorySegmentManagerReturnNullOpt) TEST_F(IceoryxRoudiMemoryManager_test, CreateAndAnnouceMemoryFailingAfterCalledTwoTimes) { auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory(); + ASSERT_FALSE(testResult.has_error()); auto result = m_roudiMemoryManagerTest->createAndAnnounceMemory(); @@ -151,13 +156,15 @@ TEST_F(IceoryxRoudiMemoryManager_test, CreateAndAnnouceMemoryFailingAfterCalledT TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryNotFailingAfterCalledTwoTimes) { auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory(); + ASSERT_FALSE(testResult.has_error()); auto result = m_roudiMemoryManagerTest->destroyMemory(); + ASSERT_FALSE(result.has_error()); auto res = m_roudiMemoryManagerTest->destroyMemory(); EXPECT_THAT(res.has_error(), Eq(false)); } -} // namespace test -} // iox +} // namespace test +} // namespace iox diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 0b88c83980..c3b73f2bdb 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -293,16 +293,7 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) { - auto errorHandlerCalled{false}; - Error errorHandlerType; - auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { - errorHandlerType = error; - errorHandlerCalled = true; - }); - - for (uint32_t i = 0U; i <= MAX_SUBSCRIBERS; ++i) - { + auto addSubscriberPort = [&](const uint32_t i) -> bool { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; @@ -312,8 +303,23 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, applicationName, m_subscriberOptions); + return publisherPort.has_error(); + }; + + for (uint32_t i = 0U; i < MAX_SUBSCRIBERS; ++i) + { + EXPECT_FALSE(addSubscriberPort(i)); } + auto errorHandlerCalled{false}; + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + EXPECT_TRUE(addSubscriberPort(MAX_SUBSCRIBERS)); + EXPECT_TRUE(errorHandlerCalled); EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } @@ -321,6 +327,7 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) { auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); + EXPECT_FALSE(subscriberPort.has_error()); auto subscriberPortDataList = sut.getSubscriberPortDataList(); ASSERT_EQ(subscriberPortDataList.size(), 1U); @@ -345,6 +352,7 @@ TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, applicationName, m_subscriberOptions); + EXPECT_FALSE(publisherPort.has_error()); } auto subscriberPortDataList = sut.getSubscriberPortDataList(); @@ -383,6 +391,11 @@ TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) { + for (uint32_t i = 0U; i < MAX_INTERFACE_NUMBER; ++i) + { + EXPECT_FALSE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error()); + } + auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = @@ -390,11 +403,7 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) errorHandlerType = error; errorHandlerCalled = true; }); - - for (uint32_t i = 0U; i <= MAX_INTERFACE_NUMBER; ++i) - { - auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); - } + EXPECT_TRUE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error()); EXPECT_TRUE(errorHandlerCalled); EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); @@ -403,6 +412,7 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) { auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + EXPECT_FALSE(interfacePort.has_error()); auto interfacePortDataList = sut.getInterfacePortDataList(); ASSERT_EQ(interfacePortDataList.size(), 1U); @@ -458,6 +468,11 @@ TEST_F(PortPool_test, AddApplicationPortWithMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError) { + for (uint32_t i = 0U; i < MAX_PROCESS_NUMBER; ++i) + { + EXPECT_FALSE(sut.addApplicationPort(m_applicationName).has_error()); + } + auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = @@ -465,11 +480,7 @@ TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError errorHandlerType = error; errorHandlerCalled = true; }); - - for (uint32_t i = 0U; i <= MAX_PROCESS_NUMBER; ++i) - { - auto applicationData = sut.addApplicationPort(m_applicationName); - } + EXPECT_TRUE(sut.addApplicationPort(m_applicationName).has_error()); EXPECT_TRUE(errorHandlerCalled); EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW); @@ -533,6 +544,11 @@ TEST_F(PortPool_test, AddConditionVariableDataWithMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) { + for (uint32_t i = 0U; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) + { + EXPECT_FALSE(sut.addConditionVariableData(m_applicationName).has_error()); + } + auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = @@ -540,11 +556,7 @@ TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) errorHandlerType = error; errorHandlerCalled = true; }); - - for (uint32_t i = 0U; i <= MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) - { - auto conditionVariableData = sut.addConditionVariableData(m_applicationName); - } + EXPECT_TRUE(sut.addConditionVariableData(m_applicationName).has_error()); EXPECT_TRUE(errorHandlerCalled); EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); diff --git a/iceoryx_utils/include/iceoryx_utils/cxx/helplets.hpp b/iceoryx_utils/include/iceoryx_utils/cxx/helplets.hpp index 16fd3bbbf8..2f81c6dd94 100644 --- a/iceoryx_utils/include/iceoryx_utils/cxx/helplets.hpp +++ b/iceoryx_utils/include/iceoryx_utils/cxx/helplets.hpp @@ -257,8 +257,19 @@ using BestFittingType_t = typename BestFittingType::Type_t; /// @endcode #define IOX_DISCARD_RESULT(expr) static_cast(expr) // NOLINT +// the __attribute__((warn_unused)) is even stronger than [[nodiscard]] therefore we prefer it +// whenever possible +#if defined(__GNUC__) || defined(__clang__) +#define IOX_NO_DISCARD __attribute__((warn_unused)) // NOLINT +#else +// on Mac OS and WIN32 we are using C++17 which makes the keyword [[nodiscard]] available +#if defined(__APPLE__) || defined(_WIN32) #define IOX_NO_DISCARD [[nodiscard]] // NOLINT - +// on an unknown platform we use for now nothing since we do not know what +#else +#define IOX_NO_DISCARD +#endif +#endif /// @brief Returns info whether called on a 32-bit system /// @return True if called on 32-bit, false if not 32-bit system constexpr bool isCompiledOn32BitSystem() diff --git a/iceoryx_utils/test/moduletests/test_cxx_expected.cpp b/iceoryx_utils/test/moduletests/test_cxx_expected.cpp index 4ddf387103..cd151d7513 100644 --- a/iceoryx_utils/test/moduletests/test_cxx_expected.cpp +++ b/iceoryx_utils/test/moduletests/test_cxx_expected.cpp @@ -185,6 +185,7 @@ TEST_F(expected_test, CreateWithValueAndMoveCtorLeadsToInvalidState) { auto sut = expected::create_value(177); auto movedValue{std::move(sut)}; + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState())); } @@ -193,6 +194,7 @@ TEST_F(expected_test, CreateWithErrorAndMoveCtorLeadsToInvalidState) { auto sut = expected::create_error(22, 33); auto movedValue{std::move(sut)}; + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState())); } @@ -201,6 +203,7 @@ TEST_F(expected_test, CreateWithValueAndMoveAssignmentLeadsToInvalidState) { auto sut = expected::create_value(73); auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState())); } @@ -209,6 +212,7 @@ TEST_F(expected_test, CreateWithErrorAndMoveAssignmentLeadsToInvalidState) { auto sut = expected::create_error(44, 55); auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState())); } @@ -217,6 +221,7 @@ TEST_F(expected_test, CreateInvalidExpectedAndCallGetErrorLeadsToInvalidState) { auto sut = expected::create_error(TestError::ERROR1); auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE)); } @@ -225,6 +230,7 @@ TEST_F(expected_test, ErrorTypeOnlyCreateInvalidExpectedAndCallGetErrorLeadsToIn { auto sut = expected::create_error(TestError::ERROR2); auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE)); } @@ -326,6 +332,7 @@ TEST_F(expected_test, ErrorTypeOnlyMoveCtorLeadsToInvalidState) { auto sut = expected::create_error(TestError::ERROR2); auto movedValue{std::move(sut)}; + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE)); } @@ -334,6 +341,7 @@ TEST_F(expected_test, ErrorTypeOnlyMoveAssignmentLeadsToInvalidState) { auto sut = expected::create_error(TestError::ERROR1); auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); ASSERT_TRUE(sut.has_error()); EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE)); } @@ -440,6 +448,7 @@ TEST_F(expected_test, WhenHavingSuccessAndMoveAssignmentCallsOrElse) { expected sut{success(1143)}; auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); TestError error{TestError::ERROR1}; sut.and_then([&](auto&) { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; }); EXPECT_THAT(error, Eq(TestError::INVALID_STATE)); @@ -449,6 +458,7 @@ TEST_F(expected_test, WhenHavingAnErrorAndMoveAssignmentCallsOrElse) { expected sut{error(TestError::ERROR1)}; auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); TestError error{TestError::ERROR1}; sut.and_then([&](auto&) { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; }); EXPECT_THAT(error, Eq(TestError::INVALID_STATE)); @@ -458,6 +468,7 @@ TEST_F(expected_test, ErrorTypeOnlyWhenHavingSuccessAndMoveAssignmentCallsOrElse { expected sut{success<>()}; auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); TestError error{TestError::ERROR1}; sut.and_then([&]() { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; }); EXPECT_THAT(error, Eq(TestError::INVALID_STATE)); @@ -467,6 +478,7 @@ TEST_F(expected_test, ErrorTypeOnlyWhenHavingAnErrorAndMoveAssignmentCallsOrElse { expected sut{error(TestError::ERROR1)}; auto movedValue = std::move(sut); + IOX_DISCARD_RESULT(movedValue); TestError error{TestError::ERROR1}; sut.and_then([&]() { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; }); EXPECT_THAT(error, Eq(TestError::INVALID_STATE)); diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index 22e34e4bfb..637f81d342 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -84,7 +84,7 @@ TEST_F(FileLock_test, SecondLockWithDifferentNameWorks) TEST_F(FileLock_test, LockAndReleaseWorks) { { - auto sut1 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); + IOX_DISCARD_RESULT(iox::posix::FileLock::create(ANOTHER_TEST_NAME)); } auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); ASSERT_FALSE(sut2.has_error());