| OLD | NEW |
| 1 //------------------------------------------------------------------------------
--------- | 1 /* |
| 2 // $Id$ | 2 * Copyright (c) 2009-2015 Erik Doernenburg and contributors |
| 3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. | 3 * |
| 4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
| 5 | 16 |
| 6 #import "NSMethodSignature+OCMAdditions.h" | 17 #import "NSMethodSignature+OCMAdditions.h" |
| 7 #import "OCMReturnValueProvider.h" | 18 #import "OCMReturnValueProvider.h" |
| 8 | 19 #import "OCMFunctions.h" |
| 9 | 20 |
| 10 @implementation OCMReturnValueProvider | 21 @implementation OCMReturnValueProvider |
| 11 | 22 |
| 12 - (id)initWithValue:(id)aValue | 23 - (instancetype)initWithValue:(id)aValue { |
| 13 { | 24 if ((self = [super init])) { |
| 14 » self = [super init]; | 25 returnValue = [aValue retain]; |
| 15 » returnValue = [aValue retain]; | 26 } |
| 16 » return self; | 27 |
| 28 return self; |
| 17 } | 29 } |
| 18 | 30 |
| 19 - (void)dealloc | 31 - (void)dealloc |
| 20 { | 32 { |
| 21 [returnValue release]; | 33 [returnValue release]; |
| 22 [super dealloc]; | 34 [super dealloc]; |
| 23 } | 35 } |
| 24 | 36 |
| 25 - (void)handleInvocation:(NSInvocation *)anInvocation | 37 - (void)handleInvocation:(NSInvocation *)anInvocation |
| 26 { | 38 { |
| 27 » const char *returnType = [[anInvocation methodSignature] methodReturnTyp
eWithoutQualifiers]; | 39 if (!OCMIsObjectType([[anInvocation methodSignature] methodReturnType])) { |
| 28 » if(strcmp(returnType, @encode(id)) != 0) | 40 @throw [NSException |
| 29 » » @throw [NSException exceptionWithName:NSInvalidArgumentException
reason:@"Expected invocation with object return type. Did you mean to use andRe
turnValue: instead?" userInfo:nil]; | 41 exceptionWithName:NSInvalidArgumentException |
| 30 » [anInvocation setReturnValue:&returnValue];» | 42 reason:@"Expected invocation with object return type. Did " |
| 43 @"you mean to use andReturnValue: instead?" |
| 44 userInfo:nil]; |
| 45 } |
| 46 NSString* sel = NSStringFromSelector([anInvocation selector]); |
| 47 if ([sel hasPrefix:@"alloc"] || [sel hasPrefix:@"new"] || |
| 48 [sel hasPrefix:@"copy"] || [sel hasPrefix:@"mutableCopy"]) { |
| 49 // methods that "create" an object return it with an extra retain count |
| 50 [returnValue retain]; |
| 51 } |
| 52 [anInvocation setReturnValue:&returnValue]; |
| 31 } | 53 } |
| 32 | 54 |
| 33 @end | 55 @end |
| OLD | NEW |