From c1fae30d635998408ec083dba8a435ee2e96d926 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Fri, 20 Jun 2014 17:21:01 +0300 Subject: [PATCH] Added SDWebImage Tests project. It uses CocoaPods (Expecta + XCTestAsync). Added some demo tests --- .../contents.xcworkspacedata | 11 +- Tests/Podfile | 14 + .../project.pbxproj | 338 ++++++++++++++++++ Tests/Tests/SDImageCacheTests.m | 43 +++ Tests/Tests/SDWebImageManagerTests.m | 57 +++ Tests/Tests/Tests-Info.plist | 22 ++ Tests/Tests/Tests-Prefix.pch | 10 + Tests/Tests/en.lproj/InfoPlist.strings | 2 + 8 files changed, 487 insertions(+), 10 deletions(-) create mode 100644 Tests/Podfile create mode 100644 Tests/SDWebImage Tests.xcodeproj/project.pbxproj create mode 100644 Tests/Tests/SDImageCacheTests.m create mode 100644 Tests/Tests/SDWebImageManagerTests.m create mode 100644 Tests/Tests/Tests-Info.plist create mode 100644 Tests/Tests/Tests-Prefix.pch create mode 100644 Tests/Tests/en.lproj/InfoPlist.strings diff --git a/SDWebImage.xcworkspace/contents.xcworkspacedata b/SDWebImage.xcworkspace/contents.xcworkspacedata index 42084772..33ebbdd1 100644 --- a/SDWebImage.xcworkspace/contents.xcworkspacedata +++ b/SDWebImage.xcworkspace/contents.xcworkspacedata @@ -1,10 +1 @@ - - - - - - - + \ No newline at end of file diff --git a/Tests/Podfile b/Tests/Podfile new file mode 100644 index 00000000..fb5409ff --- /dev/null +++ b/Tests/Podfile @@ -0,0 +1,14 @@ +xcodeproj 'SDWebImage Tests' +workspace '../SDWebImage' + +def import_pods + pod 'Expecta' # A Matcher Framework for Objective-C/Cocoa + pod 'XCTestAsync' # Extension to XCTest for asynchronous testing + pod 'SDWebImage', :path => '../' +end + +target :ios do + platform :ios, '5.0' + link_with 'Tests' + import_pods +end \ No newline at end of file diff --git a/Tests/SDWebImage Tests.xcodeproj/project.pbxproj b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj new file mode 100644 index 00000000..fd80a8eb --- /dev/null +++ b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj @@ -0,0 +1,338 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + ABC8501F672447AA91C788DA /* libPods-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EB0D107E6B4C4094BA2FEE29 /* libPods-ios.a */; }; + DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; }; + DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; }; + DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D5A195472AA00390AB0 /* UIKit.framework */; }; + DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = DA248D5F195472AA00390AB0 /* InfoPlist.strings */; }; + DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA248D68195475D800390AB0 /* SDImageCacheTests.m */; }; + DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 5421361315E74CAA8FCCC423 /* Pods-ios.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ios.xcconfig"; path = "Pods/Pods-ios.xcconfig"; sourceTree = ""; }; + DA248D53195472AA00390AB0 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + DA248D56195472AA00390AB0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + DA248D58195472AA00390AB0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + DA248D5A195472AA00390AB0 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; + DA248D5E195472AA00390AB0 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; + DA248D60195472AA00390AB0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + DA248D64195472AA00390AB0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; + DA248D68195475D800390AB0 /* SDImageCacheTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheTests.m; sourceTree = ""; }; + DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageManagerTests.m; sourceTree = ""; }; + EB0D107E6B4C4094BA2FEE29 /* libPods-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DA248D50195472AA00390AB0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */, + DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */, + DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */, + ABC8501F672447AA91C788DA /* libPods-ios.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DA248D451954721A00390AB0 = { + isa = PBXGroup; + children = ( + DA248D5C195472AA00390AB0 /* Tests */, + DA248D55195472AA00390AB0 /* Frameworks */, + DA248D54195472AA00390AB0 /* Products */, + 5421361315E74CAA8FCCC423 /* Pods-ios.xcconfig */, + ); + sourceTree = ""; + }; + DA248D54195472AA00390AB0 /* Products */ = { + isa = PBXGroup; + children = ( + DA248D53195472AA00390AB0 /* Tests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + DA248D55195472AA00390AB0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + DA248D56195472AA00390AB0 /* XCTest.framework */, + DA248D58195472AA00390AB0 /* Foundation.framework */, + DA248D5A195472AA00390AB0 /* UIKit.framework */, + EB0D107E6B4C4094BA2FEE29 /* libPods-ios.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + DA248D5C195472AA00390AB0 /* Tests */ = { + isa = PBXGroup; + children = ( + DA248D5D195472AA00390AB0 /* Supporting Files */, + DA248D68195475D800390AB0 /* SDImageCacheTests.m */, + DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */, + ); + path = Tests; + sourceTree = ""; + }; + DA248D5D195472AA00390AB0 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + DA248D5E195472AA00390AB0 /* Tests-Info.plist */, + DA248D5F195472AA00390AB0 /* InfoPlist.strings */, + DA248D64195472AA00390AB0 /* Tests-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + DA248D52195472AA00390AB0 /* Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */; + buildPhases = ( + FBC8982311CD4ED9A3006D45 /* Check Pods Manifest.lock */, + DA248D4F195472AA00390AB0 /* Sources */, + DA248D50195472AA00390AB0 /* Frameworks */, + DA248D51195472AA00390AB0 /* Resources */, + D6347736BDF64FC5A4D078A4 /* Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Tests; + productName = Tests; + productReference = DA248D53195472AA00390AB0 /* Tests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DA248D461954721A00390AB0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0510; + }; + buildConfigurationList = DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = DA248D451954721A00390AB0; + productRefGroup = DA248D54195472AA00390AB0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DA248D52195472AA00390AB0 /* Tests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DA248D51195472AA00390AB0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DA248D61195472AA00390AB0 /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + D6347736BDF64FC5A4D078A4 /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Pods-ios-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + FBC8982311CD4ED9A3006D45 /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DA248D4F195472AA00390AB0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */, + DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + DA248D5F195472AA00390AB0 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + DA248D60195472AA00390AB0 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + DA248D4A1954721A00390AB0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + DA248D4B1954721A00390AB0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; + DA248D65195472AA00390AB0 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5421361315E74CAA8FCCC423 /* Pods-ios.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = "Tests/Tests-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + WRAPPER_EXTENSION = xctest; + }; + name = Debug; + }; + DA248D66195472AA00390AB0 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5421361315E74CAA8FCCC423 /* Pods-ios.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = "Tests/Tests-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + WRAPPER_EXTENSION = xctest; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DA248D4A1954721A00390AB0 /* Debug */, + DA248D4B1954721A00390AB0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DA248D65195472AA00390AB0 /* Debug */, + DA248D66195472AA00390AB0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = DA248D461954721A00390AB0 /* Project object */; +} diff --git a/Tests/Tests/SDImageCacheTests.m b/Tests/Tests/SDImageCacheTests.m new file mode 100644 index 00000000..4858efdd --- /dev/null +++ b/Tests/Tests/SDImageCacheTests.m @@ -0,0 +1,43 @@ +// +// SDImageCacheTests.m +// SDWebImage Tests +// +// Created by Bogdan Poplauschi on 20/06/14. +// +// + +#define EXP_SHORTHAND // required by Expecta + + +#import +#import +#import + +#import "SDImageCache.h" + + +@interface SDImageCacheTests : XCTestCase + +@end + +@implementation SDImageCacheTests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testSharedImageCache { + SDImageCache *sharedImageCache = [SDImageCache sharedImageCache]; + + expect(sharedImageCache).toNot.beNil(); +} + +@end diff --git a/Tests/Tests/SDWebImageManagerTests.m b/Tests/Tests/SDWebImageManagerTests.m new file mode 100644 index 00000000..14c75aa0 --- /dev/null +++ b/Tests/Tests/SDWebImageManagerTests.m @@ -0,0 +1,57 @@ +// +// SDWebImageManagerTests.m +// SDWebImage Tests +// +// Created by Bogdan Poplauschi on 20/06/14. +// +// + +#define EXP_SHORTHAND // required by Expecta + + +#import +#import +#import + +#import "SDWebImageManager.h" + +static int64_t kAsyncTestTimeout = 5; + + +@interface SDWebImageManagerTests : XCTestCase + +@end + +@implementation SDWebImageManagerTests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testThatDownloadInvokesCompletionBlockWithCorrectParamsAsync { + NSURL *originalImageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"]; + + [[SDWebImageManager sharedManager] downloadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) { +// expect(receivedSize).to.beLessThanOrEqualTo(expectedSize); + } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + expect(image).toNot.beNil(); + expect(error).to.beNil(); + expect(originalImageURL).to.equal(imageURL); + + NSLog(@"xxxx"); + + XCAsyncSuccess(); + }]; + + XCAsyncFailAfter(kAsyncTestTimeout, @"Download image timed out"); +} + +@end diff --git a/Tests/Tests/Tests-Info.plist b/Tests/Tests/Tests-Info.plist new file mode 100644 index 00000000..82139999 --- /dev/null +++ b/Tests/Tests/Tests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.SDWebImage.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Tests/Tests/Tests-Prefix.pch b/Tests/Tests/Tests-Prefix.pch new file mode 100644 index 00000000..3fdee9d3 --- /dev/null +++ b/Tests/Tests/Tests-Prefix.pch @@ -0,0 +1,10 @@ +// +// Prefix header +// +// The contents of this file are implicitly included at the beginning of every source file. +// + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/Tests/Tests/en.lproj/InfoPlist.strings b/Tests/Tests/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/Tests/Tests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ +