Compiler confused about mock type

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Compiler confused about mock type

Postby tron_thomas » 28 Jan 2013, 04:04

I have test code like this:

Code: Select all
id mock = [OCMockObject mockForProtocol:@protocol(SomeProtocol)];
Vector direction = { 1.0f, 2.0f, 3.0f };
[[mock expect] setDirection:direction];

When I try to compile, I'm getting warnings and errors like this:

warning: multiple methods named 'setDirection:' found

error: sending'Vector' to parameter of incompatible type 'UISwipeGestureRecognizerDirection' (aka 'enum UISwipeGestureRecognizerDirection')

Obviously the compiler is not able to determine what type of object the mock is supposed to be. I'm not sure how to specify that it should deal with the setDirection method from the SomeProtocol protocol instead of a setDirection method from another class.

What can be done to make a test like this build successfully?
tron_thomas
 
Posts: 19
Joined: 04 Mar 2012, 02:14

Re: Compiler confused about mock type

Postby erik » 08 May 2013, 14:56

It should be possible to cast the return value of the expect call, e.g.

Code: Select all
[((id <SomeProtocol>)[mock expect]) setDirection:direction];
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Compiler confused about mock type

Postby tron_thomas » 11 May 2013, 23:37

I posted this problem while ago so I don't remember what I tried or how I resolved the it. It seems that I would have tried a cast like that before posting, and did find that it worked for me.

However, I did recreate the test and verified the cast did in fact result in a test that would build and run.
tron_thomas
 
Posts: 19
Joined: 04 Mar 2012, 02:14


Return to OCMock



cron