diff --git a/score/mw/com/impl/bindings/lola/skeleton_event_test.cpp b/score/mw/com/impl/bindings/lola/skeleton_event_test.cpp index cf5b2a25..d4ce8b98 100644 --- a/score/mw/com/impl/bindings/lola/skeleton_event_test.cpp +++ b/score/mw/com/impl/bindings/lola/skeleton_event_test.cpp @@ -318,5 +318,51 @@ TEST_F(SkeletonEventPrepareStopOfferFixture, StopOfferSkeletonEvent) skeleton_event_->PrepareStopOffer(); } +using SkeletonEventTimestampFixture = SkeletonEventFixture; +TEST_F(SkeletonEventTimestampFixture, SendUpdatesTimestampInControlData) +{ + // GIVEN a skeleton event that is offered + const bool enforce_max_samples{true}; + impl::tracing::SkeletonEventTracingData tracing_data{}; + InitialiseSkeletonEvent( + fake_element_fq_id_, fake_event_name_, max_samples_, max_subscribers_, enforce_max_samples, tracing_data); + + skeleton_event_->PrepareOffer(); + + // WHEN we allocate and send a first sample + auto first_allocated_slot_result = skeleton_event_->Allocate(); + ASSERT_TRUE(first_allocated_slot_result.has_value()); + auto first_allocated_slot = std::move(first_allocated_slot_result).value(); + + const impl::SampleAllocateePtrView first_view{first_allocated_slot}; + auto* first_lola_ptr = first_view.template As>(); + auto first_slot_indicator = first_lola_ptr->GetReferencedSlot(); + + auto first_send_result = skeleton_event_->Send(std::move(first_allocated_slot), score::cpp::nullopt); + ASSERT_TRUE(first_send_result.has_value()); + + // THEN its timestamp should be a valid, non-zero value + const EventSlotStatus first_final_slot_status{first_slot_indicator.GetSlotQM().load()}; + // AND the first timestamp should be 2, as it's the first one after initialization. + const auto first_timestamp = first_final_slot_status.GetTimeStamp(); + EXPECT_EQ(first_timestamp, 2U); + + // AND WHEN we allocate and send a second sample + auto second_allocated_slot_result = skeleton_event_->Allocate(); + ASSERT_TRUE(second_allocated_slot_result.has_value()); + auto second_allocated_slot = std::move(second_allocated_slot_result).value(); + + const impl::SampleAllocateePtrView second_view{second_allocated_slot}; + auto* second_lola_ptr = second_view.template As>(); + auto second_slot_indicator = second_lola_ptr->GetReferencedSlot(); + auto second_send_result = skeleton_event_->Send(std::move(second_allocated_slot), score::cpp::nullopt); + ASSERT_TRUE(second_send_result.has_value()); + + // THEN its timestamp should be exactly one greater than the first one + const EventSlotStatus second_final_slot_status{second_slot_indicator.GetSlotQM().load()}; + const auto second_timestamp = second_final_slot_status.GetTimeStamp(); + EXPECT_EQ(second_timestamp, first_timestamp + 1U) << "The second timestamp should be exactly one greater than the first."; +} + } // namespace -} // namespace score::mw::com::impl::lola +} // namespace score::mw::com::impl::lola \ No newline at end of file