Skip to content

Mocks crashing due to relative addressing #440

@dmaclach

Description

@dmaclach
- (void)testMockView {
  UIViewController *controller = [[UIViewController alloc] init];
  UIViewController *controller2 = [[UIViewController alloc] init];
  id mockController2 = OCMPartialMock(controller2);
  [controller addChildViewController:mockController2];
}

will crash with libGuardMalloc turned on. I'm guessing that the problem is that addChildViewController: is directly instance variables with its knowledge of UIViewController using offsets relative to self which in this case is a mock and not the controller itself. This ends up being a weird looking crash that is a pain to diagnose, and could end up "working" but corrupting the heap in weird and wonderful ways.

The problem can be avoided by not passing in the mock object. Should we be issuing a warning where partial mocks are being used instead of the object that they are mocking (I'm thinking -[OCMPartialMockObject handleUnRecordedInvocation:])

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions