| OLD | NEW |
| 1 //------------------------------------------------------------------------------
--------- | 1 /* |
| 2 // $Id$ | 2 * Copyright (c) 2009-2015 Erik Doernenburg and contributors |
| 3 // Copyright (c) 2009-2010 by Mulle Kybernetik. See License file for details. | 3 * |
| 4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
| 5 | 16 |
| 6 #import <objc/runtime.h> | 17 #import <objc/runtime.h> |
| 7 #import <OCMock/OCMArg.h> | 18 #import <OCMock/OCMArg.h> |
| 8 #import <OCMock/OCMConstraint.h> | 19 #import <OCMock/OCMConstraint.h> |
| 9 #import "OCMPassByRefSetter.h" | 20 #import "OCMPassByRefSetter.h" |
| 10 #import "OCMConstraint.h" | 21 #import "OCMBlockArgCaller.h" |
| 11 | 22 |
| 12 @implementation OCMArg | 23 @implementation OCMArg |
| 13 | 24 |
| 14 + (id)any | 25 + (id)any |
| 15 { | 26 { |
| 16 return [OCMAnyConstraint constraint]; | 27 return [OCMAnyConstraint constraint]; |
| 17 } | 28 } |
| 18 | 29 |
| 19 + (void *)anyPointer | 30 + (void *)anyPointer |
| 20 { | 31 { |
| 21 return (void *)0x01234567; | 32 return (void *)0x01234567; |
| 22 } | 33 } |
| 23 | 34 |
| 35 + (id __autoreleasing *)anyObjectRef |
| 36 { |
| 37 return (id *)0x01234567; |
| 38 } |
| 39 |
| 40 + (SEL)anySelector |
| 41 { |
| 42 return NSSelectorFromString(@"aSelectorThatMatchesAnySelector"); |
| 43 } |
| 44 |
| 24 + (id)isNil | 45 + (id)isNil |
| 25 { | 46 { |
| 26 return [OCMIsNilConstraint constraint]; | 47 return [OCMIsNilConstraint constraint]; |
| 27 } | 48 } |
| 28 | 49 |
| 29 + (id)isNotNil | 50 + (id)isNotNil |
| 30 { | 51 { |
| 31 return [OCMIsNotNilConstraint constraint]; | 52 return [OCMIsNotNilConstraint constraint]; |
| 32 } | 53 } |
| 33 | 54 |
| 55 + (id)isEqual:(id)value |
| 56 { |
| 57 return value; |
| 58 } |
| 59 |
| 34 + (id)isNotEqual:(id)value | 60 + (id)isNotEqual:(id)value |
| 35 { | 61 { |
| 36 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constrain
t]; | 62 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constrain
t]; |
| 37 constraint->testValue = value; | 63 constraint->testValue = value; |
| 38 return constraint; | 64 return constraint; |
| 39 } | 65 } |
| 40 | 66 |
| 67 + (id)isKindOfClass:(Class)cls |
| 68 { |
| 69 return [[[OCMBlockConstraint alloc] initWithConstraintBlock:^BOOL(id obj
) { |
| 70 return [obj isKindOfClass:cls]; |
| 71 }] autorelease]; |
| 72 } |
| 73 |
| 41 + (id)checkWithSelector:(SEL)selector onObject:(id)anObject | 74 + (id)checkWithSelector:(SEL)selector onObject:(id)anObject |
| 42 { | 75 { |
| 43 return [OCMConstraint constraintWithSelector:selector onObject:anObject]
; | 76 return [OCMConstraint constraintWithSelector:selector onObject:anObject]
; |
| 44 } | 77 } |
| 45 | 78 |
| 46 #if NS_BLOCKS_AVAILABLE | 79 + (id)checkWithBlock:(BOOL (^)(id))block |
| 47 | |
| 48 + (id)checkWithBlock:(BOOL (^)(id))block | |
| 49 { | 80 { |
| 50 return [[[OCMBlockConstraint alloc] initWithConstraintBlock:block] autor
elease]; | 81 return [[[OCMBlockConstraint alloc] initWithConstraintBlock:block] autor
elease]; |
| 51 } | 82 } |
| 52 | 83 |
| 53 #endif | |
| 54 | |
| 55 + (id *)setTo:(id)value | 84 + (id *)setTo:(id)value |
| 56 { | 85 { |
| 57 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelea
se]; | 86 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelea
se]; |
| 58 } | 87 } |
| 59 | 88 |
| 89 + (void *)setToValue:(NSValue *)value |
| 90 { |
| 91 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelea
se]; |
| 92 } |
| 93 |
| 94 + (id)invokeBlock |
| 95 { |
| 96 return [[[OCMBlockArgCaller alloc] init] autorelease]; |
| 97 } |
| 98 |
| 60 + (id)resolveSpecialValues:(NSValue *)value | 99 + (id)resolveSpecialValues:(NSValue *)value |
| 61 { | 100 { |
| 62 const char *type = [value objCType]; | 101 const char *type = [value objCType]; |
| 63 if(type[0] == '^') | 102 if(type[0] == '^') |
| 64 { | 103 { |
| 65 void *pointer = [value pointerValue]; | 104 void *pointer = [value pointerValue]; |
| 66 if(pointer == (void *)0x01234567) | 105 if(pointer == (void *)0x01234567) |
| 67 return [OCMArg any]; | 106 return [OCMArg any]; |
| 68 if((pointer != NULL) && (object_getClass((id)pointer) == [OCMPas
sByRefSetter class])) | 107 if((pointer != NULL) && (object_getClass((id)pointer) == [OCMPas
sByRefSetter class])) |
| 69 return (id)pointer; | 108 return (id)pointer; |
| 70 } | 109 } |
| 110 else if(type[0] == ':') |
| 111 { |
| 112 SEL selector; |
| 113 [value getValue:&selector]; |
| 114 if(selector == NSSelectorFromString(@"aSelectorThatMatchesAnySelector")) |
| 115 return [OCMArg any]; |
| 116 } |
| 71 return value; | 117 return value; |
| 72 } | 118 } |
| 73 | 119 |
| 74 @end | 120 @end |
| OLD | NEW |