I am working in C ++ with the Google unit test. There is still a problem in our company code that system data types, such as CTime, use, for example, the time zone for a real system (we use the CTime data type in the same way as in production code). For unit testing, we want to model different time zones, because we have a lot of problems with this.
I have already invested hours, researching how others do it, because it cannot be that other companies do not have this problem :) But I did not find a solution for this. My thoughts are: CTime itself saves time in UTC and converts it on demand into local time. My guess is that all these functions require the GetTimeZoneInformation () function, which is declared in the timestamp .h.
WINBASEAPI _Success_(return != TIME_ZONE_ID_INVALID) DWORD WINAPI GetTimeZoneInformation(_Out_ LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
So the solution could be to replace this GetTimeZoneInformation () function with a custom function, which then returns an object that I can change on demand. But I donβt know how to do this, and I also donβt know if this works then or not, because it can only be a call to this function once when the application starts.
Does anyone know how to deal with this topic? I do not want to change any behavior, I only want to configure my own time zone, without violating the time calculation mechanism. It would be best if I could somehow mock these challenges without changing the production code for this. The fact is that this program is very large, old and ... changing as little as possible is always the best :)
If I did not find an existing post that solved my problem, then I am very sorry because I either did not find it or did not understand that this could help me.
source share