Skip to content

Commit 17e5ca8

Browse files
mw/com: switch proxy event fixture to NiceMock and adapt tests
rework UnsubscribeWhileNotHoldingSamplePtrs to have nice mocks and update test logic
1 parent c7f68bc commit 17e5ca8

2 files changed

Lines changed: 11 additions & 60 deletions

File tree

score/mw/com/impl/proxy_event_test.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ struct ProxyEventStruct
7272
{
7373
using SampleType = TestSampleType;
7474
using ProxyEventType = ProxyEvent<TestSampleType>;
75-
using MockProxyEventType = StrictMock<mock_binding::ProxyEvent<TestSampleType>>;
75+
using MockProxyEventType = NiceMock<mock_binding::ProxyEvent<TestSampleType>>;
7676
};
7777
struct GenericProxyEventStruct
7878
{
7979
using SampleType = void;
8080
using ProxyEventType = GenericProxyEvent;
81-
using MockProxyEventType = StrictMock<mock_binding::GenericProxyEvent>;
81+
using MockProxyEventType = NiceMock<mock_binding::GenericProxyEvent>;
8282
};
8383
struct ProxyFieldStruct
8484
{
8585
using SampleType = TestSampleType;
8686
using ProxyEventType = ProxyField<TestSampleType>;
87-
using MockProxyEventType = StrictMock<mock_binding::ProxyEvent<TestSampleType>>;
87+
using MockProxyEventType = NiceMock<mock_binding::ProxyEvent<TestSampleType>>;
8888
};
8989

9090
/// \brief Templated test fixture for ProxyEvent functionality that works for both ProxyEvent and GenericProxyEvent
@@ -255,12 +255,10 @@ TYPED_TEST(ProxyEventDeathTest, DieOnUnsubscribingWhileHoldingSamplePtrs)
255255
Base::RecordProperty("DerivationTechnique", "Analysis of requirements");
256256

257257
// Given a subscribed proxy event that has delivered a sample which is still held
258+
ON_CALL(Base::mock_proxy_event_, Subscribe(1U)).WillByDefault(Return(score::Result<void>{}));
258259
EXPECT_CALL(Base::mock_proxy_event_, GetSubscriptionState())
259-
.WillOnce(Return(SubscriptionState::kNotSubscribed)) // called by Subscribe
260-
.WillRepeatedly(Return(SubscriptionState::kSubscribed)); // called by Unsubscribe
261-
EXPECT_CALL(Base::mock_proxy_event_, Subscribe(1U));
262-
EXPECT_CALL(Base::mock_proxy_event_, GetNewSamples(_, _));
263-
EXPECT_CALL(Base::mock_proxy_event_, Unsubscribe()).Times(AtMost(1));
260+
.WillOnce(Return(SubscriptionState::kNotSubscribed))
261+
.WillRepeatedly(Return(SubscriptionState::kSubscribed));
264262

265263
Base::mock_proxy_event_.PushFakeSample(3U);
266264
std::ignore = Base::proxy_event_.Subscribe(1U);
@@ -283,11 +281,12 @@ TYPED_TEST(ProxyEventFixture, UnsubscribeWhileNotHoldingSamplePtrs)
283281
using Base = ProxyEventFixture<TypeParam>;
284282

285283
// Given a subscribed proxy event that received a sample but no longer holds it
284+
ON_CALL(Base::mock_proxy_event_, Subscribe(1U)).WillByDefault(Return(score::Result<void>{}));
286285
EXPECT_CALL(Base::mock_proxy_event_, GetSubscriptionState())
287286
.WillOnce(Return(SubscriptionState::kNotSubscribed))
288287
.WillRepeatedly(Return(SubscriptionState::kSubscribed));
289-
EXPECT_CALL(Base::mock_proxy_event_, Subscribe(1U));
290-
EXPECT_CALL(Base::mock_proxy_event_, GetNewSamples(_, _));
288+
289+
// Expecting that Unsubscribe is called on the binding
291290
EXPECT_CALL(Base::mock_proxy_event_, Unsubscribe());
292291

293292
Base::mock_proxy_event_.PushFakeSample(3U);

score/mw/com/impl/tracing/test/proxy_event_tracing_test.cpp

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class ProxyEventTracingFixture : public ::testing::Test
104104

105105
ON_CALL(*mock_proxy_event_binding_, SetReceiveHandler(_)).WillByDefault(Return(score::Result<void>{}));
106106
ON_CALL(*mock_proxy_event_binding_, GetBindingType()).WillByDefault(Return(BindingType::kLoLa));
107+
ON_CALL(*mock_proxy_event_binding_, GetSubscriptionState())
108+
.WillByDefault(Return(SubscriptionState::kNotSubscribed));
107109
}
108110

109111
void CreateProxy()
@@ -769,7 +771,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
769771

770772
ProxyEventTracingData expected_enabled_trace_points{};
771773
expected_enabled_trace_points.enable_unsubscribe = true;
772-
expected_enabled_trace_points.enable_subscribe = true;
773774
expected_enabled_trace_points.enable_call_receive_handler = true;
774775

775776
const tracing::ServiceElementInstanceIdentifierView expected_service_element_instance_identifier_view =
@@ -790,27 +791,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
790791
typename ProxyEventTracingFixture<TypeParam>::TracePointType>(
791792
expected_enabled_trace_points, kServiceIdentifierStringView, kServiceElementName, kInstanceSpecifierStringView);
792793

793-
// Expect that GetSubscriptionState returns kNotSubscribed then kSubscribed
794-
EXPECT_CALL(*this->mock_proxy_event_binding_, GetSubscriptionState())
795-
.WillOnce(Return(SubscriptionState::kNotSubscribed))
796-
.WillOnce(Return(SubscriptionState::kSubscribed));
797-
798-
// Expect that a trace call relating to Subscribe is called
799-
tracing::ITracingRuntime::TracePointType subscribe_trace_point_type{
800-
ProxyEventTracingFixture<TypeParam>::TracePointType::SUBSCRIBE};
801-
EXPECT_CALL(tracing_runtime_mock,
802-
Trace(BindingType::kLoLa,
803-
expected_service_element_instance_identifier_view,
804-
subscribe_trace_point_type,
805-
std::optional<tracing::ITracingRuntime::TracePointDataId>{},
806-
_,
807-
_))
808-
.WillOnce(Return(Result<void>{}));
809-
810-
811-
// and that Subscribe will be called on the binding
812-
EXPECT_CALL(*this->mock_proxy_event_binding_, Subscribe(max_sample_count));
813-
814794
// Then a trace call relating to Unsubscribe should be called containing the correct max_sample_count which returns
815795
// an error
816796
tracing::ITracingRuntime::TracePointType trace_point_type{
@@ -824,9 +804,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
824804
0U))
825805
.WillOnce(Return(MakeUnexpected(tracing::TraceErrorCode::TraceErrorDisableTracePointInstance)));
826806

827-
// and that Unsubscribe will be called on the binding
828-
EXPECT_CALL(*this->mock_proxy_event_binding_, Unsubscribe());
829-
830807
// When a Proxy containing a ProxyEvent is created based on a lola deployment
831808
this->CreateProxy();
832809

@@ -857,7 +834,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
857834

858835
ProxyEventTracingData expected_enabled_trace_points{};
859836
expected_enabled_trace_points.enable_unsubscribe = true;
860-
expected_enabled_trace_points.enable_subscribe = true;
861837
expected_enabled_trace_points.enable_call_receive_handler = true;
862838

863839
const tracing::ServiceElementInstanceIdentifierView expected_service_element_instance_identifier_view =
@@ -878,27 +854,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
878854
typename ProxyEventTracingFixture<TypeParam>::TracePointType>(
879855
expected_enabled_trace_points, kServiceIdentifierStringView, kServiceElementName, kInstanceSpecifierStringView);
880856

881-
// Expect that GetSubscriptionState returns kNotSubscribed then kSubscribed
882-
EXPECT_CALL(*this->mock_proxy_event_binding_, GetSubscriptionState())
883-
.WillOnce(Return(SubscriptionState::kNotSubscribed))
884-
.WillOnce(Return(SubscriptionState::kSubscribed));
885-
886-
// Expect that a trace call relating to Subscribe is called
887-
tracing::ITracingRuntime::TracePointType subscribe_trace_point_type{
888-
ProxyEventTracingFixture<TypeParam>::TracePointType::SUBSCRIBE};
889-
EXPECT_CALL(tracing_runtime_mock,
890-
Trace(BindingType::kLoLa,
891-
expected_service_element_instance_identifier_view,
892-
subscribe_trace_point_type,
893-
std::optional<tracing::ITracingRuntime::TracePointDataId>{},
894-
_,
895-
_))
896-
.WillOnce(Return(Result<void>{}));
897-
898-
899-
// and that Subscribe will be called on the binding
900-
EXPECT_CALL(*this->mock_proxy_event_binding_, Subscribe(max_sample_count));
901-
902857
// Then a trace call relating to Unsubscribe should be called containing the correct max_sample_count which returns
903858
// an error
904859
tracing::ITracingRuntime::TracePointType trace_point_type{
@@ -912,9 +867,6 @@ TYPED_TEST(ProxyEventTracingUnsubscribeFixture,
912867
0U))
913868
.WillOnce(Return(MakeUnexpected(tracing::TraceErrorCode::TraceErrorDisableAllTracePoints)));
914869

915-
// and that Unsubscribe will be called on the binding
916-
EXPECT_CALL(*this->mock_proxy_event_binding_, Unsubscribe());
917-
918870
// When a Proxy containing a ProxyEvent is created based on a lola deployment
919871
this->CreateProxy();
920872

0 commit comments

Comments
 (0)