From 97c652e3b07f23b02c4e5183f6e37f890e32773a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 21 Dec 2016 17:41:09 +0100 Subject: [PATCH 1/4] Fixed method name --- Sparkle/SUUnarchiver.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUUnarchiver.m b/Sparkle/SUUnarchiver.m index 1f146c3f..353305e9 100644 --- a/Sparkle/SUUnarchiver.m +++ b/Sparkle/SUUnarchiver.m @@ -80,7 +80,7 @@ }); } -- (void)unarchiverDidFail:(NSError *)reason +- (void)unarchiverDidFailWithError:(NSError *)reason { NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]; if (reason) { From b03ae0d765a2265b086b05f4719fc78403ad2fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 21 Dec 2016 18:00:17 +0100 Subject: [PATCH 2/4] Moved assert --- Tests/SUUnarchiverTest.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index 3e1d55ad..c047f4c5 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -11,8 +11,7 @@ import XCTest class SUUnarchiverTest: XCTestCase { var password: String? = nil - var unarchivedExpectation: XCTestExpectation? = nil - var unarchivedResult: Bool = false + var unarchivedSuccessExpectation: XCTestExpectation? = nil func unarchiveTestAppWithExtension(_ archiveExtension: String) { @@ -26,23 +25,22 @@ class SUUnarchiverTest: XCTestCase try! fileManager.removeItem(at: tempDirectoryURL) } + self.unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))") + let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent) let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app") try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL) - self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))") - let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in - self.unarchivedResult = nil == error; - self.unarchivedExpectation!.fulfill() + XCTAssertNil(error); + self.unarchivedSuccessExpectation!.fulfill() }, progressBlock:{(progress: Double) -> Void in }); super.waitForExpectations(timeout: 7.0, handler: nil) - XCTAssertTrue(self.unarchivedResult) XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) From 8a3338b0785f968f12f55ea229174413b688f3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 21 Dec 2016 18:04:16 +0100 Subject: [PATCH 3/4] Extracted function --- Tests/SUUnarchiverTest.swift | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index c047f4c5..29acad85 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -13,8 +13,7 @@ class SUUnarchiverTest: XCTestCase var password: String? = nil var unarchivedSuccessExpectation: 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)! @@ -29,21 +28,28 @@ class SUUnarchiverTest: XCTestCase let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent) let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app") + + self.unarchiveTestSuccessAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL); + + super.waitForExpectations(timeout: 7.0, handler: nil) + + XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) + + XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) + } + + func unarchiveTestSuccessAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL) { + + let fileManager = FileManager.default try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL) - + let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in XCTAssertNil(error); self.unarchivedSuccessExpectation!.fulfill() }, progressBlock:{(progress: Double) -> Void in }); - - super.waitForExpectations(timeout: 7.0, handler: nil) - - XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) - - XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) } func testUnarchivingZip() From 2519eb573f74aebd6452627280818e1c2cbce666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 21 Dec 2016 18:04:38 +0100 Subject: [PATCH 4/4] Test unarchiving failure --- Tests/SUUnarchiverTest.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index 29acad85..25710d7e 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -12,6 +12,7 @@ class SUUnarchiverTest: XCTestCase { var password: String? = nil var unarchivedSuccessExpectation: XCTestExpectation? = nil + var unarchivedFailureExpectation: XCTestExpectation? = nil func unarchiveTestAppWithExtension(_ archiveExtension: String) { let appName = "SparkleTestCodeSignApp" @@ -25,11 +26,13 @@ class SUUnarchiverTest: XCTestCase } 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) @@ -37,6 +40,16 @@ class SUUnarchiverTest: XCTestCase XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) } + + func unarchiveTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL) { + let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension); + let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)! + + unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in + XCTAssertNotNil(error); + self.unarchivedFailureExpectation!.fulfill() + }, progressBlock:{(progress: Double) -> Void in }); + } func unarchiveTestSuccessAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL) {