Skip to content

Commit 15024b4

Browse files
committed
Add test for RtClientState GracePeriod
1 parent c8220e7 commit 15024b4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/ableton/link/tst_Controller.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,5 +393,47 @@ TEST_CASE("Controller | CallbacksCalledBySettingClientStateRealtimeSafe", "[Cont
393393
});
394394
}
395395

396+
TEST_CASE("Controller | GetClientStateRtSafeGracePeriod", "[Controller]")
397+
{
398+
using namespace std::chrono;
399+
400+
auto clock = MockClock{};
401+
auto tempoCallback = TempoClientCallback{};
402+
auto startStopStateCallback = StartStopStateClientCallback{};
403+
MockController controller(Tempo{100.0}, [](std::size_t) {}, std::ref(tempoCallback),
404+
std::ref(startStopStateCallback), clock, util::injectVal(MockIoContext{}));
405+
controller.enable(true);
406+
407+
clock.advance(microseconds{1});
408+
const auto initialTimeline =
409+
Optional<Timeline>{Timeline{Tempo{50.}, Beats{0.}, clock.micros()}};
410+
const auto initialStartStopState =
411+
Optional<StartStopState>{StartStopState{true, kAnyBeatTime, clock.micros()}};
412+
const auto initialState =
413+
IncomingClientState{initialTimeline, initialStartStopState, clock.micros()};
414+
415+
controller.setClientStateRtSafe(
416+
{initialTimeline, initialStartStopState, clock.micros()});
417+
REQUIRE(initialState == controller.clientState());
418+
REQUIRE(initialState == controller.clientStateRtSafe());
419+
420+
clock.advance(microseconds{1});
421+
const auto newTimeline =
422+
Optional<Timeline>{Timeline{Tempo{70.}, Beats{1.}, clock.micros()}};
423+
const auto newStartStopState =
424+
Optional<StartStopState>{StartStopState{false, kAnyBeatTime, clock.micros()}};
425+
const auto newState =
426+
IncomingClientState{newTimeline, newStartStopState, clock.micros()};
427+
428+
controller.setClientState({newTimeline, newStartStopState, clock.micros()});
429+
clock.advance(milliseconds{500});
430+
CHECK(newState == controller.clientState());
431+
CHECK(initialState == controller.clientStateRtSafe());
432+
433+
clock.advance(milliseconds{500});
434+
CHECK(newState == controller.clientState());
435+
CHECK(newState == controller.clientStateRtSafe());
436+
}
437+
396438
} // namespace link
397439
} // namespace ableton

0 commit comments

Comments
 (0)