Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case for coder priority in SDAnimatedImage #3103

Merged
merged 1 commit into from Oct 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions Tests/Tests/SDAnimatedImageTest.m
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property can use instance level property. No need a class property.

expect(SDImageAPNGTestCoder.sharedCoder.isCalled).beTruth();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the property is an instance level property, we can't access it. The new coder created in initWithAnimatedImageData holds it, not the sharedCoder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


@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 ()

Expand Down Expand Up @@ -561,6 +596,12 @@ - (void)test29AnimatedImageSeekFrame {
[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) {
Expand Down