ZipArchive/Tests/SSZipArchiveTests.m
Sam Soffes 23426fd0de Fixes for unzipping modification dates and add ARC support
* Add ARC support
* Fixes: One of the bugs is that the file modification dates for files being unzipped were wrong. Apparently the code was taking the MS-DOS date and time and treating it as an NSTimeInterval since Jan 1, 1980. This is not correct and was resulting in modification dates for me in 2014. — Brant Sears
* Fixes: The second bug was that the file modification dates for folders were showing up as the current date/time, but when I unzip the same archive using Apple's implementation of zip, the file modification dates for those folders were set sometime in the past. — Brant Sears
2012-05-07 23:08:49 -07:00

78 lines
3.0 KiB
Objective-C

//
// SSZipArchiveTests.m
// SSZipArchiveTests
//
// Created by Sam Soffes on 10/3/11.
// Copyright (c) 2011 Sam Soffes. All rights reserved.
//
#import "SSZipArchiveTests.h"
#import "SSZipArchive.h"
@interface SSZipArchiveTests () <SSZipArchiveDelegate>
- (NSString *)_cachesPath;
@end
@implementation SSZipArchiveTests
- (void)testZipping {
NSString *outputPath = [self _cachesPath];
NSArray *inputPaths = [NSArray arrayWithObjects:
[outputPath stringByAppendingPathComponent:@"Readme.markdown"],
[outputPath stringByAppendingPathComponent:@"LICENSE"],
nil];
NSString *archivePath = [outputPath stringByAppendingPathComponent:@"CreatedArchive.zip"];
[SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
// TODO: Make sure the files are actually unzipped. They are, but the test should be better.
STAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:archivePath], @"Archive created");
}
- (void)testUnzipping {
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"];
NSString *outputPath = [self _cachesPath];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
STAssertTrue([fileManager fileExistsAtPath:testPath], @"Readme unzipped");
testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"];
STAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped");
// Commented out to avoid checking in several gig file into the repository. Simply add a file named
// `LargeArchive.zip` to the project and uncomment out these lines to test.
// zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"LargeArchive" ofType:@"zip"];
// outputPath = [[self _cachesPath] stringByAppendingPathComponent:@"large"];
// [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath];
}
#pragma mark - Delegate
- (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path globalInfo:(unz_global_info)globalInfo {
NSLog(@"zipArchiveWillUnzipArchiveAtPath: `%@` globalInfo:", path);
}
- (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo {
NSLog(@"zipArchiveWillUnzipFileAtIndex: `%ld` totalFiles: `%ld` unzippedPath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
}
- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo {
NSLog(@"zipArchiveDidUnzipFileAtIndex: `%ld` totalFiles: `%ld` unzippedPath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
}
#pragma mark - Private
- (NSString *)_cachesPath {
return [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
stringByAppendingPathComponent:@"com.samsoffes.ssziparchive.tests"];
}
@end