Skip to content

Commit 863d7b3

Browse files
committed
Merge branch 'invocationDescriptions' of https://github.com/dmaclach/ocmock into dmaclach-invocationDescriptions
2 parents 0abeea9 + 64b0856 commit 863d7b3

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

Source/OCMock/NSInvocation+OCMAdditions.m

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#import "NSInvocation+OCMAdditions.h"
2121
#import "OCMFunctionsPrivate.h"
2222
#import "NSMethodSignature+OCMAdditions.h"
23-
23+
#import "OCMArg.h"
2424

2525
#if (TARGET_OS_OSX && (!defined(__MAC_10_10) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_10)) || \
2626
(TARGET_OS_IPHONE && (!defined(__IPHONE_8_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0))
@@ -351,6 +351,11 @@ - (NSString *)invocationDescription
351351
return [description autorelease];
352352
}
353353

354+
- (NSString *)anyPointerDescription
355+
{
356+
return @"<Any Pointer>";
357+
}
358+
354359
- (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex
355360
{
356361
const char *argType = OCMTypeWithoutQualifiers([[self methodSignature] getArgumentTypeAtIndex:(NSUInteger)argIndex]);
@@ -524,18 +529,32 @@ - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt
524529
void *buffer;
525530

526531
[self getArgument:&buffer atIndex:anInt];
527-
return [NSString stringWithFormat:@"%p", buffer];
532+
if(buffer == [OCMArg anyPointer])
533+
{
534+
return [self anyPointerDescription];
535+
}
536+
else
537+
{
538+
return [NSString stringWithFormat:@"%p", buffer];
539+
}
528540
}
529541

530542
- (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt
531543
{
532-
char buffer[104];
533544
char *cStringPtr;
534545

535546
[self getArgument:&cStringPtr atIndex:anInt];
536-
strlcpy(buffer, cStringPtr, sizeof(buffer));
537-
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
538-
return [NSString stringWithFormat:@"\"%s\"", buffer];
547+
if(cStringPtr == [OCMArg anyPointer])
548+
{
549+
return [self anyPointerDescription];
550+
}
551+
else
552+
{
553+
char buffer[104];
554+
strlcpy(buffer, cStringPtr, sizeof(buffer));
555+
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
556+
return [NSString stringWithFormat:@"\"%s\"", buffer];
557+
}
539558
}
540559

541560
- (NSString *)selectorDescriptionAtIndex:(NSInteger)anInt

Source/OCMockTests/NSInvocationOCMAdditionsTests.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <XCTest/XCTest.h>
1818
#import "NSInvocation+OCMAdditions.h"
19-
19+
#import "OCMArg.h"
2020

2121
@implementation NSValue(OCMTestAdditions)
2222

@@ -271,6 +271,15 @@ - (void)testInvocationDescriptionWithCStringArgument
271271
XCTAssertEqualObjects(expected, [invocation invocationDescription], @"");
272272
}
273273

274+
- (void)testInvocationDescriptionWithCStringArgumentAnyPointer
275+
{
276+
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithUTF8String:)];
277+
const char *cString = [OCMArg anyPointer];
278+
[invocation setArgument:&cString atIndex:2];
279+
280+
XCTAssertEqualObjects(@"initWithUTF8String:<Any Pointer>", [invocation invocationDescription]);
281+
}
282+
274283
- (void)testInvocationDescriptionWithSelectorArgument
275284
{
276285
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(respondsToSelector:)];
@@ -297,6 +306,20 @@ - (void)testInvocationDescriptionWithPointerArgument
297306
XCTAssertTrue([invocationDescription rangeOfString:expected2].length > 0, @"");
298307
}
299308

309+
- (void)testInvocationDescriptionWithPointerArgumentAnyPointer
310+
{
311+
NSInvocation *invocation = [self invocationForClass:[NSData class] selector:@selector(initWithBytes:length:)];
312+
const void *bytes = [OCMArg anyPointer];
313+
NSUInteger length = 1500;
314+
[invocation setArgument:&bytes atIndex:2];
315+
[invocation setArgument:&length atIndex:3];
316+
317+
NSString *expected = [NSString stringWithFormat:@"initWithBytes:<Any Pointer> length:%lu", (unsigned long)length];
318+
NSString *invocationDescription = [invocation invocationDescription];
319+
XCTAssertEqualObjects(expected, invocationDescription);
320+
}
321+
322+
300323
- (void)testInvocationDescriptionWithNilArgument
301324
{
302325
NSInvocation *invocation = [self invocationForClass:[NSString class] selector:@selector(initWithString:)];

0 commit comments

Comments
 (0)