ZipTests.swift 2.61 KB
Newer Older
Roy Marmelstein's avatar
Roy Marmelstein committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//
//  ZipTests.swift
//  ZipTests
//
//  Created by Roy Marmelstein on 13/12/2015.
//  Copyright © 2015 Roy Marmelstein. All rights reserved.
//

import XCTest
@testable import Zip

class ZipTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
    }
    
    override func tearDown() {
        super.tearDown()
    }
    
22 23 24 25 26 27 28 29 30
    func testQuickUnzip() {
        do {
            let fileAbsoluteURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
            let destinationURL = try Zip().quickUnzipFile(fileAbsoluteURL)
            let fileManager = NSFileManager.defaultManager()
            XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!))
        }
        catch {
            XCTFail()
Roy Marmelstein's avatar
Roy Marmelstein committed
31
        }
Roy Marmelstein's avatar
Roy Marmelstein committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
    }
    
    func testQuickUnzipNonExistingPath() {
        do {
            let filePathURL = NSBundle(forClass: ZipTests.self).resourcePath
            let fileAbsoluteURL = NSURL(string:"\(filePathURL!)/bb9.zip")
            let destinationURL = try Zip().quickUnzipFile(fileAbsoluteURL!)
            let fileManager = NSFileManager.defaultManager()
            XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!))
        }
        catch {
            XCTAssert(true)
        }
    }
46

Roy Marmelstein's avatar
Roy Marmelstein committed
47 48 49 50 51 52 53 54 55 56
    func testQuickUnzipNonZipPath() {
        do {
            let fileAbsoluteURL = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
            let destinationURL = try Zip().quickUnzipFile(fileAbsoluteURL)
            let fileManager = NSFileManager.defaultManager()
            XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!))
        }
        catch {
            XCTAssert(true)
        }
Roy Marmelstein's avatar
Roy Marmelstein committed
57 58
    }
    
Roy Marmelstein's avatar
Roy Marmelstein committed
59 60 61 62 63 64 65 66 67 68 69
    func testQuickUnzipProgress() {
        do {
            let fileAbsoluteURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
            try Zip().quickUnzipFile(fileAbsoluteURL, progress: { (progress) -> () in
                XCTAssert(true)
            })
        }
        catch {
            XCTFail()
        }
    }
70
    
71 72 73 74 75 76 77 78 79 80 81 82 83
    func testQuickZip() {
        do {
            let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
            let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
            let destinationURL = try Zip().quickZipFiles([imageURL1, imageURL2], fileName: "archive")
            let fileManager = NSFileManager.defaultManager()
            XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!))
        }
        catch {
            XCTFail()
        }
    }

Roy Marmelstein's avatar
Roy Marmelstein committed
84
}