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 | #include <stdio.h>
|
---|
21 | #else
|
---|
22 |
|
---|
23 | /*source level intercepting of function calls*/
|
---|
24 | #define fopen fopen_never_called_never_implemented_always_forgotten
|
---|
25 | #define fclose fclose_never_called_never_implemented_always_forgotten
|
---|
26 | #define fseek fseek_never_called_never_implemented_always_forgotten
|
---|
27 | #define ftell ftell_never_called_never_implemented_always_forgotten
|
---|
28 | #define fprintf fprintf_never_called_never_implemented_always_forgotten
|
---|
29 |
|
---|
30 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
31 |
|
---|
32 |
|
---|
33 | #ifdef __cplusplus
|
---|
34 | #include <cstdio.h>
|
---|
35 | extern "C"
|
---|
36 | {
|
---|
37 | #else
|
---|
38 | #include <stdio.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #undef fopen
|
---|
42 | #define fopen gb_fopen
|
---|
43 | MOCKABLE_FUNCTION(, FILE*, gb_fopen, const char*, filename, const char*, mode);
|
---|
44 |
|
---|
45 |
|
---|
46 | #undef fclose
|
---|
47 | #define fclose gb_fclose
|
---|
48 | MOCKABLE_FUNCTION(, int, fclose, FILE *, stream);
|
---|
49 |
|
---|
50 | #undef fseek
|
---|
51 | #define fseek gb_fseek
|
---|
52 | MOCKABLE_FUNCTION(, int, fseek, FILE *,stream, long int, offset, int, whence);
|
---|
53 |
|
---|
54 | #undef ftell
|
---|
55 | #define ftell gb_ftell
|
---|
56 | MOCKABLE_FUNCTION(, long int, ftell, FILE *, stream);
|
---|
57 |
|
---|
58 | #undef fprintf
|
---|
59 | #define fprintf gb_fprintf
|
---|
60 | extern int fprintf(FILE * stream, const char * format, ...);
|
---|
61 |
|
---|
62 |
|
---|
63 | #ifdef __cplusplus
|
---|
64 | }
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #endif /*GB_STDIO_INTERCEPT*/
|
---|
68 |
|
---|
69 | #endif /* GB_STDIO_H */
|
---|