OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2004-2015 Erik Doernenburg and contributors |
| 3 * |
| 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 */ |
| 16 |
| 17 #import "OCMRecorder.h" |
| 18 #import "OCMFunctions.h" |
| 19 #import <objc/runtime.h> |
| 20 |
| 21 @interface OCMStubRecorder : OCMRecorder |
| 22 |
| 23 - (id)andReturn:(id)anObject; |
| 24 - (id)andReturnValue:(NSValue *)aValue; |
| 25 - (id)andThrow:(NSException *)anException; |
| 26 - (id)andPost:(NSNotification *)aNotification; |
| 27 - (id)andCall:(SEL)selector onObject:(id)anObject; |
| 28 - (id)andDo:(void (^)(NSInvocation *invocation))block; |
| 29 - (id)andForwardToRealObject; |
| 30 |
| 31 @end |
| 32 |
| 33 @interface OCMStubRecorder (Properties) |
| 34 |
| 35 #define andReturn(aValue) _andReturn(({
\ |
| 36 __typeof__(aValue) _val = (aValue);
\ |
| 37 NSValue *_nsval = [NSValue value:&_val withObjCType:@encode(__typeof__(_val))]
; \ |
| 38 if (OCMIsObjectType(@encode(__typeof(_val)))) {
\ |
| 39 objc_setAssociatedObject(_nsval, "OCMAssociatedBoxedValue", *(__unsafe_unr
etained id *) (void *) &_val, OBJC_ASSOCIATION_RETAIN); \ |
| 40 }
\ |
| 41 _nsval;
\ |
| 42 })) |
| 43 @property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *); |
| 44 |
| 45 #define andThrow(anException) _andThrow(anException) |
| 46 @property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *); |
| 47 |
| 48 #define andPost(aNotification) _andPost(aNotification) |
| 49 @property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *); |
| 50 |
| 51 #define andCall(anObject, aSelector) _andCall(anObject, aSelector) |
| 52 @property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL); |
| 53 |
| 54 #define andDo(aBlock) _andDo(aBlock) |
| 55 @property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocatio
n *)); |
| 56 |
| 57 #define andForwardToRealObject() _andForwardToRealObject() |
| 58 @property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(voi
d); |
| 59 |
| 60 @end |
| 61 |
| 62 |
| 63 |
OLD | NEW |