1 //--------------------------------------------------------------------------------------- 2 // $Id$ 3 // Copyright (c) 2009-2010 by Mulle Kybernetik. See License file for details. 4 //--------------------------------------------------------------------------------------- 5 6 #import <objc/runtime.h> 7 #import <OCMock/OCMArg.h> 8 #import <OCMock/OCMConstraint.h> 9 #import "OCMPassByRefSetter.h" 10 #import "OCMConstraint.h" 11 12 @implementation OCMArg 13 14 + (id)any 15 { 16 return [OCMAnyConstraint constraint]; 17 } 18 19 + (void *)anyPointer 20 { 21 return (void *)0x01234567; 22 } 23 24 + (id)isNil 25 { 26 return [OCMIsNilConstraint constraint]; 27 } 28 29 + (id)isNotNil 30 { 31 return [OCMIsNotNilConstraint constraint]; 32 } 33 34 + (id)isNotEqual:(id)value 35 { 36 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constraint]; 37 constraint->testValue = value; 38 return constraint; 39 } 40 41 + (id)checkWithSelector:(SEL)selector onObject:(id)anObject 42 { 43 return [OCMConstraint constraintWithSelector:selector onObject:anObject]; 44 } 45 46 #if NS_BLOCKS_AVAILABLE 47 48 + (id)checkWithBlock:(BOOL (^)(id))block 49 { 50 return [[[OCMBlockConstraint alloc] initWithConstraintBlock:block] autorelease]; 51 } 52 53 #endif 54 55 + (id *)setTo:(id)value 56 { 57 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelease]; 58 } 59 60 + (id)resolveSpecialValues:(NSValue *)value 61 { 62 const char *type = [value objCType]; 63 if(type[0] == '^') 64 { 65 void *pointer = [value pointerValue]; 66 if(pointer == (void *)0x01234567) 67 return [OCMArg any]; 68 if((pointer != NULL) && (object_getClass((id)pointer) == [OCMPassByRefSetter class])) 69 return (id)pointer; 70 } 71 return value; 72 } 73 74 @end 75