Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / ocmock / ocmock_extensions.mm
blobbcf11b3c3dc8d5fdcc8910d1fffe69511d421adb
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.
5 #include <objc/runtime.h>
7 #include "third_party/ocmock/ocmock_extensions.h"
9 #define CR_OCMOCK_RETURN_IMPL(type_name, type) \
10   - (id)andReturn##type_name:(type)value { \
11     return [self andReturnValue:OCMOCK_VALUE(value)]; \
12   }
14 @implementation OCMockRecorder(CrExtensions)
16 CR_OCMOCK_RETURN_IMPL(Char, char);
17 CR_OCMOCK_RETURN_IMPL(UnsignedChar, unsigned char);
18 CR_OCMOCK_RETURN_IMPL(Short, short);
19 CR_OCMOCK_RETURN_IMPL(UnsignedShort, unsigned short);
20 CR_OCMOCK_RETURN_IMPL(Int, int);
21 CR_OCMOCK_RETURN_IMPL(UnsignedInt, unsigned int);
22 CR_OCMOCK_RETURN_IMPL(Long, long);
23 CR_OCMOCK_RETURN_IMPL(UnsignedLong, unsigned long);
24 CR_OCMOCK_RETURN_IMPL(LongLong, long long);
25 CR_OCMOCK_RETURN_IMPL(UnsignedLongLong, unsigned long long);
26 CR_OCMOCK_RETURN_IMPL(Float, float);
27 CR_OCMOCK_RETURN_IMPL(Double, double);
28 CR_OCMOCK_RETURN_IMPL(Bool, BOOL);
29 CR_OCMOCK_RETURN_IMPL(Integer, NSInteger);
30 CR_OCMOCK_RETURN_IMPL(UnsignedInteger, NSUInteger);
32 #if !TARGET_OS_IPHONE
33 CR_OCMOCK_RETURN_IMPL(CGFloat, CGFloat);
35 - (id)andReturnNSRect:(NSRect)rect {
36   return [self andReturnValue:[NSValue valueWithRect:rect]];
39 - (id)andReturnCGRect:(CGRect)rect {
40   return [self andReturnNSRect:NSRectFromCGRect(rect)];
43 - (id)andReturnNSPoint:(NSPoint)point {
44   return [self andReturnValue:[NSValue valueWithPoint:point]];
47 - (id)andReturnCGPoint:(CGPoint)point {
48   return [self andReturnNSPoint:NSPointFromCGPoint(point)];
50 #endif  // !TARGET_OS_IPHONE
52 @end
54 @implementation cr_OCMConformToProtocolConstraint
56 - (id)initWithProtocol:(Protocol*)protocol {
57   if (self == [super init]) {
58     protocol_ = protocol;
59   }
60   return self;
63 - (BOOL)evaluate:(id)value {
64   return protocol_conformsToProtocol(protocol_, value);
67 @end
69 @implementation OCMArg(CrExtensions)
71 + (id)conformsToProtocol:(Protocol*)protocol {
72   return [[[cr_OCMConformToProtocolConstraint alloc] initWithProtocol:protocol]
73           autorelease];
76 @end