gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 1 | /* |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 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 | |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 17 | #import <OCMock/OCMFunctions.h> |
| 18 | #import <OCMock/OCMRecorder.h> |
| 19 | |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 20 | #import <objc/runtime.h> |
| 21 | |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 22 | #if !defined(OCM_DISABLE_XCTEST_FEATURES) |
| 23 | @class XCTestExpectation; |
| 24 | #endif |
| 25 | |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 26 | @interface OCMStubRecorder : OCMRecorder |
| 27 | |
| 28 | - (id)andReturn:(id)anObject; |
| 29 | - (id)andReturnValue:(NSValue *)aValue; |
| 30 | - (id)andThrow:(NSException *)anException; |
| 31 | - (id)andPost:(NSNotification *)aNotification; |
| 32 | - (id)andCall:(SEL)selector onObject:(id)anObject; |
| 33 | - (id)andDo:(void (^)(NSInvocation *invocation))block; |
| 34 | - (id)andForwardToRealObject; |
| 35 | |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 36 | #if !defined(OCM_DISABLE_XCTEST_FEATURES) |
| 37 | - (id)andFulfill:(XCTestExpectation *)expectation; |
| 38 | #endif |
| 39 | |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 40 | @end |
| 41 | |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 42 | |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 43 | @interface OCMStubRecorder (Properties) |
| 44 | |
| 45 | #define andReturn(aValue) _andReturn(({ \ |
| 46 | __typeof__(aValue) _val = (aValue); \ |
| 47 | NSValue *_nsval = [NSValue value:&_val withObjCType:@encode(__typeof__(_val))]; \ |
| 48 | if (OCMIsObjectType(@encode(__typeof(_val)))) { \ |
| 49 | objc_setAssociatedObject(_nsval, "OCMAssociatedBoxedValue", *(__unsafe_unretained id *) (void *) &_val, OBJC_ASSOCIATION_RETAIN); \ |
| 50 | } \ |
| 51 | _nsval; \ |
| 52 | })) |
| 53 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *); |
| 54 | |
| 55 | #define andThrow(anException) _andThrow(anException) |
| 56 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *); |
| 57 | |
| 58 | #define andPost(aNotification) _andPost(aNotification) |
| 59 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *); |
| 60 | |
| 61 | #define andCall(anObject, aSelector) _andCall(anObject, aSelector) |
| 62 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL); |
| 63 | |
| 64 | #define andDo(aBlock) _andDo(aBlock) |
| 65 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *)); |
| 66 | |
| 67 | #define andForwardToRealObject() _andForwardToRealObject() |
| 68 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void); |
| 69 | |
Marijn Kruisselbrink | 1b7c4895 | 2023-08-31 16:58:34 | [diff] [blame] | 70 | #if !defined(OCM_DISABLE_XCTEST_FEATURES) |
| 71 | #define andFulfill(anExpectation) _andFulfill(anExpectation) |
| 72 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andFulfill)(XCTestExpectation *); |
| 73 | #endif |
| 74 | |
| 75 | @property (nonatomic, readonly) OCMStubRecorder *(^ _ignoringNonObjectArgs)(void); |
| 76 | |
| 77 | #define andBreak() _andDo(^(NSInvocation *_invocation) \ |
| 78 | { \ |
| 79 | __builtin_debugtrap(); \ |
| 80 | }) \ |
| 81 | |
| 82 | #define andLog(_format, ...) _andDo(^(NSInvocation *_invocation) \ |
| 83 | { \ |
| 84 | NSLog(_format, ##__VA_ARGS__); \ |
| 85 | }) \ |
| 86 | |
gambard | d8d4403 | 2017-02-09 15:41:46 | [diff] [blame] | 87 | @end |