[388] | 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_TIME_H
|
---|
| 5 | #define GB_TIME_H
|
---|
| 6 |
|
---|
| 7 | /*this file, if included instead of <stdio.h> has the following functionality:
|
---|
| 8 | 1) if GB_TIME_INTERCEPT is defined then
|
---|
| 9 | a) some of the time.h symbols shall be redefined, for example: time => gb_time
|
---|
| 10 | b) all "code" using the time will actually (because of the preprocessor) call to gb_time
|
---|
| 11 | c) gb_time shall blindly call into time, thus realizing a passthrough
|
---|
| 12 |
|
---|
| 13 | reason is: unittesting. time comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called time
|
---|
| 14 |
|
---|
| 15 | 2) if GB_TIME_INTERCEPT is not defined then
|
---|
| 16 | a) it shall include <time.h> => no passthrough, just direct linking.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #ifndef GB_TIME_INTERCEPT
|
---|
| 20 | #include <time.h>
|
---|
| 21 | #else
|
---|
| 22 |
|
---|
| 23 | /*source level intercepting of function calls*/
|
---|
| 24 | #define time time_never_called_never_implemented_always_forgotten
|
---|
| 25 | #define localtime localtime_never_called_never_implemented_always_forgotten
|
---|
| 26 | #define strftime strftime_never_called_never_implemented_always_forgotten
|
---|
| 27 |
|
---|
| 28 | #ifdef __cplusplus
|
---|
| 29 | #include <ctime.h>
|
---|
| 30 | extern "C"
|
---|
| 31 | {
|
---|
| 32 | #else
|
---|
| 33 | #include <time.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
| 37 |
|
---|
| 38 | #undef time
|
---|
| 39 | #define time gb_time
|
---|
| 40 | MOCKABLE_FUNCTION(, time_t, time, time_t *, timer);
|
---|
| 41 |
|
---|
| 42 | #undef localtime
|
---|
| 43 | #define localtime gb_localtime
|
---|
| 44 | MOCKABLE_FUNCTION(, struct tm *, localtime, const time_t *, timer);
|
---|
| 45 |
|
---|
| 46 | #undef strftime
|
---|
| 47 | #define strftime gb_strftime
|
---|
| 48 | MOCKABLE_FUNCTION(, size_t, strftime, char *, s, size_t, maxsize, const char *, format, const struct tm *, timeptr);
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | #ifdef __cplusplus
|
---|
| 52 | }
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | #endif /*GB_TIME_INTERCEPT*/
|
---|
| 56 |
|
---|
| 57 | #endif /* GB_TIME_H */
|
---|