Add the test case for cache serializer feature
This commit is contained in:
parent
b400b51cca
commit
0fb7268d2e
|
@ -157,6 +157,34 @@
|
|||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)test10ThatCacheSerializerWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Cache serializer work"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
__block NSData *imageData;
|
||||
|
||||
SDWebImageCacheSerializer *cacheSerializer = [SDWebImageCacheSerializer cacheSerializerWithBlock:^NSData * _Nullable(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL) {
|
||||
imageData = [image sd_imageDataAsFormat:SDImageFormatPNG];
|
||||
return imageData;
|
||||
}];
|
||||
|
||||
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
|
||||
manager.cacheSerializer = cacheSerializer;
|
||||
// Check download and store custom disk data
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
|
||||
[manager loadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
// Dispatch to let store disk finish
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kMinDelayNanosecond), dispatch_get_main_queue(), ^{
|
||||
NSData *diskImageData = [[SDImageCache sharedImageCache] diskImageDataForKey:kTestJPEGURL];
|
||||
expect(diskImageData).equal(imageData); // disk data equal to serializer data
|
||||
|
||||
[expectation fulfill];
|
||||
});
|
||||
}];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (NSString *)testJPEGPath {
|
||||
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
|
||||
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
|
|
Loading…
Reference in New Issue