@@ -26,6 +26,10 @@ class TestNSOperationQueue : XCTestCase {
26
26
( " test_AsyncOperation " , test_AsyncOperation) ,
27
27
( " test_isExecutingWorks " , test_isExecutingWorks) ,
28
28
( " test_MainQueueGetter " , test_MainQueueGetter) ,
29
+ ( " test_CurrentQueueOnMainQueue " , test_CurrentQueueOnMainQueue) ,
30
+ ( " test_CurrentQueueOnBackgroundQueue " , test_CurrentQueueOnBackgroundQueue) ,
31
+ ( " test_CurrentQueueWithCustomUnderlyingQueue " , test_CurrentQueueWithCustomUnderlyingQueue) ,
32
+ ( " test_CurrentQueueWithUnderlyingQueueResetToNil " , test_CurrentQueueWithUnderlyingQueueResetToNil) ,
29
33
]
30
34
}
31
35
@@ -114,6 +118,51 @@ class TestNSOperationQueue : XCTestCase {
114
118
*/
115
119
XCTAssertFalse ( OperationQueue . main. isSuspended)
116
120
}
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
+ }
117
166
}
118
167
119
168
class AsyncOperation : Operation {
0 commit comments