Skip to content

Commit d1272be

Browse files
authored
Merge pull request swiftlang#1464 from mamabusi/nskeyedarchiver-branch
2 parents 58f1b73 + 77e436d commit d1272be

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Foundation/NSPathUtilities.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public func NSFullUserName() -> String {
590590
}
591591

592592
internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, String) {
593-
let template = "." + filePath + ".tmp.XXXXXX"
593+
let template = filePath + ".tmp.XXXXXX"
594594
let maxLength = Int(PATH_MAX) + 1
595595
var buf = [Int8](repeating: 0, count: maxLength)
596596
let _ = template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)

TestFoundation/TestNSKeyedArchiver.swift

+27
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class TestNSKeyedArchiver : XCTestCase {
107107
("test_archive_uuid_bvref", test_archive_uuid_byref),
108108
("test_archive_uuid_byvalue", test_archive_uuid_byvalue),
109109
("test_archive_unhashable", test_archive_unhashable),
110+
("test_archiveRootObject_String", test_archiveRootObject_String),
111+
("test_archiveRootObject_URLRequest()", test_archiveRootObject_URLRequest),
110112
]
111113
}
112114

@@ -345,4 +347,29 @@ class TestNSKeyedArchiver : XCTestCase {
345347
XCTFail("test_archive_unhashable, de-serialization error \(error)")
346348
}
347349
}
350+
351+
func test_archiveRootObject_String() {
352+
let filePath = NSTemporaryDirectory() + "testdir\(NSUUID().uuidString)"
353+
let result = NSKeyedArchiver.archiveRootObject("Hello", toFile: filePath)
354+
XCTAssertTrue(result)
355+
do {
356+
try FileManager.default.removeItem(atPath: filePath)
357+
} catch {
358+
XCTFail("Failed to clean up file")
359+
}
360+
}
361+
362+
func test_archiveRootObject_URLRequest() {
363+
let filePath = NSTemporaryDirectory() + "testdir\(NSUUID().uuidString)"
364+
let url = URL(string: "http://swift.org")!
365+
let request = URLRequest(url: url)._bridgeToObjectiveC()
366+
let result = NSKeyedArchiver.archiveRootObject(request, toFile: filePath)
367+
XCTAssertTrue(result)
368+
do {
369+
try FileManager.default.removeItem(atPath: filePath)
370+
} catch {
371+
XCTFail("Failed to clean up file")
372+
}
373+
}
374+
348375
}

0 commit comments

Comments
 (0)