33
33
if (![manager fileExistsAtPath:resultsDirectoryPath]) @throw [NSException exceptionWithName:@"MissingResultsDirectoryException" reason:@"failed to find the results directory:" userInfo:nil];
35
35
compressionTestFilesDirectory = [[manager currentDirectoryPath] stringByAppendingPathComponent:@"content/compression"];
36
archivesDirectory = [[manager currentDirectoryPath] stringByAppendingPathComponent:@"content/archives"];
38
39
- (void)testCreateArchivev0 {
40
MPQArchive *archive = [[MPQArchive alloc] initWithFileLimit:1 error:&error];
41
MPQArchive* archive = [[MPQArchive alloc] initWithFileLimit:1 error:&error];
41
42
STAssertNotNil(archive, @"failed to create archive: %@", error);
42
43
STAssertNil(error, @"error should be nil on success");
44
// File limit should be MIN_HASH_TABLE_LENGTH
45
// file limit should be MIN_HASH_TABLE_LENGTH
45
46
STAssertEquals([archive maximumNumberOfFiles], (uint32_t)MIN_HASH_TABLE_LENGTH, @"[archive maximumNumberOfFiles] did not return MIN_HASH_TABLE_LENGTH");
46
47
// archive should be modified
47
48
STAssertTrue([archive modified], @"archive should be modified after creation");
50
STAssertNil([archive path], @"new archive should have a nil path before first write");
49
52
BOOL ok = [archive writeToFile:[resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev0.mpq"] atomically:NO error:&error];
50
53
STAssertTrue(ok, @"writeToFile:atomically:error: failed: %@", error);
52
STAssertNil(error, @"error should be nil on success");
54
// archive should not be modified
55
STAssertFalse([archive modified], @"archive should not be modified after writing");
55
// only continue if we're ok
57
// path should still be nil
58
STAssertNil([archive path], @"archive path should still be nil after failed first write");
59
// error should not be nil
60
STAssertNotNil(error, @"error should not be nil after a failure");
64
// error should be nil after success
65
STAssertNil(error, @"error should be nil on success");
66
// archive should not be modified
67
STAssertFalse([archive modified], @"archive should not be modified after writing");
68
// archive path should match the path used in write
69
STAssertEqualObjects([resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev0.mpq"], [archive path], @"archive path should match write path after successful write");
74
// try to open the archive
75
archive = [[MPQArchive alloc] initWithPath:[resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev0.mpq"] error:&error];
76
STAssertNotNil(archive, @"initWithPath:error: failed: %@", error);
78
// archive version should be MPQExtendedVersion
79
STAssertEquals([[[archive archiveInfo] objectForKey:MPQArchiveVersion] intValue], MPQOriginalVersion, @"archive version should be equal to MPQExtendedVersion");
85
- (void)testCreateArchivev1 {
87
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], MPQMaximumNumberOfFiles, [NSNumber numberWithInt:MPQExtendedVersion], MPQArchiveVersion, nil];
88
MPQArchive* archive = [[MPQArchive alloc] initWithAttributes:attributes error:&error];
89
STAssertNotNil(archive, @"failed to create archive: %@", error);
90
STAssertNil(error, @"error should be nil on success");
92
// file limit should be MIN_HASH_TABLE_LENGTH
93
STAssertEquals([archive maximumNumberOfFiles], (uint32_t)MIN_HASH_TABLE_LENGTH, @"[archive maximumNumberOfFiles] did not return MIN_HASH_TABLE_LENGTH");
94
// archive should be modified
95
STAssertTrue([archive modified], @"archive should be modified after creation");
97
STAssertNil([archive path], @"new archive should have a nil path before first write");
99
BOOL ok = [archive writeToFile:[resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev1.mpq"] atomically:NO error:&error];
100
STAssertTrue(ok, @"writeToFile:atomically:error: failed: %@", error);
102
// only continue if we're ok
104
// path should still be nil
105
STAssertNil([archive path], @"archive path should still be nil after failed first write");
106
// error should not be nil
107
STAssertNotNil(error, @"error should not be nil after a failure");
111
// error should be nil after success
112
STAssertNil(error, @"error should be nil on success");
113
// archive should not be modified
114
STAssertFalse([archive modified], @"archive should not be modified after writing");
115
// archive path should match the path used in write
116
STAssertEqualObjects([resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev1.mpq"], [archive path], @"archive path should match write path after successful write");
121
// try to open the archive
122
archive = [[MPQArchive alloc] initWithPath:[resultsDirectoryPath stringByAppendingPathComponent:@"testCreateArchivev1.mpq"] error:&error];
123
STAssertNotNil(archive, @"initWithPath:error: failed: %@", error);
125
// archive version should be MPQExtendedVersion
126
STAssertEquals([[[archive archiveInfo] objectForKey:MPQArchiveVersion] intValue], MPQExtendedVersion, @"archive version should be equal to MPQExtendedVersion");
132
- (void)_runCoreArchiveTest:(NSString*)archivePath {
135
MPQArchive* archive = [[MPQArchive alloc] initWithPath:archivePath error:&error];
137
STAssertNotNil(error, @"error should not be nil on error");
138
NSLog(@"failed to open %@: %@", archivePath, error);
141
STAssertNil(error, @"error should be nil on success");
146
- (void)testOpenArchives {
147
// all the archives in the archives folder are valid and should open without error
148
NSFileManager* manager = [NSFileManager defaultManager];
149
NSEnumerator* archivesEnum = [[manager directoryContentsAtPath:archivesDirectory] objectEnumerator];
150
NSString* archiveName;
152
while ((archiveName = [archivesEnum nextObject])) {
153
NSString* archivePath = [archivesDirectory stringByAppendingPathComponent:archiveName];
155
// skip over invisible files and directories
156
[manager fileExistsAtPath:archivePath isDirectory:&isDir];
157
if ([archiveName hasPrefix:@"."] || isDir) continue;
159
[self _runCoreArchiveTest:archivePath];