From b18b7a17feddb4854025915fc404f5e502b29305 Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 8 May 2026 16:51:15 +0200 Subject: [PATCH] mw/com: fix infinite recursion in ProxyEvent move-assignment --- score/mw/com/impl/proxy_event.h | 2 +- score/mw/com/impl/proxy_event_test.cpp | 31 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/score/mw/com/impl/proxy_event.h b/score/mw/com/impl/proxy_event.h index cd699be9b..38160790d 100644 --- a/score/mw/com/impl/proxy_event.h +++ b/score/mw/com/impl/proxy_event.h @@ -207,7 +207,7 @@ auto ProxyEvent::operator=(ProxyEvent&& other) & noexcept -> ProxyEv { if (this != &other) { - ProxyEvent::operator=(std::move(other)); + ProxyEventBase::operator=(std::move(static_cast(other))); proxy_event_mock_ = std::move(other.proxy_event_mock_); // Since the address of this event has changed, we need update the address stored in the parent proxy. ProxyBaseView proxy_base_view{proxy_base_.get()}; diff --git a/score/mw/com/impl/proxy_event_test.cpp b/score/mw/com/impl/proxy_event_test.cpp index d6b24f899..0bc254371 100644 --- a/score/mw/com/impl/proxy_event_test.cpp +++ b/score/mw/com/impl/proxy_event_test.cpp @@ -528,6 +528,37 @@ TEST(ProxyEventTest, IsMoveable) static_assert(std::is_move_assignable>::value, "Is not move assignable"); } +using ProxyEventMoveAssignmentTest = ProxyEventFixture; +TEST_F(ProxyEventMoveAssignmentTest, MoveAssignmentTransfersBindingFromSourceToDestination) +{ + RecordProperty("Verifies", "SCR-5897869"); // SWS_CM_00135 + RecordProperty("Description", + "After move-assigning one ProxyEvent into another the destination delegates calls to the source's " + "binding"); + RecordProperty("TestType", "Requirements-based test"); + RecordProperty("Priority", "1"); + RecordProperty("DerivationTechnique", "Analysis of requirements"); + + StrictMock> second_binding_mock{}; + auto second_binding_facade = std::make_unique>(second_binding_mock); + + // Given two registered ProxyEvents, each with their own binding mock + ProxyEventType second_event{empty_proxy_, std::move(second_binding_facade), kEventName2}; + ProxyBaseView{empty_proxy_}.RegisterEvent(kEventName, proxy_event_); + ProxyBaseView{empty_proxy_}.RegisterEvent(kEventName2, second_event); + + constexpr std::size_t max_sample_count{7U}; + EXPECT_CALL(second_binding_mock, GetSubscriptionState()).WillOnce(Return(SubscriptionState::kNotSubscribed)); + EXPECT_CALL(second_binding_mock, Subscribe(max_sample_count)).WillOnce(Return(score::Result{})); + + // When move-assigning the first into the second + proxy_event_ = std::move(second_event); + + // Then subsequent calls on the destination dispatch to the source's binding (proving the binding was transferred) + const auto subscribe_result = proxy_event_.Subscribe(max_sample_count); + ASSERT_TRUE(subscribe_result.has_value()); +} + TEST(ProxyEventTest, ClassTypeDependsOnEventDataType) { RecordProperty("Verifies", "SCR-29235350");