On Wed, Oct 22, 2008 at 5:27 AM, mogwaing <mogw...@gmail.com> wrote:
>
>
> I'm testing programs having some methods with system calls in them,
> which are like write(2) or read(2).
> Is there any way I can simulate those call errors with google test ?
> If it can't be done, ss there any way to simulate those system call
> errors without
> modification in source codes ?
I'm afraid you need to modify your source code to make this testable,
but it can be a good thing as in the process you can make your code's
dependencies more clear.
The standard technique for dealing with this is called "mock objects"
and "dependency injection". There are many good articles on the web
about them - try to search and read some of them.
> Hi, I'm not sure I can ask this question here, but
> I'm very appreciated if someone respond to it.
>
--
Zhanyong
I may look at contributing just such a tool to the eventual open
source mocking framework.
-Chandler
This is one of the ways you can forcibly inject this at the link
stage. There are other ways as well (you can compile test such that it
pulls the symbols directly, while still linking against the libc) but
the interesting part is finding a way to combine this technique with
mocking frame works which allow each individual test to set
independent expectations and fake functionality for various system
calls.
-Chandler