OCMock 测试结构体的地址
我想测试一些传递结构地址的代码:
MyObject myObject = ...;
MyRecord record = [someObject record]; //record is a @property
[myObject add:&record];
我模拟了 someObject
返回一条记录:
MyRecord record = ...;
[[[_mockSomeObject stub] andReturnValue:OCMOCK_VALUE(record)] record];
[[_mockMyObject expect] add:&record];
不幸的是,OCMock 失败了(我相信),因为将结构从NSValue 包装器将始终返回不同的地址。
如果参数之一是结构体的地址,有没有办法让预期正常工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅这篇关于使用 OCMock 返回结构的文章。看起来 OCMOCK_VALUE 宏并不能解决这个问题。
Look at this post on returning structs with OCMock. Looks like the OCMOCK_VALUE macro just won't cut it.