Prefetcher tests
This commit is contained in:
parent
ea0bd97d10
commit
f48a133f1b
|
@ -13,6 +13,7 @@
|
|||
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 */; };
|
||||
4369C1D11D97F80F007E863A /* SDWebImagePrefetcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4369C1D01D97F80F007E863A /* SDWebImagePrefetcherTests.m */; };
|
||||
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 */; };
|
||||
|
@ -30,6 +31,7 @@
|
|||
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>"; };
|
||||
4369C1D01D97F80F007E863A /* SDWebImagePrefetcherTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImagePrefetcherTests.m; 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>"; };
|
||||
|
@ -111,6 +113,7 @@
|
|||
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
|
||||
1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */,
|
||||
433BBBB41D7EF5C00086B6E9 /* SDWebImageDecoderTests.m */,
|
||||
4369C1D01D97F80F007E863A /* SDWebImagePrefetcherTests.m */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
|
@ -242,6 +245,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */,
|
||||
4369C1D11D97F80F007E863A /* SDWebImagePrefetcherTests.m in Sources */,
|
||||
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
|
||||
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
|
||||
433BBBB51D7EF5C00086B6E9 /* SDWebImageDecoderTests.m in Sources */,
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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 "SDWebImagePrefetcher.h"
|
||||
|
||||
@interface SDWebImagePrefetcherTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDWebImagePrefetcherTests
|
||||
|
||||
- (void)test01ThatSharedPrefetcherIsNotEqualToInitPrefetcher {
|
||||
SDWebImagePrefetcher *prefetcher = [[SDWebImagePrefetcher alloc] init];
|
||||
expect(prefetcher).toNot.equal([SDWebImagePrefetcher sharedImagePrefetcher]);
|
||||
}
|
||||
|
||||
- (void)test02PrefetchMultipleImages {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct prefetch of multiple images"];
|
||||
|
||||
NSMutableArray *imageURLs = [NSMutableArray array];
|
||||
|
||||
for (int i=40; i<43; i++) {
|
||||
NSString *imageURLString = [NSString stringWithFormat:@"https://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage%03d.jpg", i];
|
||||
NSURL *imageURL = [NSURL URLWithString:imageURLString];
|
||||
[imageURLs addObject:imageURL];
|
||||
}
|
||||
|
||||
__block int numberOfPrefetched = 0;
|
||||
|
||||
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:imageURLs progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
|
||||
numberOfPrefetched += 1;
|
||||
expect(numberOfPrefetched).to.equal(noOfFinishedUrls);
|
||||
expect(noOfFinishedUrls).to.beLessThanOrEqualTo(noOfTotalUrls);
|
||||
expect(noOfTotalUrls).to.equal(imageURLs.count);
|
||||
} completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
|
||||
expect(numberOfPrefetched).to.equal(noOfFinishedUrls);
|
||||
expect(noOfFinishedUrls).to.equal(imageURLs.count);
|
||||
expect(noOfSkippedUrls).to.equal(0);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
- (void)test03PrefetchWithEmptyArrayWillCallTheCompletionWithAllZeros {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Prefetch with empty array"];
|
||||
|
||||
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[] progress:nil completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
|
||||
expect(noOfFinishedUrls).to.equal(0);
|
||||
expect(noOfSkippedUrls).to.equal(0);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
|
||||
}
|
||||
|
||||
// TODO: test the prefetcher delegate works
|
||||
|
||||
@end
|
Loading…
Reference in New Issue