OCMOCK_ANY for values

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is OFF
Smilies are ON
Topic review
   

Expand view Topic review: OCMOCK_ANY for values

Re: OCMOCK_ANY for values

Post by 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.

Re: OCMOCK_ANY for values

Post by 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.

Re: OCMOCK_ANY for values

Post by 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

OCMOCK_ANY for values

Post by 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

Top

cron