开发者

OCMock testing the address of a struct

开发者 https://www.devze.com 2023-04-11 14:11 出处:网络
I have some code I want to test that is passing around the address of a struct: MyObject myObject = ...;

I have some code I want to test that is passing around the address of a struct:

MyObject myObject = ...;
MyRecord record = [someObject record];  //record is a @property
[myObject add:&record];

I've mocked someObject to return a record:

MyRecord record = ...;
[[[_mockSomeObject stub] andReturnValue:OCMOCK_VALUE(record)] record];
[[_mockMyObject expect] add:&rec开发者_StackOverfloword];

Unfortunately, OCMock fails (I believe) because pulling the struct out of the NSValue wrapper will always return a different address.

Is there a way to get an expectation to work correctly if one of the parameters is an address of a struct?


Look at this post on returning structs with OCMock. Looks like the OCMOCK_VALUE macro just won't cut it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号