Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155import Testing
@testable import ParcelAnimation
private final class DisplayLinkCallbackIdentity {}
@Suite("Display-link idle callback regression")@MainActorstruct DisplayLinkIdleRegressionTests { @Test func lateCallbackAfterLastCancellationCannotAdvanceClock() throws { let source = TestDisplayLink() var output: [MotionFrame] = [] let driver = DisplayLinkDriver( source: source, clock: { 0 }, onFrames: { output += $0 }, onFailure: { Issue.record("Unexpected failure: \($0)") }) try driver.schedule([request()], at: 0) let staleTick = try #require(source.callback) driver.cancel(testWindow) staleTick(100) #expect(driver.animator.timestamp == 0) #expect(output.isEmpty) #expect(!source.isRunning) try driver.schedule([request()], at: 1) #expect(source.startCount == 2) source.fire(at: 1.2) #expect(output.last?.isFinal == true) #expect(!source.isRunning) }
@Test func stoppedCallbackCannotReportClockFailure() throws { let source = TestDisplayLink() var failures: [MotionError] = [] let driver = DisplayLinkDriver( source: source, onFrames: { _ in Issue.record("Unexpected frame") }, onFailure: { failures.append($0) }) try driver.schedule([request()], at: 1) let staleTick = try #require(source.callback) driver.stop() staleTick(.nan) staleTick(0) #expect(failures.isEmpty) #expect(driver.animator.timestamp == 1) #expect(driver.animator.isIdle && !driver.isRunning) }
@Test func stopDuringActiveAnimationRejectsDelayedTicksEvenAfterRestart() throws { let source = TestDisplayLink() var output: [MotionFrame] = [] var failures: [MotionError] = [] let driver = DisplayLinkDriver( source: source, onFrames: { output += $0 }, onFailure: { failures.append($0) }) try driver.schedule([request()], at: 0) let staleTick = try #require(source.callback) source.fire(at: 0.05) #expect(output.count == 1 && output.last?.isFinal == false) #expect(!driver.animator.isIdle) let beforeStop = output driver.stop() staleTick(100) #expect(output == beforeStop) #expect(driver.animator.timestamp == 0.05) #expect(driver.animator.isIdle && !driver.isRunning)
let replacement = request(target: rect(700), generation: 1) try driver.schedule([replacement], at: 1) staleTick(.nan) staleTick(100) #expect(output == beforeStop) #expect(driver.animator.timestamp == 1) #expect(driver.isRunning && !driver.animator.isIdle) source.fire(at: 1.2) #expect(output.count == beforeStop.count + 1) #expect(output.last?.rect == replacement.target) #expect(output.last?.generation == 1 && output.last?.isFinal == true) #expect(failures.isEmpty) #expect(source.startCount == 2 && source.stopCount == 2) }
@Test(arguments: [MotionPolicy(enabled: false), MotionPolicy(reduceMotion: true)]) func pendingSettleKeepsLinkAliveUntilFinalFrameIsDelivered(policy: MotionPolicy) throws { let source = TestDisplayLink() var output: [MotionFrame] = [] var runningAtDelivery: [Bool] = [] let driver = DisplayLinkDriver( source: source, onFrames: { output += $0 runningAtDelivery.append(source.isRunning) }, onFailure: { Issue.record("Unexpected failure: \($0)") }) let motion = request() try driver.schedule([motion], at: 0) source.fire(at: 0.05) try driver.updatePolicy(policy, at: 0.05) let pendingTick = try #require(source.callback) #expect(driver.isRunning && !driver.animator.isIdle) pendingTick(1) #expect(output.count == 2) #expect(output.last?.rect == motion.target && output.last?.isFinal == true) #expect(runningAtDelivery == [true, false]) #expect(driver.animator.isIdle && !driver.isRunning) pendingTick(100) #expect(output.count == 2 && driver.animator.timestamp == 1) #expect(source.startCount == 1 && source.stopCount == 1) }
@Test func explicitStopCancelsPendingSettleWithoutWritingAfterShutdown() throws { let source = TestDisplayLink() var output: [MotionFrame] = [] let driver = DisplayLinkDriver( source: source, onFrames: { output += $0 }, onFailure: { Issue.record("Unexpected failure: \($0)") }) try driver.schedule([request()], at: 0) source.fire(at: 0.05) try driver.updatePolicy(MotionPolicy(reduceMotion: true), at: 0.05) let pendingTick = try #require(source.callback) #expect(driver.isRunning && !driver.animator.isIdle) driver.stop() pendingTick(1) #expect(output.count == 1 && output.last?.isFinal == false) #expect(driver.animator.timestamp == 0.05) #expect(driver.animator.isIdle && !driver.isRunning) #expect(source.stopCount == 1) }
@Test func replayedOldSenderCannotInvokeReplacementSourceCallback() { let oldLink = DisplayLinkCallbackIdentity() let currentLink = DisplayLinkCallbackIdentity() var callback: RegisteredDisplayLinkCallback<DisplayLinkCallbackIdentity>? = RegisteredDisplayLinkCallback( source: oldLink, callback: { _ in Issue.record("Unexpected old-source callback") }) callback = nil var ticks: [Double] = [] callback = RegisteredDisplayLinkCallback(source: currentLink, callback: { ticks.append($0) }) callback?.tick(from: oldLink, at: .nan) callback?.tick(from: oldLink, at: 100) #expect(ticks.isEmpty) callback?.tick(from: currentLink, at: 1) #expect(ticks == [1]) callback = nil callback?.tick(from: currentLink, at: 2) #expect(ticks == [1]) }
@Test func idlePolicyAndSettingsChangesDoNotStartLink() throws { let source = TestDisplayLink() let driver = DisplayLinkDriver( source: source, onFrames: { _ in Issue.record("Unexpected frame") }, onFailure: { Issue.record("Unexpected failure: \($0)") }) try driver.updatePolicy(MotionPolicy(reduceMotion: true), at: 0) try driver.updateSettings(MotionSettings(speedMultiplier: 2), at: 1) driver.cancel(testWindow) #expect(source.startCount == 0) #expect(driver.animator.isIdle && !driver.isRunning) }}