I'm learning how to use OCMock to test my iPhone's project and I have this scenario: a HeightMap class with a getHeightAtX:andY:
method, and a Render class using HeightMap
. I'm trying to unit test Render using some HeightMap
mocks. This works:
id mock = [OCMockObject mockForClass:[Chunk class]];
int h = 0;
[[[mock stub] andReturnValue:OCMOCK_VALUE(h)] getHeightAtX:0 andY:0];
Of course, works only for x=0
and y=0
. I want to test using a "flat" height map. This means I need to do something like this:
id chunk = [OCMockObject mockForClass:[Chunk class]];
int h = 0;
[[[chunk stub] andReturnValue:OCMOCK_VALUE(h)] getHeightAtX:[OCMArg any] andY:[OCMArg any]];
But this raises two compilation warnings:
warning: passing argument 1 of
'getHeightAtX:andY:'
makes integer from pointer without a cast
and a runtime error:
unexpected method invoked:
'getHeightAtX:0 andY:0 stubbed: getHeightAtX:15545040 andY:15545024'
What am I missing? I found no way to pass a anyValue
to this mock.