Permalink
Browse files

Add tests for cancellation of processes

  • Loading branch information...
1 parent 36c93c1 commit 5b5245af607102accaf4dc27fef25b21696dbdf6 @danielctull committed Jan 3, 2013
@@ -12,6 +12,13 @@
2406F97E1678B3A900428406 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2406F97D1678B3A900428406 /* ViewController.xib */; };
24244609167509D200621FFF /* DCTImageCacheAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 24244608167509D200621FFF /* DCTImageCacheAttributes.m */; };
2424460B16750AF000621FFF /* DCTImageCacheAttributes.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 24244607167509D200621FFF /* DCTImageCacheAttributes.h */; };
+ 242560F91695D4220064D510 /* libDCTImageCache.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2437B67715B97BA600750117 /* libDCTImageCache.a */; };
+ 242560FB1695D43A0064D510 /* DCTImageCache.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 24FCFA94165FEAB3006208A7 /* DCTImageCache.bundle */; };
+ 242561361695D6AA0064D510 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F2DB6216602B71008F58D5 /* UIKit.framework */; };
+ 242561371695D6AF0064D510 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24B3EEBC15A2EB1F00D5E63C /* CoreGraphics.framework */; };
+ 242561381695D6B20064D510 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F2DB5D166029B9008F58D5 /* CoreData.framework */; };
+ 242561661695DCAA0064D510 /* DCTImageCacheProcessTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 242561651695DCAA0064D510 /* DCTImageCacheProcessTests.m */; };
+ 242561691695DD180064D510 /* DCTImageCacheMockCancel.m in Sources */ = {isa = PBXBuildFile; fileRef = 242561681695DD180064D510 /* DCTImageCacheMockCancel.m */; };
242AFA47166BB78F00AC2B9F /* _DCTImageCacheFetcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 242AFA46166BB78F00AC2B9F /* _DCTImageCacheFetcher.m */; };
2437B67815B97BA600750117 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F7CB42158A1B9D00B2E33E /* Foundation.framework */; };
2437B68315B97BCE00750117 /* DCTImageCache.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 24F7CB47158A1B9D00B2E33E /* DCTImageCache.h */; };
@@ -40,7 +47,6 @@
24F7CB52158A1B9D00B2E33E /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F7CB51158A1B9D00B2E33E /* SenTestingKit.framework */; };
24F7CB55158A1B9D00B2E33E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24F7CB42158A1B9D00B2E33E /* Foundation.framework */; };
24F7CB5E158A1B9D00B2E33E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 24F7CB5C158A1B9D00B2E33E /* InfoPlist.strings */; };
- 24F7CB61158A1B9D00B2E33E /* DCTImageCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 24F7CB60158A1B9D00B2E33E /* DCTImageCacheTests.m */; };
24FCFA96165FEAB3006208A7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24FCFA95165FEAB3006208A7 /* CoreFoundation.framework */; };
24FCFAA6165FEB25006208A7 /* DCTImageCache.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 24FCFAA4165FEB25006208A7 /* DCTImageCache.xcdatamodeld */; };
/* End PBXBuildFile section */
@@ -77,6 +83,10 @@
2406F97D1678B3A900428406 /* ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = "<group>"; };
24244607167509D200621FFF /* DCTImageCacheAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCTImageCacheAttributes.h; sourceTree = "<group>"; };
24244608167509D200621FFF /* DCTImageCacheAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DCTImageCacheAttributes.m; sourceTree = "<group>"; };
+ 242561641695DCAA0064D510 /* DCTImageCacheProcessTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCTImageCacheProcessTests.h; sourceTree = "<group>"; };
+ 242561651695DCAA0064D510 /* DCTImageCacheProcessTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DCTImageCacheProcessTests.m; sourceTree = "<group>"; };
+ 242561671695DD180064D510 /* DCTImageCacheMockCancel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCTImageCacheMockCancel.h; sourceTree = "<group>"; };
+ 242561681695DD180064D510 /* DCTImageCacheMockCancel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DCTImageCacheMockCancel.m; sourceTree = "<group>"; };
242AFA45166BB78F00AC2B9F /* _DCTImageCacheFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _DCTImageCacheFetcher.h; sourceTree = "<group>"; };
242AFA46166BB78F00AC2B9F /* _DCTImageCacheFetcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _DCTImageCacheFetcher.m; sourceTree = "<group>"; };
2433AA9A1674D57700D76DCF /* _DCTImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _DCTImageCache.h; sourceTree = "<group>"; };
@@ -117,8 +127,6 @@
24F7CB51158A1B9D00B2E33E /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
24F7CB5B158A1B9D00B2E33E /* DCTImageCacheTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DCTImageCacheTests-Info.plist"; sourceTree = "<group>"; };
24F7CB5D158A1B9D00B2E33E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
- 24F7CB5F158A1B9D00B2E33E /* DCTImageCacheTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DCTImageCacheTests.h; sourceTree = "<group>"; };
- 24F7CB60158A1B9D00B2E33E /* DCTImageCacheTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DCTImageCacheTests.m; sourceTree = "<group>"; };
24FCFA94165FEAB3006208A7 /* DCTImageCache.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DCTImageCache.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
24FCFA95165FEAB3006208A7 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
24FCFA99165FEAB3006208A7 /* DCTImageCacheBundle-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DCTImageCacheBundle-Info.plist"; sourceTree = "<group>"; };
@@ -152,7 +160,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 242561361695D6AA0064D510 /* UIKit.framework in Frameworks */,
+ 242560F91695D4220064D510 /* libDCTImageCache.a in Frameworks */,
24F7CB52158A1B9D00B2E33E /* SenTestingKit.framework in Frameworks */,
+ 242561371695D6AF0064D510 /* CoreGraphics.framework in Frameworks */,
+ 242561381695D6B20064D510 /* CoreData.framework in Frameworks */,
24F7CB55158A1B9D00B2E33E /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -266,8 +278,10 @@
24F7CB59158A1B9D00B2E33E /* DCTImageCacheTests */ = {
isa = PBXGroup;
children = (
- 24F7CB5F158A1B9D00B2E33E /* DCTImageCacheTests.h */,
- 24F7CB60158A1B9D00B2E33E /* DCTImageCacheTests.m */,
+ 242561671695DD180064D510 /* DCTImageCacheMockCancel.h */,
+ 242561681695DD180064D510 /* DCTImageCacheMockCancel.m */,
+ 242561641695DCAA0064D510 /* DCTImageCacheProcessTests.h */,
+ 242561651695DCAA0064D510 /* DCTImageCacheProcessTests.m */,
24F7CB5A158A1B9D00B2E33E /* Supporting Files */,
);
path = DCTImageCacheTests;
@@ -418,6 +432,7 @@
buildActionMask = 2147483647;
files = (
24F7CB5E158A1B9D00B2E33E /* InfoPlist.strings in Resources */,
+ 242560FB1695D43A0064D510 /* DCTImageCache.bundle in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -481,7 +496,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 24F7CB61158A1B9D00B2E33E /* DCTImageCacheTests.m in Sources */,
+ 242561661695DCAA0064D510 /* DCTImageCacheProcessTests.m in Sources */,
+ 242561691695DD180064D510 /* DCTImageCacheMockCancel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -634,7 +650,6 @@
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = "DCTImageCache/DCTImageCache-Prefix.pch";
INFOPLIST_FILE = "DCTImageCacheTests/DCTImageCacheTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = octest;
@@ -649,7 +664,6 @@
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = "DCTImageCache/DCTImageCache-Prefix.pch";
INFOPLIST_FILE = "DCTImageCacheTests/DCTImageCacheTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = octest;
@@ -0,0 +1,14 @@
+//
+// DCTImageCacheMockCancel.h
+// DCTImageCache
+//
+// Created by Daniel Tull on 03.01.2013.
+// Copyright (c) 2013 Daniel Tull. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "DCTImageCache.h"
+
+@interface DCTImageCacheMockCancel : NSObject <DCTImageCacheProcess>
+@property (nonatomic, copy) void (^cancellationBlock)();
+@end
@@ -0,0 +1,15 @@
+//
+// DCTImageCacheMockCancel.m
+// DCTImageCache
+//
+// Created by Daniel Tull on 03.01.2013.
+// Copyright (c) 2013 Daniel Tull. All rights reserved.
+//
+
+#import "DCTImageCacheMockCancel.h"
+
+@implementation DCTImageCacheMockCancel
+- (void)cancel {
+ self.cancellationBlock();
+}
+@end
@@ -0,0 +1,13 @@
+//
+// DCTImageCacheProcessTests.h
+// DCTImageCache
+//
+// Created by Daniel Tull on 03.01.2013.
+// Copyright (c) 2013 Daniel Tull. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface DCTImageCacheProcessTests : SenTestCase
+
+@end
@@ -0,0 +1,141 @@
+//
+// DCTImageCacheProcessTests.m
+// DCTImageCache
+//
+// Created by Daniel Tull on 03.01.2013.
+// Copyright (c) 2013 Daniel Tull. All rights reserved.
+//
+
+#import "DCTImageCacheProcessTests.h"
+#import "DCTImageCacheMockCancel.h"
+#import "_DCTImageCacheProcessManager.h"
+
+@implementation DCTImageCacheProcessTests
+
+- (void)testCancel {
+
+ __block BOOL cancelled = NO;
+
+ DCTImageCacheMockCancel *process = [DCTImageCacheMockCancel new];
+ process.cancellationBlock = ^{
+ cancelled = YES;
+ };
+
+ _DCTImageCacheProcessManager *manager = [_DCTImageCacheProcessManager new];
+ manager.process = process;
+
+ _DCTImageCacheCancelProxy *proxy = [_DCTImageCacheCancelProxy new];
+ [manager addCancelProxy:proxy];
+
+ [proxy cancel];
+
+ STAssertTrue(cancelled, @"Process should have been cancelled.");
+}
+
+- (void)testTwoCancel {
+
+ __block BOOL cancelled = NO;
+
+ DCTImageCacheMockCancel *process = [DCTImageCacheMockCancel new];
+ process.cancellationBlock = ^{
+ cancelled = YES;
+ };
+
+ _DCTImageCacheProcessManager *manager = [_DCTImageCacheProcessManager new];
+ manager.process = process;
+
+ _DCTImageCacheCancelProxy *proxy = [_DCTImageCacheCancelProxy new];
+ [manager addCancelProxy:proxy];
+
+ _DCTImageCacheCancelProxy *proxy2 = [_DCTImageCacheCancelProxy new];
+ [manager addCancelProxy:proxy2];
+
+ STAssertFalse(cancelled, @"Process should not have been cancelled.");
+
+ [proxy cancel];
+
+ STAssertFalse(cancelled, @"Process should not have been cancelled.");
+
+ [proxy2 cancel];
+
+ STAssertTrue(cancelled, @"Process should have been cancelled.");
+}
+
+- (void)testTwoProcessCancel {
+
+ __block BOOL process1Cancelled = NO;
+ __block BOOL process2Cancelled = NO;
+
+ DCTImageCacheMockCancel *process1 = [DCTImageCacheMockCancel new];
+ process1.cancellationBlock = ^{
+ process1Cancelled = YES;
+ };
+
+ DCTImageCacheMockCancel *process2 = [DCTImageCacheMockCancel new];
+ process2.cancellationBlock = ^{
+ process2Cancelled = YES;
+ };
+
+ _DCTImageCacheProcessManager *manager1 = [_DCTImageCacheProcessManager new];
+ manager1.process = process1;
+
+ _DCTImageCacheProcessManager *manager2 = [_DCTImageCacheProcessManager new];
+ manager2.process = process2;
+
+ _DCTImageCacheCancelProxy *proxy = [_DCTImageCacheCancelProxy new];
+ [manager1 addCancelProxy:proxy];
+ [manager2 addCancelProxy:proxy];
+
+ STAssertFalse(process1Cancelled, @"Process 1 should not have been cancelled.");
+ STAssertFalse(process2Cancelled, @"Process 2 should not have been cancelled.");
+
+ [proxy cancel];
+
+ STAssertTrue(process1Cancelled, @"Process 1 should have been cancelled.");
+ STAssertTrue(process2Cancelled, @"Process 2 should have been cancelled.");
+}
+
+- (void)testTwoProcessTwoCancel {
+
+ __block BOOL process1Cancelled = NO;
+ __block BOOL process2Cancelled = NO;
+
+ DCTImageCacheMockCancel *process1 = [DCTImageCacheMockCancel new];
+ process1.cancellationBlock = ^{
+ process1Cancelled = YES;
+ };
+
+ DCTImageCacheMockCancel *process2 = [DCTImageCacheMockCancel new];
+ process2.cancellationBlock = ^{
+ process2Cancelled = YES;
+ };
+
+ _DCTImageCacheProcessManager *manager1 = [_DCTImageCacheProcessManager new];
+ manager1.process = process1;
+
+ _DCTImageCacheProcessManager *manager2 = [_DCTImageCacheProcessManager new];
+ manager2.process = process2;
+
+ _DCTImageCacheCancelProxy *proxy = [_DCTImageCacheCancelProxy new];
+ [manager1 addCancelProxy:proxy];
+ [manager2 addCancelProxy:proxy];
+
+ _DCTImageCacheCancelProxy *proxy2 = [_DCTImageCacheCancelProxy new];
+ [manager1 addCancelProxy:proxy2];
+ [manager2 addCancelProxy:proxy2];
+
+ STAssertFalse(process1Cancelled, @"Process 1 should not have been cancelled.");
+ STAssertFalse(process2Cancelled, @"Process 2 should not have been cancelled.");
+
+ [proxy cancel];
+
+ STAssertFalse(process1Cancelled, @"Process 1 should not have been cancelled.");
+ STAssertFalse(process2Cancelled, @"Process 2 should not have been cancelled.");
+
+ [proxy2 cancel];
+
+ STAssertTrue(process1Cancelled, @"Process 1 should have been cancelled.");
+ STAssertTrue(process2Cancelled, @"Process 2 should have been cancelled.");
+}
+
+@end
@@ -1,13 +0,0 @@
-//
-// DCTImageCacheTests.h
-// DCTImageCacheTests
-//
-// Created by Daniel Tull on 14.06.2012.
-// Copyright (c) 2012 Daniel Tull. All rights reserved.
-//
-
-#import <SenTestingKit/SenTestingKit.h>
-
-@interface DCTImageCacheTests : SenTestCase
-
-@end
@@ -1,32 +0,0 @@
-//
-// DCTImageCacheTests.m
-// DCTImageCacheTests
-//
-// Created by Daniel Tull on 14.06.2012.
-// Copyright (c) 2012 Daniel Tull. All rights reserved.
-//
-
-#import "DCTImageCacheTests.h"
-
-@implementation DCTImageCacheTests
-
-- (void)setUp
-{
- [super setUp];
-
- // Set-up code here.
-}
-
-- (void)tearDown
-{
- // Tear-down code here.
-
- [super tearDown];
-}
-
-- (void)testExample
-{
- STFail(@"Unit tests are not implemented yet in DCTImageCacheTests");
-}
-
-@end

0 comments on commit 5b5245a

Please sign in to comment.