diff --git a/ZipTests/ZipTests.swift b/ZipTests/ZipTests.swift index 2b59732e041af05d219f3cdb439b93ba2bdb0cc6..15b26ee7125a41225294f3142b58ea28651342f5 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")!