ios - Can I set up an OCMock object to expect a char * argument? -



ios - Can I set up an OCMock object to expect a char * argument? -

i'm trying verify method called on mocked object particular pointer value 1 of method's arguments, maintain getting "argument type '*' not supported." exception when mocked method called. here's test code:

uint8_t *buf = calloc(65, sizeof(uint8_t)); id stream = [ocmockobject nicemockforclass:[nsinputstream class]]; [[stream expect] read:buf maxlength:64]; id mystream = [[mystream alloc] initwithstream:stream]; // mystream should pass read:maxlength: phone call through stream [mystream read:buf maxlength:64]; stassertnothrow([stream verify], @"did not pass phone call through");

here's -[mystream read:maxlength:]:

- (nsinteger)read:(uint8_t *)buffer maxlength:maxlength { // internalstream stream passed -initwithstream: homecoming [self.internalstream read:buffer maxlength:maxlength]; }

when phone call -read:maxlength: on mocked stream, "argument type '*' not supported." exception. possible expect phone call specific pointer argument value?

edit:

looks issue may specific char * (or uint8_t ) arguments. objective c @encodes them '' , ocmock's type handling code treats '^'-encoded values pointers. i've tried hacking +[ocmarg resolvespecialvalues:] , -[nsinvocation getargumentatindexasobject:] (in nsinvocation+ocmadditions.m) treat '*' same '^'. has stopped exception, expectation still not met.

does know how else handle this? thanks!

i have found workaround issue. trying prepare ocmock handle '*'-encoded types rabbit hole total of hurt, able tests working creating category on nsinputstream made homecoming method signature ocmock able work with:

@interface nsinputstream (ocmockfix) + (nsmethodsignature *)instancemethodsignatureforselector:(sel)selector; - (nsmethodsignature *)methodsignatureforselector:(sel)selector; @end @implementation nsinputstream (ocmockfix) + (nsmethodsignature *)instancemethodsignatureforselector:(sel)selector { if (sel_isequal(selector, @selector(read:maxlength:))) { // original signature "i@:*i". alter '*' '^c' homecoming [nsmethodsignature signaturewithobjctypes:"i@:^ci"]; } else { homecoming [super instancemethodsignatureforselector:selector]; } } - (nsmethodsignature *)methodsignatureforselector:(sel)selector { homecoming [[self class] instancemethodsignatureforselector:selector]; } @end

ios osx cocoa ocmock

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -