| OLD | NEW |
| 1 //------------------------------------------------------------------------------
--------- | 1 /* |
| 2 // $Id$ | 2 * Copyright (c) 2005-2015 Erik Doernenburg and contributors |
| 3 // Copyright (c) 2005-2008 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 "NSMethodSignature+OCMAdditions.h" | 18 #import "NSMethodSignature+OCMAdditions.h" |
| 8 #import "OCProtocolMockObject.h" | 19 #import "OCProtocolMockObject.h" |
| 9 | 20 |
| 10 @implementation OCProtocolMockObject | 21 @implementation OCProtocolMockObject |
| 11 | 22 |
| 12 #pragma mark Initialisers, description, accessors, etc. | 23 #pragma mark Initialisers, description, accessors, etc. |
| 13 | 24 |
| 14 - (id)initWithProtocol:(Protocol *)aProtocol | 25 - (id)initWithProtocol:(Protocol *)aProtocol |
| 15 { | 26 { |
| 16 » [super init]; | 27 NSParameterAssert(aProtocol != nil); |
| 17 » mockedProtocol = aProtocol; | 28 [super init]; |
| 18 » return self; | 29 mockedProtocol = aProtocol; |
| 30 return self; |
| 19 } | 31 } |
| 20 | 32 |
| 21 - (NSString *)description | 33 - (NSString *)description |
| 22 { | 34 { |
| 23 const char* name = protocol_getName(mockedProtocol); | 35 const char* name = protocol_getName(mockedProtocol); |
| 24 return [NSString stringWithFormat:@"OCMockObject[%s]", name]; | 36 return [NSString stringWithFormat:@"OCMockObject(%s)", name]; |
| 25 } | 37 } |
| 26 | 38 |
| 27 #pragma mark Proxy API | 39 #pragma mark Proxy API |
| 28 | 40 |
| 29 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector | 41 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector |
| 30 { | 42 { |
| 31 » struct objc_method_description methodDescription = protocol_getMethodDes
cription(mockedProtocol, aSelector, YES, YES); | 43 struct { |
| 32 if(methodDescription.name == NULL) | 44 BOOL isRequired; |
| 33 » { | 45 BOOL isInstance; |
| 34 methodDescription = protocol_getMethodDescription(mockedProtocol, aSelec
tor, NO, YES); | 46 } opts[4] = {{YES, YES}, {NO, YES}, {YES, NO}, {NO, NO}}; |
| 47 for (int i = 0; i < 4; i++) { |
| 48 struct objc_method_description methodDescription = |
| 49 protocol_getMethodDescription(mockedProtocol, aSelector, |
| 50 opts[i].isRequired, opts[i].isInstance); |
| 51 if (methodDescription.name != NULL) |
| 52 return [NSMethodSignature signatureWithObjCTypes:methodDescription.types]; |
| 35 } | 53 } |
| 36 if(methodDescription.name == NULL) | 54 return nil; |
| 37 » { | |
| 38 return nil; | |
| 39 } | |
| 40 » return [NSMethodSignature signatureWithObjCTypes:methodDescription.types
]; | |
| 41 } | 55 } |
| 42 | 56 |
| 43 - (BOOL)conformsToProtocol:(Protocol *)aProtocol | 57 - (BOOL)conformsToProtocol:(Protocol *)aProtocol |
| 44 { | 58 { |
| 45 return protocol_conformsToProtocol(mockedProtocol, aProtocol); | 59 return protocol_conformsToProtocol(mockedProtocol, aProtocol); |
| 46 } | 60 } |
| 47 | 61 |
| 48 - (BOOL)respondsToSelector:(SEL)selector | 62 - (BOOL)respondsToSelector:(SEL)selector |
| 49 { | 63 { |
| 50 return ([self methodSignatureForSelector:selector] != nil); | 64 return ([self methodSignatureForSelector:selector] != nil); |
| 51 } | 65 } |
| 52 | 66 |
| 53 @end | 67 @end |
| OLD | NEW |