Open dmaclach opened 4 years ago
BTW I forgot to mention that this is an issue with 3.6 as well as head.
So here's an example that removes UIViewController
and shows that this is not just a partial mock issue:
@interface TestClassLargeClass : NSObject {
int foo[4096];
}
@end
@implementation TestClassLargeClass
- (void)messWithClass:(TestClassLargeClass *)cls
{
for(int i = 0; i < 4096; ++i) {
cls->foo[i] = i;
}
}
@end
...
- (void)testClassLargeClass {
TestClassLargeClass *one = [[TestClassLargeClass alloc] init];
id mocktwo = OCMClassMock([TestClassLargeClass class]);
[one messWithClass:mocktwo];
}
It can happen with any class that knows the internals of another. It's pretty nasty actually because it can cause very subtle memory corruption that shows up later in other tests.
will crash with
libGuardMalloc
turned on. I'm guessing that the problem is thataddChildViewController:
is directly instance variables with its knowledge ofUIViewController
using offsets relative toself
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:]
)