Skip to content

Commit ffeeed2

Browse files
committed
Merge branch 'dmaclach-invocationDescriptions'
2 parents 0abeea9 + 0bd6508 commit ffeeed2

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

Source/OCMock/NSInvocation+OCMAdditions.m

Lines changed: 21 additions & 7 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))
@@ -30,6 +30,8 @@ static BOOL OCMObjectIsClass(id object) {
3030
#define object_isClass OCMObjectIsClass
3131
#endif
3232

33+
static NSString *const OCMArgAnyPointerDescription = @"<[OCMArg anyPointer]>";
34+
3335

3436
@implementation NSInvocation(OCMAdditions)
3537

@@ -331,6 +333,7 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
331333
return nil;
332334
}
333335

336+
334337
- (NSString *)invocationDescription
335338
{
336339
NSMethodSignature *methodSignature = [self methodSignature];
@@ -381,7 +384,6 @@ - (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex
381384

382385
}
383386

384-
385387
- (NSString *)objectDescriptionAtIndex:(NSInteger)anInt
386388
{
387389
id object;
@@ -524,18 +526,30 @@ - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt
524526
void *buffer;
525527

526528
[self getArgument:&buffer atIndex:anInt];
527-
return [NSString stringWithFormat:@"%p", buffer];
529+
530+
if(buffer == [OCMArg anyPointer])
531+
return OCMArgAnyPointerDescription;
532+
else
533+
return [NSString stringWithFormat:@"%p", buffer];
528534
}
529535

530536
- (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt
531537
{
532-
char buffer[104];
533538
char *cStringPtr;
534539

535540
[self getArgument:&cStringPtr atIndex:anInt];
536-
strlcpy(buffer, cStringPtr, sizeof(buffer));
537-
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
538-
return [NSString stringWithFormat:@"\"%s\"", buffer];
541+
542+
if(cStringPtr == [OCMArg anyPointer])
543+
{
544+
return OCMArgAnyPointerDescription;
545+
}
546+
else
547+
{
548+
char buffer[104];
549+
strlcpy(buffer, cStringPtr, sizeof(buffer));
550+
strlcpy(buffer + 100, "...", (sizeof(buffer) - 100));
551+
return [NSString stringWithFormat:@"\"%s\"", buffer];
552+
}
539553
}
540554

541555
- (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:<[OCMArg anyPointer]>", [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:<[OCMArg anyPointer]> 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)