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