Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / third_party / ocmock / OCMock / OCMConstraint.m
blobb4535a4e1f3a26dccd3b0492f0ed080d8f96a9b0
1 //---------------------------------------------------------------------------------------
2 //  $Id$
3 //  Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
6 #import <OCMock/OCMConstraint.h>
9 @implementation OCMConstraint
11 + (id)constraint
13         return [[[self alloc] init] autorelease];
16 - (BOOL)evaluate:(id)value
18         return NO;
21 - (id)copyWithZone:(NSZone *)zone
23         return [self retain];
26 + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject
28         OCMInvocationConstraint *constraint = [OCMInvocationConstraint constraint];
29         NSMethodSignature *signature = [anObject methodSignatureForSelector:aSelector]; 
30         if(signature == nil)
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;
36         return constraint;
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];
45         return constraint;
49 @end
53 #pragma mark  -
55 @implementation OCMAnyConstraint
57 - (BOOL)evaluate:(id)value
59         return YES;
62 @end
66 #pragma mark  -
68 @implementation OCMIsNilConstraint
70 - (BOOL)evaluate:(id)value
72         return value == nil;
75 @end
79 #pragma mark  -
81 @implementation OCMIsNotNilConstraint
83 - (BOOL)evaluate:(id)value
85         return value != nil;
88 @end
92 #pragma mark  -
94 @implementation OCMIsNotEqualConstraint
96 - (BOOL)evaluate:(id)value
98         return ![value isEqual:testValue];
101 @end
105 #pragma mark  -
107 @implementation OCMInvocationConstraint
109 - (BOOL)evaluate:(id)value
111         [invocation setArgument:&value atIndex:2]; // should test if constraint takes arg
112         [invocation invoke];
113         BOOL returnValue;
114         [invocation getReturnValue:&returnValue];
115         return returnValue;
118 @end
120 #pragma mark  -
122 #if NS_BLOCKS_AVAILABLE
124 @implementation OCMBlockConstraint
126 - (id)initWithConstraintBlock:(BOOL (^)(id))aBlock;
128         self = [super init];
129         block = aBlock;
130         return self;
133 - (BOOL)evaluate:(id)value 
135         return block(value);
138 @end
140 #endif