From 2a28157787fb5f029ce8c09cf65987187f7755a7 Mon Sep 17 00:00:00 2001 From: seven332 Date: Sun, 11 Oct 2020 01:50:36 +0800 Subject: [PATCH] Add test case for coder priority in SDAnimatedImage --- Tests/Tests/SDAnimatedImageTest.m | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Tests/SDAnimatedImageTest.m b/Tests/Tests/SDAnimatedImageTest.m index 11936d2a..ce0c62c5 100644 --- a/Tests/Tests/SDAnimatedImageTest.m +++ b/Tests/Tests/SDAnimatedImageTest.m @@ -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) {