Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler errors in BenchTests #2598

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Bench/BenchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BenchViewController: UITableViewController {
destination.coordinate
])

let viewController = ControlRouteViewController(for: route, routeOptions: routeOptions)
let viewController = ControlRouteViewController(for: route, routeIndex: 0, routeOptions: routeOptions)
viewController.delegate = self
navigationController?.pushViewController(viewController, animated: true)
}
Expand Down
15 changes: 8 additions & 7 deletions BenchTests/BenchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BenchTests: XCTestCase, CLLocationManagerDelegate {
let trace = Fixture.locations(from: "PipeFittersUnion-FourSeasonsBoston.trace")

let locationManager = ReplayLocationManager(locations: trace)
_ = navigationViewController(route: route, routeOptions: routeOptions, locationManager: locationManager)
_ = navigationViewController(route: route, routeIndex: 0, routeOptions: routeOptions, locationManager: locationManager)

locationManager.tick()

Expand All @@ -44,7 +44,7 @@ class BenchTests: XCTestCase, CLLocationManagerDelegate {
let trace = Fixture.locations(from: "DCA-Arboretum.trace")

let locationManager = ReplayLocationManager(locations: trace)
_ = navigationViewController(route: route, routeOptions: routeOptions, locationManager: locationManager)
_ = navigationViewController(route: route, routeIndex: 0, routeOptions: routeOptions, locationManager: locationManager)

locationManager.tick()

Expand All @@ -55,20 +55,21 @@ class BenchTests: XCTestCase, CLLocationManagerDelegate {
}
}

func navigationViewController(route: Route, routeOptions: NavigationRouteOptions, locationManager: ReplayLocationManager) -> NavigationViewController {
let speechAPI = SpeechAPISpy(accessToken: token)
func navigationViewController(route: Route, routeIndex: Int, routeOptions: NavigationRouteOptions, locationManager: ReplayLocationManager) -> NavigationViewController {
let directions = DirectionsSpy()
let service = MapboxNavigationService(route: route,
let service = MapboxNavigationService(route: route, routeIndex: 0,
routeOptions: routeOptions,
directions: directions,
locationSource: locationManager,
eventsManagerType: NavigationEventsManagerSpy.self,
simulating: .never,
routerType: RouteController.self)
let voiceController = MapboxVoiceController(navigationService: service, speechClient: speechAPI, audioPlayerType: AudioPlayerDummy.self)
let speechSynthesizer = SpeechSynthesizerSpy()
let voiceController = RouteVoiceController(navigationService: service, speechSynthesizer: speechSynthesizer, accessToken: token)

let navigationOptions = NavigationOptions(navigationService: service, voiceController: voiceController)

return NavigationViewController(for: route, routeOptions: routeOptions, navigationOptions: navigationOptions)
let navigationViewController = NavigationViewController(for: route, routeIndex: routeIndex, routeOptions: routeOptions, navigationOptions: navigationOptions)
return navigationViewController
}
}
29 changes: 22 additions & 7 deletions TestHelper/SpeechAPISpy.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Foundation
import MapboxSpeech
import AVKit
import MapboxDirections
import MapboxCoreNavigation
@testable import MapboxNavigation

/**
This class can be used as a substitute for SpeechSynthesizer under test, in order to verify whether expected calls were made.
*/
Expand Down Expand Up @@ -30,21 +33,33 @@ public class SpeechAPISpy: SpeechSynthesizer {
}
}

public class AudioPlayerDummy: AVAudioPlayer {
public let sound = NSDataAsset(name: "reroute-sound", bundle: .mapboxNavigation)!

public class SpeechSynthesizerSpy: SpeechSynthesizing {
lazy var notifier: NotificationCenter = .default
fileprivate typealias Note = Notification.Name.MapboxVoiceTests

override public func prepareToPlay() -> Bool {
public init() {}

public var delegate: SpeechSynthesizingDelegate?

public var muted = false

public var volume: Float = 0

public var isSpeaking = false

public var locale: Locale?

public func prepareIncomingSpokenInstructions(_ instructions: [SpokenInstruction], locale: Locale?) {
notifier.post(name: Note.prepareToPlay, object: self)
return true
}

override public func play() -> Bool {
public func speak(_ instruction: SpokenInstruction, during legProgress: RouteLegProgress, locale: Locale?) {
notifier.post(name: Note.play, object: self)
return true
}

public func stopSpeaking() {}

public func interruptSpeaking() {}
}

extension Notification.Name {
Expand Down