Skip to content

Commit

Permalink
Updated OCMock framework and added a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Mar 16, 2015
1 parent f86e21e commit 0dc8d02
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 78 deletions.
@@ -1,15 +1,26 @@
//---------------------------------------------------------------------------------------
// $Id: NSNotificationCenter+OCMAdditions.h$
// Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------
/*
* Copyright (c) 2009-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

@class OCMockObserver;
@class OCObserverMockObject;


@interface NSNotificationCenter(OCMAdditions)

- (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender;
- (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender;

@end
33 changes: 28 additions & 5 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMArg.h
@@ -1,7 +1,18 @@
//---------------------------------------------------------------------------------------
// $Id$
// Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------
/*
* Copyright (c) 2009-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

Expand All @@ -10,15 +21,21 @@
// constraining arguments

+ (id)any;
+ (SEL)anySelector;
+ (void *)anyPointer;
+ (id __autoreleasing *)anyObjectRef;
+ (id)isNil;
+ (id)isNotNil;
+ (id)isEqual:(id)value;
+ (id)isNotEqual:(id)value;
+ (id)isKindOfClass:(Class)cls;
+ (id)checkWithSelector:(SEL)selector onObject:(id)anObject;
+ (id)checkWithBlock:(BOOL (^)(id obj))block;

// manipulating arguments

+ (id *)setTo:(id)value;
+ (void *)setToValue:(NSValue *)value;

// internal use only

Expand All @@ -27,4 +44,10 @@
@end

#define OCMOCK_ANY [OCMArg any]
#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(typeof(variable))]

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define OCMOCK_VALUE(variable) \
({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; })
#else
#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))]
#endif
39 changes: 31 additions & 8 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMConstraint.h
@@ -1,21 +1,34 @@
//---------------------------------------------------------------------------------------
// $Id$
// Copyright (c) 2007-2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------
/*
* Copyright (c) 2007-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>


@interface OCMConstraint : NSObject

+ (id)constraint;
+ (instancetype)constraint;
- (BOOL)evaluate:(id)value;

// if you are looking for any, isNil, etc, they have moved to OCMArg

+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject;
+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue;
// try to use [OCMArg checkWith...] instead of the constraintWith... methods below

+ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject;
+ (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue;

// try to use [OCMArg checkWith...] instead of constraintWithSelector in here

@end

Expand Down Expand Up @@ -44,5 +57,15 @@

@end

@interface OCMBlockConstraint : OCMConstraint
{
BOOL (^block)(id);
}

- (instancetype)initWithConstraintBlock:(BOOL (^)(id))block;

@end


#define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self]
#define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)]
36 changes: 36 additions & 0 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMLocation.h
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

@interface OCMLocation : NSObject
{
id testCase;
NSString *file;
NSUInteger line;
}

+ (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine;

- (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine;

- (id)testCase;
- (NSString *)file;
- (NSUInteger)line;

@end

extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line);
45 changes: 45 additions & 0 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMMacroState.h
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

@class OCMLocation;
@class OCMRecorder;
@class OCMStubRecorder;
@class OCMockObject;


@interface OCMMacroState : NSObject
{
OCMRecorder *recorder;
}

+ (void)beginStubMacro;
+ (OCMStubRecorder *)endStubMacro;

+ (void)beginExpectMacro;
+ (OCMStubRecorder *)endExpectMacro;

+ (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation;
+ (void)endVerifyMacro;

+ (OCMMacroState *)globalState;

- (OCMRecorder *)recorder;

- (void)switchToClassMethod;

@end
39 changes: 39 additions & 0 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMRecorder.h
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

@class OCMockObject;
@class OCMInvocationMatcher;


@interface OCMRecorder : NSProxy
{
OCMockObject *mockObject;
OCMInvocationMatcher *invocationMatcher;
}

- (instancetype)init;
- (instancetype)initWithMockObject:(OCMockObject *)aMockObject;

- (void)setMockObject:(OCMockObject *)aMockObject;

- (OCMInvocationMatcher *)invocationMatcher;

- (id)classMethod;
- (id)ignoringNonObjectArgs;

@end
56 changes: 56 additions & 0 deletions Frameworks/OCMock.framework/Versions/A/Headers/OCMStubRecorder.h
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2004-2014 Erik Doernenburg and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use these files except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#import "OCMRecorder.h"


@interface OCMStubRecorder : OCMRecorder

- (id)andReturn:(id)anObject;
- (id)andReturnValue:(NSValue *)aValue;
- (id)andThrow:(NSException *)anException;
- (id)andPost:(NSNotification *)aNotification;
- (id)andCall:(SEL)selector onObject:(id)anObject;
- (id)andDo:(void (^)(NSInvocation *invocation))block;
- (id)andForwardToRealObject;

@end


@interface OCMStubRecorder (Properties)

#define andReturn(aValue) _andReturn(({ __typeof__(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(__typeof__(_v))]; }))
@property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *);

#define andThrow(anException) _andThrow(anException)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *);

#define andPost(aNotification) _andPost(aNotification)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *);

#define andCall(anObject, aSelector) _andCall(anObject, aSelector)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL);

#define andDo(aBlock) _andDo(aBlock)
@property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *));

#define andForwardToRealObject() _andForwardToRealObject()
@property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void);

@end



0 comments on commit 0dc8d02

Please sign in to comment.