erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

how to mock a funtion of C? #396

Closed DecembeGrirl closed 4 years ago

DecembeGrirl commented 4 years ago

For example,In a function I need get a random number from arc4random(). But I don't want to creat a class for random number. How to mock the random number fixed?

imhuntingwabbits commented 4 years ago

You do not.

Also why would you need to simulate the output from arc4random()? Isn't the whole point that it's random?

Dependency and behavioral simulation in C is generally done with function pointers that callers can customize. But it's up to the library implementors to facilitate this paradigm.

Finally, please use stack overflow for questions like this.

DecembeGrirl commented 4 years ago

Thank you for your answer.