@@ -140,7 +140,6 @@ - (void)setUp
140
140
self.downloadError = nil ;
141
141
self.downloadSuccessful = NO ;
142
142
143
-
144
143
self.package = [[CCPackage alloc ] initWithName: @" testpackage"
145
144
resolution: @" phonehd"
146
145
os: @" iOS"
@@ -186,18 +185,21 @@ - (void)createDownloadFolder
186
185
187
186
- (void )testDownloadPackage
188
187
{
189
- [self startDownloadAndWaitForDelegateToReturn ];
188
+ [self waitForDelegateToReturnAfterRunningBlock: ^
189
+ {
190
+ [_download start ];
191
+ }];
190
192
191
193
NSFileManager *fileManager = [NSFileManager defaultManager ];
192
194
NSDictionary *attribs = [fileManager attributesOfItemAtPath: _localURL.path error: nil ];
193
-
195
+ XCTAssertTrue (_downloadSuccessful);
194
196
XCTAssertTrue ([fileManager fileExistsAtPath: _localURL.path]);
195
197
XCTAssertEqual ([attribs[NSFileSize ] unsignedIntegerValue ], __fileDownloadSize);
196
198
}
197
199
198
- - (void )startDownloadAndWaitForDelegateToReturn
200
+ - (void )waitForDelegateToReturnAfterRunningBlock : ( dispatch_block_t ) block
199
201
{
200
- [_download start ] ;
202
+ block () ;
201
203
202
204
while (!_downloadReturned)
203
205
{
@@ -207,21 +209,29 @@ - (void)startDownloadAndWaitForDelegateToReturn
207
209
208
210
- (void )testRangeRequest
209
211
{
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 ];
216
213
217
- [self startDownloadAndWaitForDelegateToReturn ];
214
+ [self waitForDelegateToReturnAfterRunningBlock: ^
215
+ {
216
+ [_download start ];
217
+ }];
218
218
219
219
NSFileManager *fileManager = [NSFileManager defaultManager ];
220
220
NSDictionary *attribs = [fileManager attributesOfItemAtPath: _localURL.path error: nil ];
221
+ XCTAssertTrue (_downloadSuccessful);
221
222
XCTAssertTrue ([fileManager fileExistsAtPath: _localURL.path]);
222
223
XCTAssertEqual ([attribs[NSFileSize ] unsignedIntegerValue ], __fileDownloadSize);
223
224
}
224
225
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
+
225
235
/*
226
236
- (void)testResumeDownloadedPackage
227
237
{
@@ -232,13 +242,21 @@ - (void)testPauseDownload
232
242
{
233
243
234
244
}
245
+ */
235
246
236
247
237
248
- (void )testDownloadWith404Response
238
249
{
250
+ [_package setValue: [NSURL URLWithString: @" http://package.request.fake/DOES_NOT_EXIST.zip" ] forKey: NSStringFromSelector (@selector (remoteURL ))];
239
251
252
+ [self waitForDelegateToReturnAfterRunningBlock: ^
253
+ {
254
+ [_download start ];
255
+ }];
256
+
257
+ XCTAssertFalse (_downloadSuccessful);
258
+ XCTAssertNotNil (_downloadError);
240
259
}
241
- */
242
260
243
261
244
262
#pragma mark - CCPackageDownloadDelegate
0 commit comments