Skip to content
Browse files

Removed Core

  • Loading branch information...
1 parent baffaa4 commit 0e7006c972e942e9fe075878629a3806802c24fd @cneuwirt committed Feb 9, 2014
View
26 Miruken.xcodeproj/project.pbxproj
@@ -35,9 +35,11 @@
14FD8AB718A7DBF7008077CF /* MKThreadDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AA118A7DBF7008077CF /* MKThreadDelegate.m */; };
14FD8AB818A7DBF7008077CF /* NSObject+Concurrency.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AA318A7DBF7008077CF /* NSObject+Concurrency.m */; };
14FD8AB918A7DBF7008077CF /* NSObject+Promise.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AA518A7DBF7008077CF /* NSObject+Promise.m */; };
- 14FD8AC018A7E213008077CF /* NSInvocation+Objects.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8ABF18A7E213008077CF /* NSInvocation+Objects.m */; };
14FD8AD318A7E494008077CF /* MKBufferedPromiseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AD218A7E494008077CF /* MKBufferedPromiseTests.m */; };
14FD8AD518A7E615008077CF /* MKDeferredTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AD418A7E615008077CF /* MKDeferredTests.m */; };
+ 14FD8AD818A7E867008077CF /* NSInvocation+Objects.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AD718A7E867008077CF /* NSInvocation+Objects.m */; };
+ 14FD8AD918A7E867008077CF /* NSInvocation+Objects.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8AD718A7E867008077CF /* NSInvocation+Objects.m */; };
+ 14FD8ADB18A7E88B008077CF /* MKConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 14FD8ADA18A7E88B008077CF /* MKConcurrencyTests.m */; };
EB1E2B388199486D8C25AAF8 /* libPods-Miruken.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C07D65B5617417FA5C12730 /* libPods-Miruken.a */; };
/* End PBXBuildFile section */
@@ -117,11 +119,12 @@
14FD8AA318A7DBF7008077CF /* NSObject+Concurrency.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Concurrency.m"; sourceTree = "<group>"; };
14FD8AA418A7DBF7008077CF /* NSObject+Promise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+Promise.h"; sourceTree = "<group>"; };
14FD8AA518A7DBF7008077CF /* NSObject+Promise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Promise.m"; sourceTree = "<group>"; };
- 14FD8ABE18A7E213008077CF /* NSInvocation+Objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSInvocation+Objects.h"; sourceTree = "<group>"; };
- 14FD8ABF18A7E213008077CF /* NSInvocation+Objects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+Objects.m"; sourceTree = "<group>"; };
14FD8AC118A7E2F7008077CF /* Concurrency.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Concurrency.h; sourceTree = "<group>"; };
14FD8AD218A7E494008077CF /* MKBufferedPromiseTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKBufferedPromiseTests.m; sourceTree = "<group>"; };
14FD8AD418A7E615008077CF /* MKDeferredTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKDeferredTests.m; sourceTree = "<group>"; };
+ 14FD8AD618A7E867008077CF /* NSInvocation+Objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSInvocation+Objects.h"; sourceTree = "<group>"; };
+ 14FD8AD718A7E867008077CF /* NSInvocation+Objects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+Objects.m"; sourceTree = "<group>"; };
+ 14FD8ADA18A7E88B008077CF /* MKConcurrencyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKConcurrencyTests.m; sourceTree = "<group>"; };
483F78DE848A48A69E26E684 /* Pods-Miruken.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Miruken.xcconfig"; path = "Pods/Pods-Miruken.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -185,7 +188,8 @@
children = (
14FD8A5A18A7CB18008077CF /* Miruken.h */,
14FD8A5C18A7CB18008077CF /* Miruken.m */,
- 14FD8ABD18A7E1CF008077CF /* Core */,
+ 14FD8AD618A7E867008077CF /* NSInvocation+Objects.h */,
+ 14FD8AD718A7E867008077CF /* NSInvocation+Objects.m */,
14FD8A7B18A7DBF7008077CF /* Concurrency */,
14FD8A5818A7CB18008077CF /* Supporting Files */,
);
@@ -267,19 +271,11 @@
path = Concurrency;
sourceTree = "<group>";
};
- 14FD8ABD18A7E1CF008077CF /* Core */ = {
- isa = PBXGroup;
- children = (
- 14FD8ABE18A7E213008077CF /* NSInvocation+Objects.h */,
- 14FD8ABF18A7E213008077CF /* NSInvocation+Objects.m */,
- );
- path = Core;
- sourceTree = "<group>";
- };
14FD8AD118A7E476008077CF /* Concurrency */ = {
isa = PBXGroup;
children = (
14FD8AD218A7E494008077CF /* MKBufferedPromiseTests.m */,
+ 14FD8ADA18A7E88B008077CF /* MKConcurrencyTests.m */,
14FD8AD418A7E615008077CF /* MKDeferredTests.m */,
);
path = Concurrency;
@@ -412,7 +408,7 @@
14FD8AB018A7DBF7008077CF /* MKMainThreadDelegate.m in Sources */,
14FD8AA718A7DBF7008077CF /* MKAsyncDelegate.m in Sources */,
14FD8AB718A7DBF7008077CF /* MKThreadDelegate.m in Sources */,
- 14FD8AC018A7E213008077CF /* NSInvocation+Objects.m in Sources */,
+ 14FD8AD818A7E867008077CF /* NSInvocation+Objects.m in Sources */,
14FD8AAE18A7DBF7008077CF /* MKDelayedDelegate.m in Sources */,
14FD8AB318A7DBF7008077CF /* MKOperationQueueDelegate.m in Sources */,
14FD8A5D18A7CB18008077CF /* Miruken.m in Sources */,
@@ -430,6 +426,8 @@
buildActionMask = 2147483647;
files = (
14FD8AD318A7E494008077CF /* MKBufferedPromiseTests.m in Sources */,
+ 14FD8AD918A7E867008077CF /* NSInvocation+Objects.m in Sources */,
+ 14FD8ADB18A7E88B008077CF /* MKConcurrencyTests.m in Sources */,
14FD8A7218A7CB18008077CF /* MirukenTests.m in Sources */,
14FD8AD518A7E615008077CF /* MKDeferredTests.m in Sources */,
);
View
0 Miruken/Core/NSInvocation+Objects.h → Miruken/NSInvocation+Objects.h
File renamed without changes.
View
0 Miruken/Core/NSInvocation+Objects.m → Miruken/NSInvocation+Objects.m
File renamed without changes.
View
236 MirukenTests/Concurrency/MKConcurrencyTests.m
@@ -0,0 +1,236 @@
+//
+// MKConcurrencyTests.m
+// Miruken
+//
+// Created by Craig Neuwirt on 2/9/14.
+// Copyright (c) 2014 Craig Neuwirt. All rights reserved.
+//
+
+#import <XCTest/XCTest.h>
+#import "Concurrency.h"
+
+@interface Calculator : NSObject
+
+- (NSNumber *)isOnMainThread;
+
+- (int)addSimple:(int)operand to:(int)to;
+
+- (NSNumber *)add:(int)operand to:(int)to;
+
+- (NSNumber *)divide:(double)operand by:(double)by;
+
+- (void)clear;
+
+@end
+
+@implementation Calculator
+
+- (void)clear
+{
+}
+
+- (NSNumber *)isOnMainThread
+{
+ return @([NSThread isMainThread]);
+}
+
+- (int)addSimple:(int)operand to:(int)to
+{
+ return operand + to;
+}
+
+- (NSNumber *)add:(int)operand to:(int)to
+{
+ [NSThread sleepForTimeInterval:1];
+ return @(operand + to);
+}
+
+- (NSNumber *)divide:(double)operand by:(double)by
+{
+ if (by == 0)
+ @throw [NSException exceptionWithName:NSInvalidArgumentException
+ reason:@"cannot divide by 0"
+ userInfo:nil];
+
+ return [NSNumber numberWithDouble:(operand / by)];
+}
+
+@end
+
+#pragma mark - TestAsyncDelegate
+
+@interface TestAsyncDelegate : MKAsyncDelegate
+
+@property (strong, nonatomic) id<MKAsyncResult> asyncResult;
+
+@end
+
+@implementation TestAsyncDelegate
+
+- (void)completeResult:(id<MKAsyncResult>)asyncResult
+{
+ _asyncResult = asyncResult;
+ [super completeResult:asyncResult];
+}
+
+@end
+@interface MKConcurrencyTests : XCTestCase
+
+@end
+
+@implementation MKConcurrencyTests
+
+- (void)testCanPerformInvocationsOnNewThreadWithNoResult
+{
+ Calculator *calculator = [[Calculator new] inNewThread];
+ [calculator clear];
+}
+
+- (void)testCanPerformInvocationsOnQueueWithNoResult
+{
+ NSOperationQueue *queue = [NSOperationQueue new];
+ Calculator *calculator = [[Calculator new] onQueue:queue];
+ [calculator clear];
+}
+
+- (void)testCanDispatchInvocationsOnQueueWithNoResult
+{
+ Calculator *calculator = [[Calculator new] dispatchGlobal];
+ [calculator clear];
+}
+
+- (void)testCanPerformInvocationsUsingCustomStrategyWithNoResult
+{
+ TestAsyncDelegate *testStrategy = [TestAsyncDelegate new];
+ Calculator *calculator = [[Calculator new] concurrent:testStrategy];
+ [calculator clear];
+ XCTAssertNotNil(testStrategy.asyncResult, @"AsyncResult is nil");
+}
+
+- (void)testCanPerformInvocationsOnNewThread
+{
+ Calculator *calculator = [Calculator new];
+ XCTAssertTrue([[calculator isOnMainThread] boolValue], @"Calculation should be on main thread");
+ XCTAssertFalse([[[calculator inNewThread] isOnMainThread] boolValue], @"Calculation should not be on main thread");
+}
+
+- (void)testWillReturnProxyValueForObjects
+{
+ Calculator *calculator = [[Calculator new] inNewThread];
+ NSNumber *sum = [calculator add:5 to:6];
+ XCTAssertEqual(11, [sum intValue], @"Sum should be 11");
+}
+
+- (void)testCanPerformInvocationsOnOperationQueue
+{
+ NSOperationQueue *queue = [NSOperationQueue new];
+ Calculator *calculator = [[Calculator new] onQueue:queue];
+ NSNumber *sum = [calculator add:5 to:6];
+ XCTAssertEqual(11, [sum intValue], @"Sum should be 11");
+}
+
+- (void)testCanDispatchInvocationsOnQueue
+{
+ Calculator *calculator = [[Calculator new] dispatchGlobal];
+ NSNumber *sum = [calculator add:5 to:6];
+ XCTAssertEqual(11, [sum intValue], @"Sum should be 11");
+}
+
+- (void)testCanPerformInvocationsOnImplicitQueue
+{
+ Calculator *calculator = [[Calculator new] queued];
+ NSNumber *sum = [calculator add:5 to:6];
+ XCTAssertEqual(11, [sum intValue], @"Sum should be 11");
+}
+
+- (void)testWillPropogateExceptionsFromNewThread
+{
+ Calculator *calculator = [[Calculator new] inNewThread];
+ XCTAssertThrows([[calculator divide:10 by:0] doubleValue], @"Expected division by 0 exception");
+}
+
+- (void)testWillPropogateExceptionsFromOperationQueue
+{
+ NSOperationQueue *queue = [NSOperationQueue new];
+ Calculator *calculator = [[Calculator new] onQueue:queue];
+ XCTAssertThrows([[calculator divide:10 by:0] doubleValue], @"Expected division by 0 exception");
+}
+
+- (void)testWillPropogateExceptionsFromDispatchQueue
+{
+ Calculator *calculator = [[Calculator new] dispatchGlobal];
+ XCTAssertThrows([[calculator divide:10 by:0] doubleValue], @"Expected division by 0 exception");
+}
+
+- (void)testCanGetAsyncResultForInvocaion
+{
+ __autoreleasing id<MKAsyncResult> asyncResult;
+ [[(id<MKAsyncObject>)[[Calculator new] inNewThread] outAsyncResult:&asyncResult] addSimple:5 to:6];
+ XCTAssertNotNil(asyncResult, @"AsyncResult nil");
+ int sum;
+ [asyncResult.result getValue:&sum];
+ XCTAssertEqual(11, sum, @"Sum should be 11");
+}
+
+- (void)testWillGetNotifiedWhenInvocationComplete
+{
+ __autoreleasing id<MKAsyncResult> asyncResult;
+ [[(id<MKAsyncObject>)[[Calculator new] inNewThread] outAsyncResult:&asyncResult] addSimple:5 to:6];
+ [[asyncResult promise] done:^(NSValue *result) {
+ int sum;
+ [result getValue:&sum];
+ XCTAssertEqual(11, sum, @"Sum should be 11");
+ }];
+ XCTAssertNotNil(asyncResult, @"AsyncResult nil");
+}
+
+- (void)testCanExecuteBlockOnNewThread
+{
+ Calculator *calculator = [Calculator new];
+
+ [[MKAction inNewThread] do:^{
+ XCTAssertFalse([[calculator isOnMainThread] boolValue], @"Calculation should not be on main thread");
+ }];
+}
+
+- (void)testCanExecuteBlockOnOperationQueue
+{
+ NSOperationQueue *queue = [NSOperationQueue new];
+
+ [[MKAction onQueue:queue] do:^{
+ XCTAssertEqual(queue, [NSOperationQueue currentQueue], @"Block not executed on right queue");
+ }];
+}
+
+- (void)testCanExecuteBlockOnDispatchQueue
+{
+ [[MKAction dispatchGlobal] do:^{
+ XCTAssertFalse([NSThread isMainThread], @"Block not executed on right queue");
+ }];
+}
+
+- (void)testCanExecuteBlockUsingCustomStartegy
+{
+ TestAsyncDelegate *testStrategy = [TestAsyncDelegate new];
+
+ [[MKAction concurrent:testStrategy] do:^{
+ // Nothing
+ }];
+
+ XCTAssertNotNil(testStrategy.asyncResult, @"AsyncResult is nil");
+}
+
+- (void)testCanNestInvocationsWithDifferentConcurrencyStrategues
+{
+ MKAction *action = [MKAction new];
+ NSOperationQueue *queue = [NSOperationQueue new];
+
+ [[action onQueue:queue] do:^{
+ XCTAssertEqual(queue, [NSOperationQueue currentQueue], @"Block not executed on right queue");
+ [[action onMainThread] do:^{
+ XCTAssertTrue([NSThread isMainThread], @"Block not exectued on main thread");
+ }];
+ }];
+}
+
+@end

0 comments on commit 0e7006c

Please sign in to comment.
Something went wrong with that request. Please try again.