Skip to content

Commit 3b05570

Browse files
committed
CCPackageDownload unit test added for 404 response.
1 parent 4ff444c commit 3b05570

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

UnitTests/CCPackageDownloadTests.m

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ - (void)setUp
140140
self.downloadError = nil;
141141
self.downloadSuccessful = NO;
142142

143-
144143
self.package = [[CCPackage alloc] initWithName:@"testpackage"
145144
resolution:@"phonehd"
146145
os:@"iOS"
@@ -186,18 +185,21 @@ - (void)createDownloadFolder
186185

187186
- (void)testDownloadPackage
188187
{
189-
[self startDownloadAndWaitForDelegateToReturn];
188+
[self waitForDelegateToReturnAfterRunningBlock:^
189+
{
190+
[_download start];
191+
}];
190192

191193
NSFileManager *fileManager = [NSFileManager defaultManager];
192194
NSDictionary *attribs = [fileManager attributesOfItemAtPath:_localURL.path error:nil];
193-
195+
XCTAssertTrue(_downloadSuccessful);
194196
XCTAssertTrue([fileManager fileExistsAtPath:_localURL.path]);
195197
XCTAssertEqual([attribs[NSFileSize] unsignedIntegerValue], __fileDownloadSize);
196198
}
197199

198-
- (void)startDownloadAndWaitForDelegateToReturn
200+
- (void)waitForDelegateToReturnAfterRunningBlock:(dispatch_block_t)block
199201
{
200-
[_download start];
202+
block();
201203

202204
while (!_downloadReturned)
203205
{
@@ -207,21 +209,29 @@ - (void)startDownloadAndWaitForDelegateToReturn
207209

208210
- (void)testRangeRequest
209211
{
210-
// Setting up partial download on disk
211-
NSString *fileName = [_package.remoteURL lastPathComponent];
212-
NSString *pathToPackage = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Resources-shared/Packages/%@", fileName] ofType:nil];
213-
NSData *data = [[NSData dataWithContentsOfFile:pathToPackage] subdataWithRange:NSMakeRange(0, 5000)];
214-
NSString *tempName = [_download performSelector:@selector(createTempName)];
215-
[data writeToFile:[[_localURL.path stringByDeletingLastPathComponent] stringByAppendingPathComponent:tempName] atomically:YES];
212+
[self setupPartialDownloadOnDisk];
216213

217-
[self startDownloadAndWaitForDelegateToReturn];
214+
[self waitForDelegateToReturnAfterRunningBlock:^
215+
{
216+
[_download start];
217+
}];
218218

219219
NSFileManager *fileManager = [NSFileManager defaultManager];
220220
NSDictionary *attribs = [fileManager attributesOfItemAtPath:_localURL.path error:nil];
221+
XCTAssertTrue(_downloadSuccessful);
221222
XCTAssertTrue([fileManager fileExistsAtPath:_localURL.path]);
222223
XCTAssertEqual([attribs[NSFileSize] unsignedIntegerValue], __fileDownloadSize);
223224
}
224225

226+
- (void)setupPartialDownloadOnDisk
227+
{
228+
NSString *fileName = [_package.remoteURL lastPathComponent];
229+
NSString *pathToPackage = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Resources-shared/Packages/%@", fileName] ofType:nil];
230+
NSData *data = [[NSData dataWithContentsOfFile:pathToPackage] subdataWithRange:NSMakeRange(0, 5000)];
231+
NSString *tempName = [_download performSelector:@selector(createTempName)];
232+
[data writeToFile:[[_localURL.path stringByDeletingLastPathComponent] stringByAppendingPathComponent:tempName] atomically:YES];
233+
}
234+
225235
/*
226236
- (void)testResumeDownloadedPackage
227237
{
@@ -232,13 +242,21 @@ - (void)testPauseDownload
232242
{
233243
234244
}
245+
*/
235246

236247

237248
- (void)testDownloadWith404Response
238249
{
250+
[_package setValue:[NSURL URLWithString:@"http://package.request.fake/DOES_NOT_EXIST.zip"] forKey:NSStringFromSelector(@selector(remoteURL))];
239251

252+
[self waitForDelegateToReturnAfterRunningBlock:^
253+
{
254+
[_download start];
255+
}];
256+
257+
XCTAssertFalse(_downloadSuccessful);
258+
XCTAssertNotNil(_downloadError);
240259
}
241-
*/
242260

243261

244262
#pragma mark - CCPackageDownloadDelegate

0 commit comments

Comments
 (0)