Skip to content

Commit

Permalink
Merge branch 'dmaclach-invocationDescriptions'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed Aug 10, 2020
2 parents 0abeea9 + 0bd6508 commit ffeeed2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
28 changes: 21 additions & 7 deletions Source/OCMock/NSInvocation+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "NSInvocation+OCMAdditions.h"
#import "OCMFunctionsPrivate.h"
#import "NSMethodSignature+OCMAdditions.h"

#import "OCMArg.h"

#if (TARGET_OS_OSX && (!defined(__MAC_10_10) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_10)) || \
(TARGET_OS_IPHONE && (!defined(__IPHONE_8_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0))
Expand All @@ -30,6 +30,8 @@ static BOOL OCMObjectIsClass(id object) {
#define object_isClass OCMObjectIsClass
#endif

static NSString *const OCMArgAnyPointerDescription = @"<[OCMArg anyPointer]>";


@implementation NSInvocation(OCMAdditions)

Expand Down Expand Up @@ -331,6 +333,7 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
return nil;
}


- (NSString *)invocationDescription
{
NSMethodSignature *methodSignature = [self methodSignature];
Expand Down Expand Up @@ -381,7 +384,6 @@ - (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex

}


- (NSString *)objectDescriptionAtIndex:(NSInteger)anInt
{
id object;
Expand Down Expand Up @@ -524,18 +526,30 @@ - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt
void *buffer;

[self getArgument:&buffer atIndex:anInt];
return [NSString stringWithFormat:@"%p", buffer];

if(buffer == [OCMArg anyPointer])
return OCMArgAnyPointerDescription;
else
return [NSString stringWithFormat:@"%p", buffer];
}

- (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt
{
char buffer[104];
char *cStringPtr;

[self getArgument:&cStringPtr atIndex:anInt];
strlcpy(buffer, cStringPtr, sizeof(buffer));
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
return [NSString stringWithFormat:@"\"%s\"", buffer];

if(cStringPtr == [OCMArg anyPointer])
{
return OCMArgAnyPointerDescription;
}
else
{
char buffer[104];
strlcpy(buffer, cStringPtr, sizeof(buffer));
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
return [NSString stringWithFormat:@"\"%s\"", buffer];
}
}

- (NSString *)selectorDescriptionAtIndex:(NSInteger)anInt
Expand Down
25 changes: 24 additions & 1 deletion Source/OCMockTests/NSInvocationOCMAdditionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#import <XCTest/XCTest.h>
#import "NSInvocation+OCMAdditions.h"

#import "OCMArg.h"

@implementation NSValue(OCMTestAdditions)

Expand Down Expand Up @@ -271,6 +271,15 @@ - (void)testInvocationDescriptionWithCStringArgument
XCTAssertEqualObjects(expected, [invocation invocationDescription], @"");
}

- (void)testInvocationDescriptionWithCStringArgumentAnyPointer
{
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithUTF8String:)];
const char *cString = [OCMArg anyPointer];
[invocation setArgument:&cString atIndex:2];

XCTAssertEqualObjects(@"initWithUTF8String:<[OCMArg anyPointer]>", [invocation invocationDescription]);
}

- (void)testInvocationDescriptionWithSelectorArgument
{
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(respondsToSelector:)];
Expand All @@ -297,6 +306,20 @@ - (void)testInvocationDescriptionWithPointerArgument
XCTAssertTrue([invocationDescription rangeOfString:expected2].length > 0, @"");
}

- (void)testInvocationDescriptionWithPointerArgumentAnyPointer
{
NSInvocation *invocation = [self invocationForClass:[NSData class] selector:@selector(initWithBytes:length:)];
const void *bytes = [OCMArg anyPointer];
NSUInteger length = 1500;
[invocation setArgument:&bytes atIndex:2];
[invocation setArgument:&length atIndex:3];

NSString *expected = [NSString stringWithFormat:@"initWithBytes:<[OCMArg anyPointer]> length:%lu", (unsigned long)length];
NSString *invocationDescription = [invocation invocationDescription];
XCTAssertEqualObjects(expected, invocationDescription);
}


- (void)testInvocationDescriptionWithNilArgument
{
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithString:)];
Expand Down

0 comments on commit ffeeed2

Please sign in to comment.