diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-09-25 16:34:23 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-09-26 16:35:38 +0200 |
| commit | f389956c2cd884df142adbf00ff2ac7e2f69c2b2 (patch) | |
| tree | 5f7d4869324760eb4ba0107c0356edc89efd1457 /ios/OperationsTests/OperationObserverTests.swift | |
| parent | 2e83b1ca27ff243a615ff10c94c20840b38dfd45 (diff) | |
| download | mullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.tar.xz mullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.zip | |
Move AsyncOperation into Operations static library and add separate tests
Diffstat (limited to 'ios/OperationsTests/OperationObserverTests.swift')
| -rw-r--r-- | ios/OperationsTests/OperationObserverTests.swift | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ios/OperationsTests/OperationObserverTests.swift b/ios/OperationsTests/OperationObserverTests.swift new file mode 100644 index 0000000000..c246cdc526 --- /dev/null +++ b/ios/OperationsTests/OperationObserverTests.swift @@ -0,0 +1,67 @@ +// +// OperationObserverTests.swift +// MullvadVPNTests +// +// Created by pronebird on 02/06/2022. +// Copyright © 2022 Mullvad VPN AB. All rights reserved. +// + +import Operations +import XCTest + +class OperationObserverTests: XCTestCase { + func testBlockObserver() throws { + let expectDidAttach = expectation(description: "didAttach handler") + let expectDidStart = expectation(description: "didStart handler") + let expectDidCancel = expectation(description: "didCancel handler") + expectDidCancel.isInverted = true + let expectDidFinish = expectation(description: "didAttach handler") + + let operation = AsyncBlockOperation() + operation.addBlockObserver(OperationBlockObserver( + didAttach: { op in + expectDidAttach.fulfill() + }, didStart: { op in + expectDidStart.fulfill() + }, didCancel: { op in + expectDidCancel.fulfill() + }, didFinish: { op, error in + expectDidFinish.fulfill() + } + )) + + let operationQueue = AsyncOperationQueue() + operationQueue.addOperation(operation) + + let expectations = [expectDidCancel, expectDidAttach, expectDidStart, expectDidFinish] + wait(for: expectations, timeout: 1, enforceOrder: true) + } + + func testBlockObserverWithCancelledOperation() { + let expectDidAttach = expectation(description: "didAttach handler") + let expectDidStart = expectation(description: "didStart handler") + expectDidStart.isInverted = true + let expectDidCancel = expectation(description: "didCancel handler") + let expectDidFinish = expectation(description: "didAttach handler") + + let operation = AsyncBlockOperation() + operation.addBlockObserver(OperationBlockObserver( + didAttach: { op in + expectDidAttach.fulfill() + }, didStart: { op in + expectDidStart.fulfill() + }, didCancel: { op in + expectDidCancel.fulfill() + }, didFinish: { op, error in + expectDidFinish.fulfill() + } + )) + operation.cancel() + + let operationQueue = AsyncOperationQueue() + operationQueue.addOperation(operation) + + let expectations = [expectDidAttach, expectDidCancel, expectDidStart, expectDidFinish] + wait(for: expectations, timeout: 1, enforceOrder: true) + } +} |
