Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gb_time.h Source File

gb_time.h

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #ifndef GB_TIME_H
00005 #define GB_TIME_H
00006 
00007 /*this file, if included instead of <stdio.h> has the following functionality:
00008 1) if GB_TIME_INTERCEPT is defined then
00009     a) some of the time.h symbols shall be redefined, for example: time => gb_time
00010     b) all "code" using the time will actually (because of the preprocessor) call to gb_time
00011     c) gb_time shall blindly call into time, thus realizing a passthrough
00012     
00013     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
00014 
00015 2) if GB_TIME_INTERCEPT is not defined then
00016     a) it shall include <time.h> => no passthrough, just direct linking.
00017 */
00018 
00019 #ifndef GB_TIME_INTERCEPT
00020 #include <time.h>
00021 #else
00022 
00023 /*source level intercepting of function calls*/
00024 #define time                    time_never_called_never_implemented_always_forgotten
00025 #define localtime               localtime_never_called_never_implemented_always_forgotten
00026 #define strftime                strftime_never_called_never_implemented_always_forgotten
00027 
00028 #ifdef __cplusplus
00029 #include <ctime.h>
00030 extern "C"
00031 {
00032 #else
00033 #include <time.h>
00034 #endif
00035 
00036 #include "azure_c_shared_utility/umock_c_prod.h"
00037 
00038 #undef time
00039 #define time gb_time
00040 MOCKABLE_FUNCTION(, time_t, time, time_t *, timer);
00041 
00042 #undef localtime
00043 #define localtime gb_localtime
00044 MOCKABLE_FUNCTION(, struct tm *, localtime, const time_t *, timer);
00045 
00046 #undef strftime
00047 #define strftime gb_strftime
00048 MOCKABLE_FUNCTION(, size_t, strftime, char *, s, size_t, maxsize, const char *, format, const struct tm *, timeptr);
00049 
00050 
00051 #ifdef __cplusplus
00052 }
00053 #endif
00054 
00055 #endif /*GB_TIME_INTERCEPT*/
00056 
00057 #endif /* GB_TIME_H */