Skip to content

Commit

Permalink
Merge pull request swiftlang#1464 from mamabusi/nskeyedarchiver-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci authored Mar 29, 2018
2 parents 58f1b73 + 77e436d commit d1272be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public func NSFullUserName() -> String {
}

internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, String) {
let template = "." + filePath + ".tmp.XXXXXX"
let template = filePath + ".tmp.XXXXXX"
let maxLength = Int(PATH_MAX) + 1
var buf = [Int8](repeating: 0, count: maxLength)
let _ = template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)
Expand Down
27 changes: 27 additions & 0 deletions TestFoundation/TestNSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class TestNSKeyedArchiver : XCTestCase {
("test_archive_uuid_bvref", test_archive_uuid_byref),
("test_archive_uuid_byvalue", test_archive_uuid_byvalue),
("test_archive_unhashable", test_archive_unhashable),
("test_archiveRootObject_String", test_archiveRootObject_String),
("test_archiveRootObject_URLRequest()", test_archiveRootObject_URLRequest),
]
}

Expand Down Expand Up @@ -345,4 +347,29 @@ class TestNSKeyedArchiver : XCTestCase {
XCTFail("test_archive_unhashable, de-serialization error \(error)")
}
}

func test_archiveRootObject_String() {
let filePath = NSTemporaryDirectory() + "testdir\(NSUUID().uuidString)"
let result = NSKeyedArchiver.archiveRootObject("Hello", toFile: filePath)
XCTAssertTrue(result)
do {
try FileManager.default.removeItem(atPath: filePath)
} catch {
XCTFail("Failed to clean up file")
}
}

func test_archiveRootObject_URLRequest() {
let filePath = NSTemporaryDirectory() + "testdir\(NSUUID().uuidString)"
let url = URL(string: "http://swift.org")!
let request = URLRequest(url: url)._bridgeToObjectiveC()
let result = NSKeyedArchiver.archiveRootObject(request, toFile: filePath)
XCTAssertTrue(result)
do {
try FileManager.default.removeItem(atPath: filePath)
} catch {
XCTFail("Failed to clean up file")
}
}

}

0 comments on commit d1272be

Please sign in to comment.