我试图验证一个方法将被调用的模拟对象与一个特定的指针值的方法的参数之一,但我不断收到“参数类型'*'不支持。”当模拟方法被调用时异常。这里是我的测试代码:我可以设置一个OCMock对象来期望char *参数吗?
uint8_t *buf = calloc(65, sizeof(uint8_t));
id stream = [OCMockObject niceMockForClass:[NSInputStream class]];
[[stream expect] read:buf maxLength:64];
id myStream = [[MyStream alloc] initWithStream:stream];
// myStream should pass read:maxLength: call through to stream
[myStream read:buf maxLength:64];
STAssertNoThrow([stream verify], @"Did not pass call through");
这里是-[MyStream read:maxLength:]
:
- (NSInteger)read:(uint8_t *)buffer maxLength:maxLength {
// internalStream is the stream passed to -initWithStream:
return [self.internalStream read:buffer maxLength:maxLength];
}
当我打电话 - 读取:最大长度:“参数类型‘*’不支持”的嘲笑流,我得到的例外。是否可以期待一个具有特定指针参数值的调用?
编辑:
貌似这个问题可能是特定为char *(或uint8_t )参数。 Objective C将它们编码为'',而OCMock的类型处理代码仅将'^'编码的值视为指针。我尝试过黑客+[OCMArg resolveSpecialValues:]
和-[NSInvocation getArgumentAtIndexAsObject:]
(在NSInvocation + OCMAdditions.m中)将'*'与'^'相同。这已经阻止了这个例外,但我的期望仍然没有得到满足。
有谁知道如何处理呢?谢谢!