-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for unretained and unsafeunretained arguments for stubs.
Allows marking an argument in a stub as being either 'unsafe' or 'unsafeunretained'. An unsafe object argument is retained by the stub, but not by invocations on the mock. An unsafe unretained object argument is not retained by the stub or by invocations on the mock. This allows for mocking of methods that do not retain their arguments. This should simplify testing of methods that are called in dealloc, and give people a way out of other retain-loop problems.
- Loading branch information
Showing
13 changed files
with
312 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2015-2020 Erik Doernenburg and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use these files except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
// Do not use directly. See methods and comments in OCMArg.h for usage. | ||
@interface OCMUnretainedArgument : NSObject | ||
{ | ||
id object; | ||
BOOL isSafe; | ||
} | ||
|
||
- (instancetype)initWithObject:(id)anObject safe:(BOOL)safe; | ||
- (id)object; | ||
- (BOOL)isSafe; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2015-2020 Erik Doernenburg and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use these files except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#import "OCMUnretainedArgument.h" | ||
|
||
|
||
@implementation OCMUnretainedArgument | ||
|
||
- (instancetype)initWithObject:(id)anObject safe:(BOOL)safe | ||
{ | ||
if (anObject == nil) | ||
{ | ||
[NSException raise:NSInvalidArgumentException format:@"Object must be non-nil for OCMUnretainedArgument"]; | ||
} | ||
if ((self = [super init])) | ||
{ | ||
object = anObject; | ||
isSafe = safe; | ||
if (isSafe) | ||
{ | ||
object = [anObject retain]; | ||
} | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
if (isSafe) | ||
{ | ||
[object release]; | ||
} | ||
[super dealloc]; | ||
} | ||
|
||
- (id)object | ||
{ | ||
return object; | ||
} | ||
|
||
- (BOOL)isSafe | ||
{ | ||
return isSafe; | ||
} | ||
|
||
@end |
Oops, something went wrong.