Skip to content

Commit

Permalink
Add Pause/Resume Test
Browse files Browse the repository at this point in the history
  • Loading branch information
muthenberg committed Oct 25, 2024
1 parent 5394616 commit fcd1c54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Sources/DataCapturing/Capturing/Measurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -116,7 +115,7 @@ public class MeasurementImpl {
manager.showsBackgroundLocationIndicator = true
manager.distanceFilter = kCLDistanceFilterNone
return manager
},
},*/
sensorCapturer: SensorCapturer,
locationCapturer: LocationCapturer
) {
Expand Down
43 changes: 31 additions & 12 deletions Tests/DataCapturingTests/MeasurementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with the Cyface SDK for iOS. If not, see <http://www.gnu.org/licenses/>.
*/

import XCTest
import Testing
import CoreMotion
import Combine
@testable import DataCapturing
Expand All @@ -29,29 +29,29 @@ 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.

- 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)
}

/**
Expand All @@ -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 {
Expand Down

0 comments on commit fcd1c54

Please sign in to comment.