@@ -21,6 +21,8 @@ - (void)tearDown {
2121 }
2222}
2323
24+ #pragma mark - WebCache
25+
2426- (void )testYYAnimatedImageViewSetImageWithURL {
2527 XCTestExpectation *expectation = [self expectationWithDescription: @" YYAnimatedImageView setImageWithURL" ];
2628
@@ -39,6 +41,30 @@ - (void)testYYAnimatedImageViewSetImageWithURL {
3941 [self waitForExpectationsWithCommonTimeout ];
4042}
4143
44+ #pragma mark - YYImage && SDAnimatedImage
45+
46+ - (void )testYYImageWorksForSDAnimatedImageView {
47+ SDAnimatedImageView *imageView = [SDAnimatedImageView new ];
48+ [self .window addSubview: imageView];
49+ YYImage *image = [YYImage imageWithData: [self testGIFData ]];
50+ imageView.image = image;
51+ expect (imageView.image ).notTo .beNil ();
52+ expect (imageView.currentFrame ).notTo .beNil (); // current frame
53+ expect (imageView.isAnimating ).to .beTruthy (); // animating
54+ }
55+
56+ - (void )testYYImageInitWithSDImageYYCoder {
57+ SDImageYYCoder *coder = [[SDImageYYCoder alloc ] initWithAnimatedImageData: [self testGIFData ] options: @{SDWebImageContextImageScaleFactor : @(2 )}];
58+ SDAnimatedImage *image = [[SDAnimatedImage alloc ] initWithAnimatedCoder: coder scale: 2 ];
59+ YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc ] init ];
60+ [self .window addSubview: imageView];
61+ imageView.image = image;
62+ expect (imageView.image ).notTo .beNil ();
63+ expect (imageView.image .scale ).to .equal (2 );
64+ expect (imageView.currentAnimatedImageIndex ).to .equal (0 ); // current frame
65+ expect (imageView.currentIsPlayingAnimation ).to .beTruthy (); // animating
66+ }
67+
4268- (void )testSDAnimatedImageWorksForYYAnimatedImageView {
4369 YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc ] init ];
4470 [self .window addSubview: imageView];
@@ -49,16 +75,38 @@ - (void)testSDAnimatedImageWorksForYYAnimatedImageView {
4975 expect (imageView.currentIsPlayingAnimation ).to .beTruthy (); // animating
5076}
5177
52- - (void )testYYImageWorksForSDAnimatedImageView {
78+ - (void )testSDAnimatedImageInitWithSDImageYYCoder {
79+ SDImageYYCoder *coder = [[SDImageYYCoder alloc ] initWithAnimatedImageData: [self testGIFData ] options: @{SDWebImageContextImageScaleFactor : @(2 )}];
80+ SDAnimatedImage *image = [[SDAnimatedImage alloc ] initWithAnimatedCoder: coder scale: 2 ];
5381 SDAnimatedImageView *imageView = [SDAnimatedImageView new ];
5482 [self .window addSubview: imageView];
55- YYImage *image = [YYImage imageWithData: [self testGIFData ]];
5683 imageView.image = image;
5784 expect (imageView.image ).notTo .beNil ();
85+ expect (imageView.image .scale ).to .equal (2 );
5886 expect (imageView.currentFrame ).notTo .beNil (); // current frame
5987 expect (imageView.isAnimating ).to .beTruthy (); // animating
6088}
6189
90+ #pragma mark - SDImageYYCoder
91+
92+ - (void )testSDImageYYCoderProgressiveJPEGWorks {
93+ XCTestExpectation *expectation = [self expectationWithDescription: @" Progressive JPEG download" ];
94+ // Add coder
95+ [SDImageCodersManager.sharedManager addCoder: SDImageYYCoder.sharedCoder];
96+
97+ NSURL *imageURL = [NSURL URLWithString: kTestProgressiveJPEGURL ];
98+ [[SDWebImageDownloader sharedDownloader ] downloadImageWithURL: imageURL options: SDWebImageDownloaderProgressiveLoad progress: nil completed: ^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
99+ if (image && data && !error && finished) {
100+ [expectation fulfill ];
101+ } else if (finished) {
102+ XCTFail (@" Something went wrong" );
103+ } else {
104+ // progressive updates
105+ }
106+ }];
107+ [self waitForExpectationsWithCommonTimeout ];
108+ }
109+
62110- (void )testSDImageYYCoderPNGWorks {
63111 NSURL *staticWebPURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" TestImage" withExtension: @" png" ];
64112 [self verifyCoder: [SDImageYYCoder sharedCoder ]
0 commit comments