Skip to content

Commit

Permalink
Add test for RtClientState GracePeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
fgo-ableton committed Feb 26, 2018
1 parent c8220e7 commit 15024b4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/ableton/link/tst_Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,47 @@ TEST_CASE("Controller | CallbacksCalledBySettingClientStateRealtimeSafe", "[Cont
});
}

TEST_CASE("Controller | GetClientStateRtSafeGracePeriod", "[Controller]")
{
using namespace std::chrono;

auto clock = MockClock{};
auto tempoCallback = TempoClientCallback{};
auto startStopStateCallback = StartStopStateClientCallback{};
MockController controller(Tempo{100.0}, [](std::size_t) {}, std::ref(tempoCallback),
std::ref(startStopStateCallback), clock, util::injectVal(MockIoContext{}));
controller.enable(true);

clock.advance(microseconds{1});
const auto initialTimeline =
Optional<Timeline>{Timeline{Tempo{50.}, Beats{0.}, clock.micros()}};
const auto initialStartStopState =
Optional<StartStopState>{StartStopState{true, kAnyBeatTime, clock.micros()}};
const auto initialState =
IncomingClientState{initialTimeline, initialStartStopState, clock.micros()};

controller.setClientStateRtSafe(
{initialTimeline, initialStartStopState, clock.micros()});
REQUIRE(initialState == controller.clientState());
REQUIRE(initialState == controller.clientStateRtSafe());

clock.advance(microseconds{1});
const auto newTimeline =
Optional<Timeline>{Timeline{Tempo{70.}, Beats{1.}, clock.micros()}};
const auto newStartStopState =
Optional<StartStopState>{StartStopState{false, kAnyBeatTime, clock.micros()}};
const auto newState =
IncomingClientState{newTimeline, newStartStopState, clock.micros()};

controller.setClientState({newTimeline, newStartStopState, clock.micros()});
clock.advance(milliseconds{500});
CHECK(newState == controller.clientState());
CHECK(initialState == controller.clientStateRtSafe());

clock.advance(milliseconds{500});
CHECK(newState == controller.clientState());
CHECK(newState == controller.clientStateRtSafe());
}

} // namespace link
} // namespace ableton

0 comments on commit 15024b4

Please sign in to comment.