I'm getting used to OCMock with Java / JMock background, now I [[[myMock] Stub] returnValueFromCustomMethod] someMockedMethod] I'm looking for the ability to say;
where returnValueFromCustomMethod
is defined in the test class. I was basically thinking something with the terms of [[[myMock stub]: Use of selector: @selector (myMethod :)] someMockedMethod]; But after writing, I wonder if my first approach is more understandable in any way, can anyone show me how this can be done?
My original answer was closed - Track: Okmok does not support it! If you want to change OCMock to support it, then you will need to add the ocomcorder to the BOOL returnValueIsFromInvocation
field and add a method to set it:
- (ID) and return result invocation: (NSINocation *) An invocation {returnValueIsFromInvocation = YES; Return ValueIsBoxed = No; Return ValueShouldBeThrown = No; [Return value autorlage]; Return value = [an invocation maintained]; Self return; }
then teach to call setUpReturnValue
(changes are in bold):
- (zero) setUpReturnValue: (NSIvvocation *) aInvocation {< B> If (return value isofom invocation) {nosivation * return value invocation = (nsynocation *) return value; [Return value invocation avow]; Zero * buffer = mauloq ([[an invocation method sign-inferior] method return term); [Return value invocation getValue: buffer]; [An invocation sedation value: buffer]; Free (buffer); } Other if (returnValueShouldBeThrown) {@throw returnValue; } And if (returnValueIsBoxed) {if (strcmp ([[an invocation method signup] method is returned, [(NSValue *) return value objCType] = 0) [NSException raise: NSInvalidArgumentException format: @ "return value matching method signature Do not eat. "]; Null * buffer = molok ([[an invocation method sign-inter] method return term)] [Get the return value: buffer]; [An invocation separation value: buffer]; Free ( Buffer);} Else {const char * returnType = [[an invocation method sine art]] method returns type ; Const char * returnTypeWithoutQualifiers = returnType + (Stellen (ReturnTip) - 1); if (strcmp (Return TypeWithput qualifiers, @ encode (id)) == 0 [An invocation separation value and return value];}}
It is difficult to make this change by starting sub-transformations because you have to override the methods that would return the OSMOKE Cacherer (e.g. stub
, hope
and so on) ) But the concrete subclasses of OCMockObject (OCClassMockObject and OCProtocolMockObject) By has been hidden.
Comments
Post a Comment