Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion score/mw/com/impl/bindings/lola/skeleton_event_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<test::TestSampleType> first_view{first_allocated_slot};
auto* first_lola_ptr = first_view.template As<lola::SampleAllocateePtr<test::TestSampleType>>();
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<test::TestSampleType> second_view{second_allocated_slot};
auto* second_lola_ptr = second_view.template As<lola::SampleAllocateePtr<test::TestSampleType>>();
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