Add the test for transformer property

This commit is contained in:
DreamPiggy 2018-03-17 20:56:20 +08:00
parent a2076d362e
commit 67285ee722
5 changed files with 67 additions and 1 deletions

View File

@ -41,7 +41,7 @@ typedef NS_OPTIONS(NSUInteger, SDRectCorner) {
@interface NSBezierPath (Additions)
/**
Convenience way to create a bezier path with the specify rouunding corners on macOS. Same as the one on `UIBezierPath`.
Convenience way to create a bezier path with the specify rounding corners on macOS. Same as the one on `UIBezierPath`.
*/
+ (nonnull instancetype)sd_bezierPathWithRoundedRect:(NSRect)rect byRoundingCorners:(SDRectCorner)corners cornerRadius:(CGFloat)cornerRadius;

View File

@ -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 */; };
3264FF2F205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */; };
3264FF30205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */; };
32B99E8B203AF8690017FD66 /* SDCategoriesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B99E8A203AF8690017FD66 /* SDCategoriesTests.m */; };
32B99E9B203B2EDD0017FD66 /* SDTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D7AF05F1F329763000083C2 /* SDTestCase.m */; };
32B99E9C203B2EE40017FD66 /* SDCategoriesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B99E8A203AF8690017FD66 /* SDCategoriesTests.m */; };
@ -56,6 +58,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>"; };
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>"; };
32B99E8A203AF8690017FD66 /* SDCategoriesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCategoriesTests.m; sourceTree = "<group>"; };
32B99E92203B2DF90017FD66 /* Tests Mac.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests Mac.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
32B99E96203B2DF90017FD66 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -193,6 +197,8 @@
2D7AF05F1F329763000083C2 /* SDTestCase.m */,
32E6F0301F3A1B4700A945E6 /* SDWebImageTestDecoder.h */,
32E6F0311F3A1B4700A945E6 /* SDWebImageTestDecoder.m */,
3264FF2D205D42CB00F6BD48 /* SDWebImageTestTransformer.h */,
3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */,
);
path = Tests;
sourceTree = "<group>";
@ -447,6 +453,7 @@
32B99E9E203B2F810017FD66 /* SDMockFileManager.m in Sources */,
32B99EAB203B36620017FD66 /* SDWebImageManagerTests.m in Sources */,
32B99EA9203B34B60017FD66 /* SDWebImageDecoderTests.m in Sources */,
3264FF30205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */,
32B99E9B203B2EDD0017FD66 /* SDTestCase.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -464,6 +471,7 @@
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
32B99E8B203AF8690017FD66 /* SDCategoriesTests.m in Sources */,
3264FF2F205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */,
433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -8,6 +8,7 @@
#import "SDTestCase.h"
#import <SDWebImage/SDWebImageManager.h>
#import "SDWebImageTestTransformer.h"
@interface SDWebImageManagerTests : SDTestCase
@ -135,4 +136,23 @@
[self waitForExpectationsWithTimeout:kAsyncTestTimeout * 2 handler:nil];
}
- (void)test08ThatImageTransformerWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"Image transformer work"];
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] downloader:[SDWebImageDownloader sharedDownloader]];
manager.transformer = transformer;
[[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];
}];
}];
[self waitForExpectationsWithCommonTimeout];
}
@end

View File

@ -0,0 +1,16 @@
/*
* 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 <SDWebImage/SDWebImageTransformer.h>
@interface SDWebImageTestTransformer : NSObject <SDWebImageTransformer>
@property (nonatomic, strong, nullable) UIImage *testImage;
@end

View File

@ -0,0 +1,22 @@
/*
* 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 "SDWebImageTestTransformer.h"
@implementation SDWebImageTestTransformer
- (NSString *)transformerKey {
return @"SDWebImageTestTransformer";
}
- (UIImage *)transformedImageWithImage:(UIImage *)image forKey:(NSString *)key {
return self.testImage;
}
@end