Home | History | Annotate | Download | only in ocmock
      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 
     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);
     31 
     32 #if !TARGET_OS_IPHONE
     33 CR_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