|
10 | 10 | #import "SDTestCase.h"
|
11 | 11 | #import "SDInternalMacros.h"
|
12 | 12 | #import "SDImageFramePool.h"
|
| 13 | +#import "SDWebImageTestTransformer.h" |
13 | 14 | #import <KVOController/KVOController.h>
|
14 | 15 |
|
15 | 16 | static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop count
|
@@ -808,6 +809,40 @@ - (void)test37AnimatedImageWithStaticDataBehavior {
|
808 | 809 | expect(scaledImage).notTo.equal(image);
|
809 | 810 | }
|
810 | 811 |
|
| 812 | +- (void)testAnimationTransformerWorks { |
| 813 | + XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView animationTransformer works"]; |
| 814 | + SDAnimatedImageView *imageView = [SDAnimatedImageView new]; |
| 815 | + // Setup transformer, showing which hook all frames into the test image |
| 816 | + UIImage *testImage = [[UIImage alloc] initWithData:[self testJPEGData]]; |
| 817 | + SDWebImageTestTransformer *transformer = [SDWebImageTestTransformer new]; |
| 818 | + transformer.testImage = testImage; |
| 819 | + imageView.animationTransformer = transformer; |
| 820 | + |
| 821 | +#if SD_UIKIT |
| 822 | + [self.window addSubview:imageView]; |
| 823 | +#else |
| 824 | + [self.window.contentView addSubview:imageView]; |
| 825 | +#endif |
| 826 | + SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testGIFData]]; |
| 827 | + imageView.image = image; |
| 828 | +#if SD_UIKIT |
| 829 | + [imageView startAnimating]; |
| 830 | +#else |
| 831 | + imageView.animates = YES; |
| 832 | +#endif |
| 833 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 834 | + // 0.5s is not finished, frame index should not be 0 |
| 835 | + expect(imageView.player.framePool.currentFrameCount).beGreaterThan(0); |
| 836 | + expect(imageView.currentFrameIndex).beGreaterThan(0); |
| 837 | + // Test the current frame image is hooked by transformer |
| 838 | + expect(imageView.currentFrame).equal(testImage); |
| 839 | + |
| 840 | + [expectation fulfill]; |
| 841 | + }); |
| 842 | + |
| 843 | + [self waitForExpectationsWithCommonTimeout]; |
| 844 | +} |
| 845 | + |
811 | 846 | #pragma mark - Helper
|
812 | 847 |
|
813 | 848 | - (NSString *)testGIFPath {
|
|
0 commit comments