File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -20,20 +20,23 @@ import SwiftXCTest
20
20
class TestNSPipe : XCTestCase {
21
21
22
22
func test_NSPipe( ) {
23
- let expectation = self . expectationWithDescription ( " Should read data " )
24
23
let aPipe = NSPipe ( )
25
-
26
24
let text = " test-pipe "
27
25
28
- dispatch_async ( dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0 ) ) { ( ) -> Void in
29
- let data = aPipe. fileHandleForReading. readDataOfLength ( text. characters. count)
30
- if String ( data: data, encoding: NSUTF8StringEncoding) == text {
31
- expectation. fulfill ( )
32
- }
33
- }
34
-
26
+ // First write some data into the pipe
35
27
aPipe. fileHandleForWriting. writeData ( text. dataUsingEncoding ( NSUTF8StringEncoding) !)
36
28
37
- waitForExpectationsWithTimeout ( 1.0 , handler: nil )
29
+ // Then read it out again
30
+ let data = aPipe. fileHandleForReading. readDataOfLength ( text. characters. count)
31
+
32
+ // Make sure we *did* get data
33
+ XCTAssertNotNil ( data)
34
+
35
+ // Make sure the data can be converted
36
+ let convertedData = String ( data: data, encoding: NSUTF8StringEncoding)
37
+ XCTAssertNotNil ( convertedData)
38
+
39
+ // Make sure we did get back what we wrote in
40
+ XCTAssertEqual ( text, convertedData)
38
41
}
39
42
}
You can’t perform that action at this time.
0 commit comments