File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,6 @@ - (void)stopLoading
111
111
112
112
#pragma mark - test
113
113
114
-
115
114
@interface CCPackageDownloadTests : XCTestCase <CCPackageDownloadDelegate>
116
115
117
116
@property (nonatomic , strong ) CCPackageDownload *download;
@@ -133,7 +132,7 @@ - (void)setUp
133
132
134
133
[(AppController *)[UIApplication sharedApplication ].delegate configureCocos2d ];
135
134
[[CCDirector sharedDirector ] stopAnimation ];
136
- // Sping the runloop a bit otherwise nondeterministic exceptions are thrown in the CCScheduler.
135
+ // Spin the runloop a bit otherwise nondeterministic exceptions are thrown in the CCScheduler.
137
136
[[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeInterval: 0.2 sinceDate: [NSDate date ]]];
138
137
139
138
[NSURLProtocol registerClass: [CCPackageDownloadTestURLProtocol class ]];
@@ -256,6 +255,16 @@ - (void)testDownloadWith404Response
256
255
XCTAssertNotNil (_downloadError);
257
256
}
258
257
258
+ - (void )testDownloadFolderNotAccessible
259
+ {
260
+ // Writing to root level is supposed to fail
261
+ [_download setValue: [NSURL fileURLWithPath: @" /test.zip" ] forKey: NSStringFromSelector (@selector (localURL ))];
262
+
263
+ [self startDownloadAndWaitForDelegateToReturn ];
264
+
265
+ XCTAssertFalse (_downloadSuccessful);
266
+ XCTAssertNotNil (_downloadError);
267
+ }
259
268
260
269
#pragma mark - Helper
261
270
Original file line number Diff line number Diff line change @@ -168,8 +168,10 @@ - (void)startDownloadAskingDelegateIfToResume:(BOOL)askDelegate
168
168
return ;
169
169
}
170
170
171
- if (![self createFileHandle ])
171
+ NSError *error;
172
+ if (![self createFileHandle: &error])
172
173
{
174
+ [self connection: _connection didFailWithError: error];
173
175
return ;
174
176
}
175
177
@@ -264,16 +266,15 @@ - (NSURLRequest *)createRequest
264
266
return result;
265
267
}
266
268
267
- - (BOOL )createFileHandle
269
+ - (BOOL )createFileHandle : ( NSError **) error
268
270
{
269
- NSError *error;
270
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingToURL: [NSURL fileURLWithPath: _tempPath] error: &error];
271
+ NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingToURL: [NSURL fileURLWithPath: _tempPath] error: error];
271
272
CCLOGINFO (@" [PACKAGE/DOWNLOAD][INFO] Opening/Creating file for download: %@ " , _tempPath);
272
273
273
274
if (!fileHandle)
274
275
{
275
276
[[NSFileManager defaultManager ] createFileAtPath: _tempPath contents: nil attributes: nil ];
276
- fileHandle = [NSFileHandle fileHandleForWritingToURL: [NSURL fileURLWithPath: _tempPath] error: & error];
277
+ fileHandle = [NSFileHandle fileHandleForWritingToURL: [NSURL fileURLWithPath: _tempPath] error: error];
277
278
}
278
279
279
280
if (!fileHandle)
You can’t perform that action at this time.
0 commit comments