How do I mock memory allocation failures ?
- by Andrei Ciobanu
I want to extensively test some pieces of C code for memory leaks.
On my machine I have 4 Gb of RAM, so it's very unlikely for a dynamic memory allocation to fail. Still I want to see the comportment of the code if memory allocation fails, and see if the recover mechanism is "strong" enough.
What do you suggest ? How do I emulate an environment with lower memory specs ? How do i mock my tests ?
EDIT:
I want my tests to be code independent. I only have "access" to return values for different functions in the library I am testing. I am not supposed to write "test logic" inside the code I am testing.