OLD | NEW |
1 //------------------------------------------------------------------------------
--------- | 1 /* |
2 // $Id$ | 2 * Copyright (c) 2010-2015 Erik Doernenburg and contributors |
3 // Copyright (c) 2010 by Mulle Kybernetik. See License file for details. | 3 * |
4 //------------------------------------------------------------------------------
--------- | 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 */ |
5 | 16 |
6 #import <objc/runtime.h> | 17 #import <objc/runtime.h> |
7 #import "OCPartialMockObject.h" | 18 #import "OCPartialMockObject.h" |
8 #import "OCMRealObjectForwarder.h" | 19 #import "OCMRealObjectForwarder.h" |
| 20 #import "OCMFunctions.h" |
9 | 21 |
10 | 22 |
11 @implementation OCMRealObjectForwarder | 23 @implementation OCMRealObjectForwarder |
12 | 24 |
13 - (void)handleInvocation:(NSInvocation *)anInvocation | 25 - (void)handleInvocation:(NSInvocation *)anInvocation |
14 { | 26 { |
15 id invocationTarget = [anInvocation target]; | 27 id invocationTarget = [anInvocation target]; |
16 » SEL invocationSelector = [anInvocation selector]; | 28 |
17 » SEL aliasedSelector = NSSelectorFromString([OCMRealMethodAliasPrefix str
ingByAppendingString:NSStringFromSelector(invocationSelector)]); | 29 [anInvocation setSelector:OCMAliasForOriginalSelector([anInvocation selector
])]; |
18 » | 30 » if ([invocationTarget isProxy]) |
19 » [anInvocation setSelector:aliasedSelector]; | |
20 » if([invocationTarget isProxy] && (class_getInstanceMethod([invocationTar
get class], @selector(realObject)))) | |
21 { | 31 { |
22 » » // the method has been invoked on the mock, we need to change th
e target to the real object | 32 » if (class_getInstanceMethod([invocationTarget mockObjectClass], @sel
ector(realObject))) |
23 » » [anInvocation setTarget:[(OCPartialMockObject *)invocationTarget
realObject]]; | 33 » { |
24 » } | 34 » // the method has been invoked on the mock, we need to change th
e target to the real object |
| 35 » [anInvocation setTarget:[(OCPartialMockObject *)invocationTarget
realObject]]; |
| 36 » } |
| 37 » else |
| 38 » { |
| 39 » [NSException raise:NSInternalInconsistencyException |
| 40 » format:@"Method andForwardToRealObject can only be u
sed with partial mocks and class methods."]; |
| 41 » } |
| 42 » } |
| 43 |
25 [anInvocation invoke]; | 44 [anInvocation invoke]; |
26 } | 45 } |
27 | 46 |
28 | 47 |
29 @end | 48 @end |
OLD | NEW |