At some point in my test suite, I needed to mock out a database result set and in particular to stub out the method which returns an int value for a column. I wrote the following:
- Code: Select all
id rs = [OCMockObject mockForClass:[FMResultSet class]];
int intval = 4;
[[[rs stub] andReturnValue: OCMOCK_VALUE(intval)] intForColumn:@"points"];
which returned the following compiler error: expected specifier-qualifier-list before ‘typeof'.
What was going on was that OCMOCK_VALUE was using the GCC 'typeof' extension, and that my unit test target was set up to use the -std=c99 flag for GCC which turns off the GNU extensions (such as 'typeof'). Note that I'd never actually set my target to use the c99 standard language flavor -- that's just what XCode chose for me when I set up the target.
The solution was simple: just set -std=gnu99 in the test target. Note that I only needed to set this on the testing target where I was using OCMock (and OCMOCK_VALUE in particular) -- the standard in use for my deployed target remained the same (c99 in this case).