From fcd1c54360a72214bbcad823fb694e914da5e12e Mon Sep 17 00:00:00 2001 From: Klemens Muthmann Date: Fri, 25 Oct 2024 15:06:20 +0200 Subject: [PATCH] Add Pause/Resume Test --- .../DataCapturing/Capturing/Measurement.swift | 5 +-- .../DataCapturingTests/MeasurementTests.swift | 43 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Sources/DataCapturing/Capturing/Measurement.swift b/Sources/DataCapturing/Capturing/Measurement.swift index d9067c2..3a0e3f7 100644 --- a/Sources/DataCapturing/Capturing/Measurement.swift +++ b/Sources/DataCapturing/Capturing/Measurement.swift @@ -104,10 +104,9 @@ public class MeasurementImpl { - capturingQueue: The background queue to run data capturing on, so the UI is not blocked. - locationManagerFactory: A factory creating a *CoreLocation* `LocationManager` on demand. This can also be used to inject a mock implementation. */ - @available(macOS, unavailable) public init( capturingQueue: DispatchQueue = DispatchQueue.global(qos: .userInitiated), - locationManagerFactory: (() -> LocationManager) = { + /*locationManagerFactory: (() -> LocationManager) = { let manager = CLLocationManager() manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation manager.allowsBackgroundLocationUpdates = true @@ -116,7 +115,7 @@ public class MeasurementImpl { manager.showsBackgroundLocationIndicator = true manager.distanceFilter = kCLDistanceFilterNone return manager - }, + },*/ sensorCapturer: SensorCapturer, locationCapturer: LocationCapturer ) { diff --git a/Tests/DataCapturingTests/MeasurementTests.swift b/Tests/DataCapturingTests/MeasurementTests.swift index 14ac389..a0333d7 100644 --- a/Tests/DataCapturingTests/MeasurementTests.swift +++ b/Tests/DataCapturingTests/MeasurementTests.swift @@ -17,7 +17,7 @@ * along with the Cyface SDK for iOS. If not, see . */ -import XCTest +import Testing import CoreMotion import Combine @testable import DataCapturing @@ -29,8 +29,10 @@ import Combine - Version: 2.4.1 - Since: 1.0.0 */ -@available(macOS, unavailable) -class MeasurementTests: XCTestCase { +//@available(macOS, unavailable) +struct MeasurementTests { + + let measurement = MeasurementImpl(sensorCapturer: MocSensorCapturer(), locationCapturer: MocLocationCapturer()) /** Checks correct workings of a simple start/stop lifecycle. @@ -38,20 +40,18 @@ class MeasurementTests: XCTestCase { - Throws: - `DataCapturingError.isPaused` if the service was paused and thus starting or stopping it makes no sense. If you need to continue call `resume(((DataCapturingEvent) -> Void))`. */ + @Test func testStartStop_HappyPath() async throws { - let sensorCapturer = MocSensorCapturer() - let locationCapturer = MocLocationCapturer() - let measurement = MeasurementImpl(sensorCapturer: sensorCapturer, locationCapturer: locationCapturer) - XCTAssertEqual(measurement.isPaused, false) - XCTAssertEqual(measurement.isRunning, false) + try #require(measurement.isPaused == false) + try #require(measurement.isRunning == false) try measurement.start() - XCTAssertEqual(measurement.isPaused, false) - XCTAssertEqual(measurement.isRunning, true) + try #require(measurement.isPaused == false) + try #require(measurement.isRunning == true) try measurement.stop() - XCTAssertEqual(measurement.isPaused, false) - XCTAssertEqual(measurement.isRunning, false) + try #require(measurement.isPaused == false) + try #require(measurement.isRunning == false) } /** @@ -67,7 +67,26 @@ class MeasurementTests: XCTestCase { /*func testStartPauseResumeStop_HappyPath() throws { }*/ + @Test func testStartPauseResumeStopResumeStop() throws { + try #require(!measurement.isPaused) + try #require(!measurement.isRunning) + + try measurement.start() + try #require(!measurement.isPaused) + try #require(measurement.isRunning) + + try measurement.pause() + try #require(measurement.isPaused) + try #require(!measurement.isRunning) + + try measurement.resume() + try #require(!measurement.isPaused) + try #require(measurement.isRunning) + + try measurement.stop() + try #require(!measurement.isPaused) + try #require(!measurement.isRunning) } func testStartPauseStop_HappyPath() throws {