Skip to content

Commit d4d13f9

Browse files
committed
Added Unit Test for NSPipe implementation.
The test currently only makes sure that writes into the pipe can be read correctly out of the pipe.
1 parent 47f3f93 commit d4d13f9

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */; };
1011
525AECED1BF2C9C500D15BB0 /* TestNSFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */; };
1112
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522C253A1BF16E1600804FC6 /* FoundationErrors.swift */; };
1213
528776191BF27D9500CB0090 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = 528776181BF27D9500CB0090 /* Test.plist */; };
@@ -313,6 +314,7 @@
313314
/* End PBXCopyFilesBuildPhase section */
314315

315316
/* Begin PBXFileReference section */
317+
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSPipe.swift; sourceTree = "<group>"; };
316318
522C253A1BF16E1600804FC6 /* FoundationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationErrors.swift; sourceTree = "<group>"; };
317319
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSFileManager.swift; sourceTree = "<group>"; };
318320
528776181BF27D9500CB0090 /* Test.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Test.plist; sourceTree = "<group>"; };
@@ -1004,6 +1006,7 @@
10041006
EA66F63D1BF1619600136161 /* TestNSDictionary.swift */,
10051007
EA66F63E1BF1619600136161 /* TestNSIndexSet.swift */,
10061008
EA66F63F1BF1619600136161 /* TestNSNumber.swift */,
1009+
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */,
10071010
EA66F6401BF1619600136161 /* TestNSPropertyList.swift */,
10081011
E876A73D1C1180E000F279EC /* TestNSRange.swift */,
10091012
EA66F6411BF1619600136161 /* TestNSSet.swift */,
@@ -1698,6 +1701,7 @@
16981701
EA66F6501BF1619600136161 /* TestNSNumber.swift in Sources */,
16991702
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */,
17001703
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
1704+
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
17011705
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
17021706
EA66F6541BF1619600136161 /* TestNSSet.swift in Sources */,
17031707
EA66F64A1BF1619600136161 /* TestNSArray.swift in Sources */,

TestFoundation/TestNSPipe.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
12+
import Foundation
13+
import XCTest
14+
#else
15+
import SwiftFoundation
16+
import SwiftXCTest
17+
#endif
18+
19+
20+
class TestNSPipe : XCTestCase {
21+
22+
func test_NSPipe() {
23+
let expectation = self.expectationWithDescription("Should read data")
24+
let aPipe = XNPipe()
25+
26+
let text = "test-pipe"
27+
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+
35+
aPipe.fileHandleForWriting.writeData(text.dataUsingEncoding(NSUTF8StringEncoding)!)
36+
37+
waitForExpectationsWithTimeout(1.0, handler: nil)
38+
}
39+
}

0 commit comments

Comments
 (0)