Update the test about progressive decoding of other image format
This commit is contained in:
parent
3cd71e09ce
commit
fc23b93d08
|
@ -232,7 +232,7 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
|
|||
}
|
||||
|
||||
- (void)test34CachePathForSimpleKeyWithExtension {
|
||||
NSString *cachePath = [[SDImageCache sharedImageCache] cachePathForKey:kTestJpegURL];
|
||||
NSString *cachePath = [[SDImageCache sharedImageCache] cachePathForKey:kTestJPEGURL];
|
||||
expect(cachePath).toNot.beNil();
|
||||
expect([cachePath pathExtension]).to.equal(@"jpg");
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
FOUNDATION_EXPORT const int64_t kAsyncTestTimeout;
|
||||
FOUNDATION_EXPORT const int64_t kMinDelayNanosecond;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestJpegURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestJPEGURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestProgressiveJPEGURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestPNGURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestGIFURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestWebPURL;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const kTestAPNGPURL;
|
||||
|
||||
@interface SDTestCase : XCTestCase
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
const int64_t kAsyncTestTimeout = 5;
|
||||
const int64_t kMinDelayNanosecond = NSEC_PER_MSEC * 100; // 0.1s
|
||||
NSString *const kTestJpegURL = @"http://via.placeholder.com/50x50.jpg";
|
||||
NSString *const kTestJPEGURL = @"http://via.placeholder.com/50x50.jpg";
|
||||
NSString *const kTestProgressiveJPEGURL = @"https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_progressive.jpg";
|
||||
NSString *const kTestPNGURL = @"http://via.placeholder.com/50x50.png";
|
||||
NSString *const kTestGIFURL = @"https://media.giphy.com/media/UEsrLdv7ugRTq/giphy.gif";
|
||||
NSString *const kTestWebPURL = @"http://littlesvr.ca/apng/images/SteamEngine.webp";
|
||||
NSString *const kTestAPNGPURL = @"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng";
|
||||
|
||||
@implementation SDTestCase
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIImageView setImageWithURL"];
|
||||
|
||||
UIImageView *imageView = [[UIImageView alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[imageView sd_setImageWithURL:originalImageURL
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
expect(image).toNot.beNil();
|
||||
|
@ -37,7 +37,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIImageView setHighlightedImageWithURL"];
|
||||
|
||||
UIImageView *imageView = [[UIImageView alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[imageView sd_setHighlightedImageWithURL:originalImageURL
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
expect(image).toNot.beNil();
|
||||
|
@ -54,7 +54,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"MKAnnotationView setImageWithURL"];
|
||||
|
||||
MKAnnotationView *annotationView = [[MKAnnotationView alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[annotationView sd_setImageWithURL:originalImageURL
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
expect(image).toNot.beNil();
|
||||
|
@ -71,7 +71,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setImageWithURL normalState"];
|
||||
|
||||
UIButton *button = [[UIButton alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[button sd_setImageWithURL:originalImageURL
|
||||
forState:UIControlStateNormal
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
|
@ -88,7 +88,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setImageWithURL highlightedState"];
|
||||
|
||||
UIButton *button = [[UIButton alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[button sd_setImageWithURL:originalImageURL
|
||||
forState:UIControlStateHighlighted
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
|
@ -105,7 +105,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setBackgroundImageWithURL normalState"];
|
||||
|
||||
UIButton *button = [[UIButton alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[button sd_setBackgroundImageWithURL:originalImageURL
|
||||
forState:UIControlStateNormal
|
||||
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
|
@ -122,7 +122,7 @@
|
|||
- (void)testUIViewImageProgressKVOWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView imageProgressKVO failed"];
|
||||
UIView *view = [[UIView alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
|
||||
[self.KVOController observe:view.sd_imageProgress keyPath:NSStringFromSelector(@selector(fractionCompleted)) options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
|
||||
NSProgress *progress = object;
|
||||
|
@ -133,7 +133,7 @@
|
|||
}];
|
||||
|
||||
// Clear the disk cache to force download from network
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJpegURL withCompletion:^{
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
|
||||
[view sd_internalSetImageWithURL:originalImageURL placeholderImage:nil options:0 context:nil setImageBlock:nil progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(view.sd_imageProgress.fractionCompleted).equal(1.0);
|
||||
expect([view.sd_imageProgress.userInfo[NSStringFromSelector(_cmd)] boolValue]).equal(YES);
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
- (void)test04ThatASimpleDownloadWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
|
@ -75,7 +75,7 @@
|
|||
|
||||
- (void)test06ThatUsingACustomDownloaderOperationWorks {
|
||||
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] initWithConfig:nil];
|
||||
NSURL *imageURL1 = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL1 = [NSURL URLWithString:kTestJPEGURL];
|
||||
NSURL *imageURL2 = [NSURL URLWithString:kTestPNGURL];
|
||||
NSURL *imageURL3 = [NSURL URLWithString:kTestGIFURL];
|
||||
// we try to set a usual NSOperation as operation class. Should not work
|
||||
|
@ -131,7 +131,7 @@
|
|||
|
||||
- (void)test09ThatProgressiveJPEGWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive JPEG download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestProgressiveJPEGURL];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
|
@ -161,7 +161,7 @@
|
|||
- (void)test11ThatCancelWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
SDWebImageDownloadToken *token = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
XCTFail(@"Should not get here");
|
||||
|
@ -181,7 +181,7 @@
|
|||
|
||||
- (void)test12ThatWeCanUseAnotherSessionForEachDownloadOperation {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Owned session"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
|
||||
request.HTTPShouldUsePipelining = YES;
|
||||
|
@ -207,7 +207,7 @@
|
|||
|
||||
- (void)test13ThatDownloadCanContinueWhenTheAppEntersBackground {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderContinueInBackground progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
|
@ -287,6 +287,36 @@
|
|||
}];
|
||||
}
|
||||
|
||||
- (void)test18ThatProgressiveGIFWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive GIF download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestGIFURL];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
} else if (finished) {
|
||||
XCTFail(@"Something went wrong");
|
||||
} else {
|
||||
// progressive updates
|
||||
}
|
||||
}];
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)test19ThatProgressiveAPNGWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive APNG download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestAPNGPURL];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
} else if (finished) {
|
||||
XCTFail(@"Something went wrong");
|
||||
} else {
|
||||
// progressive updates
|
||||
}
|
||||
}];
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
/**
|
||||
* Per #883 - Fix multiple requests for same image and then canceling one
|
||||
* Old SDWebImage (3.x) could not handle correctly multiple requests for the same image + cancel
|
||||
|
@ -296,7 +326,7 @@
|
|||
- (void)test20ThatDownloadingSameURLTwiceAndCancellingFirstWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
|
||||
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
|
@ -334,7 +364,7 @@
|
|||
- (void)test21ThatCancelingDownloadThenRequestingAgainWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
|
||||
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
|
@ -403,7 +433,7 @@
|
|||
components.query = @"text=Hello+World";
|
||||
mutableRequest.URL = components.URL;
|
||||
return mutableRequest;
|
||||
} else if ([request.URL.absoluteString isEqualToString:kTestJpegURL]) {
|
||||
} else if ([request.URL.absoluteString isEqualToString:kTestJPEGURL]) {
|
||||
// Test that return nil request will treat as error
|
||||
return nil;
|
||||
} else {
|
||||
|
@ -415,7 +445,7 @@
|
|||
__block BOOL firstCheck = NO;
|
||||
__block BOOL secondCheck = NO;
|
||||
|
||||
[downloader downloadImageWithURL:[NSURL URLWithString:kTestJpegURL] options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
[downloader downloadImageWithURL:[NSURL URLWithString:kTestJPEGURL] options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
// Except error
|
||||
expect(error).notTo.beNil();
|
||||
firstCheck = YES;
|
||||
|
@ -440,7 +470,7 @@
|
|||
- (void)test30CustomImageLoaderWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom image not works"];
|
||||
SDWebImageTestLoader *loader = [[SDWebImageTestLoader alloc] init];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[loader loadImageWithURL:imageURL options:0 context:nil progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
|
||||
expect(targetURL).notTo.beNil();
|
||||
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
|
@ -454,7 +484,7 @@
|
|||
|
||||
- (void)test31ThatLoadersManagerWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Loaders manager not works"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[[SDImageLoadersManager sharedManager] loadImageWithURL:imageURL options:0 context:nil progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
|
||||
expect(targetURL).notTo.beNil();
|
||||
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
- (void)test02ThatDownloadInvokesCompletionBlockWithCorrectParamsAsync {
|
||||
__block XCTestExpectation *expectation = [self expectationWithDescription:@"Image download completes"];
|
||||
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
|
||||
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL
|
||||
options:SDWebImageRefreshCached
|
||||
|
@ -111,14 +111,14 @@
|
|||
|
||||
- (void)test08ThatImageTransformerWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Image transformer work"];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
|
||||
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
SDWebImageTestTransformer *transformer = [[SDWebImageTestTransformer alloc] init];
|
||||
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
|
||||
NSString *testImagePath = [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
transformer.testImage = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
|
||||
manager.transformer = transformer;
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJpegURL withCompletion:^{
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
|
||||
[manager loadImageWithURL:imageURL options:SDWebImageTransformAnimatedImage progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(image).equal(transformer.testImage);
|
||||
[expectation fulfill];
|
||||
|
|
Loading…
Reference in New Issue