1

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?

patrick
  • 9,290
  • 13
  • 61
  • 112

2 Answers2

3

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];
Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
0

The parameter is supposed to be an object pointer. In this case it should point to an object of the NSValue class.

Jim
  • 5,940
  • 9
  • 44
  • 91