diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index 0a135e26..ec499a6b 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -11,11 +11,10 @@ import XCTest class SUUnarchiverTest: XCTestCase { var password: String? = nil - var unarchivedExpectation: XCTestExpectation? = nil - var unarchivedResult: Bool = false + var unarchivedSuccessExpectation: XCTestExpectation? = nil + var unarchivedFailureExpectation: XCTestExpectation? = nil - func unarchiveTestAppWithExtension(_ archiveExtension: String) - { + func unarchiveTestAppWithExtension(_ archiveExtension: String) { let appName = "SparkleTestCodeSignApp" let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)! @@ -26,26 +25,44 @@ class SUUnarchiverTest: XCTestCase try! fileManager.removeItem(at: tempDirectoryURL) } + self.unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))") + self.unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension))") + let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent) let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app") + + self.unarchiveTestSuccessAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL); + self.unarchiveTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL); + + super.waitForExpectations(timeout: 7.0, handler: nil) + + XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) + + XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) + } + + func unarchiveTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL) { + let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension); + let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: self.password)! + + unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in + XCTAssertNotNil(error); + self.unarchivedFailureExpectation!.fulfill() + }, progressBlock: nil); + } + + func unarchiveTestSuccessAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL) { + + let fileManager = FileManager.default try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL) - self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))") - let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: self.password)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in - self.unarchivedResult = (nil == error) - self.unarchivedExpectation!.fulfill() + XCTAssertNil(error); + self.unarchivedSuccessExpectation!.fulfill() }, progressBlock: nil); - - super.waitForExpectations(timeout: 7.0, handler: nil) - - XCTAssertTrue(self.unarchivedResult) - XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) - - XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) } func testUnarchivingZip()