Skip to content

Commit 35d66d6

Browse files
committed
check for LinControllerStatusUpdate timestamp in LinController tests
1 parent 2cf1564 commit 35d66d6

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

SilKit/source/services/lin/LinTestUtils.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ inline auto AControllerStatusUpdateWith(LinControllerStatus status)
108108
return Field(&LinControllerStatusUpdate::status, status);
109109
}
110110

111+
inline auto AControllerStatusUpdateWith(LinControllerStatus status, std::chrono::nanoseconds timestamp)
112+
-> testing::Matcher<const LinControllerStatusUpdate&>
113+
{
114+
using namespace testing;
115+
return AllOf(Field(&LinControllerStatusUpdate::status, status),
116+
Field(&LinControllerStatusUpdate::timestamp, timestamp));
117+
}
118+
111119
struct Callbacks
112120
{
113121
MOCK_METHOD3(FrameStatusHandler, void(ILinController*, const LinFrame&, LinFrameStatus));

SilKit/source/services/lin/Test_LinControllerDetailedSim.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Test_LinControllerDetailedSim : public testing::Test
5656
controllerBusSim.SetServiceDescriptor(addr1_netsim);
5757
master.SetDetailedBehavior(addr1_netsim);
5858
slave1.SetDetailedBehavior(addr1_netsim);
59+
60+
ON_CALL(participant.mockTimeProvider, Now()).WillByDefault(testing::Return(35s));
5961
}
6062

6163
protected:
@@ -197,7 +199,8 @@ TEST_F(Test_LinControllerDetailedSim, go_to_sleep)
197199
expectedMsg.responseType = LinFrameResponseType::MasterResponse;
198200

199201
EXPECT_CALL(participant, SendMsg(&master, netsimName, expectedMsg)).Times(1);
200-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::SleepPending))).Times(1);
202+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::SleepPending, 35s))).Times(1);
203+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
201204

202205
master.GoToSleep();
203206
}
@@ -210,7 +213,8 @@ TEST_F(Test_LinControllerDetailedSim, go_to_sleep_internal)
210213
master.Init(config);
211214

212215
EXPECT_CALL(participant, SendMsg(&master, netsimName, A<const LinSendFrameRequest&>())).Times(0);
213-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep))).Times(1);
216+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep, 35s))).Times(1);
217+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
214218

215219
master.GoToSleepInternal();
216220
}
@@ -262,7 +266,8 @@ TEST_F(Test_LinControllerDetailedSim, wake_up)
262266
master.Init(config);
263267

264268
EXPECT_CALL(participant, SendMsg(&master, netsimName, A<const LinWakeupPulse&>())).Times(1);
265-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1);
269+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational, 35s))).Times(1);
270+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
266271

267272
master.Wakeup();
268273
}
@@ -275,7 +280,8 @@ TEST_F(Test_LinControllerDetailedSim, wake_up_internal)
275280
master.Init(config);
276281

277282
EXPECT_CALL(participant, SendMsg(&master, netsimName, A<const LinWakeupPulse&>())).Times(0);
278-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1);
283+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational, 35s))).Times(1);
284+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
279285

280286
master.WakeupInternal();
281287
}

SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,19 @@ TEST_F(Test_LinControllerTrivialSim, go_to_sleep)
617617
{
618618
master.Init(MakeControllerConfig(LinControllerMode::Master));
619619

620-
EXPECT_CALL(participant, SendMsg(&master, ATransmissionWith(GoToSleepFrame(), LinFrameStatus::LIN_RX_OK))).Times(1);
621-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep))).Times(1);
622-
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
620+
EXPECT_CALL(participant, SendMsg(&master, ATransmissionWith(GoToSleepFrame(), LinFrameStatus::LIN_RX_OK, 35s))).Times(1);
621+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep, 35s))).Times(1);
622+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(2);
623623
master.GoToSleep();
624624
}
625625

626626
TEST_F(Test_LinControllerTrivialSim, go_to_sleep_internal)
627627
{
628628
master.Init(MakeControllerConfig(LinControllerMode::Master));
629629

630-
EXPECT_CALL(participant, SendMsg(&master, ATransmissionWith(GoToSleepFrame(), LinFrameStatus::LIN_RX_OK))).Times(0);
631-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep))).Times(1);
630+
EXPECT_CALL(participant, SendMsg(&master, ATransmissionWith(GoToSleepFrame(), LinFrameStatus::LIN_RX_OK, 35s))).Times(0);
631+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep, 35s))).Times(1);
632+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
632633

633634
master.GoToSleepInternal();
634635
}
@@ -668,8 +669,8 @@ TEST_F(Test_LinControllerTrivialSim, wake_up)
668669
master.Init(MakeControllerConfig(LinControllerMode::Master));
669670

670671
EXPECT_CALL(participant, SendMsg(&master, A<const LinWakeupPulse&>())).Times(1);
671-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1);
672-
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
672+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational, 35s))).Times(1);
673+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(2);
673674

674675
master.Wakeup();
675676
}
@@ -680,7 +681,8 @@ TEST_F(Test_LinControllerTrivialSim, wake_up_internal)
680681
master.Init(config);
681682

682683
EXPECT_CALL(participant, SendMsg(&master, A<const LinWakeupPulse&>())).Times(0);
683-
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1);
684+
EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational, 35s))).Times(1);
685+
EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1);
684686

685687
master.WakeupInternal();
686688
}

0 commit comments

Comments
 (0)