OCMock testing the address of a struct

有些话、适合烂在心里 提交于 2019-12-12 21:11:39

问题


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:&record];

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?


回答1:


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



来源:https://stackoverflow.com/questions/7666449/ocmock-testing-the-address-of-a-struct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!