Skip to content

Commit 1fa2cfd

Browse files
bubskikevints
authored andcommitted
Unit tests added for OperationQueue.current
1 parent 62aa7ff commit 1fa2cfd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

TestFoundation/TestNSOperationQueue.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class TestNSOperationQueue : XCTestCase {
2626
("test_AsyncOperation", test_AsyncOperation),
2727
("test_isExecutingWorks", test_isExecutingWorks),
2828
("test_MainQueueGetter", test_MainQueueGetter),
29+
("test_CurrentQueueOnMainQueue", test_CurrentQueueOnMainQueue),
30+
("test_CurrentQueueOnBackgroundQueue", test_CurrentQueueOnBackgroundQueue),
31+
("test_CurrentQueueWithCustomUnderlyingQueue", test_CurrentQueueWithCustomUnderlyingQueue),
32+
("test_CurrentQueueWithUnderlyingQueueResetToNil", test_CurrentQueueWithUnderlyingQueueResetToNil),
2933
]
3034
}
3135

@@ -114,6 +118,51 @@ class TestNSOperationQueue : XCTestCase {
114118
*/
115119
XCTAssertFalse(OperationQueue.main.isSuspended)
116120
}
121+
122+
func test_CurrentQueueOnMainQueue() {
123+
XCTAssertTrue(OperationQueue.main === OperationQueue.current)
124+
}
125+
126+
func test_CurrentQueueOnBackgroundQueue() {
127+
let expectation = self.expectation(description: "Background execution")
128+
129+
let operationQueue = OperationQueue()
130+
operationQueue.addOperation {
131+
XCTAssertEqual(operationQueue, OperationQueue.current)
132+
expectation.fulfill()
133+
}
134+
135+
waitForExpectations(timeout: 1)
136+
}
137+
138+
func test_CurrentQueueWithCustomUnderlyingQueue() {
139+
let expectation = self.expectation(description: "Background execution")
140+
141+
let operationQueue = OperationQueue()
142+
operationQueue.underlyingQueue = DispatchQueue(label: "underlying_queue")
143+
144+
operationQueue.addOperation {
145+
XCTAssertEqual(operationQueue, OperationQueue.current)
146+
expectation.fulfill()
147+
}
148+
149+
waitForExpectations(timeout: 1)
150+
}
151+
152+
func test_CurrentQueueWithUnderlyingQueueResetToNil() {
153+
let expectation = self.expectation(description: "Background execution")
154+
155+
let operationQueue = OperationQueue()
156+
operationQueue.underlyingQueue = DispatchQueue(label: "underlying_queue")
157+
operationQueue.underlyingQueue = nil
158+
159+
operationQueue.addOperation {
160+
XCTAssertEqual(operationQueue, OperationQueue.current)
161+
expectation.fulfill()
162+
}
163+
164+
waitForExpectations(timeout: 1)
165+
}
117166
}
118167

119168
class AsyncOperation: Operation {

0 commit comments

Comments
 (0)