From cd81881d47336269237b7e07ce2a141401488a96 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Fri, 29 Apr 2016 23:52:00 +0200 Subject: [PATCH] Adding a zip / unzip with password test --- ZipTests/ZipTests.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ZipTests/ZipTests.swift b/ZipTests/ZipTests.swift index 2b59732..15b26ee 100644 --- a/ZipTests/ZipTests.swift +++ b/ZipTests/ZipTests.swift @@ -192,6 +192,32 @@ class ZipTests: XCTestCase { } } + func testZipUnzipPassword() { + do { + let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! + let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! + let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL + let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") + try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in + print(progress) + }) + let fileManager = NSFileManager.defaultManager() + XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!)) + guard let fileExtension = zipFilePath.pathExtension, let fileName = zipFilePath.lastPathComponent else { + throw ZipError.UnzipFail + } + let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "") + let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL + let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true) + try Zip.unzipFile(zipFilePath, destination: destinationUrl, overwrite: true, password: "password", progress: nil) + XCTAssertTrue(fileManager.fileExistsAtPath(destinationUrl.path!)) + } + catch { + XCTFail() + } + } + + func testQuickUnzipSubDir() { do { let bookURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! -- 2.26.2