//--------------------------------------------------------------------------------------- // $Id: OCProtocolMockObject.m 52 2009-08-14 07:21:10Z erik $ // Copyright (c) 2005-2008 by Mulle Kybernetik. See License file for details. //--------------------------------------------------------------------------------------- #import #import "NSMethodSignature+OCMAdditions.h" #import "OCProtocolMockObject.h" @implementation OCProtocolMockObject #pragma mark Initialisers, description, accessors, etc. - (id)initWithProtocol:(Protocol *)aProtocol { [super init]; mockedProtocol = aProtocol; return self; } - (NSString *)description { return [NSString stringWithFormat:@"OCMockObject[%s]", [mockedProtocol name]]; } #pragma mark Proxy API - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { struct objc_method_description methodDescription = protocol_getMethodDescription(mockedProtocol, aSelector, YES, YES); if(methodDescription.name == NULL) { methodDescription = protocol_getMethodDescription(mockedProtocol, aSelector, NO, YES); } if(methodDescription.name == NULL) { return nil; } return [NSMethodSignature signatureWithObjCTypes:methodDescription.types]; } - (BOOL)conformsToProtocol:(Protocol *)aProtocol { return protocol_conformsToProtocol(mockedProtocol, aProtocol); } - (BOOL)respondsToSelector:(SEL)selector { return ([self methodSignatureForSelector:selector] != nil); } @end