Reputation: 9742
I was trying to do:
[[[mockQuestion stub] andReturnValue:YES] shouldNegate];
[[[mockQuestion stub] andReturnValue:123] randomNumberWithLimit];
But that gave me this warning/error "incompatible integer pointer conversion sending 'BOOL' (aka 'signed char') to parameter of type 'NSValue *'"
The only way I could figure out to get around it was to do:
BOOL boolValue = YES;
int num = 123;
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(boolValue)] shouldNegate];
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(num)] randomNumberWithLimit];
But that makes my test code seem so overly verbose.. Is there a way to do this all inline without having to set variables?
Upvotes: 1
Views: 1273
Reputation: 5960
The parameter is supposed to be an object pointer. In this case it should point to an object of the NSValue class.
Upvotes: 0
Reputation: 185701
You can use a literal style that looks like (type){value}
. This is commonly used to create struct literals but works for basic datatypes too. The important aspect here is that this type of literal creates a temporary that can be addressed. This means you can write your code like
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE((BOOL){YES})] shouldNegate];
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE((int){123})] randomNumberWithLimit];
Upvotes: 3