Added SDImageCacheConfig to all targets, test images, code coverage setting, tests for SDImageCache, SDWebImageDownloader, SDWebImageDownloaderOperation, SDWebImageDecoder
This commit is contained in:
parent
0612504f1b
commit
cfc182f2e5
|
@ -435,6 +435,18 @@
|
|||
43A62A641D0E0A8F0089D7DD /* vp8li.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D681998E6B2007367ED /* vp8li.h */; };
|
||||
43A62A651D0E0A8F0089D7DD /* webp.c in Sources */ = {isa = PBXBuildFile; fileRef = DA577D691998E6B2007367ED /* webp.c */; };
|
||||
43A62A661D0E0A8F0089D7DD /* webpi.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D6A1998E6B2007367ED /* webpi.h */; };
|
||||
43A918641D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A918651D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A918661D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A918671D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A918681D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A918691D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
|
||||
43A9186B1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43A9186D1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43A9186E1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43A9186F1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43A918701D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
|
||||
43CE75761CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
43CE75771CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
43CE75781CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -882,6 +894,8 @@
|
|||
4397D2F21D0DDD8C00BB2784 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+WebCache.h"; sourceTree = "<group>"; };
|
||||
4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+WebCache.m"; sourceTree = "<group>"; };
|
||||
43A918621D8308FE00B3925F /* SDImageCacheConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCacheConfig.h; sourceTree = "<group>"; };
|
||||
43A918631D8308FE00B3925F /* SDImageCacheConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheConfig.m; sourceTree = "<group>"; };
|
||||
43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImage.h; sourceTree = "<group>"; };
|
||||
43CE754A1CFE9427006C64D0 /* FLAnimatedImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLAnimatedImage.m; sourceTree = "<group>"; };
|
||||
43CE754B1CFE9427006C64D0 /* FLAnimatedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImageView.h; sourceTree = "<group>"; };
|
||||
|
@ -1218,6 +1232,8 @@
|
|||
children = (
|
||||
53922D85148C56230056699D /* SDImageCache.h */,
|
||||
53922D86148C56230056699D /* SDImageCache.m */,
|
||||
43A918621D8308FE00B3925F /* SDImageCacheConfig.h */,
|
||||
43A918631D8308FE00B3925F /* SDImageCacheConfig.m */,
|
||||
);
|
||||
name = Cache;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1417,6 +1433,7 @@
|
|||
431739361CDFC8B20008FEB9 /* bit_reader_inl.h in Headers */,
|
||||
4317393A1CDFC8B20008FEB9 /* color_cache.h in Headers */,
|
||||
431738E11CDFC8A40008FEB9 /* webpi.h in Headers */,
|
||||
43A918671D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
431739571CDFC8B70008FEB9 /* encode.h in Headers */,
|
||||
431739351CDFC8B20008FEB9 /* bit_reader.h in Headers */,
|
||||
43DA7D5D1D1086600028BE58 /* mips_macro.h in Headers */,
|
||||
|
@ -1488,6 +1505,7 @@
|
|||
43DA7CFE1D10865E0028BE58 /* yuv.h in Headers */,
|
||||
4314D1711D0E0E3B004B36C9 /* huffman.h in Headers */,
|
||||
4314D1721D0E0E3B004B36C9 /* SDWebImageCompat.h in Headers */,
|
||||
43A918651D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
4314D1731D0E0E3B004B36C9 /* vp8li.h in Headers */,
|
||||
4314D1741D0E0E3B004B36C9 /* types.h in Headers */,
|
||||
4314D1761D0E0E3B004B36C9 /* decode.h in Headers */,
|
||||
|
@ -1575,6 +1593,7 @@
|
|||
431BB6F91D06D2C1006A3455 /* UIImage+GIF.h in Headers */,
|
||||
431BB6FA1D06D2C1006A3455 /* SDWebImageDownloader.h in Headers */,
|
||||
431BB6FC1D06D2C1006A3455 /* SDWebImageDecoder.h in Headers */,
|
||||
43A918681D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1606,6 +1625,7 @@
|
|||
4397D2D11D0DDD8C00BB2784 /* decode.h in Headers */,
|
||||
4397D2D21D0DDD8C00BB2784 /* webpi.h in Headers */,
|
||||
43DA7DCB1D1086610028BE58 /* mips_macro.h in Headers */,
|
||||
43A918691D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
4397D2D31D0DDD8C00BB2784 /* thread.h in Headers */,
|
||||
4397D2D41D0DDD8C00BB2784 /* quant_levels.h in Headers */,
|
||||
4397D2D51D0DDD8C00BB2784 /* bit_reader_inl.h in Headers */,
|
||||
|
@ -1650,6 +1670,7 @@
|
|||
4A2CAE041AB4BB5400B6BC39 /* SDWebImage.h in Headers */,
|
||||
431739511CDFC8B70008FEB9 /* format_constants.h in Headers */,
|
||||
431739231CDFC8B20008FEB9 /* filters.h in Headers */,
|
||||
43A918661D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
4A2CAE211AB4BB7000B6BC39 /* SDWebImageManager.h in Headers */,
|
||||
4A2CAE1F1AB4BB6C00B6BC39 /* SDImageCache.h in Headers */,
|
||||
43DA7D261D10865F0028BE58 /* mips_macro.h in Headers */,
|
||||
|
@ -1755,6 +1776,7 @@
|
|||
53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
|
||||
4317387B1CDFC2580008FEB9 /* decode_vp8.h in Headers */,
|
||||
431738B61CDFC2630008FEB9 /* random.h in Headers */,
|
||||
43A918641D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2017,6 +2039,7 @@
|
|||
43DA7D361D1086600028BE58 /* alpha_processing_sse41.c in Sources */,
|
||||
43DA7D641D1086600028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
|
||||
431739461CDFC8B20008FEB9 /* random.c in Sources */,
|
||||
43A9186E1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
43DA7D3D1D1086600028BE58 /* cost_sse2.c in Sources */,
|
||||
431738DB1CDFC8A40008FEB9 /* tree.c in Sources */,
|
||||
00733A581BC4880000A5A117 /* SDWebImageManager.m in Sources */,
|
||||
|
@ -2119,6 +2142,7 @@
|
|||
43DA7CFD1D10865E0028BE58 /* yuv.c in Sources */,
|
||||
4314D1401D0E0E3B004B36C9 /* UIImageView+WebCache.m in Sources */,
|
||||
43DA7CDC1D10865E0028BE58 /* enc_mips32.c in Sources */,
|
||||
43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
4314D1411D0E0E3B004B36C9 /* SDWebImageDownloaderOperation.m in Sources */,
|
||||
43DA7CCE1D10865E0028BE58 /* cost_mips32.c in Sources */,
|
||||
4314D1421D0E0E3B004B36C9 /* webp.c in Sources */,
|
||||
|
@ -2215,6 +2239,7 @@
|
|||
43DA7DA21D1086600028BE58 /* yuv.c in Sources */,
|
||||
431BB6B91D06D2C1006A3455 /* UIButton+WebCache.m in Sources */,
|
||||
43DA7D811D1086600028BE58 /* enc_mips32.c in Sources */,
|
||||
43A9186F1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
43A62A5F1D0E0A8F0089D7DD /* quant.c in Sources */,
|
||||
43DA7D731D1086600028BE58 /* cost_mips32.c in Sources */,
|
||||
431BB6BD1D06D2C1006A3455 /* UIImage+GIF.m in Sources */,
|
||||
|
@ -2335,6 +2360,7 @@
|
|||
4397D2AA1D0DDD8C00BB2784 /* io.c in Sources */,
|
||||
43DA7DCF1D1086610028BE58 /* rescaler_neon.c in Sources */,
|
||||
43DA7DC31D1086610028BE58 /* lossless_enc_sse2.c in Sources */,
|
||||
43A918701D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
4397D2AB1D0DDD8C00BB2784 /* UIView+WebCacheOperation.m in Sources */,
|
||||
43DA7DA91D1086610028BE58 /* cost_mips_dsp_r2.c in Sources */,
|
||||
43DA7DB01D1086610028BE58 /* dec_mips32.c in Sources */,
|
||||
|
@ -2407,6 +2433,7 @@
|
|||
43DA7CFF1D10865F0028BE58 /* alpha_processing_sse41.c in Sources */,
|
||||
43DA7D2D1D10865F0028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
|
||||
4A2CAE261AB4BB7000B6BC39 /* SDWebImagePrefetcher.m in Sources */,
|
||||
43A9186D1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
43DA7D061D10865F0028BE58 /* cost_sse2.c in Sources */,
|
||||
4317391F1CDFC8B20008FEB9 /* color_cache.c in Sources */,
|
||||
4A2CAE301AB4BB7500B6BC39 /* UIImage+MultiFormat.m in Sources */,
|
||||
|
@ -2507,6 +2534,7 @@
|
|||
43DA7C911D1086570028BE58 /* alpha_processing_sse41.c in Sources */,
|
||||
43DA7CBF1D1086570028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
|
||||
5376130D155AD0D5005750A4 /* SDWebImagePrefetcher.m in Sources */,
|
||||
43A9186B1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
|
||||
43DA7C981D1086570028BE58 /* cost_sse2.c in Sources */,
|
||||
431738A81CDFC2630008FEB9 /* color_cache.c in Sources */,
|
||||
5376130E155AD0D5005750A4 /* UIButton+WebCache.m in Sources */,
|
||||
|
@ -2847,7 +2875,6 @@
|
|||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"SD_WEBP=1",
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
|
@ -2901,10 +2928,7 @@
|
|||
);
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"SD_WEBP=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
0D87E1F83BD319CEC7622E9F /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0462A7F023A057322E59B3C5 /* libPods-Tests.a */; };
|
||||
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */; };
|
||||
433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */; };
|
||||
433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBB61D7EF8200086B6E9 /* TestImage.gif */; };
|
||||
433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBB81D7EF8260086B6E9 /* TestImage.png */; };
|
||||
433BBBBB1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */; };
|
||||
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; };
|
||||
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; };
|
||||
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; };
|
||||
|
@ -22,6 +26,10 @@
|
|||
/* Begin PBXFileReference section */
|
||||
0462A7F023A057322E59B3C5 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderTests.m; sourceTree = "<group>"; };
|
||||
433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDecoderTests.m; sourceTree = "<group>"; };
|
||||
433BBBB61D7EF8200086B6E9 /* TestImage.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = TestImage.gif; sourceTree = "<group>"; };
|
||||
433BBBB81D7EF8260086B6E9 /* TestImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TestImage.png; sourceTree = "<group>"; };
|
||||
433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = MonochromeTestImage.jpg; sourceTree = "<group>"; };
|
||||
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; };
|
||||
700B00151041D7EE118B1ABD /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
A0085854E7D88C98F2F6C9FC /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
|
@ -93,12 +101,16 @@
|
|||
DA248D5C195472AA00390AB0 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */,
|
||||
433BBBB61D7EF8200086B6E9 /* TestImage.gif */,
|
||||
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */,
|
||||
433BBBB81D7EF8260086B6E9 /* TestImage.png */,
|
||||
DA248D5D195472AA00390AB0 /* Supporting Files */,
|
||||
DA248D68195475D800390AB0 /* SDImageCacheTests.m */,
|
||||
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */,
|
||||
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
|
||||
1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */,
|
||||
433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
|
@ -167,7 +179,10 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */,
|
||||
433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */,
|
||||
DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */,
|
||||
433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */,
|
||||
433BBBBB1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -229,6 +244,7 @@
|
|||
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */,
|
||||
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
|
||||
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
|
||||
433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */,
|
||||
DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
codeCoverageEnabled = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
|
@ -22,172 +22,179 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
|
|||
|
||||
@implementation SDImageCacheTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
self.sharedImageCache = [SDImageCache sharedImageCache];
|
||||
[self clearAllCaches];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testSharedImageCache {
|
||||
- (void)test01SharedImageCache {
|
||||
expect(self.sharedImageCache).toNot.beNil();
|
||||
}
|
||||
|
||||
- (void)testSingleton{
|
||||
- (void)test02Singleton{
|
||||
expect(self.sharedImageCache).to.equal([SDImageCache sharedImageCache]);
|
||||
}
|
||||
|
||||
- (void)testClearDiskCache{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
[self.sharedImageCache clearDiskOnCompletion:^{
|
||||
expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(NO);
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
|
||||
}];
|
||||
- (void)test03ImageCacheCanBeInstantiated {
|
||||
SDImageCache *imageCache = [[SDImageCache alloc] init];
|
||||
expect(imageCache).toNot.equal([SDImageCache sharedImageCache]);
|
||||
}
|
||||
|
||||
- (void)testClearMemoryCache{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test04ClearDiskCache{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Clear disk cache"];
|
||||
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
[self.sharedImageCache clearDiskOnCompletion:^{
|
||||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
if (!isInCache) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Image should not be in cache");
|
||||
}
|
||||
}];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test05ClearMemoryCache{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Clear memory cache"];
|
||||
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
[self.sharedImageCache clearMemory];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
// Seems not able to access the files correctly (maybe only from test?)
|
||||
//expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);
|
||||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
expect(isInCache).to.equal(YES);
|
||||
if (isInCache) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Image should be in cache");
|
||||
}
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
// Testing storeImage:forKey:
|
||||
- (void)testInsertionOfImage {
|
||||
- (void)test06InsertionOfImage {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey"];
|
||||
|
||||
UIImage *image = [self imageForTesting];
|
||||
[self.sharedImageCache storeImage:image forKey:kImageTestKey];
|
||||
[self.sharedImageCache storeImage:image forKey:kImageTestKey completion:nil];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.equal(image);
|
||||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
if (isInCache) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Image should be in cache");
|
||||
}
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
// Testing storeImage:forKey:toDisk:YES
|
||||
- (void)testInsertionOfImageForcingDiskStorage{
|
||||
- (void)test07InsertionOfImageForcingDiskStorage{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey toDisk=YES"];
|
||||
|
||||
UIImage *image = [self imageForTesting];
|
||||
[self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:YES];
|
||||
[self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:YES completion:nil];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
|
||||
// Seems not able to access the files correctly (maybe only from test?)
|
||||
//expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);
|
||||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
expect(isInCache).to.equal(YES);
|
||||
if (isInCache) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Image should be in cache");
|
||||
}
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
// Testing storeImage:forKey:toDisk:NO
|
||||
- (void)testInsertionOfImageOnlyInMemory {
|
||||
- (void)test08InsertionOfImageOnlyInMemory {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey toDisk=NO"];
|
||||
UIImage *image = [self imageForTesting];
|
||||
[self.sharedImageCache storeImage:image forKey:@"TestImage" toDisk:NO];
|
||||
[self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {
|
||||
expect(isInCache).to.equal(YES);
|
||||
[self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:NO completion:nil];
|
||||
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
|
||||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
if (!isInCache) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Image should not be in cache");
|
||||
}
|
||||
}];
|
||||
[self.sharedImageCache clearMemory];
|
||||
[self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {
|
||||
expect(isInCache).to.equal(NO);
|
||||
}];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil();
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)testRetrievalImageThroughNSOperation{
|
||||
//- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
||||
- (void)test09RetrieveImageThroughNSOperation{
|
||||
//- (NSOperation *)queryCacheOperationForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
||||
UIImage *imageForTesting = [self imageForTesting];
|
||||
[self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey];
|
||||
NSOperation *operation = [self.sharedImageCache queryDiskCacheForKey:kImageTestKey done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
|
||||
[self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey completion:nil];
|
||||
NSOperation *operation = [self.sharedImageCache queryCacheOperationForKey:kImageTestKey done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
|
||||
expect(image).to.equal(imageForTesting);
|
||||
}];
|
||||
expect(operation).toNot.beNil;
|
||||
}
|
||||
|
||||
- (void)testRemoveImageForKey{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey];
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||
}
|
||||
|
||||
- (void)testRemoveImageForKeyWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test10RemoveImageForKeyWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey withCompletion:^{
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRemoveImageForKeyNotFromDisk{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
}
|
||||
|
||||
- (void)testRemoveImageForKeyFromDisk{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
}
|
||||
|
||||
- (void)testRemoveImageforKeyNotFromDiskWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test11RemoveImageforKeyNotFromDiskWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO withCompletion:^{
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRemoveImageforKeyFromDiskWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test12RemoveImageforKeyFromDiskWithCompletion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
[self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:YES withCompletion:^{
|
||||
expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
|
||||
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
|
||||
}];
|
||||
}
|
||||
|
||||
// TODO -- Testing insertion with recalculate
|
||||
- (void)testInsertionOfImageOnlyInDisk {
|
||||
}
|
||||
|
||||
- (void)testInitialCacheSize{
|
||||
- (void)test20InitialCacheSize{
|
||||
expect([self.sharedImageCache getSize]).to.equal(0);
|
||||
}
|
||||
|
||||
- (void)testInitialDiskCount{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test21InitialDiskCount{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
expect([self.sharedImageCache getDiskCount]).to.equal(1);
|
||||
}
|
||||
|
||||
- (void)testDiskCountAfterInsertion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test22DiskCountAfterInsertion{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
expect([self.sharedImageCache getDiskCount]).to.equal(1);
|
||||
}
|
||||
|
||||
- (void)testDefaultCachePathForAnyKey{
|
||||
- (void)test31DefaultCachePathForAnyKey{
|
||||
NSString *path = [self.sharedImageCache defaultCachePathForKey:kImageTestKey];
|
||||
expect(path).toNot.beNil;
|
||||
}
|
||||
|
||||
- (void)testCachePathForNonExistingKey{
|
||||
- (void)test32CachePathForNonExistingKey{
|
||||
NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
|
||||
expect(path).to.beNil;
|
||||
}
|
||||
|
||||
- (void)testCachePathForExistingKey{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];
|
||||
- (void)test33CachePathForExistingKey{
|
||||
[self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
|
||||
NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
|
||||
expect(path).notTo.beNil;
|
||||
}
|
||||
|
||||
// TODO -- Testing image data insertion
|
||||
|
||||
- (void)testInsertionOfImageData {
|
||||
- (void)test40InsertionOfImageData {
|
||||
|
||||
NSData *imageData = [NSData dataWithContentsOfFile:[self testImagePath]];
|
||||
[self.sharedImageCache storeImageDataToDisk:imageData forKey:kImageTestKey];
|
||||
|
@ -202,18 +209,28 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
|
|||
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
|
||||
expect(isInCache).to.equal(YES);
|
||||
}];
|
||||
|
||||
[self.sharedImageCache calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
|
||||
expect(fileCount).to.beLessThan(100);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark Helper methods
|
||||
|
||||
- (void)clearAllCaches{
|
||||
[self.sharedImageCache clearDisk];
|
||||
[self.sharedImageCache deleteOldFilesWithCompletionBlock:nil];
|
||||
|
||||
// TODO: this is not ok, clearDiskOnCompletion will clear async, this means that when we execute the tests, the cache might not be cleared
|
||||
[self.sharedImageCache clearDiskOnCompletion:nil];
|
||||
[self.sharedImageCache clearMemory];
|
||||
}
|
||||
|
||||
- (UIImage *)imageForTesting{
|
||||
|
||||
return [UIImage imageWithContentsOfFile:[self testImagePath]];
|
||||
static UIImage *reusableImage = nil;
|
||||
if (!reusableImage) {
|
||||
reusableImage = [UIImage imageWithContentsOfFile:[self testImagePath]];
|
||||
}
|
||||
return reusableImage;
|
||||
}
|
||||
|
||||
- (NSString *)testImagePath {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define EXP_SHORTHAND // required by Expecta
|
||||
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import <Expecta.h>
|
||||
|
||||
#import "SDWebImageDecoder.h"
|
||||
|
||||
@interface SDWebImageDecoderTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDWebImageDecoderTests
|
||||
|
||||
- (void)test01ThatDecodedImageWithNilImageReturnsNil {
|
||||
expect([UIImage decodedImageWithImage:nil]).to.beNil();
|
||||
}
|
||||
|
||||
- (void)test02ThatDecodedImageWithImageWorksWithARegularJPGImage {
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
|
||||
UIImage *decodedImage = [UIImage decodedImageWithImage:image];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).toNot.equal(image);
|
||||
}
|
||||
|
||||
- (void)test03ThatDecodedImageWithImageDoesNotDecodeAnimatedImages {
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"gif"];
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
|
||||
UIImage *animatedImage = [UIImage animatedImageWithImages:@[image] duration:0];
|
||||
UIImage *decodedImage = [UIImage decodedImageWithImage:animatedImage];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).to.equal(animatedImage);
|
||||
}
|
||||
|
||||
- (void)test04ThatDecodedImageWithImageDoesNotDecodeImagesWithAlpha {
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
|
||||
UIImage *decodedImage = [UIImage decodedImageWithImage:image];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).to.equal(image);
|
||||
}
|
||||
|
||||
- (void)test05ThatDecodedImageWithImageWorksEvenWithMonochromeImage {
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"MonochromeTestImage" ofType:@"jpg"];
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
|
||||
UIImage *decodedImage = [UIImage decodedImageWithImage:image];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).toNot.equal(image);
|
||||
}
|
||||
|
||||
@end
|
|
@ -14,6 +14,46 @@
|
|||
#import <Expecta.h>
|
||||
|
||||
#import "SDWebImageDownloader.h"
|
||||
#import "SDWebImageDownloaderOperation.h"
|
||||
|
||||
/**
|
||||
* Category for SDWebImageDownloader so we can access the operationClass
|
||||
*/
|
||||
@interface SDWebImageDownloader ()
|
||||
@property (assign, nonatomic, nullable) Class operationClass;
|
||||
@property (strong, nonatomic, nonnull) NSOperationQueue *downloadQueue;
|
||||
|
||||
- (nullable SDWebImageDownloadToken *)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||
forURL:(nullable NSURL *)url
|
||||
createCallback:(SDWebImageDownloaderOperation *(^)())createCallback;
|
||||
@end
|
||||
|
||||
/**
|
||||
* A class that fits the NSOperation+SDWebImageDownloaderOperationInterface requirement so we can test
|
||||
*/
|
||||
@interface CustomDownloaderOperation : NSOperation<SDWebImageDownloaderOperationInterface>
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldDecompressImages;
|
||||
@property (nonatomic, strong, nullable) NSURLCredential *credential;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CustomDownloaderOperation
|
||||
|
||||
- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)req inSession:(nullable NSURLSession *)ses options:(SDWebImageDownloaderOptions)opt {
|
||||
if ((self = [super init])) { }
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface SDWebImageDownloaderTests : XCTestCase
|
||||
|
||||
|
@ -21,68 +61,288 @@
|
|||
|
||||
@implementation SDWebImageDownloaderTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
- (void)test01ThatSharedDownloaderIsNotEqualToInitDownloader {
|
||||
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] init];
|
||||
expect(downloader).toNot.equal([SDWebImageDownloader sharedDownloader]);
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
- (void)test02ThatByDefaultDownloaderSetsTheAcceptHTTPHeader {
|
||||
expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:@"Accept"]).to.match(@"image/\\*");
|
||||
}
|
||||
|
||||
- (void)testThatDownloadingSameURLTwiceAndCancellingFirstWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"];
|
||||
|
||||
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
XCTFail(@"Shouldn't have completed here.");
|
||||
}];
|
||||
expect(token1).toNot.beNil();
|
||||
|
||||
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
[expectation fulfill];
|
||||
}];
|
||||
expect(token2).toNot.beNil();
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] cancel:token1];
|
||||
|
||||
[self waitForExpectationsWithTimeout:5. handler:nil];
|
||||
- (void)test03ThatSetAndGetValueForHTTPHeaderFieldWork {
|
||||
NSString *headerValue = @"Tests";
|
||||
NSString *headerName = @"AppName";
|
||||
// set it
|
||||
[[SDWebImageDownloader sharedDownloader] setValue:headerValue forHTTPHeaderField:headerName];
|
||||
expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:headerName]).to.equal(headerValue);
|
||||
// clear it
|
||||
[[SDWebImageDownloader sharedDownloader] setValue:nil forHTTPHeaderField:headerName];
|
||||
expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:headerName]).to.beNil();
|
||||
}
|
||||
|
||||
- (void)testThatCancelingDownloadThenRequestingAgainWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
- (void)test04ThatASimpleDownloadWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage004.jpg"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test05ThatSetAndGetMaxConcurrentDownloadsWorks {
|
||||
NSInteger initialValue = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] setMaxConcurrentDownloads:3];
|
||||
expect([SDWebImageDownloader sharedDownloader].maxConcurrentDownloads).to.equal(3);
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] setMaxConcurrentDownloads:initialValue];
|
||||
}
|
||||
|
||||
- (void)test06ThatUsingACustomDownloaderOperationWorks {
|
||||
// we try to set a usual NSOperation as operation class. Should not work
|
||||
[[SDWebImageDownloader sharedDownloader] setOperationClass:[NSOperation class]];
|
||||
expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([SDWebImageDownloaderOperation class]);
|
||||
|
||||
// setting an NSOperation subclass that conforms to SDWebImageDownloaderOperationInterface - should work
|
||||
[[SDWebImageDownloader sharedDownloader] setOperationClass:[CustomDownloaderOperation class]];
|
||||
expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([CustomDownloaderOperation class]);
|
||||
|
||||
// back to the original value
|
||||
[[SDWebImageDownloader sharedDownloader] setOperationClass:nil];
|
||||
expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([SDWebImageDownloaderOperation class]);
|
||||
}
|
||||
|
||||
- (void)test07ThatAddProgressCallbackCompletedBlockWithNilURLCallsTheCompletionBlockWithNils {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Completion is called with nils"];
|
||||
[[SDWebImageDownloader sharedDownloader] addProgressCallback:nil completedBlock:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (!image && !data && !error) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"All params should be nil");
|
||||
}
|
||||
} forURL:nil createCallback:nil];
|
||||
[self waitForExpectationsWithTimeout:0.5 handler:nil];
|
||||
}
|
||||
|
||||
- (void)test08ThatAHTTPAuthDownloadWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"HTTP Auth download"];
|
||||
[SDWebImageDownloader sharedDownloader].username = @"httpwatch";
|
||||
[SDWebImageDownloader sharedDownloader].password = @"httpwatch01";
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
[SDWebImageDownloader sharedDownloader].username = nil;
|
||||
[SDWebImageDownloader sharedDownloader].password = nil;
|
||||
}
|
||||
|
||||
- (void)test09ThatProgressiveJPEGWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive JPEG download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage009.jpg"];
|
||||
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveDownload 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
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test10That404CaseCallsCompletionWithError {
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"];
|
||||
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"404"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
XCTFail(@"Shouldn't have completed here.");
|
||||
}];
|
||||
- (void)test11ThatCancelWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage011.jpg"];
|
||||
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");
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] cancel:token];
|
||||
|
||||
// doesn't cancel immediately - since it uses dispatch async
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(0);
|
||||
[expectation fulfill];
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test12ThatWeCanUseAnotherSessionForEachDownloadOperation {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Owned session"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage012.jpg"];
|
||||
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
|
||||
request.HTTPShouldUsePipelining = YES;
|
||||
request.allHTTPHeaderFields = @{@"Accept": @"image/*;q=0.8"};
|
||||
|
||||
SDWebImageDownloaderOperation *operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
||||
inSession:nil
|
||||
options:0];
|
||||
[operation addHandlersForProgress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||
|
||||
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
|
||||
[operation start];
|
||||
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test13ThatDownloadCanContinueWhenTheAppEntersBackground {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage013.jpg"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test14ThatPNGWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"WEBP"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test15ThatWEBPWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"WEBP"];
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"];
|
||||
[[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];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* In 4.0, via #883 added `SDWebImageDownloadToken` so we can cancel exactly the request we want
|
||||
* This test validates the scenario of making 2 requests for the same image and cancelling the 1st one
|
||||
*/
|
||||
- (void)test20ThatDownloadingSameURLTwiceAndCancellingFirstWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage020.jpg"];
|
||||
|
||||
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
XCTFail(@"Shouldn't have completed here.");
|
||||
}];
|
||||
expect(token1).toNot.beNil();
|
||||
|
||||
SDWebImageDownloadToken *token2 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect(token2).toNot.beNil();
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] cancel:token1];
|
||||
|
||||
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
[expectation fulfill];
|
||||
}];
|
||||
expect(token2).toNot.beNil();
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
[self waitForExpectationsWithTimeout:5. handler:nil];
|
||||
/**
|
||||
* 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
|
||||
* In 4.0, via #883 added `SDWebImageDownloadToken` so we can cancel exactly the request we want
|
||||
* This test validates the scenario of requesting an image, cancel and then requesting it again
|
||||
*/
|
||||
- (void)test21ThatCancelingDownloadThenRequestingAgainWorks {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||
|
||||
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage021.jpg"];
|
||||
|
||||
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
XCTFail(@"Shouldn't have completed here.");
|
||||
}];
|
||||
expect(token1).toNot.beNil();
|
||||
|
||||
[[SDWebImageDownloader sharedDownloader] cancel:token1];
|
||||
|
||||
SDWebImageDownloadToken *token2 = [[SDWebImageDownloader sharedDownloader]
|
||||
downloadImageWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
if (image && data && !error && finished) {
|
||||
[expectation fulfill];
|
||||
} else {
|
||||
NSLog(@"image = %@, data = %@, error = %@", image, data, error);
|
||||
XCTFail(@"Something went wrong");
|
||||
}
|
||||
}];
|
||||
expect(token2).toNot.beNil();
|
||||
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#import "SDWebImageManager.h"
|
||||
|
||||
static int64_t kAsyncTestTimeout = 5;
|
||||
|
||||
|
||||
@interface SDWebImageManagerTests : XCTestCase
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
Loading…
Reference in New Issue