Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: third_party/ocmock/OCMock/OCMStubRecorder.m

Issue 2410583002: Test update OCMock (Closed)
Patch Set: Patch in exactly 3.1.5 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/ocmock/OCMock/OCMStubRecorder.h ('k') | third_party/ocmock/OCMock/OCMVerifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "OCMStubRecorder.h"
18 #import "OCClassMockObject.h"
19 #import "OCMReturnValueProvider.h"
20 #import "OCMBoxedReturnValueProvider.h"
21 #import "OCMExceptionReturnValueProvider.h"
22 #import "OCMIndirectReturnValueProvider.h"
23 #import "OCMNotificationPoster.h"
24 #import "OCMBlockCaller.h"
25 #import "OCMRealObjectForwarder.h"
26 #import "OCMFunctions.h"
27 #import "OCMInvocationStub.h"
28
29 @implementation OCMStubRecorder
30
31 #pragma mark Initialisers, description, accessors, etc.
32
33 - (id)init {
34 self = [super init];
35 invocationMatcher = [[OCMInvocationStub alloc] init];
36 return self;
37 }
38
39 - (OCMInvocationStub*)stub {
40 return (OCMInvocationStub*)invocationMatcher;
41 }
42
43 #pragma mark Recording invocation actions
44
45 - (id)andReturn:(id)anObject {
46 [[self stub] addInvocationAction:[[[OCMReturnValueProvider alloc]
47 initWithValue:anObject] autorelease]];
48 return self;
49 }
50
51 - (id)andReturnValue:(NSValue*)aValue {
52 [[self stub] addInvocationAction:[[[OCMBoxedReturnValueProvider alloc]
53 initWithValue:aValue] autorelease]];
54 return self;
55 }
56
57 - (id)andThrow:(NSException*)anException {
58 [[self stub] addInvocationAction:[[[OCMExceptionReturnValueProvider alloc]
59 initWithValue:anException] autorelease]];
60 return self;
61 }
62
63 - (id)andPost:(NSNotification*)aNotification {
64 [[self stub]
65 addInvocationAction:[[[OCMNotificationPoster alloc]
66 initWithNotification:aNotification] autorelease]];
67 return self;
68 }
69
70 - (id)andCall:(SEL)selector onObject:(id)anObject {
71 [[self stub] addInvocationAction:[[[OCMIndirectReturnValueProvider alloc]
72 initWithProvider:anObject
73 andSelector:selector] autorelease]];
74 return self;
75 }
76
77 - (id)andDo:(void (^)(NSInvocation*))aBlock {
78 [[self stub] addInvocationAction:[[[OCMBlockCaller alloc]
79 initWithCallBlock:aBlock] autorelease]];
80 return self;
81 }
82
83 - (id)andForwardToRealObject {
84 [[self stub]
85 addInvocationAction:[[[OCMRealObjectForwarder alloc] init] autorelease]];
86 return self;
87 }
88
89 #pragma mark Finishing recording
90
91 - (void)forwardInvocation:(NSInvocation*)anInvocation {
92 [super forwardInvocation:anInvocation];
93 [mockObject addStub:[self stub]];
94 }
95
96 @end
97
98 @implementation OCMStubRecorder (Properties)
99
100 @dynamic _andReturn;
101
102 - (OCMStubRecorder* (^)(NSValue*))_andReturn {
103 id (^theBlock)(id) = ^(NSValue* aValue) {
104 if (OCMIsObjectType([aValue objCType])) {
105 NSValue* objValue = nil;
106 [aValue getValue:&objValue];
107 return [self andReturn:objValue];
108 } else {
109 return [self andReturnValue:aValue];
110 }
111 };
112 return [[theBlock copy] autorelease];
113 }
114
115 @dynamic _andThrow;
116
117 - (OCMStubRecorder* (^)(NSException*))_andThrow {
118 id (^theBlock)(id) = ^(NSException* anException) {
119 return [self andThrow:anException];
120 };
121 return [[theBlock copy] autorelease];
122 }
123
124 @dynamic _andPost;
125
126 - (OCMStubRecorder* (^)(NSNotification*))_andPost {
127 id (^theBlock)(id) = ^(NSNotification* aNotification) {
128 return [self andPost:aNotification];
129 };
130 return [[theBlock copy] autorelease];
131 }
132
133 @dynamic _andCall;
134
135 - (OCMStubRecorder* (^)(id, SEL))_andCall {
136 id (^theBlock)(id, SEL) = ^(id anObject, SEL aSelector) {
137 return [self andCall:aSelector onObject:anObject];
138 };
139 return [[theBlock copy] autorelease];
140 }
141
142 @dynamic _andDo;
143
144 - (OCMStubRecorder* (^)(void (^)(NSInvocation*)))_andDo {
145 id (^theBlock)(void (^)(NSInvocation*)) =
146 ^(void (^blockToCall)(NSInvocation*)) {
147 return [self andDo:blockToCall];
148 };
149 return [[theBlock copy] autorelease];
150 }
151
152 @dynamic _andForwardToRealObject;
153
154 - (OCMStubRecorder* (^)(void))_andForwardToRealObject {
155 id (^theBlock)(void) = ^(void) {
156 return [self andForwardToRealObject];
157 };
158 return [[theBlock copy] autorelease];
159 }
160
161 @end
OLDNEW
« no previous file with comments | « third_party/ocmock/OCMock/OCMStubRecorder.h ('k') | third_party/ocmock/OCMock/OCMVerifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698