Skip to content

Commit

Permalink
OnCall methods now have same signature as replaced ones.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.mulle-kybernetik.com/OCMock/trunk@54 12620d81-68e2-0310-ae40-e3f550779089
  • Loading branch information
erikdoe committed Aug 18, 2009
1 parent 3fb732b commit 09c2103
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
5 changes: 5 additions & 0 deletions Source/Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Chronological listing of changes. If a particular SVN revision has no entry, tha
check-in did not involve any code or feature changes.


2009-08-18 (r54)

* OnCall methods now have same signature as replaced ones.


2009-08-14 (r53)

* Fixed possible retain bug (Daniel Eggert)
Expand Down
4 changes: 2 additions & 2 deletions Source/OCMIndirectReturnValueProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------

#import "OCMReturnValueProvider.h"
#import <Foundation/Foundation.h>

@interface OCMIndirectReturnValueProvider : OCMReturnValueProvider
@interface OCMIndirectReturnValueProvider : NSObject
{
id provider;
SEL selector;
Expand Down
12 changes: 4 additions & 8 deletions Source/OCMIndirectReturnValueProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation OCMIndirectReturnValueProvider

- (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector
{
[super initWithValue:nil];
[super init];
provider = [aProvider retain];
selector = aSelector;
return self;
Expand All @@ -25,13 +25,9 @@ - (void)dealloc

- (void)handleInvocation:(NSInvocation *)anInvocation
{
const char *returnType = [[provider methodSignatureForSelector:selector] methodReturnTypeWithoutQualifiers];
if(strcmp(returnType, @encode(void)))
{
// TODO: Should check signature and only provide invocation when it matches first argument
returnValue = [[provider performSelector:selector withObject:anInvocation] retain];
[super handleInvocation:anInvocation];
}
[anInvocation setTarget:provider];
[anInvocation setSelector:selector];
[anInvocation invoke];
}

@end
26 changes: 7 additions & 19 deletions Source/OCMockObjectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,33 +299,21 @@ - (void)testPostsNotificationInAddtionToReturningValue
}


- (NSString *)valueForTest
- (NSString *)valueForString:(NSString *)aString andMask:(NSStringCompareOptions)mask
{
return @"value for test";
return [NSString stringWithFormat:@"[%@, %d]", aString, mask];
}

- (void)testCallsMethodAndReturnsItsReturnValueWhenAskedTo
- (void)testCallsAlternativeMethodAndPassesOriginalArgumentsAndReturnsValue
{
[[[mock stub] andCall:@selector(valueForTest) onObject:self] lowercaseString];
[[[mock stub] andCall:@selector(valueForString:andMask:) onObject:self] commonPrefixWithString:@"FOO" options:NSCaseInsensitiveSearch];

STAssertEqualObjects(@"value for test", [mock lowercaseString], @"Should have returned value from called method");
}


- (NSString *)valueForTest:(NSInvocation *)originalInvocation
{
return (id)originalInvocation;
}

- (void)testCallsMethodAndPassesOriginalInvocation
{
[[[mock stub] andCall:@selector(valueForTest:) onObject:self] lowercaseString];
NSString *returnValue = [mock commonPrefixWithString:@"FOO" options:NSCaseInsensitiveSearch];

NSInvocation *invocation = (id)[mock lowercaseString];

STAssertEquals(@selector(lowercaseString), [invocation selector], @"Should have passed and returned invocation.");
STAssertEqualObjects(@"[FOO, 1]", returnValue, @"Should have passed and returned invocation.");
}


// --------------------------------------------------------------------------------------
// returning values in pass-by-reference arguments
// --------------------------------------------------------------------------------------
Expand Down

0 comments on commit 09c2103

Please sign in to comment.