[457] | 1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
| 3 |
|
---|
| 4 | #ifndef GB_STDIO_H
|
---|
| 5 | #define GB_STDIO_H
|
---|
| 6 |
|
---|
| 7 | /*this file, if included instead of <stdio.h> has the following functionality:
|
---|
| 8 | 1) if GB_STDIO_INTERCEPT is defined then
|
---|
| 9 | a) some of the stdio.h symbols shall be redefined, for example: fopen => gb_fopen
|
---|
| 10 | b) all "code" using the fopen will actually (because of the preprocessor) call to gb_fopen
|
---|
| 11 | c) gb_fopen shall blindly call into fopen, thus realizing a passthrough
|
---|
| 12 |
|
---|
| 13 | reason is: unittesting. fopen is comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called fopen
|
---|
| 14 |
|
---|
| 15 | 2) if GB_STDIO_INTERCEPT is not defined then
|
---|
| 16 | a) it shall include <stdio.h> => no passthrough, just direct linking.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #ifndef GB_STDIO_INTERCEPT
|
---|
| 20 | #ifdef __cplusplus
|
---|
| 21 | #include <cstdio>
|
---|
| 22 | #else
|
---|
| 23 | #include <stdio.h>
|
---|
| 24 | #endif
|
---|
| 25 | #else
|
---|
| 26 |
|
---|
| 27 | /*source level intercepting of function calls*/
|
---|
| 28 | #define fopen fopen_never_called_never_implemented_always_forgotten
|
---|
| 29 | #define fclose fclose_never_called_never_implemented_always_forgotten
|
---|
| 30 | #define fseek fseek_never_called_never_implemented_always_forgotten
|
---|
| 31 | #define ftell ftell_never_called_never_implemented_always_forgotten
|
---|
| 32 | #define fprintf fprintf_never_called_never_implemented_always_forgotten
|
---|
| 33 |
|
---|
| 34 | #ifdef __cplusplus
|
---|
| 35 | #include <cstdio>
|
---|
| 36 | #else
|
---|
| 37 | #include <stdio.h>
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 | #include "umock_c/umock_c_prod.h"
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | #ifdef __cplusplus
|
---|
| 44 | extern "C"
|
---|
| 45 | {
|
---|
| 46 | #endif
|
---|
| 47 |
|
---|
| 48 | #undef fopen
|
---|
| 49 | #define fopen gb_fopen
|
---|
| 50 | MOCKABLE_FUNCTION(, FILE*, gb_fopen, const char*, filename, const char*, mode);
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | #undef fclose
|
---|
| 54 | #define fclose gb_fclose
|
---|
| 55 | MOCKABLE_FUNCTION(, int, fclose, FILE *, stream);
|
---|
| 56 |
|
---|
| 57 | #undef fseek
|
---|
| 58 | #define fseek gb_fseek
|
---|
| 59 | MOCKABLE_FUNCTION(, int, fseek, FILE *,stream, long int, offset, int, whence);
|
---|
| 60 |
|
---|
| 61 | #undef ftell
|
---|
| 62 | #define ftell gb_ftell
|
---|
| 63 | MOCKABLE_FUNCTION(, long int, ftell, FILE *, stream);
|
---|
| 64 |
|
---|
| 65 | #undef fprintf
|
---|
| 66 | #define fprintf gb_fprintf
|
---|
| 67 | extern int fprintf(FILE * stream, const char * format, ...);
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | #ifdef __cplusplus
|
---|
| 71 | }
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 | #endif /*GB_STDIO_INTERCEPT*/
|
---|
| 75 |
|
---|
| 76 | #endif /* GB_STDIO_H */
|
---|