Add the test case for these two new properties

This commit is contained in:
DreamPiggy 2019-08-27 19:41:27 +08:00
parent 1abc05e05c
commit 1f74aea686
1 changed files with 68 additions and 0 deletions

View File

@ -16,6 +16,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
@interface SDAnimatedImageView ()
@property (nonatomic, assign) BOOL isProgressive;
@property (nonatomic, strong) NSMutableDictionary<NSNumber *, UIImage *> *frameBuffer;
@end
@ -206,6 +207,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
#else
imageView.animates = NO;
#endif
[imageView removeFromSuperview];
[expectation fulfill];
}
}];
@ -298,6 +300,72 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test25AnimatedImageStopAnimatingNormal {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView stopAnimating normal behavior"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
#if SD_UIKIT
[self.window addSubview:imageView];
#else
[self.window.contentView addSubview:imageView];
#endif
// This APNG duration is 2s
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
imageView.image = image;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 0.5s is not finished, frame index should not be 0
expect(imageView.frameBuffer.count).beGreaterThan(0);
expect(imageView.currentFrameIndex).beGreaterThan(0);
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[imageView stopAnimating];
expect(imageView.frameBuffer.count).beGreaterThan(0);
expect(imageView.currentFrameIndex).beGreaterThan(0);
[imageView removeFromSuperview];
[expectation fulfill];
});
[self waitForExpectationsWithCommonTimeout];
}
- (void)test25AnimatedImageStopAnimatingClearBuffer {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView stopAnimating clear buffer when stopped"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
imageView.clearBufferWhenStopped = YES;
imageView.resetFrameIndexWhenStopped = YES;
#if SD_UIKIT
[self.window addSubview:imageView];
#else
[self.window.contentView addSubview:imageView];
#endif
// This APNG duration is 2s
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
imageView.image = image;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 0.5s is not finished, frame index should not be 0
expect(imageView.frameBuffer.count).beGreaterThan(0);
expect(imageView.currentFrameIndex).beGreaterThan(0);
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[imageView stopAnimating];
expect(imageView.frameBuffer.count).equal(0);
expect(imageView.currentFrameIndex).equal(0);
[imageView removeFromSuperview];
[expectation fulfill];
});
[self waitForExpectationsWithCommonTimeout];
}
#pragma mark - Helper
- (UIWindow *)window {
if (!_window) {