Authored by Bogdan Poplauschi

Added SDImageCacheConfig to all targets, test images, code coverage setting, tes…

…ts for SDImageCache, SDWebImageDownloader, SDWebImageDownloaderOperation, SDWebImageDecoder
@@ -435,6 +435,18 @@ @@ -435,6 +435,18 @@
435 43A62A641D0E0A8F0089D7DD /* vp8li.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D681998E6B2007367ED /* vp8li.h */; }; 435 43A62A641D0E0A8F0089D7DD /* vp8li.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D681998E6B2007367ED /* vp8li.h */; };
436 43A62A651D0E0A8F0089D7DD /* webp.c in Sources */ = {isa = PBXBuildFile; fileRef = DA577D691998E6B2007367ED /* webp.c */; }; 436 43A62A651D0E0A8F0089D7DD /* webp.c in Sources */ = {isa = PBXBuildFile; fileRef = DA577D691998E6B2007367ED /* webp.c */; };
437 43A62A661D0E0A8F0089D7DD /* webpi.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D6A1998E6B2007367ED /* webpi.h */; }; 437 43A62A661D0E0A8F0089D7DD /* webpi.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577D6A1998E6B2007367ED /* webpi.h */; };
  438 + 43A918641D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  439 + 43A918651D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  440 + 43A918661D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  441 + 43A918671D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  442 + 43A918681D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  443 + 43A918691D8308FE00B3925F /* SDImageCacheConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */; };
  444 + 43A9186B1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
  445 + 43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
  446 + 43A9186D1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
  447 + 43A9186E1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
  448 + 43A9186F1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
  449 + 43A918701D8308FE00B3925F /* SDImageCacheConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */; };
438 43CE75761CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; }; 450 43CE75761CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
439 43CE75771CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; }; 451 43CE75771CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
440 43CE75781CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; }; 452 43CE75781CFE9427006C64D0 /* FLAnimatedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -882,6 +894,8 @@ @@ -882,6 +894,8 @@
882 4397D2F21D0DDD8C00BB2784 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 894 4397D2F21D0DDD8C00BB2784 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
883 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+WebCache.h"; sourceTree = "<group>"; }; 895 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+WebCache.h"; sourceTree = "<group>"; };
884 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+WebCache.m"; sourceTree = "<group>"; }; 896 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+WebCache.m"; sourceTree = "<group>"; };
  897 + 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCacheConfig.h; sourceTree = "<group>"; };
  898 + 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheConfig.m; sourceTree = "<group>"; };
885 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImage.h; sourceTree = "<group>"; }; 899 43CE75491CFE9427006C64D0 /* FLAnimatedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImage.h; sourceTree = "<group>"; };
886 43CE754A1CFE9427006C64D0 /* FLAnimatedImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLAnimatedImage.m; sourceTree = "<group>"; }; 900 43CE754A1CFE9427006C64D0 /* FLAnimatedImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLAnimatedImage.m; sourceTree = "<group>"; };
887 43CE754B1CFE9427006C64D0 /* FLAnimatedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImageView.h; sourceTree = "<group>"; }; 901 43CE754B1CFE9427006C64D0 /* FLAnimatedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLAnimatedImageView.h; sourceTree = "<group>"; };
@@ -1218,6 +1232,8 @@ @@ -1218,6 +1232,8 @@
1218 children = ( 1232 children = (
1219 53922D85148C56230056699D /* SDImageCache.h */, 1233 53922D85148C56230056699D /* SDImageCache.h */,
1220 53922D86148C56230056699D /* SDImageCache.m */, 1234 53922D86148C56230056699D /* SDImageCache.m */,
  1235 + 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */,
  1236 + 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */,
1221 ); 1237 );
1222 name = Cache; 1238 name = Cache;
1223 sourceTree = "<group>"; 1239 sourceTree = "<group>";
@@ -1417,6 +1433,7 @@ @@ -1417,6 +1433,7 @@
1417 431739361CDFC8B20008FEB9 /* bit_reader_inl.h in Headers */, 1433 431739361CDFC8B20008FEB9 /* bit_reader_inl.h in Headers */,
1418 4317393A1CDFC8B20008FEB9 /* color_cache.h in Headers */, 1434 4317393A1CDFC8B20008FEB9 /* color_cache.h in Headers */,
1419 431738E11CDFC8A40008FEB9 /* webpi.h in Headers */, 1435 431738E11CDFC8A40008FEB9 /* webpi.h in Headers */,
  1436 + 43A918671D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1420 431739571CDFC8B70008FEB9 /* encode.h in Headers */, 1437 431739571CDFC8B70008FEB9 /* encode.h in Headers */,
1421 431739351CDFC8B20008FEB9 /* bit_reader.h in Headers */, 1438 431739351CDFC8B20008FEB9 /* bit_reader.h in Headers */,
1422 43DA7D5D1D1086600028BE58 /* mips_macro.h in Headers */, 1439 43DA7D5D1D1086600028BE58 /* mips_macro.h in Headers */,
@@ -1488,6 +1505,7 @@ @@ -1488,6 +1505,7 @@
1488 43DA7CFE1D10865E0028BE58 /* yuv.h in Headers */, 1505 43DA7CFE1D10865E0028BE58 /* yuv.h in Headers */,
1489 4314D1711D0E0E3B004B36C9 /* huffman.h in Headers */, 1506 4314D1711D0E0E3B004B36C9 /* huffman.h in Headers */,
1490 4314D1721D0E0E3B004B36C9 /* SDWebImageCompat.h in Headers */, 1507 4314D1721D0E0E3B004B36C9 /* SDWebImageCompat.h in Headers */,
  1508 + 43A918651D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1491 4314D1731D0E0E3B004B36C9 /* vp8li.h in Headers */, 1509 4314D1731D0E0E3B004B36C9 /* vp8li.h in Headers */,
1492 4314D1741D0E0E3B004B36C9 /* types.h in Headers */, 1510 4314D1741D0E0E3B004B36C9 /* types.h in Headers */,
1493 4314D1761D0E0E3B004B36C9 /* decode.h in Headers */, 1511 4314D1761D0E0E3B004B36C9 /* decode.h in Headers */,
@@ -1575,6 +1593,7 @@ @@ -1575,6 +1593,7 @@
1575 431BB6F91D06D2C1006A3455 /* UIImage+GIF.h in Headers */, 1593 431BB6F91D06D2C1006A3455 /* UIImage+GIF.h in Headers */,
1576 431BB6FA1D06D2C1006A3455 /* SDWebImageDownloader.h in Headers */, 1594 431BB6FA1D06D2C1006A3455 /* SDWebImageDownloader.h in Headers */,
1577 431BB6FC1D06D2C1006A3455 /* SDWebImageDecoder.h in Headers */, 1595 431BB6FC1D06D2C1006A3455 /* SDWebImageDecoder.h in Headers */,
  1596 + 43A918681D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1578 ); 1597 );
1579 runOnlyForDeploymentPostprocessing = 0; 1598 runOnlyForDeploymentPostprocessing = 0;
1580 }; 1599 };
@@ -1606,6 +1625,7 @@ @@ -1606,6 +1625,7 @@
1606 4397D2D11D0DDD8C00BB2784 /* decode.h in Headers */, 1625 4397D2D11D0DDD8C00BB2784 /* decode.h in Headers */,
1607 4397D2D21D0DDD8C00BB2784 /* webpi.h in Headers */, 1626 4397D2D21D0DDD8C00BB2784 /* webpi.h in Headers */,
1608 43DA7DCB1D1086610028BE58 /* mips_macro.h in Headers */, 1627 43DA7DCB1D1086610028BE58 /* mips_macro.h in Headers */,
  1628 + 43A918691D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1609 4397D2D31D0DDD8C00BB2784 /* thread.h in Headers */, 1629 4397D2D31D0DDD8C00BB2784 /* thread.h in Headers */,
1610 4397D2D41D0DDD8C00BB2784 /* quant_levels.h in Headers */, 1630 4397D2D41D0DDD8C00BB2784 /* quant_levels.h in Headers */,
1611 4397D2D51D0DDD8C00BB2784 /* bit_reader_inl.h in Headers */, 1631 4397D2D51D0DDD8C00BB2784 /* bit_reader_inl.h in Headers */,
@@ -1650,6 +1670,7 @@ @@ -1650,6 +1670,7 @@
1650 4A2CAE041AB4BB5400B6BC39 /* SDWebImage.h in Headers */, 1670 4A2CAE041AB4BB5400B6BC39 /* SDWebImage.h in Headers */,
1651 431739511CDFC8B70008FEB9 /* format_constants.h in Headers */, 1671 431739511CDFC8B70008FEB9 /* format_constants.h in Headers */,
1652 431739231CDFC8B20008FEB9 /* filters.h in Headers */, 1672 431739231CDFC8B20008FEB9 /* filters.h in Headers */,
  1673 + 43A918661D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1653 4A2CAE211AB4BB7000B6BC39 /* SDWebImageManager.h in Headers */, 1674 4A2CAE211AB4BB7000B6BC39 /* SDWebImageManager.h in Headers */,
1654 4A2CAE1F1AB4BB6C00B6BC39 /* SDImageCache.h in Headers */, 1675 4A2CAE1F1AB4BB6C00B6BC39 /* SDImageCache.h in Headers */,
1655 43DA7D261D10865F0028BE58 /* mips_macro.h in Headers */, 1676 43DA7D261D10865F0028BE58 /* mips_macro.h in Headers */,
@@ -1755,6 +1776,7 @@ @@ -1755,6 +1776,7 @@
1755 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */, 1776 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
1756 4317387B1CDFC2580008FEB9 /* decode_vp8.h in Headers */, 1777 4317387B1CDFC2580008FEB9 /* decode_vp8.h in Headers */,
1757 431738B61CDFC2630008FEB9 /* random.h in Headers */, 1778 431738B61CDFC2630008FEB9 /* random.h in Headers */,
  1779 + 43A918641D8308FE00B3925F /* SDImageCacheConfig.h in Headers */,
1758 ); 1780 );
1759 runOnlyForDeploymentPostprocessing = 0; 1781 runOnlyForDeploymentPostprocessing = 0;
1760 }; 1782 };
@@ -2017,6 +2039,7 @@ @@ -2017,6 +2039,7 @@
2017 43DA7D361D1086600028BE58 /* alpha_processing_sse41.c in Sources */, 2039 43DA7D361D1086600028BE58 /* alpha_processing_sse41.c in Sources */,
2018 43DA7D641D1086600028BE58 /* upsampling_mips_dsp_r2.c in Sources */, 2040 43DA7D641D1086600028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
2019 431739461CDFC8B20008FEB9 /* random.c in Sources */, 2041 431739461CDFC8B20008FEB9 /* random.c in Sources */,
  2042 + 43A9186E1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2020 43DA7D3D1D1086600028BE58 /* cost_sse2.c in Sources */, 2043 43DA7D3D1D1086600028BE58 /* cost_sse2.c in Sources */,
2021 431738DB1CDFC8A40008FEB9 /* tree.c in Sources */, 2044 431738DB1CDFC8A40008FEB9 /* tree.c in Sources */,
2022 00733A581BC4880000A5A117 /* SDWebImageManager.m in Sources */, 2045 00733A581BC4880000A5A117 /* SDWebImageManager.m in Sources */,
@@ -2119,6 +2142,7 @@ @@ -2119,6 +2142,7 @@
2119 43DA7CFD1D10865E0028BE58 /* yuv.c in Sources */, 2142 43DA7CFD1D10865E0028BE58 /* yuv.c in Sources */,
2120 4314D1401D0E0E3B004B36C9 /* UIImageView+WebCache.m in Sources */, 2143 4314D1401D0E0E3B004B36C9 /* UIImageView+WebCache.m in Sources */,
2121 43DA7CDC1D10865E0028BE58 /* enc_mips32.c in Sources */, 2144 43DA7CDC1D10865E0028BE58 /* enc_mips32.c in Sources */,
  2145 + 43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2122 4314D1411D0E0E3B004B36C9 /* SDWebImageDownloaderOperation.m in Sources */, 2146 4314D1411D0E0E3B004B36C9 /* SDWebImageDownloaderOperation.m in Sources */,
2123 43DA7CCE1D10865E0028BE58 /* cost_mips32.c in Sources */, 2147 43DA7CCE1D10865E0028BE58 /* cost_mips32.c in Sources */,
2124 4314D1421D0E0E3B004B36C9 /* webp.c in Sources */, 2148 4314D1421D0E0E3B004B36C9 /* webp.c in Sources */,
@@ -2215,6 +2239,7 @@ @@ -2215,6 +2239,7 @@
2215 43DA7DA21D1086600028BE58 /* yuv.c in Sources */, 2239 43DA7DA21D1086600028BE58 /* yuv.c in Sources */,
2216 431BB6B91D06D2C1006A3455 /* UIButton+WebCache.m in Sources */, 2240 431BB6B91D06D2C1006A3455 /* UIButton+WebCache.m in Sources */,
2217 43DA7D811D1086600028BE58 /* enc_mips32.c in Sources */, 2241 43DA7D811D1086600028BE58 /* enc_mips32.c in Sources */,
  2242 + 43A9186F1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2218 43A62A5F1D0E0A8F0089D7DD /* quant.c in Sources */, 2243 43A62A5F1D0E0A8F0089D7DD /* quant.c in Sources */,
2219 43DA7D731D1086600028BE58 /* cost_mips32.c in Sources */, 2244 43DA7D731D1086600028BE58 /* cost_mips32.c in Sources */,
2220 431BB6BD1D06D2C1006A3455 /* UIImage+GIF.m in Sources */, 2245 431BB6BD1D06D2C1006A3455 /* UIImage+GIF.m in Sources */,
@@ -2335,6 +2360,7 @@ @@ -2335,6 +2360,7 @@
2335 4397D2AA1D0DDD8C00BB2784 /* io.c in Sources */, 2360 4397D2AA1D0DDD8C00BB2784 /* io.c in Sources */,
2336 43DA7DCF1D1086610028BE58 /* rescaler_neon.c in Sources */, 2361 43DA7DCF1D1086610028BE58 /* rescaler_neon.c in Sources */,
2337 43DA7DC31D1086610028BE58 /* lossless_enc_sse2.c in Sources */, 2362 43DA7DC31D1086610028BE58 /* lossless_enc_sse2.c in Sources */,
  2363 + 43A918701D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2338 4397D2AB1D0DDD8C00BB2784 /* UIView+WebCacheOperation.m in Sources */, 2364 4397D2AB1D0DDD8C00BB2784 /* UIView+WebCacheOperation.m in Sources */,
2339 43DA7DA91D1086610028BE58 /* cost_mips_dsp_r2.c in Sources */, 2365 43DA7DA91D1086610028BE58 /* cost_mips_dsp_r2.c in Sources */,
2340 43DA7DB01D1086610028BE58 /* dec_mips32.c in Sources */, 2366 43DA7DB01D1086610028BE58 /* dec_mips32.c in Sources */,
@@ -2407,6 +2433,7 @@ @@ -2407,6 +2433,7 @@
2407 43DA7CFF1D10865F0028BE58 /* alpha_processing_sse41.c in Sources */, 2433 43DA7CFF1D10865F0028BE58 /* alpha_processing_sse41.c in Sources */,
2408 43DA7D2D1D10865F0028BE58 /* upsampling_mips_dsp_r2.c in Sources */, 2434 43DA7D2D1D10865F0028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
2409 4A2CAE261AB4BB7000B6BC39 /* SDWebImagePrefetcher.m in Sources */, 2435 4A2CAE261AB4BB7000B6BC39 /* SDWebImagePrefetcher.m in Sources */,
  2436 + 43A9186D1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2410 43DA7D061D10865F0028BE58 /* cost_sse2.c in Sources */, 2437 43DA7D061D10865F0028BE58 /* cost_sse2.c in Sources */,
2411 4317391F1CDFC8B20008FEB9 /* color_cache.c in Sources */, 2438 4317391F1CDFC8B20008FEB9 /* color_cache.c in Sources */,
2412 4A2CAE301AB4BB7500B6BC39 /* UIImage+MultiFormat.m in Sources */, 2439 4A2CAE301AB4BB7500B6BC39 /* UIImage+MultiFormat.m in Sources */,
@@ -2507,6 +2534,7 @@ @@ -2507,6 +2534,7 @@
2507 43DA7C911D1086570028BE58 /* alpha_processing_sse41.c in Sources */, 2534 43DA7C911D1086570028BE58 /* alpha_processing_sse41.c in Sources */,
2508 43DA7CBF1D1086570028BE58 /* upsampling_mips_dsp_r2.c in Sources */, 2535 43DA7CBF1D1086570028BE58 /* upsampling_mips_dsp_r2.c in Sources */,
2509 5376130D155AD0D5005750A4 /* SDWebImagePrefetcher.m in Sources */, 2536 5376130D155AD0D5005750A4 /* SDWebImagePrefetcher.m in Sources */,
  2537 + 43A9186B1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,
2510 43DA7C981D1086570028BE58 /* cost_sse2.c in Sources */, 2538 43DA7C981D1086570028BE58 /* cost_sse2.c in Sources */,
2511 431738A81CDFC2630008FEB9 /* color_cache.c in Sources */, 2539 431738A81CDFC2630008FEB9 /* color_cache.c in Sources */,
2512 5376130E155AD0D5005750A4 /* UIButton+WebCache.m in Sources */, 2540 5376130E155AD0D5005750A4 /* UIButton+WebCache.m in Sources */,
@@ -2847,7 +2875,6 @@ @@ -2847,7 +2875,6 @@
2847 GCC_NO_COMMON_BLOCKS = YES; 2875 GCC_NO_COMMON_BLOCKS = YES;
2848 GCC_OPTIMIZATION_LEVEL = 0; 2876 GCC_OPTIMIZATION_LEVEL = 0;
2849 GCC_PREPROCESSOR_DEFINITIONS = ( 2877 GCC_PREPROCESSOR_DEFINITIONS = (
2850 - "SD_WEBP=1",  
2851 "DEBUG=1", 2878 "DEBUG=1",
2852 "$(inherited)", 2879 "$(inherited)",
2853 ); 2880 );
@@ -2901,10 +2928,7 @@ @@ -2901,10 +2928,7 @@
2901 ); 2928 );
2902 GCC_C_LANGUAGE_STANDARD = gnu99; 2929 GCC_C_LANGUAGE_STANDARD = gnu99;
2903 GCC_NO_COMMON_BLOCKS = YES; 2930 GCC_NO_COMMON_BLOCKS = YES;
2904 - GCC_PREPROCESSOR_DEFINITIONS = (  
2905 - "SD_WEBP=1",  
2906 - "$(inherited)",  
2907 - ); 2931 + GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
2908 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 2932 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
2909 GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 2933 GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
2910 GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 2934 GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
@@ -9,6 +9,10 @@ @@ -9,6 +9,10 @@
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 0D87E1F83BD319CEC7622E9F /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0462A7F023A057322E59B3C5 /* libPods-Tests.a */; }; 10 0D87E1F83BD319CEC7622E9F /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0462A7F023A057322E59B3C5 /* libPods-Tests.a */; };
11 1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */; }; 11 1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */; };
  12 + 433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */; };
  13 + 433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBB61D7EF8200086B6E9 /* TestImage.gif */; };
  14 + 433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBB81D7EF8260086B6E9 /* TestImage.png */; };
  15 + 433BBBBB1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */; };
12 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; }; 16 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; };
13 DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; }; 17 DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; };
14 DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; }; 18 DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; };
@@ -22,6 +26,10 @@ @@ -22,6 +26,10 @@
22 /* Begin PBXFileReference section */ 26 /* Begin PBXFileReference section */
23 0462A7F023A057322E59B3C5 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 27 0462A7F023A057322E59B3C5 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
24 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderTests.m; sourceTree = "<group>"; }; 28 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderTests.m; sourceTree = "<group>"; };
  29 + 433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDecoderTests.m; sourceTree = "<group>"; };
  30 + 433BBBB61D7EF8200086B6E9 /* TestImage.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = TestImage.gif; sourceTree = "<group>"; };
  31 + 433BBBB81D7EF8260086B6E9 /* TestImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TestImage.png; sourceTree = "<group>"; };
  32 + 433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = MonochromeTestImage.jpg; sourceTree = "<group>"; };
25 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; }; 33 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; };
26 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>"; }; 34 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>"; };
27 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>"; }; 35 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 @@ @@ -93,12 +101,16 @@
93 DA248D5C195472AA00390AB0 /* Tests */ = { 101 DA248D5C195472AA00390AB0 /* Tests */ = {
94 isa = PBXGroup; 102 isa = PBXGroup;
95 children = ( 103 children = (
  104 + 433BBBBA1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg */,
  105 + 433BBBB61D7EF8200086B6E9 /* TestImage.gif */,
96 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */, 106 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */,
  107 + 433BBBB81D7EF8260086B6E9 /* TestImage.png */,
97 DA248D5D195472AA00390AB0 /* Supporting Files */, 108 DA248D5D195472AA00390AB0 /* Supporting Files */,
98 DA248D68195475D800390AB0 /* SDImageCacheTests.m */, 109 DA248D68195475D800390AB0 /* SDImageCacheTests.m */,
99 DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */, 110 DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */,
100 DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */, 111 DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
101 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */, 112 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */,
  113 + 433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */,
102 ); 114 );
103 path = Tests; 115 path = Tests;
104 sourceTree = "<group>"; 116 sourceTree = "<group>";
@@ -167,7 +179,10 @@ @@ -167,7 +179,10 @@
167 buildActionMask = 2147483647; 179 buildActionMask = 2147483647;
168 files = ( 180 files = (
169 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */, 181 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */,
  182 + 433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */,
170 DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */, 183 DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */,
  184 + 433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */,
  185 + 433BBBBB1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg in Resources */,
171 ); 186 );
172 runOnlyForDeploymentPostprocessing = 0; 187 runOnlyForDeploymentPostprocessing = 0;
173 }; 188 };
@@ -229,6 +244,7 @@ @@ -229,6 +244,7 @@
229 1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */, 244 1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */,
230 DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */, 245 DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
231 DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */, 246 DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
  247 + 433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */,
232 DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */, 248 DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */,
233 ); 249 );
234 runOnlyForDeploymentPostprocessing = 0; 250 runOnlyForDeploymentPostprocessing = 0;
@@ -10,7 +10,8 @@ @@ -10,7 +10,8 @@
10 buildConfiguration = "Debug" 10 buildConfiguration = "Debug"
11 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 11 selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 12 selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13 - shouldUseLaunchSchemeArgsEnv = "YES"> 13 + shouldUseLaunchSchemeArgsEnv = "YES"
  14 + codeCoverageEnabled = "YES">
14 <Testables> 15 <Testables>
15 <TestableReference 16 <TestableReference
16 skipped = "NO"> 17 skipped = "NO">
@@ -22,172 +22,179 @@ NSString *kImageTestKey = @"TestImageKey.jpg"; @@ -22,172 +22,179 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
22 22
23 @implementation SDImageCacheTests 23 @implementation SDImageCacheTests
24 24
25 -- (void)setUp  
26 -{ 25 +- (void)setUp {
27 [super setUp]; 26 [super setUp];
28 // Put setup code here. This method is called before the invocation of each test method in the class. 27 // Put setup code here. This method is called before the invocation of each test method in the class.
29 self.sharedImageCache = [SDImageCache sharedImageCache]; 28 self.sharedImageCache = [SDImageCache sharedImageCache];
30 [self clearAllCaches]; 29 [self clearAllCaches];
31 } 30 }
32 31
33 -- (void)tearDown  
34 -{  
35 - // Put teardown code here. This method is called after the invocation of each test method in the class.  
36 - [super tearDown];  
37 -}  
38 -  
39 -- (void)testSharedImageCache { 32 +- (void)test01SharedImageCache {
40 expect(self.sharedImageCache).toNot.beNil(); 33 expect(self.sharedImageCache).toNot.beNil();
41 } 34 }
42 35
43 -- (void)testSingleton{ 36 +- (void)test02Singleton{
44 expect(self.sharedImageCache).to.equal([SDImageCache sharedImageCache]); 37 expect(self.sharedImageCache).to.equal([SDImageCache sharedImageCache]);
45 } 38 }
46 39
47 -- (void)testClearDiskCache{  
48 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 40 +- (void)test03ImageCacheCanBeInstantiated {
  41 + SDImageCache *imageCache = [[SDImageCache alloc] init];
  42 + expect(imageCache).toNot.equal([SDImageCache sharedImageCache]);
  43 +}
  44 +
  45 +- (void)test04ClearDiskCache{
  46 + XCTestExpectation *expectation = [self expectationWithDescription:@"Clear disk cache"];
  47 +
  48 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
49 [self.sharedImageCache clearDiskOnCompletion:^{ 49 [self.sharedImageCache clearDiskOnCompletion:^{
50 - expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(NO); 50 + [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
  51 + if (!isInCache) {
  52 + [expectation fulfill];
  53 + } else {
  54 + XCTFail(@"Image should not be in cache");
  55 + }
  56 + }];
51 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]); 57 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
52 }]; 58 }];
  59 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
53 } 60 }
54 61
55 -- (void)testClearMemoryCache{  
56 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 62 +- (void)test05ClearMemoryCache{
  63 + XCTestExpectation *expectation = [self expectationWithDescription:@"Clear memory cache"];
  64 +
  65 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
57 [self.sharedImageCache clearMemory]; 66 [self.sharedImageCache clearMemory];
58 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil; 67 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
59 - // Seems not able to access the files correctly (maybe only from test?)  
60 - //expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);  
61 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) { 68 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
62 - expect(isInCache).to.equal(YES); 69 + if (isInCache) {
  70 + [expectation fulfill];
  71 + } else {
  72 + XCTFail(@"Image should be in cache");
  73 + }
63 }]; 74 }];
  75 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
64 } 76 }
65 77
66 // Testing storeImage:forKey: 78 // Testing storeImage:forKey:
67 -- (void)testInsertionOfImage { 79 +- (void)test06InsertionOfImage {
  80 + XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey"];
  81 +
68 UIImage *image = [self imageForTesting]; 82 UIImage *image = [self imageForTesting];
69 - [self.sharedImageCache storeImage:image forKey:kImageTestKey]; 83 + [self.sharedImageCache storeImage:image forKey:kImageTestKey completion:nil];
70 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image); 84 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
71 - expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.equal(image); 85 + [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
  86 + if (isInCache) {
  87 + [expectation fulfill];
  88 + } else {
  89 + XCTFail(@"Image should be in cache");
  90 + }
  91 + }];
  92 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
72 } 93 }
73 94
74 // Testing storeImage:forKey:toDisk:YES 95 // Testing storeImage:forKey:toDisk:YES
75 -- (void)testInsertionOfImageForcingDiskStorage{ 96 +- (void)test07InsertionOfImageForcingDiskStorage{
  97 + XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey toDisk=YES"];
  98 +
76 UIImage *image = [self imageForTesting]; 99 UIImage *image = [self imageForTesting];
77 - [self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:YES]; 100 + [self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:YES completion:nil];
78 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image); 101 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal(image);
79 - // Seems not able to access the files correctly (maybe only from test?)  
80 - //expect([self.sharedImageCache diskImageExistsWithKey:kImageTestKey]).to.equal(YES);  
81 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) { 102 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
82 - expect(isInCache).to.equal(YES); 103 + if (isInCache) {
  104 + [expectation fulfill];
  105 + } else {
  106 + XCTFail(@"Image should be in cache");
  107 + }
83 }]; 108 }];
  109 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
84 } 110 }
85 111
86 // Testing storeImage:forKey:toDisk:NO 112 // Testing storeImage:forKey:toDisk:NO
87 -- (void)testInsertionOfImageOnlyInMemory { 113 +- (void)test08InsertionOfImageOnlyInMemory {
  114 + XCTestExpectation *expectation = [self expectationWithDescription:@"storeImage forKey toDisk=NO"];
88 UIImage *image = [self imageForTesting]; 115 UIImage *image = [self imageForTesting];
89 - [self.sharedImageCache storeImage:image forKey:@"TestImage" toDisk:NO];  
90 - [self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {  
91 - expect(isInCache).to.equal(YES); 116 + [self.sharedImageCache storeImage:image forKey:kImageTestKey toDisk:NO completion:nil];
  117 +
  118 + expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
  119 + [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
  120 + if (!isInCache) {
  121 + [expectation fulfill];
  122 + } else {
  123 + XCTFail(@"Image should not be in cache");
  124 + }
92 }]; 125 }];
93 [self.sharedImageCache clearMemory]; 126 [self.sharedImageCache clearMemory];
94 - [self.sharedImageCache diskImageExistsWithKey:@"TestImage" completion:^(BOOL isInCache) {  
95 - expect(isInCache).to.equal(NO);  
96 - }]; 127 + expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil();
  128 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
97 } 129 }
98 130
99 -- (void)testRetrievalImageThroughNSOperation{  
100 - //- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock; 131 +- (void)test09RetrieveImageThroughNSOperation{
  132 + //- (NSOperation *)queryCacheOperationForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
101 UIImage *imageForTesting = [self imageForTesting]; 133 UIImage *imageForTesting = [self imageForTesting];
102 - [self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey];  
103 - NSOperation *operation = [self.sharedImageCache queryDiskCacheForKey:kImageTestKey done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) { 134 + [self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey completion:nil];
  135 + NSOperation *operation = [self.sharedImageCache queryCacheOperationForKey:kImageTestKey done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
104 expect(image).to.equal(imageForTesting); 136 expect(image).to.equal(imageForTesting);
105 }]; 137 }];
106 expect(operation).toNot.beNil; 138 expect(operation).toNot.beNil;
107 } 139 }
108 140
109 -- (void)testRemoveImageForKey{  
110 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];  
111 - [self.sharedImageCache removeImageForKey:kImageTestKey];  
112 - expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;  
113 - expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;  
114 -}  
115 -  
116 -- (void)testRemoveImageForKeyWithCompletion{  
117 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 141 +- (void)test10RemoveImageForKeyWithCompletion{
  142 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
118 [self.sharedImageCache removeImageForKey:kImageTestKey withCompletion:^{ 143 [self.sharedImageCache removeImageForKey:kImageTestKey withCompletion:^{
119 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil; 144 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
120 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil; 145 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
121 }]; 146 }];
122 } 147 }
123 148
124 -- (void)testRemoveImageForKeyNotFromDisk{  
125 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];  
126 - [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];  
127 - expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;  
128 - expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;  
129 -}  
130 -  
131 -- (void)testRemoveImageForKeyFromDisk{  
132 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey];  
133 - [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO];  
134 - expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;  
135 - expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;  
136 -}  
137 -  
138 -- (void)testRemoveImageforKeyNotFromDiskWithCompletion{  
139 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 149 +- (void)test11RemoveImageforKeyNotFromDiskWithCompletion{
  150 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
140 [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO withCompletion:^{ 151 [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:NO withCompletion:^{
141 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil; 152 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).toNot.beNil;
142 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil; 153 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
143 }]; 154 }];
144 } 155 }
145 156
146 -- (void)testRemoveImageforKeyFromDiskWithCompletion{  
147 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 157 +- (void)test12RemoveImageforKeyFromDiskWithCompletion{
  158 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
148 [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:YES withCompletion:^{ 159 [self.sharedImageCache removeImageForKey:kImageTestKey fromDisk:YES withCompletion:^{
149 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil; 160 expect([self.sharedImageCache imageFromDiskCacheForKey:kImageTestKey]).to.beNil;
150 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil; 161 expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.beNil;
151 }]; 162 }];
152 } 163 }
153 164
154 -// TODO -- Testing insertion with recalculate  
155 -- (void)testInsertionOfImageOnlyInDisk {  
156 -}  
157 -  
158 -- (void)testInitialCacheSize{ 165 +- (void)test20InitialCacheSize{
159 expect([self.sharedImageCache getSize]).to.equal(0); 166 expect([self.sharedImageCache getSize]).to.equal(0);
160 } 167 }
161 168
162 -- (void)testInitialDiskCount{  
163 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 169 +- (void)test21InitialDiskCount{
  170 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
164 expect([self.sharedImageCache getDiskCount]).to.equal(1); 171 expect([self.sharedImageCache getDiskCount]).to.equal(1);
165 } 172 }
166 173
167 -- (void)testDiskCountAfterInsertion{  
168 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 174 +- (void)test22DiskCountAfterInsertion{
  175 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
169 expect([self.sharedImageCache getDiskCount]).to.equal(1); 176 expect([self.sharedImageCache getDiskCount]).to.equal(1);
170 } 177 }
171 178
172 -- (void)testDefaultCachePathForAnyKey{ 179 +- (void)test31DefaultCachePathForAnyKey{
173 NSString *path = [self.sharedImageCache defaultCachePathForKey:kImageTestKey]; 180 NSString *path = [self.sharedImageCache defaultCachePathForKey:kImageTestKey];
174 expect(path).toNot.beNil; 181 expect(path).toNot.beNil;
175 } 182 }
176 183
177 -- (void)testCachePathForNonExistingKey{ 184 +- (void)test32CachePathForNonExistingKey{
178 NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]]; 185 NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
179 expect(path).to.beNil; 186 expect(path).to.beNil;
180 } 187 }
181 188
182 -- (void)testCachePathForExistingKey{  
183 - [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey]; 189 +- (void)test33CachePathForExistingKey{
  190 + [self.sharedImageCache storeImage:[self imageForTesting] forKey:kImageTestKey completion:nil];
184 NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]]; 191 NSString *path = [self.sharedImageCache cachePathForKey:kImageTestKey inPath:[self.sharedImageCache defaultCachePathForKey:kImageTestKey]];
185 expect(path).notTo.beNil; 192 expect(path).notTo.beNil;
186 } 193 }
187 194
188 // TODO -- Testing image data insertion 195 // TODO -- Testing image data insertion
189 196
190 -- (void)testInsertionOfImageData { 197 +- (void)test40InsertionOfImageData {
191 198
192 NSData *imageData = [NSData dataWithContentsOfFile:[self testImagePath]]; 199 NSData *imageData = [NSData dataWithContentsOfFile:[self testImagePath]];
193 [self.sharedImageCache storeImageDataToDisk:imageData forKey:kImageTestKey]; 200 [self.sharedImageCache storeImageDataToDisk:imageData forKey:kImageTestKey];
@@ -202,18 +209,28 @@ NSString *kImageTestKey = @"TestImageKey.jpg"; @@ -202,18 +209,28 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
202 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) { 209 [self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
203 expect(isInCache).to.equal(YES); 210 expect(isInCache).to.equal(YES);
204 }]; 211 }];
  212 +
  213 + [self.sharedImageCache calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
  214 + expect(fileCount).to.beLessThan(100);
  215 + }];
205 } 216 }
206 217
207 #pragma mark Helper methods 218 #pragma mark Helper methods
208 219
209 - (void)clearAllCaches{ 220 - (void)clearAllCaches{
210 - [self.sharedImageCache clearDisk]; 221 + [self.sharedImageCache deleteOldFilesWithCompletionBlock:nil];
  222 +
  223 + // TODO: this is not ok, clearDiskOnCompletion will clear async, this means that when we execute the tests, the cache might not be cleared
  224 + [self.sharedImageCache clearDiskOnCompletion:nil];
211 [self.sharedImageCache clearMemory]; 225 [self.sharedImageCache clearMemory];
212 } 226 }
213 227
214 - (UIImage *)imageForTesting{ 228 - (UIImage *)imageForTesting{
215 -  
216 - return [UIImage imageWithContentsOfFile:[self testImagePath]]; 229 + static UIImage *reusableImage = nil;
  230 + if (!reusableImage) {
  231 + reusableImage = [UIImage imageWithContentsOfFile:[self testImagePath]];
  232 + }
  233 + return reusableImage;
217 } 234 }
218 235
219 - (NSString *)testImagePath { 236 - (NSString *)testImagePath {
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + * (c) Matt Galloway
  5 + *
  6 + * For the full copyright and license information, please view the LICENSE
  7 + * file that was distributed with this source code.
  8 + */
  9 +
  10 +#define EXP_SHORTHAND // required by Expecta
  11 +
  12 +
  13 +#import <XCTest/XCTest.h>
  14 +#import <Expecta.h>
  15 +
  16 +#import "SDWebImageDecoder.h"
  17 +
  18 +@interface SDWebImageDecoderTests : XCTestCase
  19 +
  20 +@end
  21 +
  22 +@implementation SDWebImageDecoderTests
  23 +
  24 +- (void)test01ThatDecodedImageWithNilImageReturnsNil {
  25 + expect([UIImage decodedImageWithImage:nil]).to.beNil();
  26 +}
  27 +
  28 +- (void)test02ThatDecodedImageWithImageWorksWithARegularJPGImage {
  29 + NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"];
  30 + UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
  31 + UIImage *decodedImage = [UIImage decodedImageWithImage:image];
  32 + expect(decodedImage).toNot.beNil();
  33 + expect(decodedImage).toNot.equal(image);
  34 +}
  35 +
  36 +- (void)test03ThatDecodedImageWithImageDoesNotDecodeAnimatedImages {
  37 + NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"gif"];
  38 + UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
  39 + UIImage *animatedImage = [UIImage animatedImageWithImages:@[image] duration:0];
  40 + UIImage *decodedImage = [UIImage decodedImageWithImage:animatedImage];
  41 + expect(decodedImage).toNot.beNil();
  42 + expect(decodedImage).to.equal(animatedImage);
  43 +}
  44 +
  45 +- (void)test04ThatDecodedImageWithImageDoesNotDecodeImagesWithAlpha {
  46 + NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
  47 + UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
  48 + UIImage *decodedImage = [UIImage decodedImageWithImage:image];
  49 + expect(decodedImage).toNot.beNil();
  50 + expect(decodedImage).to.equal(image);
  51 +}
  52 +
  53 +- (void)test05ThatDecodedImageWithImageWorksEvenWithMonochromeImage {
  54 + NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"MonochromeTestImage" ofType:@"jpg"];
  55 + UIImage *image = [UIImage imageWithContentsOfFile:testImagePath];
  56 + UIImage *decodedImage = [UIImage decodedImageWithImage:image];
  57 + expect(decodedImage).toNot.beNil();
  58 + expect(decodedImage).toNot.equal(image);
  59 +}
  60 +
  61 +@end
@@ -14,6 +14,46 @@ @@ -14,6 +14,46 @@
14 #import <Expecta.h> 14 #import <Expecta.h>
15 15
16 #import "SDWebImageDownloader.h" 16 #import "SDWebImageDownloader.h"
  17 +#import "SDWebImageDownloaderOperation.h"
  18 +
  19 +/**
  20 + * Category for SDWebImageDownloader so we can access the operationClass
  21 + */
  22 +@interface SDWebImageDownloader ()
  23 +@property (assign, nonatomic, nullable) Class operationClass;
  24 +@property (strong, nonatomic, nonnull) NSOperationQueue *downloadQueue;
  25 +
  26 +- (nullable SDWebImageDownloadToken *)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock
  27 + completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock
  28 + forURL:(nullable NSURL *)url
  29 + createCallback:(SDWebImageDownloaderOperation *(^)())createCallback;
  30 +@end
  31 +
  32 +/**
  33 + * A class that fits the NSOperation+SDWebImageDownloaderOperationInterface requirement so we can test
  34 + */
  35 +@interface CustomDownloaderOperation : NSOperation<SDWebImageDownloaderOperationInterface>
  36 +
  37 +@property (nonatomic, assign) BOOL shouldDecompressImages;
  38 +@property (nonatomic, strong, nullable) NSURLCredential *credential;
  39 +
  40 +@end
  41 +
  42 +@implementation CustomDownloaderOperation
  43 +
  44 +- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)req inSession:(nullable NSURLSession *)ses options:(SDWebImageDownloaderOptions)opt {
  45 + if ((self = [super init])) { }
  46 + return self;
  47 +}
  48 +
  49 +- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
  50 + completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
  51 + return nil;
  52 +}
  53 +
  54 +@end
  55 +
  56 +
17 57
18 @interface SDWebImageDownloaderTests : XCTestCase 58 @interface SDWebImageDownloaderTests : XCTestCase
19 59
@@ -21,68 +61,288 @@ @@ -21,68 +61,288 @@
21 61
22 @implementation SDWebImageDownloaderTests 62 @implementation SDWebImageDownloaderTests
23 63
24 -- (void)setUp  
25 -{  
26 - [super setUp];  
27 - // Put setup code here. This method is called before the invocation of each test method in the class. 64 +- (void)test01ThatSharedDownloaderIsNotEqualToInitDownloader {
  65 + SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] init];
  66 + expect(downloader).toNot.equal([SDWebImageDownloader sharedDownloader]);
28 } 67 }
29 68
30 -- (void)tearDown  
31 -{  
32 - // Put teardown code here. This method is called after the invocation of each test method in the class.  
33 - [super tearDown]; 69 +- (void)test02ThatByDefaultDownloaderSetsTheAcceptHTTPHeader {
  70 + expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:@"Accept"]).to.match(@"image/\\*");
34 } 71 }
35 72
36 -- (void)testThatDownloadingSameURLTwiceAndCancellingFirstWorks {  
37 - XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"]; 73 +- (void)test03ThatSetAndGetValueForHTTPHeaderFieldWork {
  74 + NSString *headerValue = @"Tests";
  75 + NSString *headerName = @"AppName";
  76 + // set it
  77 + [[SDWebImageDownloader sharedDownloader] setValue:headerValue forHTTPHeaderField:headerName];
  78 + expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:headerName]).to.equal(headerValue);
  79 + // clear it
  80 + [[SDWebImageDownloader sharedDownloader] setValue:nil forHTTPHeaderField:headerName];
  81 + expect([[SDWebImageDownloader sharedDownloader] valueForHTTPHeaderField:headerName]).to.beNil();
  82 +}
38 83
39 - NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"]; 84 +- (void)test04ThatASimpleDownloadWorks {
  85 + XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
  86 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage004.jpg"];
  87 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  88 + if (image && data && !error && finished) {
  89 + [expectation fulfill];
  90 + } else {
  91 + XCTFail(@"Something went wrong");
  92 + }
  93 + }];
  94 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  95 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  96 +}
40 97
41 - id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL  
42 - options:0  
43 - progress:nil  
44 - completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {  
45 - XCTFail(@"Shouldn't have completed here.");  
46 - }];  
47 - expect(token1).toNot.beNil(); 98 +- (void)test05ThatSetAndGetMaxConcurrentDownloadsWorks {
  99 + NSInteger initialValue = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
  100 +
  101 + [[SDWebImageDownloader sharedDownloader] setMaxConcurrentDownloads:3];
  102 + expect([SDWebImageDownloader sharedDownloader].maxConcurrentDownloads).to.equal(3);
  103 +
  104 + [[SDWebImageDownloader sharedDownloader] setMaxConcurrentDownloads:initialValue];
  105 +}
48 106
49 - id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL  
50 - options:0  
51 - progress:nil  
52 - completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {  
53 - [expectation fulfill];  
54 - }];  
55 - expect(token2).toNot.beNil(); 107 +- (void)test06ThatUsingACustomDownloaderOperationWorks {
  108 + // we try to set a usual NSOperation as operation class. Should not work
  109 + [[SDWebImageDownloader sharedDownloader] setOperationClass:[NSOperation class]];
  110 + expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([SDWebImageDownloaderOperation class]);
  111 +
  112 + // setting an NSOperation subclass that conforms to SDWebImageDownloaderOperationInterface - should work
  113 + [[SDWebImageDownloader sharedDownloader] setOperationClass:[CustomDownloaderOperation class]];
  114 + expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([CustomDownloaderOperation class]);
  115 +
  116 + // back to the original value
  117 + [[SDWebImageDownloader sharedDownloader] setOperationClass:nil];
  118 + expect([SDWebImageDownloader sharedDownloader].operationClass).to.equal([SDWebImageDownloaderOperation class]);
  119 +}
56 120
57 - [[SDWebImageDownloader sharedDownloader] cancel:token1]; 121 +- (void)test07ThatAddProgressCallbackCompletedBlockWithNilURLCallsTheCompletionBlockWithNils {
  122 + XCTestExpectation *expectation = [self expectationWithDescription:@"Completion is called with nils"];
  123 + [[SDWebImageDownloader sharedDownloader] addProgressCallback:nil completedBlock:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  124 + if (!image && !data && !error) {
  125 + [expectation fulfill];
  126 + } else {
  127 + XCTFail(@"All params should be nil");
  128 + }
  129 + } forURL:nil createCallback:nil];
  130 + [self waitForExpectationsWithTimeout:0.5 handler:nil];
  131 +}
58 132
59 - [self waitForExpectationsWithTimeout:5. handler:nil]; 133 +- (void)test08ThatAHTTPAuthDownloadWorks {
  134 + XCTestExpectation *expectation = [self expectationWithDescription:@"HTTP Auth download"];
  135 + [SDWebImageDownloader sharedDownloader].username = @"httpwatch";
  136 + [SDWebImageDownloader sharedDownloader].password = @"httpwatch01";
  137 + NSURL *imageURL = [NSURL URLWithString:@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633"];
  138 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  139 + if (image && data && !error && finished) {
  140 + [expectation fulfill];
  141 + } else {
  142 + XCTFail(@"Something went wrong");
  143 + }
  144 + }];
  145 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  146 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  147 + [SDWebImageDownloader sharedDownloader].username = nil;
  148 + [SDWebImageDownloader sharedDownloader].password = nil;
60 } 149 }
61 150
62 -- (void)testThatCancelingDownloadThenRequestingAgainWorks {  
63 - XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"]; 151 +- (void)test09ThatProgressiveJPEGWorks {
  152 + XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive JPEG download"];
  153 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage009.jpg"];
  154 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveDownload progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  155 + if (image && data && !error && finished) {
  156 + [expectation fulfill];
  157 + } else if (finished) {
  158 + XCTFail(@"Something went wrong");
  159 + } else {
  160 + // progressive updates
  161 + }
  162 + }];
  163 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  164 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  165 +}
64 166
  167 +- (void)test10That404CaseCallsCompletionWithError {
65 NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"]; 168 NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"];
  169 +
  170 + XCTestExpectation *expectation = [self expectationWithDescription:@"404"];
  171 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  172 + if (!image && !data && error && finished) {
  173 + [expectation fulfill];
  174 + } else {
  175 + XCTFail(@"Something went wrong");
  176 + }
  177 + }];
  178 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  179 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  180 +}
  181 +
  182 +- (void)test11ThatCancelWorks {
  183 + XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel"];
  184 +
  185 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage011.jpg"];
  186 + SDWebImageDownloadToken *token = [[SDWebImageDownloader sharedDownloader]
  187 + downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  188 + XCTFail(@"Should not get here");
  189 + }];
  190 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  191 +
  192 + [[SDWebImageDownloader sharedDownloader] cancel:token];
  193 +
  194 + // doesn't cancel immediately - since it uses dispatch async
  195 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  196 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(0);
  197 + [expectation fulfill];
  198 + });
  199 +
  200 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  201 +}
  202 +
  203 +- (void)test12ThatWeCanUseAnotherSessionForEachDownloadOperation {
  204 + XCTestExpectation *expectation = [self expectationWithDescription:@"Owned session"];
  205 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage012.jpg"];
  206 +
  207 + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
  208 + request.HTTPShouldUsePipelining = YES;
  209 + request.allHTTPHeaderFields = @{@"Accept": @"image/*;q=0.8"};
  210 +
  211 + SDWebImageDownloaderOperation *operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
  212 + inSession:nil
  213 + options:0];
  214 + [operation addHandlersForProgress:^(NSInteger receivedSize, NSInteger expectedSize) {
  215 +
  216 + } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  217 + if (image && data && !error && finished) {
  218 + [expectation fulfill];
  219 + } else {
  220 + XCTFail(@"Something went wrong");
  221 + }
  222 + }];
  223 +
  224 + [operation start];
  225 +
  226 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  227 +}
  228 +
  229 +- (void)test13ThatDownloadCanContinueWhenTheAppEntersBackground {
  230 + XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
  231 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage013.jpg"];
  232 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderContinueInBackground progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  233 + if (image && data && !error && finished) {
  234 + [expectation fulfill];
  235 + } else {
  236 + XCTFail(@"Something went wrong");
  237 + }
  238 + }];
  239 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  240 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  241 +}
  242 +
  243 +- (void)test14ThatPNGWorks {
  244 + XCTestExpectation *expectation = [self expectationWithDescription:@"WEBP"];
  245 + NSURL *imageURL = [NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"];
  246 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  247 + if (image && data && !error && finished) {
  248 + [expectation fulfill];
  249 + } else {
  250 + XCTFail(@"Something went wrong");
  251 + }
  252 + }];
  253 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  254 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  255 +}
66 256
67 - id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL  
68 - options:0  
69 - progress:nil  
70 - completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {  
71 - XCTFail(@"Shouldn't have completed here.");  
72 - }]; 257 +- (void)test15ThatWEBPWorks {
  258 + XCTestExpectation *expectation = [self expectationWithDescription:@"WEBP"];
  259 + NSURL *imageURL = [NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"];
  260 + [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
  261 + if (image && data && !error && finished) {
  262 + [expectation fulfill];
  263 + } else {
  264 + XCTFail(@"Something went wrong");
  265 + }
  266 + }];
  267 + expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);
  268 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  269 +}
  270 +
  271 +/**
  272 + * Per #883 - Fix multiple requests for same image and then canceling one
  273 + * Old SDWebImage (3.x) could not handle correctly multiple requests for the same image + cancel
  274 + * In 4.0, via #883 added `SDWebImageDownloadToken` so we can cancel exactly the request we want
  275 + * This test validates the scenario of making 2 requests for the same image and cancelling the 1st one
  276 + */
  277 +- (void)test20ThatDownloadingSameURLTwiceAndCancellingFirstWorks {
  278 + XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
  279 +
  280 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage020.jpg"];
  281 +
  282 + SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
  283 + downloadImageWithURL:imageURL
  284 + options:0
  285 + progress:nil
  286 + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  287 + XCTFail(@"Shouldn't have completed here.");
  288 + }];
73 expect(token1).toNot.beNil(); 289 expect(token1).toNot.beNil();
  290 +
  291 + SDWebImageDownloadToken *token2 = [[SDWebImageDownloader sharedDownloader]
  292 + downloadImageWithURL:imageURL
  293 + options:0
  294 + progress:nil
  295 + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  296 + if (image && data && !error && finished) {
  297 + [expectation fulfill];
  298 + } else {
  299 + XCTFail(@"Something went wrong");
  300 + }
  301 + }];
  302 + expect(token2).toNot.beNil();
74 303
75 [[SDWebImageDownloader sharedDownloader] cancel:token1]; 304 [[SDWebImageDownloader sharedDownloader] cancel:token1];
76 305
77 - id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL  
78 - options:0  
79 - progress:nil  
80 - completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {  
81 - [expectation fulfill];  
82 - }];  
83 - expect(token2).toNot.beNil(); 306 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
  307 +}
84 308
85 - [self waitForExpectationsWithTimeout:5. handler:nil]; 309 +/**
  310 + * Per #883 - Fix multiple requests for same image and then canceling one
  311 + * Old SDWebImage (3.x) could not handle correctly multiple requests for the same image + cancel
  312 + * In 4.0, via #883 added `SDWebImageDownloadToken` so we can cancel exactly the request we want
  313 + * This test validates the scenario of requesting an image, cancel and then requesting it again
  314 + */
  315 +- (void)test21ThatCancelingDownloadThenRequestingAgainWorks {
  316 + XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
  317 +
  318 + NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage021.jpg"];
  319 +
  320 + SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
  321 + downloadImageWithURL:imageURL
  322 + options:0
  323 + progress:nil
  324 + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  325 + XCTFail(@"Shouldn't have completed here.");
  326 + }];
  327 + expect(token1).toNot.beNil();
  328 +
  329 + [[SDWebImageDownloader sharedDownloader] cancel:token1];
  330 +
  331 + SDWebImageDownloadToken *token2 = [[SDWebImageDownloader sharedDownloader]
  332 + downloadImageWithURL:imageURL
  333 + options:0
  334 + progress:nil
  335 + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  336 + if (image && data && !error && finished) {
  337 + [expectation fulfill];
  338 + } else {
  339 + NSLog(@"image = %@, data = %@, error = %@", image, data, error);
  340 + XCTFail(@"Something went wrong");
  341 + }
  342 + }];
  343 + expect(token2).toNot.beNil();
  344 +
  345 + [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
86 } 346 }
87 347
88 @end 348 @end
@@ -14,8 +14,6 @@ @@ -14,8 +14,6 @@
14 14
15 #import "SDWebImageManager.h" 15 #import "SDWebImageManager.h"
16 16
17 -static int64_t kAsyncTestTimeout = 5;  
18 -  
19 17
20 @interface SDWebImageManagerTests : XCTestCase 18 @interface SDWebImageManagerTests : XCTestCase
21 19