Skip to content

Commit c7d9bff

Browse files
committed
Fix all the SDAddtions category naming typo to SDAdditions, update tests
1 parent 4b785fa commit c7d9bff

17 files changed

+165
-112
lines changed

Example/Tests/SDTestCase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
FOUNDATION_EXPORT const int64_t kAsyncTestTimeout;
1717
FOUNDATION_EXPORT const int64_t kMinDelayNanosecond;
1818
FOUNDATION_EXPORT NSString * _Nonnull const kTestJPEGURL;
19+
FOUNDATION_EXPORT NSString * _Nonnull const kTestProgressiveJPEGURL;
1920
FOUNDATION_EXPORT NSString * _Nonnull const kTestPNGURL;
2021
FOUNDATION_EXPORT NSString * _Nonnull const kTestGIFURL;
2122
FOUNDATION_EXPORT NSString * _Nonnull const kTestWebPURL;
23+
FOUNDATION_EXPORT NSString * _Nonnull const kTestAPNGPURL;
2224

2325
@interface SDTestCase : XCTestCase
2426

Example/Tests/SDTestCase.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
const int64_t kAsyncTestTimeout = 5;
1111
const int64_t kMinDelayNanosecond = NSEC_PER_MSEC * 100; // 0.1s
1212
NSString *const kTestJPEGURL = @"http://via.placeholder.com/50x50.jpg";
13+
NSString *const kTestProgressiveJPEGURL = @"https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_progressive.jpg";
1314
NSString *const kTestPNGURL = @"http://via.placeholder.com/50x50.png";
1415
NSString *const kTestGIFURL = @"https://media.giphy.com/media/UEsrLdv7ugRTq/giphy.gif";
1516
NSString *const kTestWebPURL = @"http://littlesvr.ca/apng/images/SteamEngine.webp";
17+
NSString *const kTestAPNGPURL = @"https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png";
1618

1719
@implementation SDTestCase
1820

Example/Tests/SDYYCacheTests.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ - (void)testCustomImageCache {
6464

6565
- (void)testYYCacheQueryOp {
6666
XCTestExpectation *expectation = [self expectationWithDescription:@"SDImageCache query op works"];
67-
[SDYYCacheTests.sharedCache setObject:[self testJPEGImage] forKey:kTestImageKeyJPEG];
67+
NSData *imageData = [NSData dataWithContentsOfFile:[self testJPEGPath]];
68+
[SDYYCacheTests.sharedCache.diskCache setObject:imageData forKey:kTestImageKeyJPEG];
6869
[SDYYCacheTests.sharedCache queryImageForKey:kTestImageKeyJPEG options:0 context:nil completion:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
6970
expect(image).notTo.beNil();
7071
[expectation fulfill];

Example/Tests/SDYYImageTests.m

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)