Add test case for coder priority in SDAnimatedImage

This commit is contained in:
seven332 2020-10-11 01:50:36 +08:00
parent b57eae42df
commit 2a28157787
1 changed files with 41 additions and 0 deletions

View File

@ -13,6 +13,41 @@
static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop count
// Check whether the coder is called
@interface SDImageAPNGTestCoder : SDImageAPNGCoder
@property (nonatomic, class, assign) BOOL isCalled;
@end
@implementation SDImageAPNGTestCoder
static BOOL _isCalled;
+ (BOOL)isCalled {
return _isCalled;
}
+ (void)setIsCalled:(BOOL)isCalled {
_isCalled = isCalled;
}
+ (instancetype)sharedCoder {
static SDImageAPNGTestCoder *coder;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
coder = [[SDImageAPNGTestCoder alloc] init];
});
return coder;
}
- (instancetype)initWithAnimatedImageData:(NSData *)data options:(SDImageCoderOptions *)options {
SDImageAPNGTestCoder.isCalled = YES;
return [super initWithAnimatedImageData:data options:options];
}
@end
// Internal header
@interface SDAnimatedImageView ()
@ -561,6 +596,12 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test30AnimatedImageCoderPriority {
[SDImageCodersManager.sharedManager addCoder:SDImageAPNGTestCoder.sharedCoder];
[SDAnimatedImage imageWithData:[self testAPNGPData]];
expect(SDImageAPNGTestCoder.isCalled).equal(YES);
}
#pragma mark - Helper
- (UIWindow *)window {
if (!_window) {