Crash after multiple stubs on class method

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Crash after multiple stubs on class method

Postby aki_null » 02 Jul 2013, 09:55

Hi,

I found an issue where OCMock would cause stack overflow and crash in certain situations. I have wrote an example test code to replicate the problem:

Code: Select all
- (void)testRevertsMultipleExpectsOnStopMocking
{
  id mock = [[OCClassMockObject alloc] initWithClass:[TestClassWithClassMethods class]];
  [[[[mock expect] classMethod] andReturn:@"mocked-foo"] foo];
  [[[[mock expect] classMethod] andReturn:@"mocked-foo2"] foo];
 
  STAssertEqualObjects(@"mocked-foo", [TestClassWithClassMethods foo], @"Should have stubbed class method 'foo'.");
  STAssertEqualObjects(@"mocked-foo2", [TestClassWithClassMethods foo], @"Should have stubbed class method 'foo2'.");
 
  [mock stopMocking];
 
  STAssertEqualObjects(@"Foo-ClassMethod", [TestClassWithClassMethods foo], @"Should have 'unstubbed' class method 'foo'.");
}


The above code performs expect twice on a class method, which is possible with instance methods. However, it seems to crash with stack overflow in this case. The same issue seems to exist for stubs too.

Is this an expected behaviour? If they are, I think it would be nice to have a little note on the documentation (I'm assuming that the only documentation is http://ocmock.org/features/ ), or have the OCMock print out errors in the console.
aki_null
 

Re: Crash after multiple stubs on class method

Postby erik » 02 Jul 2013, 11:23

Your test case should work. I'll look into it.
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Crash after multiple stubs on class method

Postby erik » 03 Jul 2013, 10:30

This was a genuine bug. A missing check caused a problem (to say it mildly) when the same class method was expected more than once. It's fixed in the source now, will be in the 2.2.1 release.

Thank you for reporting this with a great test case.
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Crash after multiple stubs on class method

Postby aki_null » 03 Jul 2013, 10:36

Thanks a lot for fixing this bug! It'll be so much easier to write these kinds of tests. :D
aki_null
 


Return to OCMock