Update the custom downloader operation to fix test
This commit is contained in:
parent
1dcd4441e1
commit
793b7e33a8
|
@ -12,6 +12,8 @@
|
|||
2D7AF0601F329763000083C2 /* SDTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D7AF05F1F329763000083C2 /* SDTestCase.m */; };
|
||||
321259EC1F39E3240096FE0E /* TestImageStatic.webp in Resources */ = {isa = PBXBuildFile; fileRef = 321259EB1F39E3240096FE0E /* TestImageStatic.webp */; };
|
||||
321259EE1F39E4110096FE0E /* TestImageAnimated.webp in Resources */ = {isa = PBXBuildFile; fileRef = 321259ED1F39E4110096FE0E /* TestImageAnimated.webp */; };
|
||||
3226ECBB20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */; };
|
||||
3226ECBC20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */; };
|
||||
3254C32020641077008D1022 /* SDWebImageTransformerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3254C31F20641077008D1022 /* SDWebImageTransformerTests.m */; };
|
||||
3254C32120641077008D1022 /* SDWebImageTransformerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3254C31F20641077008D1022 /* SDWebImageTransformerTests.m */; };
|
||||
3264FF2F205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */; };
|
||||
|
@ -63,6 +65,8 @@
|
|||
2D7AF05F1F329763000083C2 /* SDTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDTestCase.m; sourceTree = "<group>"; };
|
||||
321259EB1F39E3240096FE0E /* TestImageStatic.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImageStatic.webp; sourceTree = "<group>"; };
|
||||
321259ED1F39E4110096FE0E /* TestImageAnimated.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImageAnimated.webp; sourceTree = "<group>"; };
|
||||
3226ECB920754F7700FAFACF /* SDWebImageTestDownloadOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestDownloadOperation.h; sourceTree = "<group>"; };
|
||||
3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestDownloadOperation.m; sourceTree = "<group>"; };
|
||||
3254C31F20641077008D1022 /* SDWebImageTransformerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTransformerTests.m; sourceTree = "<group>"; };
|
||||
3264FF2D205D42CB00F6BD48 /* SDWebImageTestTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestTransformer.h; sourceTree = "<group>"; };
|
||||
3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestTransformer.m; sourceTree = "<group>"; };
|
||||
|
@ -206,6 +210,8 @@
|
|||
37D122871EC48B5E00D98CEB /* SDMockFileManager.m */,
|
||||
2D7AF05E1F329763000083C2 /* SDTestCase.h */,
|
||||
2D7AF05F1F329763000083C2 /* SDTestCase.m */,
|
||||
3226ECB920754F7700FAFACF /* SDWebImageTestDownloadOperation.h */,
|
||||
3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */,
|
||||
32E6F0301F3A1B4700A945E6 /* SDWebImageTestDecoder.h */,
|
||||
32E6F0311F3A1B4700A945E6 /* SDWebImageTestDecoder.m */,
|
||||
3264FF2D205D42CB00F6BD48 /* SDWebImageTestTransformer.h */,
|
||||
|
@ -469,6 +475,7 @@
|
|||
32B99EA9203B34B60017FD66 /* SDWebImageDecoderTests.m in Sources */,
|
||||
3264FF30205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */,
|
||||
32B99E9B203B2EDD0017FD66 /* SDTestCase.m in Sources */,
|
||||
3226ECBC20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -477,6 +484,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
32E6F0321F3A1B4700A945E6 /* SDWebImageTestDecoder.m in Sources */,
|
||||
3226ECBB20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */,
|
||||
3254C32020641077008D1022 /* SDWebImageTransformerTests.m in Sources */,
|
||||
32A571562037DB2D002EDAAE /* SDAnimatedImageTest.m in Sources */,
|
||||
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#import <SDWebImage/SDWebImageDownloader.h>
|
||||
#import <SDWebImage/SDWebImageDownloaderOperation.h>
|
||||
#import <SDWebImage/SDWebImageCodersManager.h>
|
||||
#import "SDWebImageTestDownloadOperation.h"
|
||||
#import "SDWebImageTestDecoder.h"
|
||||
|
||||
/**
|
||||
|
@ -29,42 +30,6 @@
|
|||
createCallback:(SDWebImageDownloaderOperation *(^)(void))createCallback;
|
||||
@end
|
||||
|
||||
/**
|
||||
* A class that fits the NSOperation+SDWebImageDownloaderOperation requirement so we can test
|
||||
*/
|
||||
@interface CustomDownloaderOperation : NSOperation<SDWebImageDownloaderOperation>
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldDecompressImages;
|
||||
@property (nonatomic, strong, nullable) NSURLCredential *credential;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CustomDownloaderOperation
|
||||
|
||||
- (instancetype)initWithRequest:(NSURLRequest *)request inSession:(NSURLSession *)session options:(SDWebImageDownloaderOptions)options {
|
||||
return [self initWithRequest:request inSession:session options:options context:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRequest:(NSURLRequest *)request inSession:(NSURLSession *)session options:(SDWebImageDownloaderOptions)options context:(SDWebImageContext *)context {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)cancel:(id)token {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface SDWebImageDownloaderTests : SDTestCase
|
||||
|
||||
|
@ -127,10 +92,10 @@
|
|||
expect([operation class]).to.equal([SDWebImageDownloaderOperation class]);
|
||||
|
||||
// setting an NSOperation subclass that conforms to SDWebImageDownloaderOperation - should work
|
||||
downloader.config.operationClass = [CustomDownloaderOperation class];
|
||||
downloader.config.operationClass = [SDWebImageTestDownloadOperation class];
|
||||
token = [downloader downloadImageWithURL:imageURL2 options:0 progress:nil completed:nil];
|
||||
operation = token.downloadOperation;
|
||||
expect([operation class]).to.equal([CustomDownloaderOperation class]);
|
||||
expect([operation class]).to.equal([SDWebImageTestDownloadOperation class]);
|
||||
|
||||
// back to the original value
|
||||
downloader.config.operationClass = nil;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* This file is part of the SDWebImage package.
|
||||
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||
* (c) Matt Galloway
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <SDWebImage/SDWebImageDownloaderOperation.h>
|
||||
|
||||
/**
|
||||
* A class that fits the NSOperation+SDWebImageDownloaderOperation requirement so we can test
|
||||
*/
|
||||
@interface SDWebImageTestDownloadOperation : NSOperation <SDWebImageDownloaderOperation>
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldDecompressImages;
|
||||
@property (nonatomic, strong, nullable) NSURLCredential *credential;
|
||||
@property (nonatomic, strong, nullable) NSURLRequest *request;
|
||||
@property (nonatomic, strong, nullable) NSURLResponse *response;
|
||||
|
||||
@end
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of the SDWebImage package.
|
||||
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||
* (c) Matt Galloway
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
#import "SDWebImageTestDownloadOperation.h"
|
||||
|
||||
@implementation SDWebImageTestDownloadOperation
|
||||
|
||||
@synthesize executing = _executing;
|
||||
@synthesize finished = _finished;
|
||||
|
||||
- (void)start {
|
||||
self.finished = NO;
|
||||
self.executing = YES;
|
||||
// Do nothing but keep running
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
if (self.isFinished) return;
|
||||
[super cancel];
|
||||
}
|
||||
|
||||
- (BOOL)isConcurrent {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setFinished:(BOOL)finished {
|
||||
[self willChangeValueForKey:@"isFinished"];
|
||||
_finished = finished;
|
||||
[self didChangeValueForKey:@"isFinished"];
|
||||
}
|
||||
|
||||
- (void)setExecuting:(BOOL)executing {
|
||||
[self willChangeValueForKey:@"isExecuting"];
|
||||
_executing = executing;
|
||||
[self didChangeValueForKey:@"isExecuting"];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRequest:(NSURLRequest *)request inSession:(NSURLSession *)session options:(SDWebImageDownloaderOptions)options {
|
||||
return [self initWithRequest:request inSession:session options:options context:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithRequest:(NSURLRequest *)request inSession:(NSURLSession *)session options:(SDWebImageDownloaderOptions)options context:(SDWebImageContext *)context {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.request = request;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||
return NSStringFromClass([self class]);
|
||||
}
|
||||
|
||||
- (BOOL)cancel:(id)token {
|
||||
[self cancel];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue