diff --git a/Source/OCMock/NSInvocation+OCMAdditions.m b/Source/OCMock/NSInvocation+OCMAdditions.m index 112d7a77..ae5f1c38 100644 --- a/Source/OCMock/NSInvocation+OCMAdditions.m +++ b/Source/OCMock/NSInvocation+OCMAdditions.m @@ -80,7 +80,7 @@ - (void)retainObjectArgumentsExcludingObject:(id)objectToExclude for(NSUInteger index = 2; index < numberOfArguments; index++) { const char *argumentType = [[self methodSignature] getArgumentTypeAtIndex:index]; - if(OCMIsObjectType(argumentType) && !OCMIsClassType(argumentType)) + if(OCMIsObjectType(argumentType)) { id argument; [self getArgument:&argument atIndex:index]; @@ -102,7 +102,7 @@ - (void)retainObjectArgumentsExcludingObject:(id)objectToExclude } const char *returnType = [[self methodSignature] methodReturnType]; - if(OCMIsObjectType(returnType) && !OCMIsClassType(returnType)) + if(OCMIsObjectType(returnType)) { id returnValue; [self getReturnValue:&returnValue]; diff --git a/Source/OCMock/OCMFunctions.m b/Source/OCMock/OCMFunctions.m index 758ed3d2..69bbdaad 100644 --- a/Source/OCMock/OCMFunctions.m +++ b/Source/OCMock/OCMFunctions.m @@ -48,11 +48,6 @@ static BOOL OCMIsUnqualifiedClassType(const char *unqualifiedObjCType) return (strcmp(unqualifiedObjCType, @encode(Class)) == 0); } -BOOL OCMIsClassType(const char *objCType) -{ - return OCMIsUnqualifiedClassType(OCMTypeWithoutQualifiers(objCType)); -} - static BOOL OCMIsUnqualifiedBlockType(const char *unqualifiedObjCType) { diff --git a/Source/OCMock/OCMFunctionsPrivate.h b/Source/OCMock/OCMFunctionsPrivate.h index 1984c228..96a2721a 100644 --- a/Source/OCMock/OCMFunctionsPrivate.h +++ b/Source/OCMock/OCMFunctionsPrivate.h @@ -21,7 +21,6 @@ @class OCPartialMockObject; -BOOL OCMIsClassType(const char *objCType); BOOL OCMIsBlockType(const char *objCType); BOOL OCMIsObjectType(const char *objCType); const char *OCMTypeWithoutQualifiers(const char *objCType); diff --git a/Source/OCMockTests/OCMockObjectTests.m b/Source/OCMockTests/OCMockObjectTests.m index 62ad5639..79c62f72 100644 --- a/Source/OCMockTests/OCMockObjectTests.m +++ b/Source/OCMockTests/OCMockObjectTests.m @@ -172,6 +172,22 @@ - (void)doStuffWithBlock:(void (^)(id arg))block; @end +@interface TestClassWithClassArgMethod : NSObject + +- (void)doStuffWithClass:(Class)aClass; + +@end + +@implementation TestClassWithClassArgMethod + +- (void)doStuffWithClass:(Class)aClass +{ + // stubbed out anyway +} + +@end + + static NSString *TestNotification = @"TestNotification"; @@ -986,7 +1002,6 @@ - (void)testFailsVerifyExpectedMethodsWithDelay XCTAssertThrows([mock verifyWithDelay:0.1], @"Should have raised an exception because method was not called."); } - // -------------------------------------------------------------------------------------- // ordered expectations // -------------------------------------------------------------------------------------- @@ -1171,7 +1186,8 @@ - (void)testVerifyWithDelayDoesNotWaitForRejects XCTAssertTrue([end timeIntervalSinceDate:start] < 3, @"Should have returned before delay was up"); } -- (void)testNoResetMockStateOnInit + +- (void)testDoesNotReinitialiseMockWhenInitIsCalledMoreThanOnce { mock = OCMClassMock([TestClassWithProperty class]); OCMStub([mock alloc]).andReturn(mock); @@ -1181,6 +1197,17 @@ - (void)testNoResetMockStateOnInit XCTAssertEqualObjects(@"foo", object.title); } + +- (void)testClassArgsAreRetained +{ + + id mockWithClassMethod = OCMClassMock([TestClassWithClassArgMethod class]); + @autoreleasepool { + [[mockWithClassMethod stub] doStuffWithClass:[OCMArg any]]; + } + XCTAssertNoThrow([mockWithClassMethod doStuffWithClass:[NSString class]]); +} + @end