Merge pull request #3103 from seven332/master

Test case for coder priority in SDAnimatedImage
This commit is contained in:
DreamPiggy 2020-10-12 16:26:54 +08:00 committed by GitHub
commit a55ffe0b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {