6

I have a method of the followng signature;

- (NSInteger) getFirstVisitTimeStamp;

When I use OCMock to mock and return a value, the test fails with the below error.

[[[[YSNYI13NMockingTest mockedYI13N] expect] andReturnValue:@(12345)] getFirstVisitTimeStamp];

Error:

file:///%3Cunknown%3E: test failure:
failed: Return value does not match method signature; signature declares 'q' but value is 'i'.

Can anyone help ?

nicael
  • 18,550
  • 13
  • 57
  • 90
mohkhan
  • 11,925
  • 2
  • 24
  • 27

2 Answers2

9

On 64-bit devices, NSInteger is declared as long, but the value you are returning is being typed as int. Try forcing your value to a long by adding l after the number:

[[[[YSNYI13NMockingTest mockedYI13N] expect] andReturnValue:@(12345l)] getFirstVisitTimeStamp];
mspensieri
  • 3,501
  • 15
  • 18
  • Well so..I spent like 40 mins trying to solve...and of curse.."q" means long long and "i" integer...XD Thanks a lot mate! – Matteo Gobbi Feb 07 '17 at 12:02
3

As @michaels hinted at in the comments, and after searching a bit further into your error message, this appears to be related to an open bug in OCMock.

It seems using OCMOCK_VALUE(...) might work for you instead.

shortstuffsushi
  • 2,271
  • 19
  • 33
  • I tried using ```OCMOCK_VALUE(...)``` . it didn't work. – mohkhan Jun 03 '14 at 21:52
  • Explicitly casting the number as a long, as suggested by @michaels, may work as well. – shortstuffsushi Jun 03 '14 at 21:53
  • It is a known problem. For a normal human all the numbers look the same. The runtime use many different number types, though. One approach to address this mismatch is to add code to OCMock to automatically convert numbers of different types. This is discussed in the open issue mentioned above. The problem is that when you look at all the edge cases, and the capabilities of the runtime, it's not straight-forward to decide what these conversions should be. – Erik Doernenburg Jun 04 '14 at 16:52
  • @ErikDoernenburg, what about the non-normal humans? I know what you're saying, though. I'm not sure what the best solution would be, but it seemed that the OCMOCK_VALUE was suggested as a workaround. – shortstuffsushi Jun 04 '14 at 17:21