Skip to content

Commit

Permalink
Merge pull request #129 from madsolar8582/modernobjc
Browse files Browse the repository at this point in the history
Use Literals and Object Subscripting
  • Loading branch information
erikdoe committed Aug 20, 2014
2 parents 60be17f + 7389f42 commit f4a0e27
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
26 changes: 13 additions & 13 deletions Source/OCMock/NSInvocation+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,73 +59,73 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
{
int value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithInt:value];
return @(value);
}
case 's':
{
short value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithShort:value];
return @(value);
}
case 'l':
{
long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithLong:value];
return @(value);
}
case 'q':
{
long long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithLongLong:value];
return @(value);
}
case 'c':
{
char value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithChar:value];
return @(value);
}
case 'C':
{
unsigned char value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedChar:value];
return @(value);
}
case 'I':
{
unsigned int value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedInt:value];
return @(value);
}
case 'S':
{
unsigned short value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedShort:value];
return @(value);
}
case 'L':
{
unsigned long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedLong:value];
return @(value);
}
case 'Q':
{
unsigned long long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedLongLong:value];
return @(value);
}
case 'f':
{
float value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithFloat:value];
return @(value);
}
case 'd':
{
double value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithDouble:value];
return @(value);
}
case 'D':
{
Expand All @@ -137,7 +137,7 @@ - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex
{
bool value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithBool:value];
return @(value);
}
case '^':
case '*':
Expand Down
2 changes: 1 addition & 1 deletion Source/OCMock/NSObject+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector
{
NSMethodSignature *sig = [self instanceMethodSignatureForSelector:aSelector];
needsStructureReturn = [sig usesSpecialStructureReturn];
[_OCMReturnTypeCache setObject:[NSNumber numberWithBool:needsStructureReturn] forKey:cacheKey];
[_OCMReturnTypeCache setObject:@(needsStructureReturn) forKey:cacheKey];
}
else
{
Expand Down
30 changes: 15 additions & 15 deletions Source/OCMock/NSValue+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ static CFNumberType OCMNumberTypeForObjCType(const char *objcType)

static NSNumber *OCMNumberForValue(NSValue *value)
{
#define CREATE_NUM(_type, _meth) ({ _type _v; [value getValue:&_v]; [NSNumber _meth _v]; })
#define CREATE_NUM(_type) ({ _type _v; [value getValue:&_v]; @(_v); })
switch([value objCType][0])
{
case 'c': return CREATE_NUM(char, numberWithChar:);
case 'C': return CREATE_NUM(unsigned char, numberWithUnsignedChar:);
case 'B': return CREATE_NUM(bool, numberWithBool:);
case 's': return CREATE_NUM(short, numberWithShort:);
case 'S': return CREATE_NUM(unsigned short, numberWithUnsignedShort:);
case 'i': return CREATE_NUM(int, numberWithInt:);
case 'I': return CREATE_NUM(unsigned int, numberWithUnsignedInt:);
case 'l': return CREATE_NUM(long, numberWithLong:);
case 'L': return CREATE_NUM(unsigned long, numberWithUnsignedLong:);
case 'q': return CREATE_NUM(long long, numberWithLongLong:);
case 'Q': return CREATE_NUM(unsigned long long, numberWithUnsignedLongLong:);
case 'f': return CREATE_NUM(float, numberWithFloat:);
case 'd': return CREATE_NUM(double, numberWithDouble:);
case 'c': return CREATE_NUM(char);
case 'C': return CREATE_NUM(unsigned char);
case 'B': return CREATE_NUM(bool);
case 's': return CREATE_NUM(short);
case 'S': return CREATE_NUM(unsigned short);
case 'i': return CREATE_NUM(int);
case 'I': return CREATE_NUM(unsigned int);
case 'l': return CREATE_NUM(long);
case 'L': return CREATE_NUM(unsigned long);
case 'q': return CREATE_NUM(long long);
case 'Q': return CREATE_NUM(unsigned long long);
case 'f': return CREATE_NUM(float);
case 'd': return CREATE_NUM(double);
default: return nil;
}
}
Expand Down Expand Up @@ -104,4 +104,4 @@ - (BOOL)getBytes:(void *)outputBuf objCType:(const char *)targetType
}


@end
@end
6 changes: 3 additions & 3 deletions Source/OCMockTests/NSInvocationOCMAdditionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)testInvocationDescriptionWithObjectArgument
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it one argument (starts at index 2)
NSNumber *argument = [NSNumber numberWithInt:1];
NSNumber *argument = @1;
[invocation setArgument:&argument atIndex:2];

NSString *expected = [NSString stringWithFormat:@"isEqualToNumber:%d", 1];
Expand Down Expand Up @@ -80,7 +80,7 @@ - (void)testInvocationDescriptionWithObjectArguments
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it two arguments
NSNumber *argumentOne = [NSNumber numberWithInt:1];
NSNumber *argumentOne = @1;
NSString *argumentTwo = @"TEST_STRING";
[invocation setArgument:&argumentOne atIndex:2];
[invocation setArgument:&argumentTwo atIndex:3];
Expand All @@ -96,7 +96,7 @@ - (void)testInvocationDescriptionWithArrayArgument
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it one argument (starts at index 2)
NSArray *argument = [NSArray arrayWithObject:@"TEST_STRING"];
NSArray *argument = @[@"TEST_STRING"];
[invocation setArgument:&argument atIndex:2];

NSString *expected = [NSString stringWithFormat:@"addObjectsFromArray:%@", [argument description]];
Expand Down
6 changes: 3 additions & 3 deletions Source/OCMockTests/OCObserverMockObjectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)testAcceptsExpectedNotification
- (void)testAcceptsExpectedNotificationWithSpecifiedObjectAndUserInfo
{
[center addMockObserver:mock name:TestNotificationOne object:nil];
NSDictionary *info = [NSDictionary dictionaryWithObject:@"foo" forKey:@"key"];
NSDictionary *info = @{@"key": @"foo"};
[[mock expect] notificationWithName:TestNotificationOne object:self userInfo:info];

[center postNotificationName:TestNotificationOne object:self userInfo:info];
Expand Down Expand Up @@ -121,9 +121,9 @@ - (void)testRaisesWhenNotificationWithWrongUserInfoIsReceived
{
[center addMockObserver:mock name:TestNotificationOne object:nil];
[[mock expect] notificationWithName:TestNotificationOne object:self
userInfo:[NSDictionary dictionaryWithObject:@"foo" forKey:@"key"]];
userInfo:@{@"key": @"foo"}];
XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string]
userInfo:[NSDictionary dictionaryWithObject:@"bar" forKey:@"key"]]);
userInfo:@{@"key": @"bar"}]);
}

- (void)testRaisesOnVerifyWhenExpectedNotificationIsNotSent
Expand Down

0 comments on commit f4a0e27

Please sign in to comment.