1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <objc/runtime.h> 6 7#include "third_party/ocmock/ocmock_extensions.h" 8 9#define CR_OCMOCK_RETURN_IMPL(type_name, type) \ 10 - (id)andReturn##type_name:(type)value { \ 11 return [self andReturnValue:OCMOCK_VALUE(value)]; \ 12 } 13 14@implementation OCMockRecorder(CrExtensions) 15 16CR_OCMOCK_RETURN_IMPL(Char, char); 17CR_OCMOCK_RETURN_IMPL(UnsignedChar, unsigned char); 18CR_OCMOCK_RETURN_IMPL(Short, short); 19CR_OCMOCK_RETURN_IMPL(UnsignedShort, unsigned short); 20CR_OCMOCK_RETURN_IMPL(Int, int); 21CR_OCMOCK_RETURN_IMPL(UnsignedInt, unsigned int); 22CR_OCMOCK_RETURN_IMPL(Long, long); 23CR_OCMOCK_RETURN_IMPL(UnsignedLong, unsigned long); 24CR_OCMOCK_RETURN_IMPL(LongLong, long long); 25CR_OCMOCK_RETURN_IMPL(UnsignedLongLong, unsigned long long); 26CR_OCMOCK_RETURN_IMPL(Float, float); 27CR_OCMOCK_RETURN_IMPL(Double, double); 28CR_OCMOCK_RETURN_IMPL(Bool, BOOL); 29CR_OCMOCK_RETURN_IMPL(Integer, NSInteger); 30CR_OCMOCK_RETURN_IMPL(UnsignedInteger, NSUInteger); 31 32#if !TARGET_OS_IPHONE 33CR_OCMOCK_RETURN_IMPL(CGFloat, CGFloat); 34 35- (id)andReturnNSRect:(NSRect)rect { 36 return [self andReturnValue:[NSValue valueWithRect:rect]]; 37} 38 39- (id)andReturnCGRect:(CGRect)rect { 40 return [self andReturnNSRect:NSRectFromCGRect(rect)]; 41} 42 43- (id)andReturnNSPoint:(NSPoint)point { 44 return [self andReturnValue:[NSValue valueWithPoint:point]]; 45} 46 47- (id)andReturnCGPoint:(CGPoint)point { 48 return [self andReturnNSPoint:NSPointFromCGPoint(point)]; 49} 50#endif // !TARGET_OS_IPHONE 51 52@end 53 54@implementation cr_OCMConformToProtocolConstraint 55 56- (id)initWithProtocol:(Protocol*)protocol { 57 if (self == [super init]) { 58 protocol_ = protocol; 59 } 60 return self; 61} 62 63- (BOOL)evaluate:(id)value { 64 return protocol_conformsToProtocol(protocol_, value); 65} 66 67@end 68 69@implementation OCMArg(CrExtensions) 70 71+ (id)conformsToProtocol:(Protocol*)protocol { 72 return [[[cr_OCMConformToProtocolConstraint alloc] initWithProtocol:protocol] 73 autorelease]; 74} 75 76@end 77