Skip to content

Commit

Permalink
Add a unit test for zipArchiveProgressEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Mar 22, 2014
1 parent 281571d commit 4fca963
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Tests/SSZipArchiveTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
@interface SSZipArchiveTests : XCTestCase <SSZipArchiveDelegate>
@end

@implementation SSZipArchiveTests
@implementation SSZipArchiveTests {
NSMutableArray *progressEvents;
}

- (void)setUp {
[super setUp];
progressEvents = [NSMutableArray array];
}

- (void)tearDown {
[super tearDown];
Expand Down Expand Up @@ -65,6 +72,22 @@ - (void)testUnzipping {
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];

[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];

// 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 objectAtIndex:0] intValue]);
XCTAssertTrue(619 == [[progressEvents objectAtIndex:1] intValue]);
XCTAssertTrue(1114 == [[progressEvents objectAtIndex:2] intValue]);
XCTAssertTrue(1436 == [[progressEvents objectAtIndex:3] intValue]);
}


- (void)testUnzippingWithPassword {
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestPasswordArchive" ofType:@"zip"];
Expand Down Expand Up @@ -260,6 +283,11 @@ - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger
NSLog(@"*** zipArchiveDidUnzipFileAtIndex: `%d` totalFiles: `%d` archivePath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
}

- (void)zipArchiveProgressEvent:(NSInteger)loaded total:(NSInteger)total {
NSLog(@"*** zipArchiveProgressEvent: loaded: `%d` total: `%d`", loaded, total);
[progressEvents addObject:[[NSNumber alloc] initWithInteger:loaded]];
}


#pragma mark - Private

Expand Down

0 comments on commit 4fca963

Please sign in to comment.