Crash when partially mocking an NSURL

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 when partially mocking an NSURL

Postby Tchav » 06 May 2011, 18:25

Hello there,
I'm experimenting TDD on a small test project, using OCMock.
So far, everything's been working like a charm.
But I've been trying to partially mock an NSURL and it crashes my app.
I stripped down the faulty code, and basically it the following :

NSURL * realURL = [NSURL URLWithString:@"http://www.google.com"];
id mockURL = [OCMockObject partialMockForObject:realURL];
NSURLRequest * aRequest = [NSURLRequest requestWithURL:mockURL]; << "Program received signal "EXC_BAD_ACCESS""

(it's not my real test case, but it's the smallest amount of code I need to reproduce the crash).

Is it some expected behaviour ?

I'm using Xcode 4.0 and OCMock 1.77.

Thanks a lot !
Tchav
 
Posts: 1
Joined: 06 May 2011, 18:18

Re: Crash when partially mocking an NSURL

Postby erik » 26 May 2011, 11:41

You can't use partial mocks with toll-free bridged classes, and it looks like NSURL is one of these:

"NSURL is “toll-free bridged” with its Core Foundation counterpart, CFURLRef. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object, providing you cast one type to the other. In an API where you see an NSURL * parameter, you can pass in a CFURLRef, and in an API where you see a CFURLRef parameter, you can pass in a pointer to an NSURL instance. This approach also applies to your concrete subclasses of NSURL. See “Interchangeable Data Types” for more information on toll-free bridging."

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html


If anyone has an idea how to make this work....
erik
 
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Crash when partially mocking an NSURL

Postby taoy » 12 Mar 2013, 12:07

Could this be the reason why I am getting a crash trying to mock NSString? (and NSAttributedString).

(See: http://www.mulle-kybernetik.com/forum/viewtopic.php?f=4&t=285&hilit=EXC_BAD_ACCESS )
taoy
 
Posts: 4
Joined: 10 Sep 2012, 08:25


Return to OCMock



cron