[go: nahoru, domu]

blob: a00c64bf1803d5f085d2df8a7615b9ff707c6641 [file] [log] [blame]
gambardd8d44032017-02-09 15:41:461/*
Marijn Kruisselbrink1b7c48952023-08-31 16:58:342 * Copyright (c) 2004-2021 Erik Doernenburg and contributors
gambardd8d44032017-02-09 15:41:463 *
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 Kruisselbrink1b7c48952023-08-31 16:58:3417#import <OCMock/OCMFunctions.h>
18#import <OCMock/OCMRecorder.h>
19
gambardd8d44032017-02-09 15:41:4620#import <objc/runtime.h>
21
Marijn Kruisselbrink1b7c48952023-08-31 16:58:3422#if !defined(OCM_DISABLE_XCTEST_FEATURES)
23@class XCTestExpectation;
24#endif
25
gambardd8d44032017-02-09 15:41:4626@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 Kruisselbrink1b7c48952023-08-31 16:58:3436#if !defined(OCM_DISABLE_XCTEST_FEATURES)
37- (id)andFulfill:(XCTestExpectation *)expectation;
38#endif
39
gambardd8d44032017-02-09 15:41:4640@end
41
Marijn Kruisselbrink1b7c48952023-08-31 16:58:3442
gambardd8d44032017-02-09 15:41:4643@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 Kruisselbrink1b7c48952023-08-31 16:58:3470#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
gambardd8d44032017-02-09 15:41:4687@end