Sometimes I get a EXC_BAD_ACCESS when running this test:
- (void)testThatItDoesNotSaveLoadedImageIfNotIntializedWithModifiesFileCacheOption {
BETwoLayerCacheImageProvider *imageProvider = [[BETwoLayerCacheImageProvider alloc] initWithCache:self.cacheMock imageLoader:self.imageLoaderMock options:0 scale:2.f];
__block UIImage *expectedImage = [UIImage new];
[[self.cacheMock reject] saveImageAtURLInFileCache:[OCMArg any] forURL:[OCMArg any]];
[[self.cacheMock reject] saveImageInFileCache:[OCMArg any] forURL:[OCMArg any]];
__weak typeof(self) welf = self;
OCMStub([self.imageLoaderMock downloadImageWithURL:[OCMArg any] completionCallback:[OCMArg any]]).andDo(^(NSInvocation *invocation) {
// [invocation retainArguments];
void (^callback)(UIImage *image, NSError *error, NSString *imageURL, NSURL *temporaryImageURL) = nil;
[invocation getArgument:&callback atIndex:3];
callback(expectedImage, nil, welf.smallImageURL, [NSURL fileURLWithPath:@"/file:///fixtureURL"]);
});
[imageProvider fetchImageForImageData:self.imageData size:self.smallImageSize withCompletionCallback:^(UIImage *anImage, id<BEImageAware> imageData, CGSize requestedSize) {}];
OCMVerifyAllWithDelay(self.cacheMock, 0.1f);
}
EXC_BAD_ACCESS happens here:
- (void)forwardInvocationForClassObject:(NSInvocation *)anInvocation
{
// in here "self" is a reference to the real class, not the mock
OCClassMockObject *mock = OCMGetAssociatedMockForClass((Class) self, YES);
if(mock == nil)
{
[NSException raise:NSInternalInconsistencyException format:@"No mock for class %@", NSStringFromClass((Class)self)];
}
if([mock handleInvocation:anInvocation] == NO)
{
[anInvocation setSelector:OCMAliasForOriginalSelector([anInvocation selector])];
[anInvocation invoke]; /// EXC_BAD_ACCESS
}
}
The weird thing is that it never crashes when I run only this one test, but I crashes almost always when I tun all my tests (with cmd+u).
I tried to add [invocation retainArguments], it did not help, and I think should not be here. Anyone had such problems?
Aucun commentaire:
Enregistrer un commentaire