vendredi 26 février 2016

mocking UIImagePNGRepresentation

I am trying to mock UIImagePNGRepresentation using OCMock. UIImagePNGRepresentation accepts UIImage and returns NSData.

But it seems as you can't mock it as an ordinary function.

What I have tried is the following, but it does not compile.

id mockAlbumArt = [OCMockObject niceMockForClass:[UIImage class]];
id mockImageData = [OCMockObject niceMockForClass:[NSData class]];

id uiimageMock = [OCMockObject niceMockForClass:[UIImage class]];
[[[uiimageMock expect] andReturn:mockImageData] UIImagePNGRepresentation:mockAlbumArt];

If you look at the header for UIImage, UIImagePNGRepresentation is defined as:

UIKIT_EXTERN  NSData * __nullable UIImagePNGRepresentation(UIImage * __nonnull image);                               // return image as PNG. May return nil if image has no CGImageRef or invalid bitmap format

Has anyone done the mocking of the function before? Any help will be appreciated, thank you.

Aucun commentaire:

Enregistrer un commentaire