gpt4 book ai didi

ios - 如何将结构参数与 OCMock 匹配?

转载 作者:可可西里 更新时间:2023-11-01 05:41:09 27 4
gpt4 key购买 nike

所以我在名为 PopoverProvider

的类中有一个具有以下签名的方法
- (void)showPopoverForAction:(MESAction *)action fromRect:(CGRect)rect inView:(UIView *)view onDoneBlock:(MESActionPopoverDoneBlock)block;

我想验证它是否像这样被调用:

// popoverProvider is a PopoverProvider
[[[popoverProvider expect] andReturn:mockRecipeIngredientViewController]
showPopoverForAction:[OCMArg any]
fromRect:[OCMArg any] // !!!!
inView:[OCMArg any]
onDoneBlock:[OCMArg any]
];

标记的行导致问题:[OCMArg any]CGRect 不匹配,这是一种结构类型。

最佳答案

在这种情况下,由于您不关心 rect 的值,我会使用:

[[[[popoverProvider expect] andReturn:mockRecipeIngredientViewController] ignoringNonObjectArgs]
showPopoverForAction:[OCMArg any]
fromRect:CGRectMake(0.0f,0.0f,0.0f,0.0f)
inView:[OCMArg any]
onDoneBlock:[OCMArg any]
];

如果您想忽略一个结构但检查另一个结构,您可以这样做:

[[[[[popoverProvider expect] andReturn:mockRecipeIngredientViewController] ignoringNonObjectArgs]  andDo:^(NSInvocation *invocation) {
CGRect theSize;
[invocation getArgument:&theSize atIndex:6];
STAssertEquals(theSize, CGSizeMake(20.0f,20.0f), @"No match!");
}]
showPopoverForAction:[OCMArg any]
fromRect:CGRectMake(0.0f,0.0f,0.0f,0.0f)
inView:[OCMArg any]
onDoneBlock:[OCMArg any]
someSize:CGSizeMake(0.0f,0.0f)
];

关于ios - 如何将结构参数与 OCMock 匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22933470/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com