OCMOCK_ANY for values

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.

OCMOCK_ANY for values

Postby phodgson » 02 Feb 2011, 22:18

Hi,

I'm trying to check that a method is being called on an object, but I don't care about the arguments. One of the arguments is a value (a SEL). Here's an example that shows the problem I'm getting:

Code: Select all
   [[mockActionConfirmer expect] confirmActionWithCallback:OCMOCK_ANY onObject:OCMOCK_ANY];
   [mockActionConfirmer confirmActionWithCallback:@selector(dummySelector) onObject:nil];   
   [mockActionConfirmer verify];


This fails with :
Code: Select all
2011-02-02 12:15:24.879Unit Tests[53791:903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'OCMockObject[ActionConfirmer]: unexpected method invoked: confirmActionWithCallback:@selector(dummySelector) onObject:nil


   expected:    confirmActionWithCallback:@selector((null)) onObject:<OCMAnyConstraint: 0x5e3c270>'



I'm assuming this doesn't work because I'm trying to use OCMOCK_ANY to set an expectation for a value type (SEL). Is there a way for me to set such an expectation?

Cheers,
Pete
phodgson
 

Re: OCMOCK_ANY for values

Postby erik » 02 Feb 2011, 22:39

A very reasonable request but unfortunately we haven't found a good enough solution to do this. Some background in the discussion of this topic:

http://www.mulle-kybernetik.com/forum/viewtopic.php?f=4&t=72
erik
 
Posts: 71
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: OCMOCK_ANY for values

Postby fourdman » 27 Oct 2011, 23:50

I have an idea that may be helpful for SEL-typed arguments in particular. This will not work for any other primitive type, but the point is that SEL is a special pointer. Right now it's converted into a string in getArgumentAtIndexAsObject: and then later treated as a usual object. And in fact that's the only reason why it's impossible to allow any selector to be passed. We could return a special OCMSelectorObject there and then handle it specially in matchesInvocation:. The latter is the only caller of getArgumentAtIndexAsObject: so far.
fourdman
 

Re: OCMOCK_ANY for values

Postby fourdman » 27 Oct 2011, 23:56

Of course, that doesn't solve the problem if caller does something like this [anObject doActionWithCallback:(SEL)0x1234567] // and 0x1234567 turns out to be our special pointer value.
But I'm sure that this is acceptable and much better than nothing.
fourdman
 


Return to OCMock



cron