summaryrefslogtreecommitdiffstats
path: root/third_party/ocmock/OCMock/OCProtocolMockObject.m
blob: 20d35c11b42eb0c256ee43d6e750e0f8a30e766f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//---------------------------------------------------------------------------------------
//  $Id: OCProtocolMockObject.m 52 2009-08-14 07:21:10Z erik $
//  Copyright (c) 2005-2008 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------

#import <objc/runtime.h>
#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