QuietUnrar/Carthage/Checkouts/UnzipKit/Tests/ListFilenamesTests.m

135 lines
4.9 KiB
Objective-C

//
// ListFilenamesTests.m
// UnzipKit
//
// Created by Dov Frankel on 7/16/15.
// Copyright (c) 2015 Abbey Code. All rights reserved.
//
#import "UZKArchiveTestCase.h"
#import "UnzipKit.h"
@interface ListFilenamesTests : UZKArchiveTestCase
@end
@implementation ListFilenamesTests
- (void)testListFilenames
{
NSArray *testArchives = @[@"Test Archive.zip",
@"Test Archive (Password).zip"];
NSSet *expectedFileSet = self.nonZipTestFilePaths;
NSArray *expectedFiles = [expectedFileSet.allObjects sortedArrayUsingSelector:@selector(compare:)];
for (NSString *testArchiveName in testArchives) {
NSURL *testArchiveURL = self.testFileURLs[testArchiveName];
UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL error:nil];
NSError *error = nil;
NSArray *filesInArchive = [archive listFilenames:&error];
XCTAssertNil(error, @"Error returned by listFilenames");
XCTAssertNotNil(filesInArchive, @"No list of files returned");
XCTAssertEqual(filesInArchive.count, expectedFileSet.count,
@"Incorrect number of files listed in archive");
for (NSUInteger i = 0; i < filesInArchive.count; i++) {
NSString *archiveFilename = filesInArchive[i];
NSString *expectedFilename = expectedFiles[i];
XCTAssertEqualObjects(archiveFilename, expectedFilename, @"Incorrect filename listed");
}
}
}
- (void)testListFilenames_Unicode
{
NSURL *testArchiveURL = self.unicodeFileURLs[@"Ⓣest Ⓐrchive.zip"];
NSSet *expectedFileSet = self.nonZipUnicodeFilePaths;
NSArray *expectedFiles = [expectedFileSet.allObjects sortedArrayUsingSelector:@selector(compare:)];
UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL error:nil];
NSError *error = nil;
NSArray *filesInArchive = [archive listFilenames:&error];
XCTAssertNil(error, @"Error returned by listFilenames");
XCTAssertNotNil(filesInArchive, @"No list of files returned");
XCTAssertEqual(filesInArchive.count, expectedFileSet.count,
@"Incorrect number of files listed in archive");
for (NSUInteger i = 0; i < filesInArchive.count; i++) {
NSString *archiveFilename = filesInArchive[i];
NSString *expectedFilename = expectedFiles[i];
XCTAssertEqualObjects(archiveFilename, expectedFilename, @"Incorrect filename listed");
}
}
- (void)testListFilenames_Password
{
NSURL *testArchiveURL = self.testFileURLs[@"Test Archive (Password).zip"];
UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL password:@"password" error:nil];
NSSet *expectedFileSet = self.nonZipTestFilePaths;
NSArray *expectedFiles = [expectedFileSet.allObjects sortedArrayUsingSelector:@selector(compare:)];
NSArray *filesInArchive = nil;
NSError *error = nil;
filesInArchive = [archive listFilenames:&error];
XCTAssertNil(error, @"Error returned by listFilenames");
XCTAssertEqual(filesInArchive.count, expectedFileSet.count,
@"Incorrect number of files listed in archive");
for (NSUInteger i = 0; i < filesInArchive.count; i++) {
NSString *archiveFilename = filesInArchive[i];
NSString *expectedFilename = expectedFiles[i];
XCTAssertEqualObjects(archiveFilename, expectedFilename, @"Incorrect filename listed");
}
}
- (void)testListFilenames_NoPasswordGiven
{
NSURL *testArchiveURL = self.testFileURLs[@"Test Archive (Password).zip"];
UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL error:nil];
NSSet *expectedFileSet = self.nonZipTestFilePaths;
NSArray *expectedFiles = [expectedFileSet.allObjects sortedArrayUsingSelector:@selector(compare:)];
NSArray *filesInArchive = nil;
NSError *error = nil;
filesInArchive = [archive listFilenames:&error];
XCTAssertNil(error, @"Error returned by listFilenames");
XCTAssertEqual(filesInArchive.count, expectedFileSet.count,
@"Incorrect number of files listed in archive");
for (NSUInteger i = 0; i < filesInArchive.count; i++) {
NSString *archiveFilename = filesInArchive[i];
NSString *expectedFilename = expectedFiles[i];
XCTAssertEqualObjects(archiveFilename, expectedFilename, @"Incorrect filename listed");
}
}
- (void)testListFilenames_InvalidArchive
{
NSURL *testURLA = self.testFileURLs[@"Test File A.txt"];
UZKArchive *archive = [[UZKArchive alloc] initWithURL:testURLA error:nil];
NSError *error = nil;
NSArray *files = [archive listFilenames:&error];
XCTAssertNotNil(error, @"List files of invalid archive succeeded");
XCTAssertNil(files, @"List returned for invalid archive");
XCTAssertEqual(error.code, UZKErrorCodeBadZipFile, @"Unexpected error code returned");
}
@end