| 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" | |
| 11 | 21 |
| 12 @implementation OCMArg | 22 @implementation OCMArg |
| 13 | 23 |
| 14 + (id)any | 24 + (id)any |
| 15 { | 25 { |
| 16 return [OCMAnyConstraint constraint]; | 26 return [OCMAnyConstraint constraint]; |
| 17 } | 27 } |
| 18 | 28 |
| 19 + (void *)anyPointer | 29 + (void *)anyPointer |
| 20 { | 30 { |
| 21 return (void *)0x01234567; | 31 return (void *)0x01234567; |
| 22 } | 32 } |
| 23 | 33 |
| 34 + (id __autoreleasing*)anyObjectRef { |
| 35 return (id*)0x01234567; |
| 36 } |
| 37 |
| 38 + (SEL)anySelector { |
| 39 return NSSelectorFromString(@"aSelectorThatMatchesAnySelector"); |
| 40 } |
| 41 |
| 24 + (id)isNil | 42 + (id)isNil |
| 25 { | 43 { |
| 26 return [OCMIsNilConstraint constraint]; | 44 return [OCMIsNilConstraint constraint]; |
| 27 } | 45 } |
| 28 | 46 |
| 29 + (id)isNotNil | 47 + (id)isNotNil |
| 30 { | 48 { |
| 31 return [OCMIsNotNilConstraint constraint]; | 49 return [OCMIsNotNilConstraint constraint]; |
| 32 } | 50 } |
| 33 | 51 |
| 52 + (id)isEqual:(id)value { |
| 53 return value; |
| 54 } |
| 55 |
| 34 + (id)isNotEqual:(id)value | 56 + (id)isNotEqual:(id)value |
| 35 { | 57 { |
| 36 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constrain
t]; | 58 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constrain
t]; |
| 37 constraint->testValue = value; | 59 constraint->testValue = value; |
| 38 return constraint; | 60 return constraint; |
| 39 } | 61 } |
| 40 | 62 |
| 63 + (id)isKindOfClass:(Class)cls { |
| 64 return [[[OCMBlockConstraint alloc] initWithConstraintBlock:^BOOL(id obj) { |
| 65 return [obj isKindOfClass:cls]; |
| 66 }] autorelease]; |
| 67 } |
| 68 |
| 41 + (id)checkWithSelector:(SEL)selector onObject:(id)anObject | 69 + (id)checkWithSelector:(SEL)selector onObject:(id)anObject |
| 42 { | 70 { |
| 43 return [OCMConstraint constraintWithSelector:selector onObject:anObject]
; | 71 return [OCMConstraint constraintWithSelector:selector onObject:anObject]
; |
| 44 } | 72 } |
| 45 | 73 |
| 46 #if NS_BLOCKS_AVAILABLE | 74 + (id)checkWithBlock:(BOOL (^)(id))block { |
| 47 | 75 return |
| 48 + (id)checkWithBlock:(BOOL (^)(id))block | 76 [[[OCMBlockConstraint alloc] initWithConstraintBlock:block] autorelease]; |
| 49 { | |
| 50 » return [[[OCMBlockConstraint alloc] initWithConstraintBlock:block] autor
elease]; | |
| 51 } | 77 } |
| 52 | 78 |
| 53 #endif | |
| 54 | |
| 55 + (id *)setTo:(id)value | 79 + (id *)setTo:(id)value |
| 56 { | 80 { |
| 57 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelea
se]; | 81 return (id *)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelea
se]; |
| 58 } | 82 } |
| 59 | 83 |
| 84 + (void*)setToValue:(NSValue*)value { |
| 85 return (id*)[[[OCMPassByRefSetter alloc] initWithValue:value] autorelease]; |
| 86 } |
| 87 |
| 60 + (id)resolveSpecialValues:(NSValue *)value | 88 + (id)resolveSpecialValues:(NSValue *)value |
| 61 { | 89 { |
| 62 const char *type = [value objCType]; | 90 const char *type = [value objCType]; |
| 63 if(type[0] == '^') | 91 if(type[0] == '^') |
| 64 { | 92 { |
| 65 void *pointer = [value pointerValue]; | 93 void *pointer = [value pointerValue]; |
| 66 if(pointer == (void *)0x01234567) | 94 if(pointer == (void *)0x01234567) |
| 67 return [OCMArg any]; | 95 return [OCMArg any]; |
| 68 if((pointer != NULL) && (object_getClass((id)pointer) == [OCMPas
sByRefSetter class])) | 96 if((pointer != NULL) && (object_getClass((id)pointer) == [OCMPas
sByRefSetter class])) |
| 69 return (id)pointer; | 97 return (id)pointer; |
| 70 » } | 98 } else if (type[0] == ':') { |
| 71 » return value; | 99 SEL selector; |
| 100 [value getValue:&selector]; |
| 101 if (selector == |
| 102 NSSelectorFromString(@"aSelectorThatMatchesAnySelector")) |
| 103 return [OCMArg any]; |
| 104 } |
| 105 return value; |
| 72 } | 106 } |
| 73 | 107 |
| 74 @end | 108 @end |
| OLD | NEW |