11
11
#import " SDWebImageTestCache.h"
12
12
#import " SDWebImageTestLoader.h"
13
13
14
+ // Keep strong references for object
15
+ @interface SDObjectContainer <ObjectType> : NSObject
16
+ @property (nonatomic , strong , readwrite ) ObjectType object;
17
+ @end
18
+
19
+ @implementation SDObjectContainer
20
+ @end
21
+
14
22
@interface SDWebImageManagerTests : SDTestCase
15
23
16
24
@end
@@ -27,14 +35,24 @@ - (void)test02ThatDownloadInvokesCompletionBlockWithCorrectParamsAsync {
27
35
28
36
NSURL *originalImageURL = [NSURL URLWithString: kTestJPEGURL ];
29
37
30
- [[SDWebImageManager sharedManager ] loadImageWithURL: originalImageURL
31
- options: SDWebImageRefreshCached
32
- progress: nil
33
- completed: ^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
38
+ [SDImageCache.sharedImageCache removeImageFromMemoryForKey: kTestJPEGURL ];
39
+ [SDImageCache.sharedImageCache removeImageFromDiskForKey: kTestJPEGURL ];
40
+ SDObjectContainer<SDWebImageCombinedOperation *> *container = [SDObjectContainer new ];
41
+ container.object = [[SDWebImageManager sharedManager ] loadImageWithURL: originalImageURL
42
+ options: 0
43
+ progress: nil
44
+ completed: ^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
34
45
expect (image).toNot .beNil ();
35
46
expect (error).to .beNil ();
36
47
expect (originalImageURL).to .equal (imageURL);
37
-
48
+
49
+ // When download, the cache operation will reset to nil since it's always finished
50
+ SDWebImageCombinedOperation *operation = container.object ;
51
+ expect (container).notTo .beNil ();
52
+ expect (operation.cacheOperation ).beNil ();
53
+ expect (operation.loaderOperation ).notTo .beNil ();
54
+ container.object = nil ;
55
+
38
56
[expectation fulfill ];
39
57
expectation = nil ;
40
58
}];
@@ -49,7 +67,7 @@ - (void)test03ThatDownloadWithIncorrectURLInvokesCompletionBlockWithAnErrorAsync
49
67
NSURL *originalImageURL = [NSURL URLWithString: @" http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.png" ];
50
68
51
69
[[SDWebImageManager sharedManager ] loadImageWithURL: originalImageURL
52
- options: SDWebImageRefreshCached
70
+ options: 0
53
71
progress: nil
54
72
completed: ^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
55
73
expect (image).to .beNil ();
0 commit comments