Commit 361c51ba authored by Mostafa Berg's avatar Mostafa Berg

+Updated tests to user Swift 3.0, all tests passing

parent a34b598d
...@@ -21,10 +21,10 @@ class ZipTests: XCTestCase { ...@@ -21,10 +21,10 @@ class ZipTests: XCTestCase {
func testQuickUnzip() { func testQuickUnzip() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).urlForResource("bb8", withExtension: "zip")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath: destinationURL.path!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -33,11 +33,11 @@ class ZipTests: XCTestCase { ...@@ -33,11 +33,11 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonExistingPath() { func testQuickUnzipNonExistingPath() {
do { do {
let filePathURL = NSBundle(forClass: ZipTests.self).resourcePath let filePathURL = Bundle(for: ZipTests.self).resourcePath
let filePath = NSURL(string:"\(filePathURL!)/bb9.zip") let filePath = NSURL(string:"\(filePathURL!)/bb9.zip")
let destinationURL = try Zip.quickUnzipFile(filePath!) let destinationURL = try Zip.quickUnzipFile(filePath! as URL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path!))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -46,10 +46,10 @@ class ZipTests: XCTestCase { ...@@ -46,10 +46,10 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonZipPath() { func testQuickUnzipNonZipPath() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let filePath = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path!))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -58,7 +58,7 @@ class ZipTests: XCTestCase { ...@@ -58,7 +58,7 @@ class ZipTests: XCTestCase {
func testQuickUnzipProgress() { func testQuickUnzipProgress() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).urlForResource("bb8", withExtension: "zip")!
try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in
XCTAssert(true) XCTAssert(true)
}) })
...@@ -71,9 +71,9 @@ class ZipTests: XCTestCase { ...@@ -71,9 +71,9 @@ class ZipTests: XCTestCase {
func testQuickUnzipOnlineURL() { func testQuickUnzipOnlineURL() {
do { do {
let filePath = NSURL(string: "http://www.google.com/google.zip")! let filePath = NSURL(string: "http://www.google.com/google.zip")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath as URL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path!))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -82,15 +82,15 @@ class ZipTests: XCTestCase { ...@@ -82,15 +82,15 @@ class ZipTests: XCTestCase {
func testUnzip() { func testUnzip() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).urlForResource("bb8", withExtension: "zip")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: { (progress) -> () in try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(documentsFolder.path!)) XCTAssertTrue(fileManager.fileExists(atPath:documentsFolder.path!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -99,14 +99,14 @@ class ZipTests: XCTestCase { ...@@ -99,14 +99,14 @@ class ZipTests: XCTestCase {
func testImplicitProgressUnzip() { func testImplicitProgressUnzip() {
do { do {
let progress = NSProgress() let progress = Progress()
progress.totalUnitCount = 1 progress.totalUnitCount = 1
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).urlForResource("bb8", withExtension: "zip")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
progress.becomeCurrentWithPendingUnitCount(1) progress.becomeCurrent(withPendingUnitCount: 1)
try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: nil) try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: nil)
progress.resignCurrent() progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
...@@ -119,16 +119,16 @@ class ZipTests: XCTestCase { ...@@ -119,16 +119,16 @@ class ZipTests: XCTestCase {
func testImplicitProgressZip() { func testImplicitProgressZip() {
do { do {
let progress = NSProgress() let progress = Progress()
progress.totalUnitCount = 1 progress.totalUnitCount = 1
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).urlForResource("kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
progress.becomeCurrentWithPendingUnitCount(1) progress.becomeCurrent(withPendingUnitCount: 1)
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: nil) try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: nil)
progress.resignCurrent() progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
...@@ -141,11 +141,11 @@ class ZipTests: XCTestCase { ...@@ -141,11 +141,11 @@ class ZipTests: XCTestCase {
func testQuickZip() { func testQuickZip() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).urlForResource("kYkLkPf", withExtension: "gif")!
let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive") let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive")
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -154,20 +154,20 @@ class ZipTests: XCTestCase { ...@@ -154,20 +154,20 @@ class ZipTests: XCTestCase {
func testQuickZipFolder() { func testQuickZipFolder() {
do { do {
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).urlForResource("kYkLkPf", withExtension: "gif")!
let folderURL = NSBundle(forClass: ZipTests.self).bundleURL.URLByAppendingPathComponent("Directory") let folderURL = try Bundle(for: ZipTests.self).bundleURL.appendingPathComponent("Directory")
let targetImageURL1 = folderURL.URLByAppendingPathComponent("3crBXeO.gif") let targetImageURL1 = try folderURL.appendingPathComponent("3crBXeO.gif")
let targetImageURL2 = folderURL.URLByAppendingPathComponent("kYkLkPf.gif") let targetImageURL2 = try folderURL.appendingPathComponent("kYkLkPf.gif")
if fileManager.fileExistsAtPath(folderURL.path!) { if fileManager.fileExists(atPath:folderURL.path!) {
try fileManager.removeItemAtURL(folderURL) try fileManager.removeItem(at: folderURL)
} }
try fileManager.createDirectoryAtURL(folderURL, withIntermediateDirectories: false, attributes: nil) try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: false, attributes: nil)
try fileManager.copyItemAtURL(imageURL1, toURL: targetImageURL1) try fileManager.copyItem(at: imageURL1, to: targetImageURL1)
try fileManager.copyItemAtURL(imageURL2, toURL: targetImageURL2) try fileManager.copyItem(at: imageURL2, to: targetImageURL2)
let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory") let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory")
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -177,15 +177,15 @@ class ZipTests: XCTestCase { ...@@ -177,15 +177,15 @@ class ZipTests: XCTestCase {
func testZip() { func testZip() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).urlForResource("kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: { (progress) -> () in try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path!)!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -194,23 +194,23 @@ class ZipTests: XCTestCase { ...@@ -194,23 +194,23 @@ class ZipTests: XCTestCase {
func testZipUnzipPassword() { func testZipUnzipPassword() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).urlForResource("3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).urlForResource("kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: "password", progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path!)!))
guard let fileExtension = zipFilePath.pathExtension, let fileName = zipFilePath.lastPathComponent else { guard let fileExtension = zipFilePath?.pathExtension, let fileName = zipFilePath?.lastPathComponent else {
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "") let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true) let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
try Zip.unzipFile(zipFilePath, destination: destinationUrl, overwrite: true, password: "password", progress: nil) try Zip.unzipFile(zipFilePath!, destination: destinationUrl!, overwrite: true, password: "password", progress: nil)
XCTAssertTrue(fileManager.fileExistsAtPath(destinationUrl.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(destinationUrl?.path!)!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -220,16 +220,15 @@ class ZipTests: XCTestCase { ...@@ -220,16 +220,15 @@ class ZipTests: XCTestCase {
func testQuickUnzipSubDir() { func testQuickUnzipSubDir() {
do { do {
let bookURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let bookURL = Bundle(for: ZipTests.self).urlForResource("bb8", withExtension: "zip")!
let unzipDestination = try Zip.quickUnzipFile(bookURL) let unzipDestination = try Zip.quickUnzipFile(bookURL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let subDir = try unzipDestination.appendingPathComponent("subDir")
let subDir = unzipDestination.URLByAppendingPathComponent("subDir") let imageURL = try subDir.appendingPathComponent("r2W9yu9").appendingPathExtension("gif")
let imageURL = subDir.URLByAppendingPathComponent("r2W9yu9").URLByAppendingPathExtension("gif")
XCTAssertTrue(fileManager.fileExistsAtPath(unzipDestination.path!)) XCTAssertTrue(fileManager.fileExists(atPath:unzipDestination.path!))
XCTAssertTrue(fileManager.fileExistsAtPath(subDir.path!)) XCTAssertTrue(fileManager.fileExists(atPath:subDir.path!))
XCTAssertTrue(fileManager.fileExistsAtPath(imageURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:imageURL.path!))
} catch { } catch {
XCTFail() XCTFail()
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment