1 //---------------------------------------------------------------------------------------
3 // Copyright (c) 2005-2008 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
6 #import <objc/runtime.h>
7 #import "NSMethodSignature+OCMAdditions.h"
8 #import "OCProtocolMockObject.h"
10 @implementation OCProtocolMockObject
12 #pragma mark Initialisers, description, accessors, etc.
14 - (id)initWithProtocol:(Protocol *)aProtocol
17 mockedProtocol = aProtocol;
21 - (NSString *)description
23 const char* name = protocol_getName(mockedProtocol);
24 return [NSString stringWithFormat:@"OCMockObject[%s]", name];
27 #pragma mark Proxy API
29 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
31 struct objc_method_description methodDescription = protocol_getMethodDescription(mockedProtocol, aSelector, YES, YES);
32 if(methodDescription.name == NULL)
34 methodDescription = protocol_getMethodDescription(mockedProtocol, aSelector, NO, YES);
36 if(methodDescription.name == NULL)
40 return [NSMethodSignature signatureWithObjCTypes:methodDescription.types];
43 - (BOOL)conformsToProtocol:(Protocol *)aProtocol
45 return protocol_conformsToProtocol(mockedProtocol, aProtocol);
48 - (BOOL)respondsToSelector:(SEL)selector
50 return ([self methodSignatureForSelector:selector] != nil);