From 761c3c36c8c42f4ba466bd548a72e03346ca7842 Mon Sep 17 00:00:00 2001 From: Hendrik von Prince Date: Tue, 7 Jan 2014 16:21:47 +0100 Subject: [PATCH] fixed the code according to carllindbergs comment - it will now also work for typedefs on classes that have ivars. Also adapted the tests, so that the new behavior is also tested. --- Source/OCMock/OCMReturnValueProvider.m | 4 ++-- Source/OCMockTests/OCMockObjectProtocolMocksTests.m | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/OCMock/OCMReturnValueProvider.m b/Source/OCMock/OCMReturnValueProvider.m index 18c3ded7..abd28f09 100644 --- a/Source/OCMock/OCMReturnValueProvider.m +++ b/Source/OCMock/OCMReturnValueProvider.m @@ -26,8 +26,8 @@ - (void)handleInvocation:(NSInvocation *)anInvocation { const char *returnType = [[anInvocation methodSignature] methodReturnTypeWithoutQualifiers]; if(strcmp(returnType, @encode(id)) != 0) { - // if the returnType is a typedef to an object, it has the form ^{OriginalClass=#} - NSString *regexString = @"^\\^\\{(.*)=#@*\\}"; + // if the returnType is a typedef to an object, it has the form ^{OriginClass=#} + NSString *regexString = @"^\\^\\{(.*)=#.*\\}"; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:0 error:NULL]; NSString *type = [NSString stringWithCString:returnType encoding:NSASCIIStringEncoding]; if([regex numberOfMatchesInString:type options:0 range:NSMakeRange(0, type.length)] == 0) diff --git a/Source/OCMockTests/OCMockObjectProtocolMocksTests.m b/Source/OCMockTests/OCMockObjectProtocolMocksTests.m index 61a16964..3a77d427 100644 --- a/Source/OCMockTests/OCMockObjectProtocolMocksTests.m +++ b/Source/OCMockTests/OCMockObjectProtocolMocksTests.m @@ -17,7 +17,10 @@ - (int)primitiveValue; - (id)objectValue; @end -@interface InterfaceForTypedef : NSObject +@interface InterfaceForTypedef : NSObject { + int prop1; + NSObject *prop2; +} @end @implementation InterfaceForTypedef @@ -88,19 +91,19 @@ - (void)testDoesNotRespondToInvalidProtocolSelector - (void)testWithTypedefReturnType { id mock = [OCMockObject mockForProtocol:@protocol(ProtocolWithTypedefs)]; STAssertNoThrow([[[mock stub] andReturn:[TypedefInterface new]] typedefReturnValue1], @"Should accept a typedefed return-type"); - STAssertNoThrow([mock typedefReturnValue1], @"bla"); + STAssertNoThrow([mock typedefReturnValue1], nil); } - (void)testWithTypedefPointerReturnType { id mock = [OCMockObject mockForProtocol:@protocol(ProtocolWithTypedefs)]; STAssertNoThrow([[[mock stub] andReturn:[TypedefInterface new]] typedefReturnValue2], @"Should accept a typedefed return-type"); - STAssertNoThrow([mock typedefReturnValue2], @"bla"); + STAssertNoThrow([mock typedefReturnValue2], nil); } - (void)testWithTypedefParameter { id mock = [OCMockObject mockForProtocol:@protocol(ProtocolWithTypedefs)]; STAssertNoThrow([[mock stub] typedefParameter:nil], @"Should accept a typedefed parameter-type"); - STAssertNoThrow([mock typedefParameter:nil], @"bla"); + STAssertNoThrow([mock typedefParameter:nil], nil); }