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

Side by Side Diff: third_party/ocmock/OCMock/OCMRecorder.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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014-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 <objc/runtime.h>
18 #import "OCMRecorder.h"
19 #import "OCMockObject.h"
20 #import "OCMInvocationMatcher.h"
21 #import "OCClassMockObject.h"
22
23 @implementation OCMRecorder
24
25 - (instancetype)init {
26 // no super, we're inheriting from NSProxy
27 return self;
28 }
29
30 - (instancetype)initWithMockObject:(OCMockObject*)aMockObject {
31 [self init];
32 [self setMockObject:aMockObject];
33 return self;
34 }
35
36 - (void)setMockObject:(OCMockObject*)aMockObject {
37 mockObject = aMockObject;
38 }
39
40 - (void)dealloc {
41 [invocationMatcher release];
42 [super dealloc];
43 }
44
45 - (NSString*)description {
46 return [invocationMatcher description];
47 }
48
49 - (OCMInvocationMatcher*)invocationMatcher {
50 return invocationMatcher;
51 }
52
53 #pragma mark Modifying the matcher
54
55 - (id)classMethod {
56 // should we handle the case where this is called with a mock that isn't a
57 // class mock?
58 [invocationMatcher setRecordedAsClassMethod:YES];
59 return self;
60 }
61
62 - (id)ignoringNonObjectArgs {
63 [invocationMatcher setIgnoreNonObjectArgs:YES];
64 return self;
65 }
66
67 #pragma mark Recording the actual invocation
68
69 - (NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector {
70 if ([invocationMatcher recordedAsClassMethod])
71 return [[(OCClassMockObject*)mockObject mockedClass]
72 methodSignatureForSelector:aSelector];
73
74 NSMethodSignature* signature =
75 [mockObject methodSignatureForSelector:aSelector];
76 if (signature == nil) {
77 // if we're a working with a class mock and there is a class method,
78 // auto-switch
79 if (([object_getClass(mockObject)
80 isSubclassOfClass:[OCClassMockObject class]]) &&
81 ([[(OCClassMockObject*)mockObject mockedClass]
82 respondsToSelector:aSelector])) {
83 [self classMethod];
84 signature = [self methodSignatureForSelector:aSelector];
85 }
86 }
87 return signature;
88 }
89
90 - (void)forwardInvocation:(NSInvocation*)anInvocation {
91 [anInvocation setTarget:nil];
92 [invocationMatcher setInvocation:anInvocation];
93 }
94
95 - (void)doesNotRecognizeSelector:(SEL)aSelector {
96 [NSException raise:NSInvalidArgumentException
97 format:@"%@: cannot stub/expect/verify method '%@' because no "
98 @"such method exists in the mocked class.",
99 mockObject, NSStringFromSelector(aSelector)];
100 }
101
102 @end
OLDNEW
« no previous file with comments | « third_party/ocmock/OCMock/OCMRecorder.h ('k') | third_party/ocmock/OCMock/OCMReturnValueProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698