Add test case for options manager, ensure it works

This commit is contained in:
DreamPiggy 2019-05-23 21:55:39 +08:00
parent 26d1a95cca
commit 0dbcb98c6f
1 changed files with 27 additions and 0 deletions

View File

@ -185,6 +185,33 @@
[self waitForExpectationsWithCommonTimeout];
}
- (void)test11ThatOptionsProcessorWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"Options processor work"];
__block BOOL optionsProcessorCalled = NO;
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
manager.optionsProcessor = [SDWebImageOptionsProcessor optionsProcessorWithBlock:^SDWebImageOptionsResult * _Nullable(NSURL * _Nonnull url, SDWebImageOptions options, SDWebImageContext * _Nullable context) {
if ([url.absoluteString isEqualToString:kTestPNGURL]) {
optionsProcessorCalled = YES;
return [[SDWebImageOptionsResult alloc] initWithOptions:0 context:@{SDWebImageContextImageScaleFactor : @(3)}];
} else {
return nil;
}
}];
NSURL *url = [NSURL URLWithString:kTestPNGURL];
[[SDImageCache sharedImageCache] removeImageForKey:kTestPNGURL withCompletion:^{
[manager loadImageWithURL:url options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
expect(image.scale).equal(3);
expect(optionsProcessorCalled).beTruthy();
[expectation fulfill];
}];
}];
[self waitForExpectationsWithCommonTimeout];
}
- (NSString *)testJPEGPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];