1 //---------------------------------------------------------------------------------------
3 // Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
6 #import <OCMock/OCMConstraint.h>
9 @implementation OCMConstraint
13 return [[[self alloc] init] autorelease];
16 - (BOOL)evaluate:(id)value
21 - (id)copyWithZone:(NSZone *)zone
26 + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject
28 OCMInvocationConstraint *constraint = [OCMInvocationConstraint constraint];
29 NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector];
31 [NSException raise:NSInvalidArgumentException format:@"Unkown selector %@ used in constraint.", NSStringFromSelector(aSelector)];
32 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
33 [invocation setTarget:anObject];
34 [invocation setSelector:aSelector];
35 constraint->invocation = invocation;
39 + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue
41 OCMInvocationConstraint *constraint = [self constraintWithSelector:aSelector onObject:anObject];
42 if([[constraint->invocation methodSignature] numberOfArguments] < 4)
43 [NSException raise:NSInvalidArgumentException format:@"Constraint with value requires selector with two arguments."];
44 [constraint->invocation setArgument:&aValue atIndex:3];
55 @implementation OCMAnyConstraint
57 - (BOOL)evaluate:(id)value
68 @implementation OCMIsNilConstraint
70 - (BOOL)evaluate:(id)value
81 @implementation OCMIsNotNilConstraint
83 - (BOOL)evaluate:(id)value
94 @implementation OCMIsNotEqualConstraint
96 - (BOOL)evaluate:(id)value
98 return ![value isEqual:testValue];
107 @implementation OCMInvocationConstraint
109 - (BOOL)evaluate:(id)value
111 [invocation setArgument:&value atIndex:2]; // should test if constraint takes arg
114 [invocation getReturnValue:&returnValue];
122 #if NS_BLOCKS_AVAILABLE
124 @implementation OCMBlockConstraint
126 - (id)initWithConstraintBlock:(BOOL (^)(id))aBlock;
133 - (BOOL)evaluate:(id)value