blob: 60d135e45891b09bca571098db3b705390a87f7d [file] [log] [blame]
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif
class TestNSFileHandle : XCTestCase {
static var allTests : [(String, (TestNSFileHandle) -> () throws -> ())] {
return [
("test_pipe", test_pipe),
]
}
func test_pipe() {
let pipe = NSPipe()
let inputs = ["Hello", "world", "🐶"]
for input in inputs {
let inputData = input.data(using: NSUTF8StringEncoding)!
// write onto pipe
pipe.fileHandleForWriting.writeData(inputData)
let outputData = pipe.fileHandleForReading.availableData
let output = String(data: outputData, encoding: NSUTF8StringEncoding)
XCTAssertEqual(output, input)
}
}
}