Skip to content

Commit

Permalink
Add failing test for ZipArchive#14
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed May 9, 2012
1 parent b7598bc commit d646bf9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Tests/SSZipArchive.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
B215FB6A143AD576003AC546 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = B215FB53143AD460003AC546 /* unzip.c */; };
B215FB6B143AD576003AC546 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = B215FB55143AD460003AC546 /* zip.c */; };
B215FB6D143AD6FF003AC546 /* TestArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B215FB6C143AD6FF003AC546 /* TestArchive.zip */; };
B2283D5D155AD80F00F9395A /* Unicode.zip in Resources */ = {isa = PBXBuildFile; fileRef = B2283D5C155AD80F00F9395A /* Unicode.zip */; };
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */; };
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */; };
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */; };
Expand All @@ -41,6 +42,7 @@
B215FB61143AD514003AC546 /* SSZipArchiveTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSZipArchiveTests.m; sourceTree = "<group>"; };
B215FB64143AD527003AC546 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
B215FB6C143AD6FF003AC546 /* TestArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestArchive.zip; sourceTree = "<group>"; };
B2283D5C155AD80F00F9395A /* Unicode.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = Unicode.zip; sourceTree = "<group>"; };
B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestPasswordArchive.zip; sourceTree = "<group>"; };
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = IncorrectHeaders.zip; sourceTree = "<group>"; };
C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SymbolicLink.zip; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,6 +120,7 @@
B215FB5E143AD505003AC546 /* SSZipArchiveTests */ = {
isa = PBXGroup;
children = (
B2283D5C155AD80F00F9395A /* Unicode.zip */,
B215FB61143AD514003AC546 /* SSZipArchiveTests.m */,
B215FB5F143AD514003AC546 /* SSZipArchiveTests-Info.plist */,
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */,
Expand Down Expand Up @@ -184,6 +187,7 @@
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */,
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */,
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */,
B2283D5D155AD80F00F9395A /* Unicode.zip in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
43 changes: 29 additions & 14 deletions Tests/SSZipArchiveTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ - (NSString *)_calculateMD5Digest:(NSData *)data;

@implementation SSZipArchiveTests

- (void)setUp {
[[NSFileManager defaultManager] removeItemAtPath:[self _cachesPath:nil] error:nil];
}
//- (void)setUp {
// [[NSFileManager defaultManager] removeItemAtPath:[self _cachesPath:nil] error:nil];
//}


- (void)testZipping {
Expand Down Expand Up @@ -70,38 +70,53 @@ - (void)testUnzippingWithPassword {
}

- (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"];

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

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];
STAssertTrue([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"];

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

NSString* testSymlink = [outputPath stringByAppendingPathComponent:@"SymbolicLink/GitHub.app"];
NSString *testSymlink = [outputPath stringByAppendingPathComponent:@"SymbolicLink/GitHub.app"];

NSError* error = nil;
NSString* symlinkPath = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath:testSymlink error:&error];
NSError *error = nil;
NSString *symlinkPath = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath:testSymlink error:&error];

bool symbolicLinkPersists = ((symlinkPath != nil) && [symlinkPath isEqualToString:@"/Applications/GitHub.app"]) && (error == nil);

STAssertTrue(symbolicLinkPersists, @"Symbolic links should persist from the original archive to the outputted files.");
}


- (void)testUnzippingWithUnicodeFilenameInside {
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Unicode" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"Unicode"];

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

bool unicodeFilenameWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Unicode/Accént.txt"]];

bool unicodeFolderWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Unicode/Fólder"]];

STAssertTrue(unicodeFilenameWasExtracted, @"Files with filenames in unicode should be extracted properly.");
STAssertTrue(unicodeFolderWasExtracted, @"Folders with names in unicode should be extracted propertly.");
}


// 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.
//
Expand Down
Binary file added Tests/Unicode.zip
Binary file not shown.

0 comments on commit d646bf9

Please sign in to comment.