Create repository
[fwd.git] / prod / qdunittest.h
1 /*
2  * QuanDocs unit test mock injection
3  *
4  * For some of our unit tests, we will want to override some libc functions with mock versions.
5  * I could do this by playing games with object link order and using dlsym(RTLD_NEXT) to follow the chain.
6  *
7  * But, that gets a bit tricky.  For example, consider mocking write(), but leaving printf(), which may 
8  * well be implemented in a way that calls write(stdout, ...), unintercepted.
9  * 
10  * Thus, I opt to use a compile-time #define to reroute only our explicit calls to the libc functions 
11  * to their mock variants.
12  */
13
14 #ifndef __QD_UNITTEST_H__
15 #define __QD_UNITTEST_H__
16
17 #ifdef QD_UNITTEST
18 #  define read(fd, buf, count)  qdMock_read(fd, buf, count)
19 #  define write(fd, buf, count) qdMock_write(fd, buf, count)
20 #endif /* QD_UNITTEST */
21
22 #endif /* __QD_UNITTEST_H__ */
23
24