使用OCMock或Hamcrest的结构体 [英] Using a struct with OCMock or Hamcrest

查看:274
本文介绍了使用OCMock或Hamcrest的结构体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打了一个路障,我想知道这里辉煌的集体心灵能否帮助。在ObjC CocoaTouch我试图嘲笑一个对象,它接受struct参数并返回一个结构。 OCMock正在嘲笑一个发球,所以我试着用Hamcrest匹配器包装。没有死。我测试的函数/方法看起来像这样:

I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with a Hamcrest matcher. No die. The function/method I'm testing looks something like this:

- (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPoint;

我使用这样的代码:

#define OCMOCK_STRUCT(atype, variable) [NSValue value:&variable withObjCType:@encode(atype)]
-(void) testMyWidget
{
    CLLocationCoordinate2D ulLL = (CLLocationCoordinate2D){123,456};
    CLLocationCoordinate2D lrLL = (CLLocationCoordinate2D){654,321};
    [[[(id)myObj expect] andReturn:OCMOCK_STRUCT(CLLocationCoordinate2D, ulLL)] pixelToLatLong:(CGPoint){0,0}];
    [[[(id)myObj expect] andReturn:OCMOCK_STRUCT(CLLocationCoordinate2D, lrLL)] pixelToLatLong:(CGPoint){320,460}];//lower right point
}

这种工作。所以在我的对象,我测试我进行必要的必要的编辑,以获得一个绿色的条...错误..绿色按钮在构建信息窗口。当我确定我的测试应该通过我得到断言失败的错误。错误通知我方法被意外调用,并列出这些结构的值作为问号。我尝试用Hamcrest匹配器包装结构体,但我不知道。我准备好打破我的调试器,这将毫无疑问地告诉我什么问题。这里有任何人有类似的麻烦与OCMock / Hamcrest和结构?

That kinda works. So in my object that I'm testing I make the necessary required edits to get a green bar... err.. green button in the build info window. When I'm certain that my test should pass I get assertion failed errors. The errors inform me that the method was invoked unexpectedly and lists the values for these structs as question marks. I tried wrapping the structs with Hamcrest matchers but I'm getting nowhere. I'm getting ready to break out my debugger which will no doubt show me what's wrong. Has anybody here had similar trouble with OCMock/Hamcrest and structs? If so, what's the best way to handle these types?

推荐答案

最好的答案实际上是Cliff自己: http://codeforfun.wordpress.com/2009/02/07/ocmock-return -a-struct /

The best answer is actually Cliff's himself: http://codeforfun.wordpress.com/2009/02/07/ocmock-return-a-struct/

他没有更新这个问题,耻辱:)

He just didn't update this question, shame shame :)

这篇关于使用OCMock或Hamcrest的结构体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆