diff --git a/ObjectiveCExample/ObjectiveCExample.xcodeproj/project.pbxproj b/ObjectiveCExample/ObjectiveCExample.xcodeproj/project.pbxproj index 1dc3efa..4bedfab 100644 --- a/ObjectiveCExample/ObjectiveCExample.xcodeproj/project.pbxproj +++ b/ObjectiveCExample/ObjectiveCExample.xcodeproj/project.pbxproj @@ -43,6 +43,12 @@ 3793E6EE1F7F6059000B1A19 /* TestPasswordArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 8DFE1A1C1BDAA10100709011 /* TestPasswordArchive.zip */; }; 3793E6EF1F7F6059000B1A19 /* Unicode.zip in Resources */ = {isa = PBXBuildFile; fileRef = 8DFE1A1D1BDAA10100709011 /* Unicode.zip */; }; 3793E6F01F7F605C000B1A19 /* PermissionsTestApp.app in Resources */ = {isa = PBXBuildFile; fileRef = 8DFE1A181BDAA10100709011 /* PermissionsTestApp.app */; }; + 37FF0CB31F8533E0006E4361 /* CancelDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB21F8533E0006E4361 /* CancelDelegate.m */; }; + 37FF0CB41F8533E0006E4361 /* CancelDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB21F8533E0006E4361 /* CancelDelegate.m */; }; + 37FF0CB51F8533E0006E4361 /* CancelDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB21F8533E0006E4361 /* CancelDelegate.m */; }; + 37FF0CB81F853459006E4361 /* ProgressDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB71F853459006E4361 /* ProgressDelegate.m */; }; + 37FF0CB91F853459006E4361 /* ProgressDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB71F853459006E4361 /* ProgressDelegate.m */; }; + 37FF0CBA1F853459006E4361 /* ProgressDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37FF0CB71F853459006E4361 /* ProgressDelegate.m */; }; 6BFA1E5841DFEC4E21BA7543 /* Pods_core_ObjectiveCExampleTests_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38A85B006A1C84E475375AE1 /* Pods_core_ObjectiveCExampleTests_macOS.framework */; }; 8DFE19EF1BDA9FF300709011 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFE19EE1BDA9FF300709011 /* main.m */; }; 8DFE19F21BDA9FF300709011 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFE19F11BDA9FF300709011 /* AppDelegate.m */; }; @@ -79,6 +85,10 @@ 254DE0B206EE66F57BBE7EEE /* Pods-core-ObjectiveCExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-core-ObjectiveCExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-core-ObjectiveCExample/Pods-core-ObjectiveCExample.release.xcconfig"; sourceTree = ""; }; 3773ADAE1F7F44D8009A4B2D /* ObjectiveCExampleTests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveCExampleTests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 3793E6D71F7F5F93000B1A19 /* ObjectiveCExampleTests_tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveCExampleTests_tvOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 37FF0CB11F8533E0006E4361 /* CancelDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CancelDelegate.h; sourceTree = ""; }; + 37FF0CB21F8533E0006E4361 /* CancelDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CancelDelegate.m; sourceTree = ""; }; + 37FF0CB61F853459006E4361 /* ProgressDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ProgressDelegate.h; sourceTree = ""; }; + 37FF0CB71F853459006E4361 /* ProgressDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProgressDelegate.m; sourceTree = ""; }; 38A85B006A1C84E475375AE1 /* Pods_core_ObjectiveCExampleTests_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_core_ObjectiveCExampleTests_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 48AB7DF053F85FCC6AFB0C26 /* Pods-core-ObjectiveCExampleTests_macOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-core-ObjectiveCExampleTests_macOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-core-ObjectiveCExampleTests_macOS/Pods-core-ObjectiveCExampleTests_macOS.debug.xcconfig"; sourceTree = ""; }; 49974600DB985CD98FC3AD39 /* Pods_core_ObjectiveCExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_core_ObjectiveCExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -94,7 +104,7 @@ 8DFE19FC1BDA9FF300709011 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 8DFE19FE1BDA9FF300709011 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8DFE1A031BDA9FF300709011 /* ObjectiveCExampleTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveCExampleTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 8DFE1A071BDA9FF300709011 /* SSZipArchiveTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SSZipArchiveTests.m; sourceTree = ""; }; + 8DFE1A071BDA9FF300709011 /* SSZipArchiveTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSZipArchiveTests.m; sourceTree = ""; }; 8DFE1A091BDA9FF300709011 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8DFE1A121BDAA0A800709011 /* CollectingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectingDelegate.h; sourceTree = ""; }; 8DFE1A131BDAA0A800709011 /* CollectingDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectingDelegate.m; sourceTree = ""; }; @@ -228,6 +238,10 @@ 8DFE1A1E1BDAA10100709011 /* Multi_Zip_Test */, 8DFE1A121BDAA0A800709011 /* CollectingDelegate.h */, 8DFE1A131BDAA0A800709011 /* CollectingDelegate.m */, + 37FF0CB11F8533E0006E4361 /* CancelDelegate.h */, + 37FF0CB21F8533E0006E4361 /* CancelDelegate.m */, + 37FF0CB61F853459006E4361 /* ProgressDelegate.h */, + 37FF0CB71F853459006E4361 /* ProgressDelegate.m */, 8DFE1A071BDA9FF300709011 /* SSZipArchiveTests.m */, 8DFE1A091BDA9FF300709011 /* Info.plist */, ); @@ -699,7 +713,9 @@ buildActionMask = 2147483647; files = ( 3773ADB71F7F4541009A4B2D /* SSZipArchiveTests.m in Sources */, + 37FF0CB91F853459006E4361 /* ProgressDelegate.m in Sources */, 3773ADB61F7F453E009A4B2D /* CollectingDelegate.m in Sources */, + 37FF0CB41F8533E0006E4361 /* CancelDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -708,7 +724,9 @@ buildActionMask = 2147483647; files = ( 3793E6E01F7F604B000B1A19 /* SSZipArchiveTests.m in Sources */, + 37FF0CBA1F853459006E4361 /* ProgressDelegate.m in Sources */, 3793E6DF1F7F6048000B1A19 /* CollectingDelegate.m in Sources */, + 37FF0CB51F8533E0006E4361 /* CancelDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -727,7 +745,9 @@ buildActionMask = 2147483647; files = ( 8DFE1A141BDAA0A800709011 /* CollectingDelegate.m in Sources */, + 37FF0CB81F853459006E4361 /* ProgressDelegate.m in Sources */, 8DFE1A081BDA9FF300709011 /* SSZipArchiveTests.m in Sources */, + 37FF0CB31F8533E0006E4361 /* CancelDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.h b/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.h new file mode 100644 index 0000000..abfcb7c --- /dev/null +++ b/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.h @@ -0,0 +1,17 @@ +// +// CancelDelegate.h +// ObjectiveCExample +// +// Created by Antoine Cœur on 04/10/2017. +// + +#import +#import "SSZipArchive.h" + +@interface CancelDelegate : NSObject +@property (nonatomic, assign) int numFilesUnzipped; +@property (nonatomic, assign) int numFilesToUnzip; +@property (nonatomic, assign) BOOL didUnzipArchive; +@property (nonatomic, assign) int loaded; +@property (nonatomic, assign) int total; +@end diff --git a/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.m b/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.m new file mode 100644 index 0000000..e37a184 --- /dev/null +++ b/ObjectiveCExample/ObjectiveCExampleTests/CancelDelegate.m @@ -0,0 +1,29 @@ +// +// CancelDelegate.m +// ObjectiveCExample +// +// Created by Antoine Cœur on 04/10/2017. +// + +#import "CancelDelegate.h" + +@implementation CancelDelegate +- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo +{ + _numFilesUnzipped = (int)fileIndex + 1; +} +- (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo +{ + //return YES; + return _numFilesUnzipped < _numFilesToUnzip; +} +- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath +{ + _didUnzipArchive = YES; +} +- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total +{ + _loaded = (int)loaded; + _total = (int)total; +} +@end diff --git a/ObjectiveCExample/ObjectiveCExampleTests/CollectingDelegate.m b/ObjectiveCExample/ObjectiveCExampleTests/CollectingDelegate.m index dca70c2..a24fab6 100644 --- a/ObjectiveCExample/ObjectiveCExampleTests/CollectingDelegate.m +++ b/ObjectiveCExample/ObjectiveCExampleTests/CollectingDelegate.m @@ -7,11 +7,9 @@ #import "CollectingDelegate.h" -@implementation CollectingDelegate { - -} -@synthesize files = _files; +@implementation CollectingDelegate +@synthesize files = _files; - (instancetype)init { self = [super init]; diff --git a/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.h b/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.h new file mode 100644 index 0000000..2aebb20 --- /dev/null +++ b/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.h @@ -0,0 +1,17 @@ +// +// ProgressDelegate.h +// ObjectiveCExample +// +// Created by Antoine Cœur on 04/10/2017. +// + +#import +#import "SSZipArchive.h" + +@interface ProgressDelegate : NSObject +{ +@public + NSMutableArray *progressEvents; +} + +@end diff --git a/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.m b/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.m new file mode 100644 index 0000000..07abef2 --- /dev/null +++ b/ObjectiveCExample/ObjectiveCExampleTests/ProgressDelegate.m @@ -0,0 +1,46 @@ +// +// ProgressDelegate.m +// ObjectiveCExample +// +// Created by Antoine Cœur on 04/10/2017. +// + +#import "ProgressDelegate.h" + +@implementation ProgressDelegate + +- (instancetype)init +{ + self = super.init; + progressEvents = [NSMutableArray array]; + return self; +} + +- (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo { + NSLog(@"*** zipArchiveWillUnzipArchiveAtPath: `%@` zipInfo:", path); +} + +- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath { + NSLog(@"*** zipArchiveDidUnzipArchiveAtPath: `%@` zipInfo: unzippedPath: `%@`", path, unzippedPath); +} + +- (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo +{ + NSLog(@"*** zipArchiveShouldUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); + return YES; +} + +- (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo { + NSLog(@"*** zipArchiveWillUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); +} + +- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo { + NSLog(@"*** zipArchiveDidUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); +} + +- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total { + NSLog(@"*** zipArchiveProgressEvent: loaded: `%llu` total: `%llu`", loaded, total); + [progressEvents addObject:@(loaded)]; +} + +@end diff --git a/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m b/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m index 807b899..fd9280f 100644 --- a/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m +++ b/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m @@ -11,46 +11,16 @@ #import #import "CollectingDelegate.h" +#import "CancelDelegate.h" +#import "ProgressDelegate.h" -@interface CancelDelegate : NSObject -@property (nonatomic, assign) int numFilesUnzipped; -@property (nonatomic, assign) int numFilesToUnzip; -@property (nonatomic, assign) BOOL didUnzipArchive; -@property (nonatomic, assign) int loaded; -@property (nonatomic, assign) int total; +@interface SSZipArchiveTests : XCTestCase @end -@implementation CancelDelegate -- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo -{ - _numFilesUnzipped = (int)fileIndex + 1; -} -- (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo -{ - //return YES; - return _numFilesUnzipped < _numFilesToUnzip; -} -- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath -{ - _didUnzipArchive = YES; -} -- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total -{ - _loaded = (int)loaded; - _total = (int)total; -} -@end - -@interface SSZipArchiveTests : XCTestCase -@end - -@implementation SSZipArchiveTests { - NSMutableArray *progressEvents; -} +@implementation SSZipArchiveTests - (void)setUp { [super setUp]; - progressEvents = [NSMutableArray array]; } - (void)tearDown { @@ -122,7 +92,8 @@ NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"]; NSString *outputPath = [self _cachesPath:@"Regular"]; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -132,11 +103,13 @@ testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"]; XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped"); } + - (void)testSmallFileUnzipping { NSString *zipPath = [[NSBundle bundleForClass: [self class]] pathForResource:@"TestArchive" ofType:@"zip"]; NSString *outputPath = [self _cachesPath:@"Regular"]; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -146,21 +119,21 @@ testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"]; XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped"); } + - (void)testUnzippingProgress { NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"]; NSString *outputPath = [self _cachesPath:@"Progress"]; - [progressEvents removeAllObjects]; - - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + ProgressDelegate *delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); // 4 events: the first, then for each of the two files one, then the final event - XCTAssertTrue(4 == [progressEvents count], @"Expected 4 progress events"); - XCTAssertTrue(0 == [progressEvents[0] intValue]); - XCTAssertTrue(619 == [progressEvents[1] intValue]); - XCTAssertTrue(1114 == [progressEvents[2] intValue]); - XCTAssertTrue(1436 == [progressEvents[3] intValue]); + XCTAssertTrue(4 == [delegate->progressEvents count], @"Expected 4 progress events"); + XCTAssertTrue(0 == [delegate->progressEvents[0] intValue]); + XCTAssertTrue(619 == [delegate->progressEvents[1] intValue]); + XCTAssertTrue(1114 == [delegate->progressEvents[2] intValue]); + XCTAssertTrue(1436 == [delegate->progressEvents[3] intValue]); } @@ -169,7 +142,8 @@ NSString *outputPath = [self _cachesPath:@"Password"]; NSError *error = nil; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd" error:&error delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd" error:&error delegate:delegate]; XCTAssertTrue(success); NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -185,7 +159,8 @@ NSString *outputPath = [self _cachesPath:@"Password"]; NSError *error = nil; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd123" error:&error delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd123" error:&error delegate:delegate]; XCTAssertFalse(success); NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -247,7 +222,8 @@ outputPath = [self _cachesPath:@"UnicodePassword"]; NSError *error = nil; - success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath overwrite:YES password:@"ꊐ⌒Ⅳ🤐" error:&error delegate:self]; + id delegate = [ProgressDelegate new]; + success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath overwrite:YES password:@"ꊐ⌒Ⅳ🤐" error:&error delegate:delegate]; XCTAssertTrue(success); NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -261,28 +237,30 @@ //Temp Disabled test, fix is not yet in the AES version of the unzip lib //- (void)testUnzippingTruncatedFileFix { -// NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"]; -// NSString* outputPath = [self _cachesPath:@"IncorrectHeaders"]; +// NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"]; +// NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"]; // -// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; +// id delegate = [ProgressDelegate new]; +// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; // XCTAssertTrue(success); // -// NSString* intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5"; +// NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5"; // -// NSString* filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"]; -// NSData* data = [NSData dataWithContentsOfFile:filePath]; +// NSString *filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"]; +// NSData *data = [NSData dataWithContentsOfFile:filePath]; // -// NSString* actualReadmeTxtMD5 = [self _calculateMD5Digest:data]; +// NSString *actualReadmeTxtMD5 = [self _calculateMD5Digest:data]; // XCTAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original."); //} - (void)testUnzippingWithSymlinkedFileInside { - NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SymbolicLink" ofType:@"zip"]; - NSString* outputPath = [self _cachesPath:@"SymbolicLink"]; + NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SymbolicLink" ofType:@"zip"]; + NSString *outputPath = [self _cachesPath:@"SymbolicLink"]; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); NSString *testSymlink = [outputPath stringByAppendingPathComponent:@"SymbolicLink/Xcode.app"]; @@ -296,10 +274,11 @@ - (void)testUnzippingWithRelativeSymlink { NSString *resourceName = @"RelativeSymbolicLink"; - NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:resourceName ofType:@"zip"]; - NSString* outputPath = [self _cachesPath:resourceName]; + NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:resourceName ofType:@"zip"]; + NSString *outputPath = [self _cachesPath:resourceName]; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); // Determine where the symlinks are @@ -319,10 +298,11 @@ - (void)testUnzippingWithUnicodeFilenameInside { - NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Unicode" ofType:@"zip"]; - NSString* outputPath = [self _cachesPath:@"Unicode"]; + NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Unicode" ofType:@"zip"]; + NSString *outputPath = [self _cachesPath:@"Unicode"]; - BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); bool unicodeFilenameWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Accént.txt"]]; @@ -348,7 +328,8 @@ BOOL success = [SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths]; XCTAssertTrue(success); - success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath delegate:self]; + id delegate = [ProgressDelegate new]; + success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath delegate:delegate]; XCTAssertTrue(success); NSDictionary *createdFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[outputPath stringByAppendingPathComponent:@"Readme.markdown"] error:nil]; @@ -450,38 +431,6 @@ XCTAssertEqualObjects(collector.files[1], [outputPath stringByAppendingString:@"/Readme.markdown"]); } -#pragma mark - SSZipArchiveDelegate - -- (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo { - NSLog(@"*** zipArchiveWillUnzipArchiveAtPath: `%@` zipInfo:", path); -} - - -- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath { - NSLog(@"*** zipArchiveDidUnzipArchiveAtPath: `%@` zipInfo: unzippedPath: `%@`", path, unzippedPath); -} - -- (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo -{ - NSLog(@"*** zipArchiveShouldUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); - return YES; -} - -- (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo { - NSLog(@"*** zipArchiveWillUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); -} - - -- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo { - NSLog(@"*** zipArchiveDidUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", (int)fileIndex, (int)totalFiles, archivePath); -} - -- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total { - NSLog(@"*** zipArchiveProgressEvent: loaded: `%llu` total: `%llu`", loaded, total); - [progressEvents addObject:@(loaded)]; -} - - #pragma mark - Private - (NSString *)_cachesPath:(NSString *)directory { @@ -491,10 +440,7 @@ path = [path stringByAppendingPathComponent:directory]; } - NSFileManager *fileManager = [NSFileManager defaultManager]; - if (![fileManager fileExistsAtPath:path]) { - [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil]; - } + [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil]; return path; }