Skip to content

Commit

Permalink
Merge branch 'jackwu95-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed May 27, 2018
2 parents 24758f8 + bbee598 commit 4334d66
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/OCMock/NSInvocation+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down
5 changes: 0 additions & 5 deletions Source/OCMock/OCMFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion Source/OCMock/OCMFunctionsPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 29 additions & 2 deletions Source/OCMockTests/OCMockObjectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ - (void)doStuffWithBlock:(void (^)(id<TestProtocol> 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";


Expand Down Expand Up @@ -986,7 +1002,6 @@ - (void)testFailsVerifyExpectedMethodsWithDelay
XCTAssertThrows([mock verifyWithDelay:0.1], @"Should have raised an exception because method was not called.");
}


// --------------------------------------------------------------------------------------
// ordered expectations
// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
Expand All @@ -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


0 comments on commit 4334d66

Please sign in to comment.