|
| 1 | +/* |
| 2 | + * Copyright (c) 2004-2018 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 <OCMock/OCMRecorder.h> |
| 18 | +#import <OCMock/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 | + |
| 34 | +@interface OCMStubRecorder (Properties) |
| 35 | + |
| 36 | +#define andReturn(aValue) _andReturn(({ \ |
| 37 | + __typeof__(aValue) _val = (aValue); \ |
| 38 | + NSValue *_nsval = [NSValue value:&_val withObjCType:@encode(__typeof__(_val))]; \ |
| 39 | + if (OCMIsObjectType(@encode(__typeof(_val)))) { \ |
| 40 | + objc_setAssociatedObject(_nsval, "OCMAssociatedBoxedValue", *(__unsafe_unretained id *) (void *) &_val, OBJC_ASSOCIATION_RETAIN); \ |
| 41 | + } \ |
| 42 | + _nsval; \ |
| 43 | +})) |
| 44 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *); |
| 45 | + |
| 46 | +#define andThrow(anException) _andThrow(anException) |
| 47 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *); |
| 48 | + |
| 49 | +#define andPost(aNotification) _andPost(aNotification) |
| 50 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *); |
| 51 | + |
| 52 | +#define andCall(anObject, aSelector) _andCall(anObject, aSelector) |
| 53 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL); |
| 54 | + |
| 55 | +#define andDo(aBlock) _andDo(aBlock) |
| 56 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *)); |
| 57 | + |
| 58 | +#define andForwardToRealObject() _andForwardToRealObject() |
| 59 | +@property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void); |
| 60 | + |
| 61 | +@end |
| 62 | + |
| 63 | + |
| 64 | + |
0 commit comments