OCMock returning values
I'm trying to write a test for a method where the output depends on an NSDate's timeIntervalSinceNow return value. I'd like to specify the return value in my tests so I can test certain scenarios.
I'm having a really hard time getting thi开发者_如何学Pythons OCMock object returning what I'd like. Here's my code:
id mock = [OCMockObject mockForClass:[NSDate class]];
NSTimeInterval t = 20.0;
[[[mock stub] andReturnValue:OCMOCK_VALUE(t)] timeIntervalSinceNow];
STAssertEquals([mock timeIntervalSinceNow], 20.0, @"Should be eql.");
This generates a "error: expected specifier-qualifier-list before 'typeof" error.
Any thoughts? I'm new to ObjC, so any other related tips are greatly appreciated.
Thanks.
Actually, it is a compiler error, not an OCMock error.
This has something to do with the way the OCMOCK_VALUE(t)
macro works. It is defined as:
#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(typeof(variable))]
The typeof() directive is not part of C89, so make sure you have set your compiler to use -std=gnu89
or std=gnu99
flag. According to the Apple docs, if you set it to Compiler Default
this is equivalent to gnu89, which is fine also.
This is probably the cause of your error.
精彩评论