Permalink
Browse files

A full complement of unit tests.

Signed-off-by: Zachary Waldowski <zwaldowski@gmail.com>
  • Loading branch information...
1 parent 59055c7 commit e6e6bd6f2e1b5637c6dec2bf234713197c078fcd @zwaldowski zwaldowski committed Jun 5, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -41,7 +41,7 @@
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0440"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "6C10426D157E7158001AF708"
+ BuildableName = "A2DD iOS Tests.octest"
+ BlueprintName = "iOS Tests"
+ ReferencedContainer = "container:A2DynamicDelegate.xcodeproj">
+ </BuildableReference>
+ </TestableReference>
+ </Testables>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
@@ -0,0 +1,18 @@
+//
+// A2BlockClosureTests.h
+// A2DynamicDelegate
+//
+// Created by Zachary Waldowski on 6/5/12.
+// Copyright (c) 2012 Pandamonia LLC. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface A2BlockClosureTests : SenTestCase
+
+- (void)testBlock;
+- (void)testBlockWithArguments;
+- (void)testFunctionInterface;
+- (void)testFunctionInterfaceWithArguments;
+
+@end
@@ -0,0 +1,70 @@
+//
+// A2BlockClosureTests.m
+// A2DynamicDelegate
+//
+// Created by Zachary Waldowski on 6/5/12.
+// Copyright (c) 2012 Pandamonia LLC. All rights reserved.
+//
+
+#import "A2BlockClosureTests.h"
+#import "A2BlockClosure.h"
+
+@implementation A2BlockClosureTests
+
+- (void)testBlock
+{
+ BOOL(^block)(void) = ^BOOL{
+ return YES;
+ };
+ NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:"c@:"];
+ A2BlockClosure *closure = [[A2BlockClosure alloc] initWithBlock: block methodSignature: signature];
+ STAssertNotNil(closure, @"Could not init closure");
+ STAssertNotNil(closure.block, @"Closure couldn't get block");
+ BOOL(^blockPull)(void) = closure.block;
+ BOOL result = blockPull();
+ STAssertTrue(result, @"Block not run");
+}
+
+- (void)testBlockWithArguments
+{
+ BOOL(^block)(int, NSString *) = ^BOOL(int val, NSString *str){
+ return (val == 42 && [str isEqualToString:@"Test"]);
+ };
+ NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:"c@:i@"];
+ A2BlockClosure *closure = [[A2BlockClosure alloc] initWithBlock: block methodSignature: signature];
+ STAssertNotNil(closure, @"Could not init closure");
+ STAssertNotNil(closure.block, @"Closure couldn't get block");
+ BOOL(^blockPull)(int, NSString *) = closure.block;
+ BOOL result = blockPull(42, @"Test");
+ STAssertTrue(result, @"Block not run");
+}
+
+- (void)testFunctionInterface
+{
+ BOOL(^block)(void) = ^BOOL{
+ return YES;
+ };
+ NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:"c@:"];
+ A2BlockClosure *closure = [[A2BlockClosure alloc] initWithBlock: block methodSignature: signature];
+ STAssertNotNil(closure, @"Could not init closure");
+ STAssertNotNil(closure.functionPointer, @"Closure couldn't get function interface");
+ IMP interface = closure.functionPointer;
+ BOOL result = (BOOL)interface(self, NULL);
+ STAssertTrue(result, @"Block not run");
+}
+
+- (void)testFunctionInterfaceWithArguments
+{
+ BOOL(^block)(int, NSString *) = ^BOOL(int val, NSString *str){
+ return (val == 42 && [str isEqualToString:@"Test"]);
+ };
+ NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:"c@:i@"];
+ A2BlockClosure *closure = [[A2BlockClosure alloc] initWithBlock: block methodSignature: signature];
+ STAssertNotNil(closure, @"Could not init closure");
+ STAssertNotNil(closure.functionPointer, @"Closure couldn't get function interface");
+ IMP interface = closure.functionPointer;
+ BOOL result = (BOOL)interface(self, NULL, 42, @"Test");
+ STAssertTrue(result, @"Block not run");
+}
+
+@end
@@ -0,0 +1,170 @@
+//
+// A2BlockDelegateTests.h
+// A2DynamicDelegate
+//
+// Created by Zachary Waldowski on 6/5/12.
+// Copyright (c) 2012 Pandamonia LLC. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "A2DynamicDelegateTests.h"
+
+#pragma mark -
+
+@interface TestReturnObject (A2BlockDelegate)
+
+@property (nonatomic, copy) NSString *(^testReturnObjectBlock)(void);
+
+@end
+
+#pragma mark -
+
+@interface TestReturnStruct (A2BlockDelegate)
+
+@property (nonatomic, copy) MyStruct(^testReturnStructBlock)(void);
+
+@end
+
+#pragma mark -
+
+@interface TestPassObject (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithObjectBlock)(NSString *);
+
+@end
+
+#pragma mark -
+
+@interface TestPassChar (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithCharBlock)(char);
+
+@end
+
+#pragma mark -
+
+@interface TestPassUChar (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithUCharBlock)(unsigned char);
+
+@end
+
+#pragma mark -
+
+@interface TestPassShort (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithShortBlock)(short);
+
+@end
+
+#pragma mark -
+
+@interface TestPassUShort (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithUShortBlock)(unsigned short);
+
+@end
+
+#pragma mark -
+
+@interface TestPassInt (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithIntBlock)(int);
+
+@end
+
+#pragma mark -
+
+@interface TestPassUInt (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithUIntBlock)(unsigned int);
+
+@end
+
+#pragma mark -
+
+@interface TestPassLong (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithLongBlock)(long);
+
+@end
+
+#pragma mark -
+
+@interface TestPassULong (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithULongBlock)(unsigned long);
+
+@end
+
+#pragma mark -
+
+@interface TestPassLongLong (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithLongLongBlock)(long long);
+
+@end
+
+#pragma mark -
+
+@interface TestPassULongLong (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithULongLongBlock)(unsigned long long);
+
+@end
+
+#pragma mark -
+
+@interface TestPassFloat (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithFloatBlock)(float);
+
+@end
+
+#pragma mark -=
+
+@interface TestPassDouble (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithDoubleBlock)(double);
+
+@end
+
+#pragma mark -
+
+@interface TestPassArray (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithArrayBlock)(int []);
+
+@end
+
+#pragma mark -
+
+@interface TestPassStruct (A2BlockDelegate)
+
+@property (nonatomic, copy) BOOL(^testWithStructBlock)(MyStruct);
+
+@end
+
+#pragma mark -
+
+@interface A2BlockDelegateTests : SenTestCase
+
+- (void)testReturnObject;
+- (void)testReturnStruct;
+- (void)testPassObject;
+- (void)testPassChar;
+- (void)testPassUChar;
+- (void)testPassShort;
+- (void)testPassUShort;
+- (void)testPassInt;
+- (void)testPassUInt;
+- (void)testPassLong;
+- (void)testPassULong;
+- (void)testPassLongLong;
+- (void)testPassULongLong;
+- (void)testPassFloat;
+- (void)testPassDouble;
+- (void)testPassArray;
+- (void)testPassStruct;
+
+@end
Oops, something went wrong.

0 comments on commit e6e6bd6

Please sign in to comment.