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
22 + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject
24 OCMInvocationConstraint *constraint = [OCMInvocationConstraint constraint];
25 NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector];
27 [NSException raise:NSInvalidArgumentException format:@"Unkown selector %@ used in constraint.", NSStringFromSelector(aSelector)];
28 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
29 [invocation setTarget:anObject];
30 [invocation setSelector:aSelector];
31 constraint->invocation = invocation;
35 + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue
37 OCMInvocationConstraint *constraint = [self constraintWithSelector:aSelector onObject:anObject];
38 if([[constraint->invocation methodSignature] numberOfArguments] < 4)
39 [NSException raise:NSInvalidArgumentException format:@"Constraint with value requires selector with two arguments."];
40 [constraint->invocation setArgument:&aValue atIndex:3];
51 @implementation OCMAnyConstraint
53 - (BOOL)evaluate:(id)value
64 @implementation OCMIsNilConstraint
66 - (BOOL)evaluate:(id)value
77 @implementation OCMIsNotNilConstraint
79 - (BOOL)evaluate:(id)value
90 @implementation OCMIsNotEqualConstraint
92 - (BOOL)evaluate:(id)value
94 return ![value isEqual:testValue];
103 @implementation OCMInvocationConstraint
105 - (BOOL)evaluate:(id)value
107 [invocation setArgument:&value atIndex:2]; // should test if constraint takes arg
110 [invocation getReturnValue:&returnValue];
118 #if NS_BLOCKS_AVAILABLE
120 @implementation OCMBlockConstraint
122 - (id)initWithConstraintBlock:(BOOL (^)(id))aBlock;
129 - (BOOL)evaluate:(id)value