Skip to content

Commit

Permalink
Fix issues identified by Facebook Infer
Browse files Browse the repository at this point in the history
  • Loading branch information
madsolar8582 committed Jun 20, 2015
1 parent da6dc18 commit e50f4f9
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 30 deletions.
7 changes: 5 additions & 2 deletions Source/OCMock/OCMBlockCaller.m
Expand Up @@ -21,8 +21,11 @@ @implementation OCMBlockCaller

-(id)initWithCallBlock:(void (^)(NSInvocation *))theBlock
{
self = [super init];
block = [theBlock copy];
if ((self = [super init]))
{
block = [theBlock copy];
}

return self;
}

Expand Down
9 changes: 6 additions & 3 deletions Source/OCMock/OCMConstraint.m
Expand Up @@ -134,8 +134,11 @@ @implementation OCMBlockConstraint

- (instancetype)initWithConstraintBlock:(BOOL (^)(id))aBlock
{
self = [super init];
block = [aBlock copy];
if ((self = [super init]))
{
block = [aBlock copy];
}

return self;
}

Expand All @@ -146,7 +149,7 @@ - (void)dealloc {

- (BOOL)evaluate:(id)value
{
return block(value);
return block ? block(value) : NO;
}


Expand Down
8 changes: 4 additions & 4 deletions Source/OCMock/OCMFunctions.m
Expand Up @@ -189,8 +189,8 @@ Class OCMGetIsa(id object)

#pragma mark Alias for renaming real methods

NSString *OCMRealMethodAliasPrefix = @"ocmock_replaced_";
const char *OCMRealMethodAliasPrefixCString = "ocmock_replaced_";
static NSString *const OCMRealMethodAliasPrefix = @"ocmock_replaced_";
static const char *const OCMRealMethodAliasPrefixCString = "ocmock_replaced_";

BOOL OCMIsAliasSelector(SEL selector)
{
Expand All @@ -217,7 +217,7 @@ SEL OCMOriginalSelectorForAlias(SEL selector)

#pragma mark Wrappers around associative references

NSString *OCMClassMethodMockObjectKey = @"OCMClassMethodMockObjectKey";
static NSString *const OCMClassMethodMockObjectKey = @"OCMClassMethodMockObjectKey";

void OCMSetAssociatedMockForClass(OCClassMockObject *mock, Class aClass)
{
Expand All @@ -238,7 +238,7 @@ void OCMSetAssociatedMockForClass(OCClassMockObject *mock, Class aClass)
return mock;
}

NSString *OCMPartialMockObjectKey = @"OCMPartialMockObjectKey";
static NSString *const OCMPartialMockObjectKey = @"OCMPartialMockObjectKey";

void OCMSetAssociatedMockForObject(OCClassMockObject *mock, id anObject)
{
Expand Down
9 changes: 6 additions & 3 deletions Source/OCMock/OCMIndirectReturnValueProvider.m
Expand Up @@ -23,9 +23,12 @@ @implementation OCMIndirectReturnValueProvider

- (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector
{
self = [super init];
provider = [aProvider retain];
selector = aSelector;
if ((self = [super init]))
{
provider = [aProvider retain];
selector = aSelector;
}

return self;
}

Expand Down
11 changes: 7 additions & 4 deletions Source/OCMock/OCMLocation.m
Expand Up @@ -25,10 +25,13 @@ + (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(

- (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine
{
self = [super init];
testCase = aTestCase;
file = [aFile retain];
line = aLine;
if ((self = [super init]))
{
testCase = aTestCase;
file = [aFile retain];
line = aLine;
}

return self;
}

Expand Down
9 changes: 6 additions & 3 deletions Source/OCMock/OCMMacroState.m
Expand Up @@ -24,7 +24,7 @@

@implementation OCMMacroState

OCMMacroState *globalState;
static OCMMacroState *globalState;

#pragma mark Methods to begin/end macros

Expand Down Expand Up @@ -79,8 +79,11 @@ + (OCMMacroState *)globalState

- (id)initWithRecorder:(OCMRecorder *)aRecorder
{
self = [super init];
recorder = [aRecorder retain];
if ((self = [super init]))
{
recorder = [aRecorder retain];
}

return self;
}

Expand Down
7 changes: 5 additions & 2 deletions Source/OCMock/OCMNotificationPoster.m
Expand Up @@ -21,8 +21,11 @@ @implementation OCMNotificationPoster

- (id)initWithNotification:(id)aNotification
{
self = [super init];
notification = [aNotification retain];
if ((self = [super init]))
{
notification = [aNotification retain];
}

return self;
}

Expand Down
7 changes: 5 additions & 2 deletions Source/OCMock/OCMPassByRefSetter.m
Expand Up @@ -21,8 +21,11 @@ @implementation OCMPassByRefSetter

- (id)initWithValue:(id)aValue
{
self = [super init];
value = [aValue retain];
if ((self = [super init]))
{
value = [aValue retain];
}

return self;
}

Expand Down
7 changes: 5 additions & 2 deletions Source/OCMock/OCMReturnValueProvider.m
Expand Up @@ -23,8 +23,11 @@ @implementation OCMReturnValueProvider

- (instancetype)initWithValue:(id)aValue
{
self = [super init];
returnValue = [aValue retain];
if ((self = [super init]))
{
returnValue = [aValue retain];
}

return self;
}

Expand Down
7 changes: 5 additions & 2 deletions Source/OCMock/OCMVerifier.m
Expand Up @@ -25,8 +25,11 @@ @implementation OCMVerifier

- (id)init
{
self = [super init];
invocationMatcher = [[OCMInvocationMatcher alloc] init];
if ((self = [super init]))
{
invocationMatcher = [[OCMInvocationMatcher alloc] init];
}

return self;
}

Expand Down
9 changes: 6 additions & 3 deletions Source/OCMock/OCObserverMockObject.m
Expand Up @@ -26,9 +26,12 @@ @implementation OCObserverMockObject

- (id)init
{
self = [super init];
recorders = [[NSMutableArray alloc] init];
centers = [[NSMutableArray alloc] init];
if ((self = [super init]))
{
recorders = [[NSMutableArray alloc] init];
centers = [[NSMutableArray alloc] init];
}

return self;
}

Expand Down
6 changes: 6 additions & 0 deletions Source/OCMockTests/OCMConstraintTests.m
Expand Up @@ -143,5 +143,11 @@ -(void)testBlockConstraintCanCaptureArgument
XCTAssertEqualObjects(@"bar", captured, @"Should have captured value from last invocation.");
}

- (void)testEvaluateNilBlockReturnsNo
{
OCMBlockConstraint *constraint = [[OCMBlockConstraint alloc] initWithConstraintBlock:nil];

XCTAssertFalse([constraint evaluate:@"foo"]);
}

@end

0 comments on commit e50f4f9

Please sign in to comment.