mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
95 lines
2.9 KiB
Swift
95 lines
2.9 KiB
Swift
//
|
|
// SUUnarchiverTest.swift
|
|
// Sparkle
|
|
//
|
|
// Created by Mayur Pawashe on 9/4/15.
|
|
// Copyright © 2015 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
|
|
class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
|
|
{
|
|
var password: String? = nil
|
|
var unarchivedExpectation: XCTestExpectation? = nil
|
|
var unarchivedResult: Bool = false
|
|
|
|
func unarchiverDidFail()
|
|
{
|
|
self.unarchivedResult = false
|
|
self.unarchivedExpectation!.fulfill()
|
|
}
|
|
|
|
func unarchiverDidFinish()
|
|
{
|
|
self.unarchivedResult = true
|
|
self.unarchivedExpectation!.fulfill()
|
|
}
|
|
|
|
func unarchiveTestAppWithExtension(archiveExtension: String)
|
|
{
|
|
let appName = "SparkleTestCodeSignApp"
|
|
let archiveResourceURL = NSBundle(forClass: self.dynamicType).URLForResource(appName, withExtension: archiveExtension)!
|
|
|
|
let fileManager = NSFileManager.defaultManager()
|
|
|
|
let tempDirectoryURL = try! fileManager.URLForDirectory(.ItemReplacementDirectory, inDomain: .UserDomainMask, appropriateForURL: NSURL(fileURLWithPath: NSHomeDirectory()), create: true)
|
|
defer {
|
|
try! fileManager.removeItemAtURL(tempDirectoryURL)
|
|
}
|
|
|
|
let tempArchiveURL = tempDirectoryURL.URLByAppendingPathComponent(archiveResourceURL.lastPathComponent!)
|
|
let extractedAppURL = tempDirectoryURL.URLByAppendingPathComponent(appName).URLByAppendingPathExtension("app")
|
|
|
|
try! fileManager.copyItemAtURL(archiveResourceURL, toURL: tempArchiveURL)
|
|
|
|
self.unarchivedExpectation = super.expectationWithDescription("Unarchived Application (format: \(archiveExtension))")
|
|
|
|
let unarchiver = SUUnarchiver.unarchiverForPath(tempArchiveURL.path!, updatingHostBundlePath: nil, decryptionPassword: self.password, delegate: self)
|
|
unarchiver!.start()
|
|
|
|
super.waitForExpectationsWithTimeout(7.0, handler: nil)
|
|
|
|
XCTAssertTrue(self.unarchivedResult)
|
|
XCTAssertTrue(fileManager.fileExistsAtPath(extractedAppURL.path!))
|
|
|
|
XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path!))
|
|
}
|
|
|
|
func testUnarchivingZip()
|
|
{
|
|
self.unarchiveTestAppWithExtension("zip")
|
|
}
|
|
|
|
func testUnarchivingTarDotGz()
|
|
{
|
|
self.unarchiveTestAppWithExtension("tar.gz")
|
|
}
|
|
|
|
func testUnarchivingTar()
|
|
{
|
|
self.unarchiveTestAppWithExtension("tar")
|
|
}
|
|
|
|
func testUnarchivingTarDotBz2()
|
|
{
|
|
self.unarchiveTestAppWithExtension("tar.bz2")
|
|
}
|
|
|
|
func testUnarchivingTarDotXz()
|
|
{
|
|
self.unarchiveTestAppWithExtension("tar.xz")
|
|
}
|
|
|
|
func testUnarchivingDmg()
|
|
{
|
|
self.unarchiveTestAppWithExtension("dmg")
|
|
}
|
|
|
|
func testUnarchivingEncryptedDmg()
|
|
{
|
|
self.password = "testpass";
|
|
self.unarchiveTestAppWithExtension("enc.dmg")
|
|
}
|
|
}
|