Skip to content

Commit

Permalink
Add Test for 32-bit Overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiede committed Aug 31, 2018
1 parent e403004 commit ded8806
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Tests/CoreTests/BehaviorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ class MockBehaviorChannel: BehaviorChannel {
var rootController: BehaviorController?
var lastUpdate: Date = Date.distantPast
var brightnessDelta: Double = 1.0
var interval: TimeInterval = 30.0

func set(layer: ChannelLayer, forType type: ChannelLayerType) {
// Not Needed for Tests
}

func segment(forDate date: Date) -> ChannelSegment {
let startDate = date.addingTimeInterval(-30.0)
let endDate = date.addingTimeInterval(30.0)
let startDate = date.addingTimeInterval(-self.interval)
let endDate = date.addingTimeInterval(self.interval)
return MockChannelSegment(startBrightness: 0.0, endBrightness: brightnessDelta, startDate: startDate, endDate: endDate)
}

Expand Down Expand Up @@ -172,6 +173,32 @@ class BehaviorTests: XCTestCase {
}
}
}

func testDefaultNextUpdateLargeInterval() {
let testBehavior = DefaultLightBehavior()
let mockController = MockBehaviorController(channelCount: 1)

for case let channel as MockBehaviorChannel in mockController.channelControllers.values {
channel.brightnessDelta = 1.0 / 4096
channel.interval = 60 * 30.0
}

let refreshDate = Date()
let result = testBehavior.nextUpdate(forController: mockController, forDate: refreshDate)

switch result {
case .repeating( _, let dispatchInterval):
switch dispatchInterval {
case .milliseconds(let milliseconds):
// Good
XCTAssertGreaterThan(milliseconds, 1000 * 1000)
default:
XCTFail("Long intervals shouldn't provide anything but milliseconds")
}
default:
XCTFail("Should get a repeating interval")
}
}

func testPreviewRefresh() {
let startDate = Date()
Expand Down

0 comments on commit ded8806

Please sign in to comment.